Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,242 changes: 4,592 additions & 2,650 deletions Cargo.lock

Large diffs are not rendered by default.

251 changes: 127 additions & 124 deletions Cargo.toml

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ sp-arithmetic.workspace = true
frame-system.workspace = true
frame-support.workspace = true
pallet-balances.workspace = true
sp-std.workspace = true
sp-core.workspace = true
sp-keyring.workspace = true
sp-runtime.workspace = true
sp-io.workspace = true
pallet-dispenser.workspace = true
Expand Down Expand Up @@ -78,7 +78,7 @@ pallet-aura.workspace = true
pallet-session.workspace = true
pallet-proxy-bonding.workspace = true
pallet-skip-feeless-payment.workspace = true
xcm-fee-payment-runtime-api.workspace = true
xcm-runtime-apis.workspace = true
hex-literal.workspace = true
hex.workspace = true
assets-common.workspace = true
Expand Down Expand Up @@ -145,10 +145,11 @@ std = [
"sp-core/std",
"sp-io/std",
"sp-runtime/std",
"sp-std/std",
"rococo-runtime-constants/std",
"rococo-runtime/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm-fee-payment-runtime-api/std",
"xcm-runtime-apis/std",
"xcm/std",
]
development-settings = [ "polimec-runtime/development-settings" ]
Expand Down Expand Up @@ -190,5 +191,7 @@ runtime-benchmarks = [
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"xcm-fee-payment-runtime-api/runtime-benchmarks",
"xcm-runtime-apis/runtime-benchmarks",
"assets-common/runtime-benchmarks",
"pallet-transaction-payment/runtime-benchmarks"
]
72 changes: 35 additions & 37 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use sp_arithmetic::{FixedU128, Percent};
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_consensus_beefy::ecdsa_crypto::AuthorityId as BeefyId;
use sp_core::{sr25519, storage::Storage, Pair, Public};
use sp_core::{crypto::get_public_from_string_or_panic, sr25519, storage::Storage};
use sp_runtime::{bounded_vec, BuildStorage, Perbill};
pub use xcm;
use xcm_emulator::{helpers::get_account_id_from_seed, Chain, Parachain};
use xcm_emulator::{Chain, Parachain};

pub const XCM_V2: u32 = 3;
pub const XCM_V3: u32 = 2;
Expand Down Expand Up @@ -60,11 +60,6 @@ fn polimec_inflation_config() -> polimec_runtime::pallet_parachain_staking::Infl
}
}

/// Helper function to generate a crypto pair from seed
fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None).expect("static values are valid; qed").public()
}

pub struct Prices {
pub dot: FixedU128,
pub usdc: FixedU128,
Expand Down Expand Up @@ -153,20 +148,7 @@ pub mod accounts {
pub const FERDIE_STASH: &str = "Ferdie//stash";

pub fn init_balances() -> Vec<AccountId> {
vec![
get_account_id_from_seed::<sr25519::Public>(ALICE),
get_account_id_from_seed::<sr25519::Public>(BOB),
get_account_id_from_seed::<sr25519::Public>(CHARLIE),
get_account_id_from_seed::<sr25519::Public>(DAVE),
get_account_id_from_seed::<sr25519::Public>(EVE),
get_account_id_from_seed::<sr25519::Public>(FERDIE),
get_account_id_from_seed::<sr25519::Public>(ALICE_STASH),
get_account_id_from_seed::<sr25519::Public>(BOB_STASH),
get_account_id_from_seed::<sr25519::Public>(CHARLIE_STASH),
get_account_id_from_seed::<sr25519::Public>(DAVE_STASH),
get_account_id_from_seed::<sr25519::Public>(EVE_STASH),
get_account_id_from_seed::<sr25519::Public>(FERDIE_STASH),
]
sp_keyring::AccountKeyring::iter().map(|a| a.to_account_id()).collect()
}
}

Expand All @@ -175,22 +157,34 @@ pub mod collators {

pub fn invulnerables_asset_hub() -> Vec<(AccountId, AssetHubPolkadotAuraId)> {
vec![
(get_account_id_from_seed::<sr25519::Public>("Alice"), get_from_seed::<AssetHubPolkadotAuraId>("Alice")),
(get_account_id_from_seed::<sr25519::Public>("Bob"), get_from_seed::<AssetHubPolkadotAuraId>("Bob")),
(
sp_keyring::AccountKeyring::Alice.to_account_id(),
get_public_from_string_or_panic::<AssetHubPolkadotAuraId>("Alice"),
),
(
sp_keyring::AccountKeyring::Bob.to_account_id(),
get_public_from_string_or_panic::<AssetHubPolkadotAuraId>("Bob"),
),
]
}

pub fn invulnerables() -> Vec<(AccountId, AuraId)> {
vec![
(get_account_id_from_seed::<sr25519::Public>("Alice"), get_from_seed::<AuraId>("Alice")),
(get_account_id_from_seed::<sr25519::Public>("Bob"), get_from_seed::<AuraId>("Bob")),
(sp_keyring::AccountKeyring::Alice.to_account_id(), get_public_from_string_or_panic::<AuraId>("Alice")),
(sp_keyring::AccountKeyring::Bob.to_account_id(), get_public_from_string_or_panic::<AuraId>("Bob")),
]
}

pub fn initial_authorities() -> Vec<(AccountId, AuraId)> {
vec![
(get_account_id_from_seed::<sr25519::Public>("COLL_1"), get_from_seed::<AuraId>("COLL_1")),
(get_account_id_from_seed::<sr25519::Public>("COLL_2"), get_from_seed::<AuraId>("COLL_2")),
(
get_public_from_string_or_panic::<sr25519::Public>("COLL_1").into(),
get_public_from_string_or_panic::<AuraId>("COLL_1"),
),
(
get_public_from_string_or_panic::<sr25519::Public>("COLL_2").into(),
get_public_from_string_or_panic::<AuraId>("COLL_2"),
),
]
}
}
Expand All @@ -212,15 +206,15 @@ pub mod validators {
)> {
let seed = "Alice";
vec![(
get_account_id_from_seed::<sr25519::Public>(&format!("{}//stash", seed)),
get_account_id_from_seed::<sr25519::Public>(seed),
get_from_seed::<BabeId>(seed),
get_from_seed::<GrandpaId>(seed),
get_from_seed::<ImOnlineId>(seed),
get_from_seed::<ValidatorId>(seed),
get_from_seed::<AssignmentId>(seed),
get_from_seed::<AuthorityDiscoveryId>(seed),
get_from_seed::<BeefyId>(seed),
sp_keyring::AccountKeyring::AliceStash.to_account_id(),
sp_keyring::AccountKeyring::Alice.to_account_id(),
get_public_from_string_or_panic::<BabeId>(seed),
get_public_from_string_or_panic::<GrandpaId>(seed),
get_public_from_string_or_panic::<ImOnlineId>(seed),
get_public_from_string_or_panic::<ValidatorId>(seed),
get_public_from_string_or_panic::<AssignmentId>(seed),
get_public_from_string_or_panic::<AuthorityDiscoveryId>(seed),
get_public_from_string_or_panic::<BeefyId>(seed),
)]
}
}
Expand Down Expand Up @@ -282,6 +276,7 @@ pub mod polkadot {
)
})
.collect::<Vec<_>>(),
..Default::default()
},
babe: rococo_runtime::BabeConfig {
authorities: Default::default(),
Expand Down Expand Up @@ -358,8 +353,9 @@ pub mod polimec {
let usdc_asset_id = AcceptedFundingAsset::USDC.id();
let eth_asset_id = AcceptedFundingAsset::ETH.id();

let ah_location: Location = (Parent, xcm::v4::Junction::Parachain(1000)).into();
let mut funded_accounts = vec![(
PolimecNet::sovereign_account_id_of((Parent, xcm::prelude::Parachain(1000)).into()),
PolimecNet::sovereign_account_id_of(ah_location.try_into().expect("convertible; qed")),
INITIAL_DEPOSIT,
)];
let alice_account = PolimecNet::account_id_of(accounts::ALICE);
Expand Down Expand Up @@ -393,6 +389,7 @@ pub mod polimec {
(eth_asset_id, "Local ETH".as_bytes().to_vec(), "ETH".as_bytes().to_vec(), 18),
],
accounts: vec![],
next_asset_id: None,
},
parachain_info: polimec_runtime::ParachainInfoConfig { parachain_id: PARA_ID.into(), ..Default::default() },
session: polimec_runtime::SessionConfig {
Expand All @@ -406,6 +403,7 @@ pub mod polimec {
)
})
.collect(),
..Default::default()
},
aura: Default::default(),
aura_ext: Default::default(),
Expand Down
3 changes: 2 additions & 1 deletion integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ mod tests;
pub use constants::{accounts::*, polimec, polkadot};
pub use frame_support::{assert_noop, assert_ok, pallet_prelude::Weight, parameter_types, traits::Hooks};
pub use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber};
use polkadot_primitives::runtime_api::runtime_decl_for_parachain_host::ParachainHostV12;
pub use sp_core::{sr25519, storage::Storage, Encode, Get};
pub use xcm::prelude::*;
pub use xcm::v4::*;
pub use xcm_emulator::{
assert_expected_events, bx, decl_test_networks, decl_test_parachains, decl_test_relay_chains,
helpers::{weight_within_threshold, within_threshold},
Expand Down
66 changes: 58 additions & 8 deletions integration-tests/src/tests/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,19 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::*;
use frame_support::{assert_ok, dispatch::GetDispatchInfo, traits::tokens::currency::VestingSchedule};
use frame_support::{
assert_ok, dispatch::GetDispatchInfo, pallet_prelude::TransactionSource, traits::tokens::currency::VestingSchedule,
};
use pallet_asset_tx_payment::Val;
use pallet_skip_feeless_payment::Intermediate;
use polimec_common::credentials::{Did, InvestorType};
use polimec_common_test_utils::{get_fake_jwt, get_mock_jwt_with_cid, get_test_jwt};
use polimec_runtime::PLMC;
use sp_runtime::{generic::Era, traits::SignedExtension, AccountId32, DispatchError};
use sp_runtime::{
generic::Era,
traits::{TransactionExtension, TxBaseImplication},
AccountId32, DispatchError,
};
use tests::defaults::*;

#[test]
Expand Down Expand Up @@ -64,7 +72,7 @@ fn dispenser_signed_extensions_pass_for_new_account() {
let jwt = get_test_jwt(who.clone(), InvestorType::Retail);
let free_call = PolimecCall::Dispenser(pallet_dispenser::Call::dispense { jwt: jwt.clone() });
let paid_call = PolimecCall::System(frame_system::Call::remark { remark: vec![69, 69] });
let extra: polimec_runtime::SignedExtra = (
let extra: polimec_runtime::TxExtension = (
frame_system::CheckNonZeroSender::<PolimecRuntime>::new(),
frame_system::CheckSpecVersion::<PolimecRuntime>::new(),
frame_system::CheckTxVersion::<PolimecRuntime>::new(),
Expand All @@ -76,15 +84,57 @@ fn dispenser_signed_extensions_pass_for_new_account() {
PolimecRuntime,
pallet_asset_tx_payment::ChargeAssetTxPayment<PolimecRuntime>,
>::from(pallet_asset_tx_payment::ChargeAssetTxPayment::<PolimecRuntime>::from(0u64.into(), None)),
frame_metadata_hash_extension::CheckMetadataHash::<PolimecRuntime>::new(true),
frame_metadata_hash_extension::CheckMetadataHash::<PolimecRuntime>::new_with_custom_hash([0u8; 32]),
);

// `InitialPayment` struct from pallet_asset_tx_payment doesn't implement Debug and PartialEq to compare to a specific Error or use assert_ok!
assert!(extra.validate(&who, &paid_call, &paid_call.get_dispatch_info(), 0).is_err());
assert!(extra.clone().pre_dispatch(&who, &paid_call, &paid_call.get_dispatch_info(), 0).is_err());
assert!(extra
.validate(
polimec_runtime::RuntimeOrigin::signed(who.clone()),
&paid_call,
&paid_call.get_dispatch_info(),
0,
extra.implicit().unwrap(),
&TxBaseImplication(()),
TransactionSource::External
)
.is_err());
assert!(extra
.clone()
.prepare(
(
(),
(),
(),
(),
(),
pallet_dispenser::extensions::Val::CheckNonce((who.clone(), 0)),
0,
Intermediate::Apply(Val::Charge { tip: 0, who: who.clone(), fee: 0 }),
(),
),
&polimec_runtime::RuntimeOrigin::signed(who.clone()),
&paid_call,
&paid_call.get_dispatch_info(),
0
)
.is_err());

let val = extra
.validate(
polimec_runtime::RuntimeOrigin::signed(who.clone()),
&free_call,
&free_call.get_dispatch_info(),
0,
extra.implicit().unwrap(),
&TxBaseImplication(()),
TransactionSource::External,
)
.unwrap();

assert!(extra.validate(&who, &free_call, &free_call.get_dispatch_info(), 0).is_ok());
assert!(extra.pre_dispatch(&who, &free_call, &free_call.get_dispatch_info(), 0).is_ok());
assert!(extra
.prepare(val.1, &polimec_runtime::RuntimeOrigin::signed(who), &free_call, &free_call.get_dispatch_info(), 0)
.is_ok());
});
}

Expand Down
Loading