Skip to content

Commit

Permalink
Update erc721 pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
MRamanenkau committed Jul 5, 2023
1 parent 3ec2224 commit 67e827b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions pallets/erc721/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ impl frame_system::Config for Test {
type BaseCallFilter = Everything;
type BlockWeights = ();
type BlockLength = ();
type Origin = Origin;
type Call = Call;
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type DbWeight = ();
type Version = ();
Expand All @@ -60,7 +60,7 @@ ord_parameter_types! {
impl pallet_balances::Config for Test {
type Balance = u64;
type DustRemoval = ();
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = System;
type WeightInfo = ();
Expand All @@ -74,12 +74,12 @@ parameter_types! {
}

impl Config for Test {
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type Identifier = Erc721Id;
}

pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, u64, Call, ()>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<u32, u64, RuntimeCall, ()>;

frame_support::construct_runtime!(
pub enum Test where
Expand Down
26 changes: 13 additions & 13 deletions pallets/erc721/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg(test)]

use super::mock::{new_test_ext, Erc721, Origin, Test, USER_A, USER_B, USER_C};
use super::mock::{new_test_ext, Erc721, RuntimeOrigin, Test, USER_A, USER_B, USER_C};
use super::*;
use frame_support::{assert_noop, assert_ok};
use sp_core::U256;
Expand All @@ -14,7 +14,7 @@ fn mint_burn_tokens() {
let metadata_b: Vec<u8> = vec![4, 5, 6];

assert_ok!(Erc721::mint(
Origin::root(),
RuntimeOrigin::root(),
USER_A,
id_a,
metadata_a.clone()
Expand All @@ -28,12 +28,12 @@ fn mint_burn_tokens() {
);
assert_eq!(Erc721::token_count(), 1.into());
assert_noop!(
Erc721::mint(Origin::root(), USER_A, id_a, metadata_a.clone()),
Erc721::mint(RuntimeOrigin::root(), USER_A, id_a, metadata_a.clone()),
Error::<Test>::TokenAlreadyExists
);

assert_ok!(Erc721::mint(
Origin::root(),
RuntimeOrigin::root(),
USER_A,
id_b,
metadata_b.clone()
Expand All @@ -47,16 +47,16 @@ fn mint_burn_tokens() {
);
assert_eq!(Erc721::token_count(), 2.into());
assert_noop!(
Erc721::mint(Origin::root(), USER_A, id_b, metadata_b.clone()),
Erc721::mint(RuntimeOrigin::root(), USER_A, id_b, metadata_b.clone()),
Error::<Test>::TokenAlreadyExists
);

assert_ok!(Erc721::burn(Origin::root(), id_a));
assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_a));
assert_eq!(Erc721::token_count(), 1.into());
assert!(!<Tokens>::contains_key(&id_a));
assert!(!<TokenOwner<Test>>::contains_key(&id_a));

assert_ok!(Erc721::burn(Origin::root(), id_b));
assert_ok!(Erc721::burn(RuntimeOrigin::root(), id_b));
assert_eq!(Erc721::token_count(), 0.into());
assert!(!<Tokens>::contains_key(&id_b));
assert!(!<TokenOwner<Test>>::contains_key(&id_b));
Expand All @@ -72,28 +72,28 @@ fn transfer_tokens() {
let metadata_b: Vec<u8> = vec![4, 5, 6];

assert_ok!(Erc721::mint(
Origin::root(),
RuntimeOrigin::root(),
USER_A,
id_a,
metadata_a.clone()
));
assert_ok!(Erc721::mint(
Origin::root(),
RuntimeOrigin::root(),
USER_A,
id_b,
metadata_b.clone()
));

assert_ok!(Erc721::transfer(Origin::signed(USER_A), USER_B, id_a));
assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_B, id_a));
assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_B);

assert_ok!(Erc721::transfer(Origin::signed(USER_A), USER_C, id_b));
assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_A), USER_C, id_b));
assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_C);

assert_ok!(Erc721::transfer(Origin::signed(USER_B), USER_A, id_a));
assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_B), USER_A, id_a));
assert_eq!(Erc721::owner_of(id_a).unwrap(), USER_A);

assert_ok!(Erc721::transfer(Origin::signed(USER_C), USER_A, id_b));
assert_ok!(Erc721::transfer(RuntimeOrigin::signed(USER_C), USER_A, id_b));
assert_eq!(Erc721::owner_of(id_b).unwrap(), USER_A);
})
}

0 comments on commit 67e827b

Please sign in to comment.