Skip to content

Commit

Permalink
bugfixes (#438)
Browse files Browse the repository at this point in the history
## What?
- Fix lingering bugs in compilation, and tests
- Fmt
- Clippy
  • Loading branch information
JuaniRios authored Jan 16, 2025
1 parent ad6d1f4 commit b1c86f6
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 71 deletions.
4 changes: 2 additions & 2 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl PricesBuilder {
Self { dot: None, usdc: None, usdt: None, plmc: None, weth: None }
}

pub fn default() -> Prices {
pub fn default_prices() -> Prices {
Prices {
dot: FixedU128::from_rational(69, 1),
usdc: FixedU128::from_rational(1, 1),
Expand Down Expand Up @@ -198,6 +198,7 @@ pub mod collators {
pub mod validators {
use super::*;

#[allow(clippy::type_complexity)]
pub fn initial_authorities() -> Vec<(
AccountId,
AccountId,
Expand Down Expand Up @@ -484,7 +485,6 @@ pub mod polimec {
(dave_account.clone(), 0),
(eve_account.clone(), 0),
],
..Default::default()
},
democracy: Default::default(),
parachain_system: Default::default(),
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/tests/ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn create_settled_project() -> (ProjectId, Vec<AccountId>) {

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

#[test]
fn cannot_start_pallet_migration_with_unsettled_participations() {
polimec::set_prices(PricesBuilder::default());
polimec::set_prices(PricesBuilder::default_prices());

let tup_1 = create_project_with_unsettled_participation(ParticipationType::Evaluation);
let tup_2 = create_project_with_unsettled_participation(ParticipationType::Bid);
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/tests/otm_edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn after_otm_fee_user_goes_under_ed_reverts() {
let issuer: PolimecAccountId = ISSUER.into();
let bobert: PolimecAccountId = BOBERT.into();

polimec::set_prices(PricesBuilder::default());
polimec::set_prices(PricesBuilder::default_prices());
PolimecNet::execute_with(|| {
let project_metadata = default_project_metadata(issuer.clone());

Expand Down
5 changes: 1 addition & 4 deletions nodes/parachain/src/chain_spec/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ use polimec_runtime::{
AccountId, AuraId as AuthorityId, Balance, BlockchainOperationTreasury, ContributionTreasuryAccount,
ExistentialDeposit, FeeRecipient, OracleProvidersMembershipConfig, Runtime, TreasuryAccount, PLMC,
};
use sp_core::{
crypto::{Ss58AddressFormat, UncheckedInto},
sr25519,
};
use sp_core::{crypto::UncheckedInto, sr25519};
use sp_runtime::{traits::AccountIdConversion, Perbill, Percent};
pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;

Expand Down
18 changes: 5 additions & 13 deletions pallets/funding/src/functions/1_application.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![allow(clippy::wildcard_imports)]
#![allow(clippy::type_complexity)]

use sp_runtime::offchain::http::Method::Post;
use super::*;

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

Ok(PostDispatchInfo{
actual_weight: None,
pays_fee: Pays::No,
})
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

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

Ok(PostDispatchInfo{
actual_weight: None,
pays_fee: Pays::No,
}) }
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

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

Ok(PostDispatchInfo{
actual_weight: None,
pays_fee: Pays::No,
}) }
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}
}
5 changes: 1 addition & 4 deletions pallets/funding/src/functions/2_evaluation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ impl<T: Config> Pallet<T> {
false,
)?;

Ok(PostDispatchInfo{
actual_weight: None,
pays_fee: Pays::No,
})
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

#[transactional]
Expand Down
23 changes: 10 additions & 13 deletions pallets/funding/src/functions/7_ct_migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ impl<T: Config> Pallet<T> {
false,
)?;

Ok(PostDispatchInfo{
actual_weight: None,
pays_fee: Pays::No,
}) }
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

#[transactional]
pub fn do_confirm_offchain_migration(
Expand Down Expand Up @@ -85,10 +83,8 @@ impl<T: Config> Pallet<T> {
false,
)?;

Ok(PostDispatchInfo{
actual_weight: None,
pays_fee: Pays::No,
}) }
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

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

Ok(PostDispatchInfo{
actual_weight: None,
pays_fee: Pays::No,
}) }
Ok(PostDispatchInfo { actual_weight: None, pays_fee: Pays::No })
}

/// Handle the migration readiness check response from the project chain.
#[transactional]
Expand Down
1 change: 0 additions & 1 deletion pallets/funding/src/functions/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,6 @@ impl<T: Config> Pallet<T> {
frame_system::Pallet::<T>::account_nonce(polimec_account),
);


let ecdsa_signature = EcdsaSignature::from_slice(&signature_bytes).unwrap();
let public_compressed: EcdsaPublic = ecdsa_signature.recover_prehashed(&hashed_message).unwrap();
let public_uncompressed = k256::ecdsa::VerifyingKey::from_sec1_bytes(&public_compressed).unwrap();
Expand Down
22 changes: 15 additions & 7 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ pub mod pallet {
origin: OriginFor<T>,
jwt: UntrustedToken,
project: ProjectMetadataOf<T>,
) -> DispatchResult {
) -> DispatchResultWithPostInfo {
let (account, did, investor_type, _cid) =
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
Expand All @@ -715,7 +715,11 @@ pub mod pallet {

#[pallet::call_index(1)]
#[pallet::weight(WeightInfoOf::<T>::remove_project())]
pub fn remove_project(origin: OriginFor<T>, jwt: UntrustedToken, project_id: ProjectId) -> DispatchResult {
pub fn remove_project(
origin: OriginFor<T>,
jwt: UntrustedToken,
project_id: ProjectId,
) -> DispatchResultWithPostInfo {
let (account, did, investor_type, _cid) =
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
Expand All @@ -730,7 +734,7 @@ pub mod pallet {
jwt: UntrustedToken,
project_id: ProjectId,
new_project_metadata: ProjectMetadataOf<T>,
) -> DispatchResult {
) -> DispatchResultWithPostInfo {
let (account, _did, investor_type, _cid) =
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
Expand All @@ -740,7 +744,11 @@ pub mod pallet {
/// Starts the evaluation round of a project. It needs to be called by the project issuer.
#[pallet::call_index(3)]
#[pallet::weight(WeightInfoOf::<T>::start_evaluation())]
pub fn start_evaluation(origin: OriginFor<T>, jwt: UntrustedToken, project_id: ProjectId) -> DispatchResult {
pub fn start_evaluation(
origin: OriginFor<T>,
jwt: UntrustedToken,
project_id: ProjectId,
) -> DispatchResultWithPostInfo {
let (account, _did, investor_type, _cid) =
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
Expand Down Expand Up @@ -1024,7 +1032,7 @@ pub mod pallet {
origin: OriginFor<T>,
jwt: UntrustedToken,
project_id: ProjectId,
) -> DispatchResult {
) -> DispatchResultWithPostInfo {
let (account, _did, investor_type, _cid) =
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
Expand All @@ -1051,7 +1059,7 @@ pub mod pallet {
jwt: UntrustedToken,
project_id: ProjectId,
para_id: ParaId,
) -> DispatchResult {
) -> DispatchResultWithPostInfo {
let (account, _did, investor_type, _cid) =
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
Expand All @@ -1065,7 +1073,7 @@ pub mod pallet {
origin: OriginFor<T>,
jwt: UntrustedToken,
project_id: ProjectId,
) -> DispatchResult {
) -> DispatchResultWithPostInfo {
let (account, _did, investor_type, _cid) =
T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?;
ensure!(investor_type == InvestorType::Institutional, Error::<T>::WrongInvestorType);
Expand Down
1 change: 0 additions & 1 deletion pallets/funding/src/runtime_api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::traits::BondingRequirementCalculation;
#[allow(clippy::wildcard_imports)]
use crate::{traits::BondingRequirementCalculation, *};
use alloc::{collections::BTreeMap, string::String};
Expand Down
4 changes: 2 additions & 2 deletions pallets/oracle-ocw/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub mod pallet {
None
}
})
.collect::<Vec<AssetName>>();
.collect::<Vec<AssetName>>();

if assets.is_empty() {
log::trace!(target: LOG_TARGET, "Assets to fetch list is empty :c");
Expand Down Expand Up @@ -221,8 +221,8 @@ pub mod pallet {
impl<T: Config> Pallet<T> {
fn fetch_prices(assets: Vec<AssetName>) -> BTreeMap<AssetName, FixedU128> {
let fetchers = vec![
KrakenFetcher::get_moving_average,
BitFinexFetcher::get_moving_average,
KrakenFetcher::get_moving_average,
BitStampFetcher::get_moving_average,
CoinbaseFetcher::get_moving_average,
XTFetcher::get_moving_average,
Expand Down
19 changes: 13 additions & 6 deletions pallets/oracle-ocw/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,26 @@ pub fn new_test_ext_with_offchain_storage(

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

for (asset, response) in BITFINEX_RESPONSES.iter() {
for (asset, response) in KRAKEN_RESPONSES.iter() {
state.expect_request(testing::PendingRequest {
method: "GET".into(),
uri: format!("https://api-pub.bitfinex.com/v2/candles/trade%3A1m%3At{}/hist?limit=15", asset),
uri: format!("https://api.kraken.com/0/public/OHLC?pair={}&interval=1", asset),
response: Some(response.to_vec()),
sent: true,
..Default::default()
});
}

for (asset, response) in BITSTAMP_RESPONSES.iter() {
state.expect_request(testing::PendingRequest {
method: "GET".into(),
Expand All @@ -222,13 +223,15 @@ pub fn price_oracle_response(state: &mut testing::OffchainState) {
..Default::default()
});
}

state.expect_request(testing::PendingRequest {
method: "GET".into(),
uri: "https://sapi.xt.com/v4/public/kline?symbol=plmc_usdt&interval=30m&limit=10".into(),
response: Some(XT_PLMC_CORRECT.to_vec()),
sent: true,
..Default::default()
});

state.expect_request(testing::PendingRequest {
method: "GET".into(),
uri: "https://api.mexc.com/api/v3/klines?symbol=PLMCUSDT&interval=30m&limit=10".into(),
Expand Down Expand Up @@ -265,8 +268,12 @@ pub fn assert_close_enough(a: FixedU128, b: FixedU128) {
}
}

pub(crate) const KRAKEN_RESPONSES: &[(&str, &[u8])] =
&[("USDTZUSD", KRAKEN_USDT_CORRECT), ("USDCUSD", KRAKEN_USDC_CORRECT), ("DOTUSD", KRAKEN_DOT_CORRECT)];
pub(crate) const KRAKEN_RESPONSES: &[(&str, &[u8])] = &[
("USDTZUSD", KRAKEN_USDT_CORRECT),
("USDCUSD", KRAKEN_USDC_CORRECT),
("DOTUSD", KRAKEN_DOT_CORRECT),
("XETHZUSD", KRAKEN_WETH_CORRECT)
];
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}}"#;
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}}"#;
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}}"#;
Expand Down
Loading

0 comments on commit b1c86f6

Please sign in to comment.