Skip to content

Commit

Permalink
fix: INV4 tests + missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
arrudagates committed Dec 3, 2023
1 parent 63c6687 commit d59709f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 23 deletions.
37 changes: 37 additions & 0 deletions INV4/pallet-inv4/src/account_derivation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use crate::{Config, Pallet};
use codec::{Compact, Encode};
use sp_io::hashing::blake2_256;
use xcm::latest::{BodyId, BodyPart, Junction, Junctions};

pub trait CoreAccountDerivation<T: Config> {
fn derive_core_account(core_id: T::CoreId) -> T::AccountId;
fn core_location(core_id: T::CoreId) -> Junctions;
}

impl<T: Config> CoreAccountDerivation<T> for Pallet<T>
where
T::AccountId: From<[u8; 32]>,
{
fn derive_core_account(core_id: T::CoreId) -> T::AccountId {
(
b"GlobalConsensus",
T::GLOBAL_NETWORK_ID,
b"Parachain",
Compact::<u32>::from(T::PARA_ID),
(b"Body", BodyId::Index(core_id.into()), BodyPart::Voice).encode(),
)
.using_encoded(blake2_256)
.into()
}

fn core_location(core_id: T::CoreId) -> Junctions {
Junctions::X3(
Junction::GlobalConsensus(T::GLOBAL_NETWORK_ID),
Junction::Parachain(T::PARA_ID),
Junction::Plurality {
id: BodyId::Index(core_id.into()),
part: BodyPart::Voice,
},
)
}
}
26 changes: 13 additions & 13 deletions INV4/pallet-inv4/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ use orml_asset_registry::AssetMetadata;
use pallet_balances::AccountData;
use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::{testing::Header, traits::IdentityLookup};
use sp_runtime::{testing::Header, traits::IdentityLookup, AccountId32};
use sp_std::{convert::TryInto, vec};
use xcm::latest::NetworkId;

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;
type Balance = u128;

type AccountId = u32;
type BlockNumber = u64;

type AccountId = AccountId32;

pub const EXISTENTIAL_DEPOSIT: Balance = 1_000_000_000;

pub const ALICE: AccountId = 0;
pub const BOB: AccountId = 1;
pub const CHARLIE: AccountId = 2;
pub const DAVE: AccountId = 3;
pub const ALICE: AccountId = AccountId::new([0u8; 32]);
pub const BOB: AccountId = AccountId::new([1u8; 32]);
pub const CHARLIE: AccountId = AccountId::new([2u8; 32]);
pub const DAVE: AccountId = AccountId::new([3u8; 32]);

frame_support::construct_runtime!(
pub enum Test where
Expand Down Expand Up @@ -281,7 +282,7 @@ impl MultisigFeeHandler<Test> for FeeCharger {
) -> Result<Self::Pre, frame_support::unsigned::TransactionValidityError> {
Ok((
0u128,
*who,
who.clone(),
(),
match fee_asset {
FeeAsset::TNKR => None,
Expand Down Expand Up @@ -323,14 +324,16 @@ impl pallet::Config for Test {
type RuntimeOrigin = RuntimeOrigin;
type CoreCreationFee = CoreCreationFee;
type FeeCharger = FeeCharger;
type GenesisHash = GenesisHash;
type WeightInfo = crate::weights::SubstrateWeight<Test>;

type Tokens = Tokens;
type KSMAssetId = RelayAssetId;
type KSMCoreCreationFee = KSMCoreCreationFee;

type MaxCallSize = MaxCallSize;

const GLOBAL_NETWORK_ID: NetworkId = NetworkId::Kusama;
const PARA_ID: u32 = 2125;
}

pub struct ExtBuilder;
Expand All @@ -354,10 +357,7 @@ impl ExtBuilder {
(ALICE, INITIAL_BALANCE),
(BOB, INITIAL_BALANCE),
(CHARLIE, INITIAL_BALANCE),
(
account_derivation::derive_core_account::<Test, u32, u32>(0u32),
INITIAL_BALANCE,
),
(INV4::derive_core_account(0u32), INITIAL_BALANCE),
],
}
.assimilate_storage(&mut t)
Expand Down
20 changes: 10 additions & 10 deletions INV4/pallet-inv4/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn create_core_works() {
assert_eq!(
INV4::core_storage(0u32),
Some(CoreInfo {
account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
account: INV4::derive_core_account(0u32),
metadata: vec![].try_into().unwrap(),
minimum_support: Perbill::from_percent(1),
required_approval: Perbill::from_percent(1),
Expand Down Expand Up @@ -77,7 +77,7 @@ fn create_core_works() {
assert_eq!(
INV4::core_storage(1u32),
Some(CoreInfo {
account: account_derivation::derive_core_account::<Test, u32, u32>(1u32),
account: INV4::derive_core_account(1u32),
metadata: vec![1, 2, 3].try_into().unwrap(),
minimum_support: Perbill::from_percent(100),
required_approval: Perbill::from_percent(100),
Expand Down Expand Up @@ -160,7 +160,7 @@ fn set_parameters_works() {
assert_eq!(
INV4::core_storage(0u32),
Some(CoreInfo {
account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
account: INV4::derive_core_account(0u32),
metadata: vec![1, 2, 3].try_into().unwrap(),
minimum_support: Perbill::from_percent(100),
required_approval: Perbill::from_percent(100),
Expand Down Expand Up @@ -438,7 +438,7 @@ fn operate_multisig_works() {
System::assert_has_event(
Event::MultisigExecuted {
core_id: 0u32,
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
executor_account: INV4::derive_core_account(0u32),
voter: ALICE,
call: call.clone(),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call),
Expand Down Expand Up @@ -468,7 +468,7 @@ fn operate_multisig_works() {
System::assert_has_event(
Event::MultisigVoteStarted {
core_id: 0u32,
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
executor_account: INV4::derive_core_account(0u32),
voter: ALICE,
votes_added: Vote::Aye(CoreSeedBalance::get()),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call),
Expand Down Expand Up @@ -815,7 +815,7 @@ fn vote_multisig_works() {
System::assert_has_event(
Event::MultisigVoteAdded {
core_id: 0u32,
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
executor_account: INV4::derive_core_account(0u32),
voter: BOB,
votes_added: Vote::Nay(CoreSeedBalance::get()),
current_votes: Tally::from_parts(
Expand Down Expand Up @@ -866,7 +866,7 @@ fn vote_multisig_works() {
System::assert_has_event(
Event::MultisigExecuted {
core_id: 0u32,
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
executor_account: INV4::derive_core_account(0u32),
voter: BOB,
call: call2.clone(),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call2),
Expand Down Expand Up @@ -1043,7 +1043,7 @@ fn withdraw_vote_multisig_works() {
System::assert_has_event(
Event::MultisigVoteAdded {
core_id: 0u32,
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
executor_account: INV4::derive_core_account(0u32),
voter: BOB,
votes_added: Vote::Nay(CoreSeedBalance::get()),
current_votes: Tally::from_parts(
Expand Down Expand Up @@ -1093,7 +1093,7 @@ fn withdraw_vote_multisig_works() {
System::assert_has_event(
Event::MultisigVoteWithdrawn {
core_id: 0u32,
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
executor_account: INV4::derive_core_account(0u32),
voter: BOB,
votes_removed: Vote::Nay(CoreSeedBalance::get()),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call2),
Expand Down Expand Up @@ -1134,7 +1134,7 @@ fn withdraw_vote_multisig_works() {
System::assert_has_event(
Event::MultisigVoteWithdrawn {
core_id: 0u32,
executor_account: account_derivation::derive_core_account::<Test, u32, u32>(0u32),
executor_account: INV4::derive_core_account(0u32),
voter: ALICE,
votes_removed: Vote::Aye(CoreSeedBalance::get()),
call_hash: <<Test as frame_system::Config>::Hashing as Hash>::hash_of(&call2),
Expand Down

0 comments on commit d59709f

Please sign in to comment.