Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
9450283
upgrade v.0.9.37 - build
enthusiastmartin Feb 28, 2023
f09f458
revert nft changes
enthusiastmartin Feb 28, 2023
3b3e30d
update inspect adfadpter
enthusiastmartin Feb 28, 2023
8aef29e
update registry tests
enthusiastmartin Feb 28, 2023
8aef2a7
update collator-rewards tests
enthusiastmartin Feb 28, 2023
6f4233c
fix `InspectEnumerable` trait
Roznovjak Feb 28, 2023
f957e0a
update currencies tests
enthusiastmartin Feb 28, 2023
3c50e53
update duster tests
enthusiastmartin Feb 28, 2023
7f02f26
update ema oracle tests
enthusiastmartin Feb 28, 2023
f985255
update faucet tests
enthusiastmartin Feb 28, 2023
7c487df
update lm tests
enthusiastmartin Feb 28, 2023
faea3f5
update price-oracle tests
enthusiastmartin Feb 28, 2023
87b9079
Merge pull request #173 from galacticcouncil/fix/nft_trait
enthusiastmartin Mar 3, 2023
d43298b
fix multi payment tests to reflect changes in 37
enthusiastmartin Mar 3, 2023
6affba6
fix stableswap tests to reflect changes in 37
enthusiastmartin Mar 3, 2023
3e0a6fb
fix tx pause tests to reflect changes in 37
enthusiastmartin Mar 3, 2023
03aab95
fix route-executor tests to reflect changes in 37
enthusiastmartin Mar 3, 2023
e411cec
Reformat
enthusiastmartin Mar 3, 2023
934224b
Reformat
enthusiastmartin Mar 3, 2023
30b953d
bump versions
enthusiastmartin Mar 3, 2023
9e44b8d
add protobuf to gh workflow
enthusiastmartin Mar 3, 2023
3f3de45
add protobuf to gh workflow
enthusiastmartin Mar 3, 2023
31200a4
set default storage version
Roznovjak Mar 22, 2023
dd88646
Merge branch 'main' into v0.9.37
enthusiastmartin Mar 23, 2023
108d74f
math update
enthusiastmartin Mar 23, 2023
3c34413
update otc pallet to 37
enthusiastmartin Mar 23, 2023
2eeb98d
v0.9.38
enthusiastmartin Mar 30, 2023
a655b19
Merge branch 'main' into v0.9.37
Roznovjak Apr 12, 2023
b2ca40c
Merge pull request #191 from galacticcouncil/duster/storage_version
Roznovjak Apr 13, 2023
ec42a11
Merge branch 'main' into v0.9.37
Roznovjak Apr 18, 2023
6195cb1
fix renamed `EnsureOrigin` method in benchmarks
Roznovjak Apr 20, 2023
952c55e
satisfy clippy
Roznovjak Apr 20, 2023
474064e
Merge branch 'main' into v0.9.37
Roznovjak Apr 22, 2023
d048e91
Merge branch 'v0.9.37' into v0.9.38
Roznovjak Apr 22, 2023
b100a9a
use hydradx_math merge commit
Roznovjak May 8, 2023
c81eeb7
Merge branch 'main' into v0.9.38
Roznovjak May 15, 2023
6c5dbe0
Merge branch 'main' into v0.9.38
Roznovjak May 20, 2023
8611693
add missing impl to `MultiInspectAdapter`
Roznovjak May 20, 2023
2a316a6
remove empty file
Roznovjak May 20, 2023
6649bf4
fix typo
Roznovjak May 20, 2023
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
Prev Previous commit
Next Next commit
fix InspectEnumerable trait
  • Loading branch information
Roznovjak committed Feb 28, 2023
commit 6f4233c804da6395c042016824eec3c326b4d8e8
30 changes: 14 additions & 16 deletions nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,41 +484,39 @@ impl<T: Config> Inspect<T::AccountId> for Pallet<T> {
}
}


use frame_support::storage::KeyPrefixIterator;

impl<T: Config> InspectEnumerable<T::AccountId> for Pallet<T> {
type CollectionsIterator = KeyPrefixIterator<<T as Config>::NftCollectionId>;
type ItemsIterator = KeyPrefixIterator<<T as Config>::NftItemId>;
type OwnedIterator = KeyPrefixIterator<(<T as Config>::NftCollectionId, <T as Config>::NftItemId)>;
type OwnedInCollectionIterator = KeyPrefixIterator<<T as Config>::NftItemId>;
type CollectionsIterator = Box<dyn Iterator<Item = <T as Config>::NftCollectionId>>;
type ItemsIterator = Box<dyn Iterator<Item = <T as Config>::NftItemId>>;
type OwnedIterator = Box<dyn Iterator<Item = (<T as Config>::NftCollectionId, <T as Config>::NftItemId)>>;
type OwnedInCollectionIterator = Box<dyn Iterator<Item = <T as Config>::NftItemId>>;

/// Returns an iterator of the collections in existence.
fn collections() -> Self::CollectionsIterator {
Collections::<T>::iter_keys()
Box::new(Collections::<T>::iter_keys())
}

/// Returns an iterator of the items of a `collection` in existence.
fn items(collection: &Self::CollectionId) -> Self::ItemsIterator{
Items::<T>::iter_key_prefix(collection)
fn items(collection: &Self::CollectionId) -> Self::ItemsIterator {
Box::new(Items::<T>::iter_key_prefix(collection))
}

/// Returns an iterator of the items of all collections owned by `who`.
fn owned(who: &T::AccountId) -> Self::OwnedIterator {
Box::new(
pallet_uniques::Pallet::<T>::owned(who)
.map(|(collection_id, item_id)| (collection_id.into(), item_id.into()))
.map(|(collection_id, item_id)| (collection_id.into(), item_id.into())),
)
}

/// Returns an iterator of the items of `collection` owned by `who`.
fn owned_in_collection(
collection: &Self::CollectionId,
who: &T::AccountId,
) -> Self::OwnedInCollectionIterator {
fn owned_in_collection(collection: &Self::CollectionId, who: &T::AccountId) -> Self::OwnedInCollectionIterator {
Box::new(
pallet_uniques::Pallet::<T>::owned_in_collection(
&(Into::<<T as pallet_uniques::Config>::CollectionId>::into(*collection)),
who,
)
.map(|i| i.into())
.map(|i| i.into()),
)
}
}

Expand Down
14 changes: 7 additions & 7 deletions nft/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl NftPermission<CollectionType> for NftTestPermissions {
}

impl Config for Test {
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_nft::weights::BasiliskWeight<Test>;
type NftCollectionId = CollectionId;
type NftItemId = ItemId;
Expand All @@ -107,7 +107,7 @@ parameter_types! {
}

impl pallet_uniques::Config for Test {
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type CollectionId = CollectionId;
type ItemId = ItemId;
type Currency = Balances;
Expand Down Expand Up @@ -137,16 +137,16 @@ impl frame_system::Config for Test {
type BlockWeights = ();
type BlockLength = ();
type DbWeight = ();
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 = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type BlockHashCount = BlockHashCount;
type Version = ();
type PalletInfo = PalletInfo;
Expand All @@ -165,7 +165,7 @@ parameter_types! {
}
impl pallet_balances::Config for Test {
type Balance = Balance;
type Event = Event;
type RuntimeEvent = RuntimeEvent;
type DustRemoval = ();
type ExistentialDeposit = ExistentialDeposit;
type AccountStore = frame_system::Pallet<Test>;
Expand Down Expand Up @@ -211,6 +211,6 @@ impl ExtBuilder {
}
}

pub fn expect_events(e: Vec<Event>) {
pub fn expect_events(e: Vec<RuntimeEvent>) {
e.into_iter().for_each(frame_system::Pallet::<Test>::assert_has_event);
}
68 changes: 45 additions & 23 deletions nft/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn create_collection_works() {
b"metadata".to_vec().try_into().unwrap();

assert_ok!(NFTPallet::create_collection(
Origin::signed(ALICE),
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_0,
Default::default(), // Marketplace
metadata.clone()
Expand All @@ -53,7 +53,7 @@ fn create_collection_works() {
// not allowed in Permissions
assert_noop!(
NFTPallet::create_collection(
Origin::signed(ALICE),
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_2,
CollectionType::LiquidityMining,
metadata.clone()
Expand All @@ -64,7 +64,7 @@ fn create_collection_works() {
// existing collection ID
assert_noop!(
NFTPallet::create_collection(
Origin::signed(ALICE),
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_0,
CollectionType::Marketplace,
metadata.clone()
Expand All @@ -75,7 +75,7 @@ fn create_collection_works() {
// reserved collection ID
assert_noop!(
NFTPallet::create_collection(
Origin::signed(ALICE),
RuntimeOrigin::signed(ALICE),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was Origin renamed to RuntimeOrigin and Event to RuntimeEvent?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO to differentiate outer enums that are created by construct_runtime macro from nested enums from pallets.
You can see it in this example:
RuntimeCall::Balances(pallet_balances::Call::transfer { dest: ALICE, value: 10 })

COLLECTION_ID_RESERVED,
CollectionType::Marketplace,
metadata
Expand Down Expand Up @@ -105,7 +105,7 @@ fn mint_works() {
));

assert_ok!(NFTPallet::mint(
Origin::signed(ALICE),
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_0,
ITEM_ID_0,
metadata.clone()
Expand All @@ -127,25 +127,40 @@ fn mint_works() {

// duplicate item
assert_noop!(
NFTPallet::mint(Origin::signed(ALICE), COLLECTION_ID_0, ITEM_ID_0, metadata.clone()),
NFTPallet::mint(
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_0,
ITEM_ID_0,
metadata.clone()
),
pallet_uniques::Error::<Test>::AlreadyExists
);

// not allowed in Permissions
assert_noop!(
NFTPallet::mint(Origin::signed(ALICE), COLLECTION_ID_1, ITEM_ID_0, metadata.clone()),
NFTPallet::mint(
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_1,
ITEM_ID_0,
metadata.clone()
),
Error::<Test>::NotPermitted
);

// not owner
assert_noop!(
NFTPallet::mint(Origin::signed(BOB), COLLECTION_ID_0, ITEM_ID_1, metadata.clone()),
NFTPallet::mint(RuntimeOrigin::signed(BOB), COLLECTION_ID_0, ITEM_ID_1, metadata.clone()),
Error::<Test>::NotPermitted
);

// invalid collection ID
assert_noop!(
NFTPallet::mint(Origin::signed(ALICE), NON_EXISTING_COLLECTION_ID, ITEM_ID_0, metadata),
NFTPallet::mint(
RuntimeOrigin::signed(ALICE),
NON_EXISTING_COLLECTION_ID,
ITEM_ID_0,
metadata
),
Error::<Test>::CollectionUnknown
);
});
Expand Down Expand Up @@ -174,32 +189,32 @@ fn transfer_works() {

// not existing
assert_noop!(
NFTPallet::transfer(Origin::signed(CHARLIE), COLLECTION_ID_2, ITEM_ID_0, ALICE),
NFTPallet::transfer(RuntimeOrigin::signed(CHARLIE), COLLECTION_ID_2, ITEM_ID_0, ALICE),
Error::<Test>::CollectionUnknown
);

// not owner
assert_noop!(
NFTPallet::transfer(Origin::signed(CHARLIE), COLLECTION_ID_0, ITEM_ID_0, ALICE),
NFTPallet::transfer(RuntimeOrigin::signed(CHARLIE), COLLECTION_ID_0, ITEM_ID_0, ALICE),
Error::<Test>::NotPermitted
);

// not allowed in Permissions
assert_noop!(
NFTPallet::transfer(Origin::signed(ALICE), COLLECTION_ID_1, ITEM_ID_0, BOB),
NFTPallet::transfer(RuntimeOrigin::signed(ALICE), COLLECTION_ID_1, ITEM_ID_0, BOB),
Error::<Test>::NotPermitted
);

assert_ok!(NFTPallet::transfer(
Origin::signed(ALICE),
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_0,
ITEM_ID_0,
ALICE
));
assert_eq!(NFTPallet::owner(&COLLECTION_ID_0, &ITEM_ID_0).unwrap(), ALICE);

assert_ok!(NFTPallet::transfer(
Origin::signed(ALICE),
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_0,
ITEM_ID_0,
BOB
Expand Down Expand Up @@ -239,17 +254,21 @@ fn burn_works() {

// not owner
assert_noop!(
NFTPallet::burn(Origin::signed(BOB), COLLECTION_ID_0, ITEM_ID_0),
NFTPallet::burn(RuntimeOrigin::signed(BOB), COLLECTION_ID_0, ITEM_ID_0),
Error::<Test>::NotPermitted
);

// not allowed in Permissions
assert_noop!(
NFTPallet::burn(Origin::signed(ALICE), COLLECTION_ID_1, ITEM_ID_0),
NFTPallet::burn(RuntimeOrigin::signed(ALICE), COLLECTION_ID_1, ITEM_ID_0),
Error::<Test>::NotPermitted
);

assert_ok!(NFTPallet::burn(Origin::signed(ALICE), COLLECTION_ID_0, ITEM_ID_0));
assert_ok!(NFTPallet::burn(
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_0,
ITEM_ID_0
));
assert!(!<Items<Test>>::contains_key(COLLECTION_ID_0, ITEM_ID_0));

expect_events(vec![crate::Event::ItemBurned {
Expand All @@ -261,7 +280,7 @@ fn burn_works() {

// not existing
assert_noop!(
NFTPallet::burn(Origin::signed(ALICE), COLLECTION_ID_0, ITEM_ID_0),
NFTPallet::burn(RuntimeOrigin::signed(ALICE), COLLECTION_ID_0, ITEM_ID_0),
Error::<Test>::ItemUnknown
);
});
Expand Down Expand Up @@ -289,24 +308,27 @@ fn destroy_collection_works() {

// existing item
assert_noop!(
NFTPallet::destroy_collection(Origin::signed(ALICE), COLLECTION_ID_0),
NFTPallet::destroy_collection(RuntimeOrigin::signed(ALICE), COLLECTION_ID_0),
Error::<Test>::TokenCollectionNotEmpty
);
assert_ok!(NFTPallet::do_burn(ALICE, COLLECTION_ID_0, ITEM_ID_0));

// not allowed in Permissions
assert_noop!(
NFTPallet::destroy_collection(Origin::signed(ALICE), COLLECTION_ID_1),
NFTPallet::destroy_collection(RuntimeOrigin::signed(ALICE), COLLECTION_ID_1),
Error::<Test>::NotPermitted
);

// not owner
assert_noop!(
NFTPallet::destroy_collection(Origin::signed(CHARLIE), COLLECTION_ID_0),
NFTPallet::destroy_collection(RuntimeOrigin::signed(CHARLIE), COLLECTION_ID_0),
pallet_uniques::Error::<Test>::NoPermission
);

assert_ok!(NFTPallet::destroy_collection(Origin::signed(ALICE), COLLECTION_ID_0));
assert_ok!(NFTPallet::destroy_collection(
RuntimeOrigin::signed(ALICE),
COLLECTION_ID_0
));
assert_eq!(NFTPallet::collections(COLLECTION_ID_0), None);

expect_events(vec![crate::Event::CollectionDestroyed {
Expand All @@ -317,7 +339,7 @@ fn destroy_collection_works() {

// not existing
assert_noop!(
NFTPallet::destroy_collection(Origin::signed(ALICE), COLLECTION_ID_0),
NFTPallet::destroy_collection(RuntimeOrigin::signed(ALICE), COLLECTION_ID_0),
Error::<Test>::CollectionUnknown
);
});
Expand Down