Skip to content

Commit

Permalink
chore: update pallet & runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Nov 12, 2024
1 parent 9668232 commit 9978db3
Show file tree
Hide file tree
Showing 15 changed files with 964 additions and 854 deletions.
286 changes: 109 additions & 177 deletions pallets/api/src/fungibles/tests.rs

Large diffs are not rendered by default.

61 changes: 36 additions & 25 deletions pallets/api/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use codec::{Decode, Encode};
use frame_support::{
derive_impl, parameter_types,
traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, ConstU64, Everything},
};
use frame_system::{EnsureRoot, EnsureSigned};
use pallet_nfts::PalletFeatures;
use scale_info::TypeInfo;
use sp_core::H256;
use sp_runtime::{
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify},
BuildStorage, MultiSignature,
traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Lazy, Verify},
BuildStorage,
};

pub(crate) const ALICE: u8 = 1;
pub(crate) const BOB: u8 = 2;
pub(crate) const CHARLIE: u8 = 3;
pub(crate) const ALICE: AccountId = 1;
pub(crate) const BOB: AccountId = 2;
pub(crate) const CHARLIE: AccountId = 3;
pub(crate) const INIT_AMOUNT: Balance = 100_000_000 * UNIT;
pub(crate) const UNIT: Balance = 10_000_000_000;

type Block = frame_system::mocking::MockBlock<Test>;
pub(crate) type AccountId = <AccountPublic as IdentifyAccount>::AccountId;
pub(crate) type AccountId = u64;
pub(crate) type Balance = u128;
// For terminology in tests.
pub(crate) type TokenId = u32;
type Signature = MultiSignature;
type AccountPublic = <Signature as Verify>::Signer;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
Expand Down Expand Up @@ -99,7 +99,7 @@ impl pallet_assets::Config<AssetsInstance> for Test {
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<Self::AccountId>>;
type Currency = Balances;
type Extra = ();
type ForceOrigin = EnsureRoot<Self::AccountId>;
type ForceOrigin = EnsureRoot<u64>;
type Freezer = ();
type MetadataDepositBase = ConstU128<1>;
type MetadataDepositPerByte = ConstU128<1>;
Expand All @@ -119,12 +119,35 @@ parameter_types! {
pub storage Features: PalletFeatures = PalletFeatures::all_enabled();
}

#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode, TypeInfo)]
pub struct Noop;

impl IdentifyAccount for Noop {
type AccountId = AccountId;

fn into_account(self) -> Self::AccountId {
0
}
}

impl Verify for Noop {
type Signer = Noop;

fn verify<L: Lazy<[u8]>>(
&self,
_msg: L,
_signer: &<Self::Signer as IdentifyAccount>::AccountId,
) -> bool {
false
}
}

impl pallet_nfts::Config for Test {
type ApprovalsLimit = ConstU32<10>;
type AttributeDepositBase = ConstU128<1>;
type CollectionDeposit = ConstU128<2>;
type CollectionId = u32;
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<Self::AccountId>>;
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<u64>>;
type Currency = Balances;
type DepositPerByte = ConstU128<1>;
type Features = Features;
Expand All @@ -140,11 +163,8 @@ impl pallet_nfts::Config for Test {
type MaxDeadlineDuration = ConstU64<10000>;
type MaxTips = ConstU32<10>;
type MetadataDepositBase = ConstU128<1>;
/// Using `AccountPublic` here makes it trivial to convert to `AccountId` via `into_account()`.
type OffchainPublic = AccountPublic;
/// Off-chain = signature On-chain - therefore no conversion needed.
/// It needs to be From<MultiSignature> for benchmarking.
type OffchainSignature = Signature;
type OffchainPublic = Noop;
type OffchainSignature = Noop;
type RuntimeEvent = RuntimeEvent;
type StringLimit = ConstU32<50>;
type ValueLimit = ConstU32<50>;
Expand All @@ -155,22 +175,13 @@ impl crate::nonfungibles::Config for Test {
type RuntimeEvent = RuntimeEvent;
}

/// Initialize a new account ID.
pub(crate) fn account(id: u8) -> AccountId {
[id; 32].into()
}

pub(crate) fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::<Test>::default()
.build_storage()
.expect("Frame system builds valid default genesis config");

pallet_balances::GenesisConfig::<Test> {
balances: vec![
(account(ALICE), INIT_AMOUNT),
(account(BOB), INIT_AMOUNT),
(account(CHARLIE), INIT_AMOUNT),
],
balances: vec![(ALICE, INIT_AMOUNT), (BOB, INIT_AMOUNT), (CHARLIE, INIT_AMOUNT)],
}
.assimilate_storage(&mut t)
.expect("Pallet balances storage can be assimilated");
Expand Down
Loading

0 comments on commit 9978db3

Please sign in to comment.