Skip to content

Commit b1c86f6

Browse files
authoredJan 16, 2025
bugfixes (#438)
## What? - Fix lingering bugs in compilation, and tests - Fmt - Clippy
1 parent ad6d1f4 commit b1c86f6

File tree

14 files changed

+72
-71
lines changed

14 files changed

+72
-71
lines changed
 

‎integration-tests/src/constants.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl PricesBuilder {
8989
Self { dot: None, usdc: None, usdt: None, plmc: None, weth: None }
9090
}
9191

92-
pub fn default() -> Prices {
92+
pub fn default_prices() -> Prices {
9393
Prices {
9494
dot: FixedU128::from_rational(69, 1),
9595
usdc: FixedU128::from_rational(1, 1),
@@ -198,6 +198,7 @@ pub mod collators {
198198
pub mod validators {
199199
use super::*;
200200

201+
#[allow(clippy::type_complexity)]
201202
pub fn initial_authorities() -> Vec<(
202203
AccountId,
203204
AccountId,
@@ -484,7 +485,6 @@ pub mod polimec {
484485
(dave_account.clone(), 0),
485486
(eve_account.clone(), 0),
486487
],
487-
..Default::default()
488488
},
489489
democracy: Default::default(),
490490
parachain_system: Default::default(),

‎integration-tests/src/tests/ct_migration.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {
190190

191191
#[test]
192192
fn full_pallet_migration_test() {
193-
polimec::set_prices(PricesBuilder::default());
193+
polimec::set_prices(PricesBuilder::default_prices());
194194
let (project_id, participants) = create_settled_project();
195195
let _project_status =
196196
PolimecNet::execute_with(|| pallet_funding::ProjectsDetails::<PolimecRuntime>::get(project_id).unwrap().status);
@@ -296,7 +296,7 @@ fn create_project_with_unsettled_participation(participation_type: Participation
296296

297297
#[test]
298298
fn cannot_start_pallet_migration_with_unsettled_participations() {
299-
polimec::set_prices(PricesBuilder::default());
299+
polimec::set_prices(PricesBuilder::default_prices());
300300

301301
let tup_1 = create_project_with_unsettled_participation(ParticipationType::Evaluation);
302302
let tup_2 = create_project_with_unsettled_participation(ParticipationType::Bid);

‎integration-tests/src/tests/otm_edge_cases.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn after_otm_fee_user_goes_under_ed_reverts() {
121121
let issuer: PolimecAccountId = ISSUER.into();
122122
let bobert: PolimecAccountId = BOBERT.into();
123123

124-
polimec::set_prices(PricesBuilder::default());
124+
polimec::set_prices(PricesBuilder::default_prices());
125125
PolimecNet::execute_with(|| {
126126
let project_metadata = default_project_metadata(issuer.clone());
127127

‎nodes/parachain/src/chain_spec/common.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ use polimec_runtime::{
1313
AccountId, AuraId as AuthorityId, Balance, BlockchainOperationTreasury, ContributionTreasuryAccount,
1414
ExistentialDeposit, FeeRecipient, OracleProvidersMembershipConfig, Runtime, TreasuryAccount, PLMC,
1515
};
16-
use sp_core::{
17-
crypto::{Ss58AddressFormat, UncheckedInto},
18-
sr25519,
19-
};
16+
use sp_core::{crypto::UncheckedInto, sr25519};
2017
use sp_runtime::{traits::AccountIdConversion, Perbill, Percent};
2118
pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
2219

‎pallets/funding/src/functions/1_application.rs

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![allow(clippy::wildcard_imports)]
22
#![allow(clippy::type_complexity)]
33

4-
use sp_runtime::offchain::http::Method::Post;
54
use super::*;
65

76
impl<T: Config> Pallet<T> {
@@ -92,10 +91,7 @@ impl<T: Config> Pallet<T> {
9291
// * Emit events *
9392
Self::deposit_event(Event::ProjectCreated { project_id, issuer: issuer.clone(), metadata: project_metadata });
9493

95-
Ok(PostDispatchInfo{
96-
actual_weight: None,
97-
pays_fee: Pays::No,
98-
})
94+
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
9995
}
10096

10197
#[transactional]
@@ -123,10 +119,8 @@ impl<T: Config> Pallet<T> {
123119
// * Emit events *
124120
Self::deposit_event(Event::MetadataEdited { project_id, metadata: new_project_metadata });
125121

126-
Ok(PostDispatchInfo{
127-
actual_weight: None,
128-
pays_fee: Pays::No,
129-
}) }
122+
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
123+
}
130124

131125
#[transactional]
132126
pub fn do_remove_project(issuer: AccountIdOf<T>, project_id: ProjectId, did: Did) -> DispatchResultWithPostInfo {
@@ -146,8 +140,6 @@ impl<T: Config> Pallet<T> {
146140
// * Emit events *
147141
Self::deposit_event(Event::ProjectRemoved { project_id, issuer });
148142

149-
Ok(PostDispatchInfo{
150-
actual_weight: None,
151-
pays_fee: Pays::No,
152-
}) }
143+
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
144+
}
153145
}

‎pallets/funding/src/functions/2_evaluation.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ impl<T: Config> Pallet<T> {
2626
false,
2727
)?;
2828

29-
Ok(PostDispatchInfo{
30-
actual_weight: None,
31-
pays_fee: Pays::No,
32-
})
29+
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
3330
}
3431

3532
#[transactional]

‎pallets/funding/src/functions/7_ct_migration.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ impl<T: Config> Pallet<T> {
2121
false,
2222
)?;
2323

24-
Ok(PostDispatchInfo{
25-
actual_weight: None,
26-
pays_fee: Pays::No,
27-
}) }
24+
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
25+
}
2826

2927
#[transactional]
3028
pub fn do_confirm_offchain_migration(
@@ -85,10 +83,8 @@ impl<T: Config> Pallet<T> {
8583
false,
8684
)?;
8785

88-
Ok(PostDispatchInfo{
89-
actual_weight: None,
90-
pays_fee: Pays::No,
91-
}) }
86+
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
87+
}
9288

9389
/// Handle the channel open request from the relay on behalf of a parachain.
9490
/// If the parachain id belongs to a funded project with the same project id, then send an acceptance message and a request for a
@@ -210,7 +206,10 @@ impl<T: Config> Pallet<T> {
210206
/// After the bidirectional HRMP channels are established, check that the project chain has the Polimec receiver pallet,
211207
/// and has minted the amount of CTs sold to the Polimec sovereign account.
212208
#[transactional]
213-
pub fn do_start_pallet_migration_readiness_check(caller: &AccountIdOf<T>, project_id: ProjectId) -> DispatchResultWithPostInfo {
209+
pub fn do_start_pallet_migration_readiness_check(
210+
caller: &AccountIdOf<T>,
211+
project_id: ProjectId,
212+
) -> DispatchResultWithPostInfo {
214213
// * Get variables *
215214
let mut project_details = ProjectsDetails::<T>::get(project_id).ok_or(Error::<T>::ProjectDetailsNotFound)?;
216215
let Some(MigrationType::Pallet(ref mut migration_info)) = project_details.migration_type else {
@@ -302,10 +301,8 @@ impl<T: Config> Pallet<T> {
302301
// * Emit events *
303302
Self::deposit_event(Event::<T>::MigrationReadinessCheckStarted { project_id, caller: caller.clone() });
304303

305-
Ok(PostDispatchInfo{
306-
actual_weight: None,
307-
pays_fee: Pays::No,
308-
}) }
304+
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
305+
}
309306

310307
/// Handle the migration readiness check response from the project chain.
311308
#[transactional]

‎pallets/funding/src/functions/misc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ impl<T: Config> Pallet<T> {
456456
frame_system::Pallet::<T>::account_nonce(polimec_account),
457457
);
458458

459-
460459
let ecdsa_signature = EcdsaSignature::from_slice(&signature_bytes).unwrap();
461460
let public_compressed: EcdsaPublic = ecdsa_signature.recover_prehashed(&hashed_message).unwrap();
462461
let public_uncompressed = k256::ecdsa::VerifyingKey::from_sec1_bytes(&public_compressed).unwrap();

‎pallets/funding/src/lib.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ pub mod pallet {
706706
origin: OriginFor<T>,
707707
jwt: UntrustedToken,
708708
project: ProjectMetadataOf<T>,
709-
) -> DispatchResult {
709+
) -> DispatchResultWithPostInfo {
710710
let (account, did, investor_type, _cid) =
711711
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
712712
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
@@ -715,7 +715,11 @@ pub mod pallet {
715715

716716
#[pallet::call_index(1)]
717717
#[pallet::weight(WeightInfoOf::<T>::remove_project())]
718-
pub fn remove_project(origin: OriginFor<T>, jwt: UntrustedToken, project_id: ProjectId) -> DispatchResult {
718+
pub fn remove_project(
719+
origin: OriginFor<T>,
720+
jwt: UntrustedToken,
721+
project_id: ProjectId,
722+
) -> DispatchResultWithPostInfo {
719723
let (account, did, investor_type, _cid) =
720724
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
721725
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
@@ -730,7 +734,7 @@ pub mod pallet {
730734
jwt: UntrustedToken,
731735
project_id: ProjectId,
732736
new_project_metadata: ProjectMetadataOf<T>,
733-
) -> DispatchResult {
737+
) -> DispatchResultWithPostInfo {
734738
let (account, _did, investor_type, _cid) =
735739
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
736740
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
@@ -740,7 +744,11 @@ pub mod pallet {
740744
/// Starts the evaluation round of a project. It needs to be called by the project issuer.
741745
#[pallet::call_index(3)]
742746
#[pallet::weight(WeightInfoOf::<T>::start_evaluation())]
743-
pub fn start_evaluation(origin: OriginFor<T>, jwt: UntrustedToken, project_id: ProjectId) -> DispatchResult {
747+
pub fn start_evaluation(
748+
origin: OriginFor<T>,
749+
jwt: UntrustedToken,
750+
project_id: ProjectId,
751+
) -> DispatchResultWithPostInfo {
744752
let (account, _did, investor_type, _cid) =
745753
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
746754
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
@@ -1024,7 +1032,7 @@ pub mod pallet {
10241032
origin: OriginFor<T>,
10251033
jwt: UntrustedToken,
10261034
project_id: ProjectId,
1027-
) -> DispatchResult {
1035+
) -> DispatchResultWithPostInfo {
10281036
let (account, _did, investor_type, _cid) =
10291037
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
10301038
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
@@ -1051,7 +1059,7 @@ pub mod pallet {
10511059
jwt: UntrustedToken,
10521060
project_id: ProjectId,
10531061
para_id: ParaId,
1054-
) -> DispatchResult {
1062+
) -> DispatchResultWithPostInfo {
10551063
let (account, _did, investor_type, _cid) =
10561064
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
10571065
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
@@ -1065,7 +1073,7 @@ pub mod pallet {
10651073
origin: OriginFor<T>,
10661074
jwt: UntrustedToken,
10671075
project_id: ProjectId,
1068-
) -> DispatchResult {
1076+
) -> DispatchResultWithPostInfo {
10691077
let (account, _did, investor_type, _cid) =
10701078
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
10711079
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);

‎pallets/funding/src/runtime_api.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::traits::BondingRequirementCalculation;
21
#[allow(clippy::wildcard_imports)]
32
use crate::{traits::BondingRequirementCalculation, *};
43
use alloc::{collections::BTreeMap, string::String};

‎pallets/oracle-ocw/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub mod pallet {
189189
None
190190
}
191191
})
192-
.collect::<Vec<AssetName>>();
192+
.collect::<Vec<AssetName>>();
193193

194194
if assets.is_empty() {
195195
log::trace!(target: LOG_TARGET, "Assets to fetch list is empty :c");
@@ -221,8 +221,8 @@ pub mod pallet {
221221
impl<T: Config> Pallet<T> {
222222
fn fetch_prices(assets: Vec<AssetName>) -> BTreeMap<AssetName, FixedU128> {
223223
let fetchers = vec![
224-
KrakenFetcher::get_moving_average,
225224
BitFinexFetcher::get_moving_average,
225+
KrakenFetcher::get_moving_average,
226226
BitStampFetcher::get_moving_average,
227227
CoinbaseFetcher::get_moving_average,
228228
XTFetcher::get_moving_average,

‎pallets/oracle-ocw/src/mock.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -185,25 +185,26 @@ pub fn new_test_ext_with_offchain_storage(
185185

186186
// Store the expected responses in the order we expect, to later assert as part of the request processing.
187187
pub fn price_oracle_response(state: &mut testing::OffchainState) {
188-
for (asset, response) in KRAKEN_RESPONSES.iter() {
188+
for (asset, response) in BITFINEX_RESPONSES.iter() {
189189
state.expect_request(testing::PendingRequest {
190190
method: "GET".into(),
191-
uri: format!("https://api.kraken.com/0/public/OHLC?pair={}&interval=1", asset),
191+
uri: format!("https://api-pub.bitfinex.com/v2/candles/trade%3A1m%3At{}/hist?limit=15", asset),
192192
response: Some(response.to_vec()),
193193
sent: true,
194194
..Default::default()
195195
});
196196
}
197197

198-
for (asset, response) in BITFINEX_RESPONSES.iter() {
198+
for (asset, response) in KRAKEN_RESPONSES.iter() {
199199
state.expect_request(testing::PendingRequest {
200200
method: "GET".into(),
201-
uri: format!("https://api-pub.bitfinex.com/v2/candles/trade%3A1m%3At{}/hist?limit=15", asset),
201+
uri: format!("https://api.kraken.com/0/public/OHLC?pair={}&interval=1", asset),
202202
response: Some(response.to_vec()),
203203
sent: true,
204204
..Default::default()
205205
});
206206
}
207+
207208
for (asset, response) in BITSTAMP_RESPONSES.iter() {
208209
state.expect_request(testing::PendingRequest {
209210
method: "GET".into(),
@@ -222,13 +223,15 @@ pub fn price_oracle_response(state: &mut testing::OffchainState) {
222223
..Default::default()
223224
});
224225
}
226+
225227
state.expect_request(testing::PendingRequest {
226228
method: "GET".into(),
227229
uri: "https://sapi.xt.com/v4/public/kline?symbol=plmc_usdt&interval=30m&limit=10".into(),
228230
response: Some(XT_PLMC_CORRECT.to_vec()),
229231
sent: true,
230232
..Default::default()
231233
});
234+
232235
state.expect_request(testing::PendingRequest {
233236
method: "GET".into(),
234237
uri: "https://api.mexc.com/api/v3/klines?symbol=PLMCUSDT&interval=30m&limit=10".into(),
@@ -265,8 +268,12 @@ pub fn assert_close_enough(a: FixedU128, b: FixedU128) {
265268
}
266269
}
267270

268-
pub(crate) const KRAKEN_RESPONSES: &[(&str, &[u8])] =
269-
&[("USDTZUSD", KRAKEN_USDT_CORRECT), ("USDCUSD", KRAKEN_USDC_CORRECT), ("DOTUSD", KRAKEN_DOT_CORRECT)];
271+
pub(crate) const KRAKEN_RESPONSES: &[(&str, &[u8])] = &[
272+
("USDTZUSD", KRAKEN_USDT_CORRECT),
273+
("USDCUSD", KRAKEN_USDC_CORRECT),
274+
("DOTUSD", KRAKEN_DOT_CORRECT),
275+
("XETHZUSD", KRAKEN_WETH_CORRECT)
276+
];
270277
const KRAKEN_USDT_CORRECT: &[u8] = br#"{"error":[],"result":{"USDTZUSD":[[1701877920,"1.00009","1.00011","1.00008","1.00009","1.00010","58759.32214931",36],[1701877980,"1.00009","1.00011","1.00009","1.00010","1.00010","17156.51835679",18],[1701878040,"1.00011","1.00011","1.00010","1.00010","1.00010","231514.66903930",13],[1701878100,"1.00010","1.00015","1.00010","1.00014","1.00012","10577.17236868",27],[1701878160,"1.00015","1.00020","1.00015","1.00019","1.00017","1026827.06857105",67],[1701878220,"1.00019","1.00019","1.00018","1.00019","1.00018","44228.73461655",28],[1701878280,"1.00018","1.00018","1.00015","1.00015","1.00016","41144.63245059",23],[1701878340,"1.00014","1.00015","1.00013","1.00013","1.00013","252283.11050904",67],[1701878400,"1.00014","1.00014","1.00012","1.00014","1.00012","34519.85524461",23],[1701878460,"1.00013","1.00013","1.00008","1.00009","1.00010","49702.48469208",40],[1701878520,"1.00009","1.00016","1.00009","1.00016","1.00012","83532.48937609",43],[1701878580,"1.00016","1.00018","1.00015","1.00018","1.00017","340329.29664927",27],[1701878640,"1.00018","1.00018","1.00015","1.00015","1.00016","125875.61559451",33],[1701878700,"1.00015","1.00015","1.00010","1.00011","1.00012","63925.70403795",32],[1701878760,"1.00010","1.00010","1.00008","1.00008","1.00009","53316.20999461",26]],"last":1699977300}}"#;
271278
const KRAKEN_USDC_CORRECT: &[u8] = br#"{"error":[],"result":{"USDCUSD":[[1701878040,"1.0001","1.0001","1.0000","1.0000","1.0000","2210.00000000",2],[1701878100,"1.0002","1.0002","1.0002","1.0002","1.0002","999.00000000",1],[1701878160,"1.0001","1.0002","1.0001","1.0002","1.0001","7201.85053234",9],[1701878220,"1.0001","1.0001","1.0001","1.0001","1.0001","15.71930681",1],[1701878280,"1.0000","1.0001","1.0000","1.0001","1.0000","102108.24129487",5],[1701878340,"1.0001","1.0001","1.0001","1.0001","0.0000","0.00000000",0],[1701878400,"1.0001","1.0001","1.0001","1.0001","1.0001","1451.37880000",1],[1701878460,"1.0001","1.0001","1.0000","1.0000","1.0000","11005.00000000",2],[1701878520,"1.0001","1.0001","1.0000","1.0000","1.0000","6760.93865300",3],[1701878580,"1.0000","1.0000","1.0000","1.0000","0.0000","0.00000000",0],[1701878640,"1.0000","1.0001","1.0000","1.0001","1.0000","1290.84392400",4],[1701878700,"1.0000","1.0001","1.0000","1.0001","1.0000","53.03306930",2],[1701878760,"1.0000","1.0000","1.0000","1.0000","1.0000","16711.33870874",7],[1701878820,"1.0000","1.0000","1.0000","1.0000","1.0000","10007.53328427",2],[1701878880,"0.9999","0.9999","0.9999","0.9999","0.9999","1000.00000000",1]],"last":1699977300}}"#;
272279
const KRAKEN_DOT_CORRECT: &[u8] = br#"{"error":[],"result":{"DOTUSD":[[1701878100,"6.1473","6.1474","6.1473","6.1474","6.1473","102.00000000",2],[1701878160,"6.1446","6.1446","6.1378","6.1409","6.1399","56.11963595",4],[1701878220,"6.1251","6.1473","6.1233","6.1473","6.1268","992.18112927",12],[1701878280,"6.1468","6.1500","6.1383","6.1383","6.1463","365.21179340",29],[1701878340,"6.1401","6.1401","6.1378","6.1378","6.1393","57.06050109",5],[1701878400,"6.1298","6.1380","6.1279","6.1380","6.1361","968.44275786",8],[1701878460,"6.1403","6.1407","6.1390","6.1390","6.1400","507.81565634",8],[1701878520,"6.1391","6.1500","6.1385","6.1500","6.1422","344.07407967",5],[1701878580,"6.1499","6.1573","6.1473","6.1573","6.1491","3563.21894841",32],[1701878640,"6.1594","6.1602","6.1552","6.1552","6.1591","1461.51440086",22],[1701878700,"6.1612","6.1622","6.1544","6.1544","6.1598","447.90016651",9],[1701878760,"6.1452","6.1452","6.1407","6.1407","6.1421","225.30037904",6],[1701878820,"6.1192","6.1192","6.1044","6.1044","6.1145","154.45052403",8],[1701878880,"6.1111","6.1126","6.1082","6.1124","6.1116","186.62943447",4],[1701878940,"6.1126","6.1199","6.1124","6.1197","6.1160","145.34596966",7]],"last":1699977300}}"#;

0 commit comments

Comments
 (0)