Skip to content

Commit

Permalink
fix: pallet tests + integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Oct 31, 2024
1 parent 6db7c47 commit c5751f9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
5 changes: 3 additions & 2 deletions pallets/api/src/nonfungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,9 @@ pub mod pallet {
),
Collection(collection) =>
ReadResult::Collection(pallet_nfts::Collection::<T>::get(collection)),
ItemMetadata { collection, item } =>
ReadResult::ItemMetadata(NftsOf::<T>::item_metadata(collection, item)),
ItemMetadata { collection, item } => ReadResult::ItemMetadata(
NftsOf::<T>::item_metadata(collection, item).map(|metadata| metadata.into()),
),
NextCollectionId => ReadResult::NextCollectionId(
NextCollectionIdOf::<T>::get().or(T::CollectionId::initial_value()),
),
Expand Down
10 changes: 5 additions & 5 deletions pallets/api/src/nonfungibles/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod encoding_read_result {

#[test]
fn get_attribute() {
let mut attribute = Some(BoundedVec::truncate_from("some attribute".as_bytes().to_vec()));
let mut attribute = Some("some attribute".as_bytes().to_vec());
assert_eq!(
ReadResult::GetAttribute::<Test>(attribute.clone()).encode(),
attribute.encode()
Expand Down Expand Up @@ -98,7 +98,7 @@ mod encoding_read_result {

#[test]
fn item_metadata_works() {
let mut data = Some(BoundedVec::truncate_from("some metadata".as_bytes().to_vec()));
let mut data = Some("some metadata".as_bytes().to_vec());
assert_eq!(ReadResult::ItemMetadata::<Test>(data.clone()).encode(), data.encode());
data = None;
assert_eq!(ReadResult::ItemMetadata::<Test>(data.clone()).encode(), data.encode());
Expand Down Expand Up @@ -135,15 +135,15 @@ fn mint_works() {
let collection = nfts::create_collection(owner);

// Successfully mint a new collection item.
let balance_before_mint = AccountBalance::<Test>::get(collection, account(owner));
let balance_before_mint = AccountBalance::<Test>::get(collection, owner);
assert_ok!(NonFungibles::mint(
signed(owner),
account(owner),
owner,
collection,
ITEM,
MintWitness { mint_price: None, owned_item: None }
));
let balance_after_mint = AccountBalance::<Test>::get(collection, account(owner));
let balance_after_mint = AccountBalance::<Test>::get(collection, owner);
assert_eq!(balance_after_mint, 1);
assert_eq!(balance_after_mint - balance_before_mint, 1);
System::assert_last_event(
Expand Down
8 changes: 4 additions & 4 deletions pop-api/integration-tests/src/nonfungibles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ fn approve_item_attributes_works() {
RuntimeOrigin::signed(ALICE),
collection,
Some(item),
pallet_nfts::AttributeNamespace::ALICE,
pallet_nfts::AttributeNamespace::Account(ALICE),
BoundedVec::truncate_from("some attribute".as_bytes().to_vec()),
BoundedVec::truncate_from("some value".as_bytes().to_vec()),
));
assert_eq!(
pallet_nfts::Attribute::<Runtime>::get((
collection,
Some(item),
pallet_nfts::AttributeNamespace::ALICE,
pallet_nfts::AttributeNamespace::Account(ALICE),
AttributeKey::truncate_from("some attribute".as_bytes().to_vec()),
))
.map(|attribute| attribute.0),
Expand All @@ -286,7 +286,7 @@ fn cancel_item_attributes_approval_works() {
RuntimeOrigin::signed(ALICE),
collection,
Some(item),
pallet_nfts::AttributeNamespace::ALICE,
pallet_nfts::AttributeNamespace::Account(ALICE),
BoundedVec::truncate_from("some attribute".as_bytes().to_vec()),
BoundedVec::truncate_from("some value".as_bytes().to_vec()),
));
Expand All @@ -301,7 +301,7 @@ fn cancel_item_attributes_approval_works() {
RuntimeOrigin::signed(ALICE),
collection,
Some(item),
pallet_nfts::AttributeNamespace::ALICE,
pallet_nfts::AttributeNamespace::Account(ALICE),
BoundedVec::truncate_from("some attribute".as_bytes().to_vec()),
BoundedVec::truncate_from("some value".as_bytes().to_vec()),
)
Expand Down
9 changes: 8 additions & 1 deletion runtime/devnet/src/config/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ impl<T: frame_system::Config> Contains<RuntimeRead> for Filter<T> {
mod tests {
use codec::Encode;
use pallet_api::fungibles::Call::*;
use pallet_nfts::MintWitness;
use sp_core::{bounded_vec, crypto::AccountId32};
use RuntimeCall::{Balances, Fungibles, NonFungibles};

Expand Down Expand Up @@ -359,6 +360,7 @@ mod tests {
approved: false,
}),
NonFungibles(create {
id: 0,
admin: ACCOUNT,
config: CreateCollectionConfig {
max_supply: Some(0),
Expand Down Expand Up @@ -395,7 +397,12 @@ mod tests {
witness: CancelAttributesApprovalWitness { account_attributes: 0 },
}),
NonFungibles(set_max_supply { collection: 0, max_supply: 0 }),
NonFungibles(mint { to: ACCOUNT, collection: 0, item: 0, mint_price: None }),
NonFungibles(mint {
to: ACCOUNT,
collection: 0,
item: 0,
witness: MintWitness { mint_price: None, owned_item: None },
}),
NonFungibles(burn { collection: 0, item: 0 }),
]
.iter()
Expand Down

0 comments on commit c5751f9

Please sign in to comment.