Skip to content

Commit

Permalink
fix: working unsigned creation of collections and tokens; updated get…
Browse files Browse the repository at this point in the history
…_nft_detail to return relevant NftAssetData instead of NftClassData
  • Loading branch information
chexware committed Jul 20, 2024
1 parent 16a984e commit dff52ad
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 47 deletions.
11 changes: 3 additions & 8 deletions modules/bridge/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use sp_core::H256;
use sp_runtime::traits::AccountIdConversion;
use sp_runtime::{traits::IdentityLookup, ModuleError, Perbill};

use core_primitives::{Attributes, CollectionType, NFTTrait, NftClassData, NftMetadata, TokenType};
use core_primitives::{Attributes, CollectionType, NFTTrait, NftClassData, NftMetadata, TokenType, NftAssetData};
use primitives::{
continuum::MapTrait, Amount, ClassId, EstateId, FungibleTokenId, GroupCollectionId, MapSpotId, TokenId,
UndeployedLandBlockId,
Expand Down Expand Up @@ -383,16 +383,11 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
CLASS_FUND_ID
}

fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftClassData<Balance>, DispatchError> {
let new_data = NftClassData {
fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftAssetData<Balance>, DispatchError> {
let new_data = NftAssetData {
deposit: 0,
attributes: test_attributes(1),
token_type: TokenType::Transferable,
collection_type: CollectionType::Collectable,
is_locked: false,
royalty_fee: Perbill::from_percent(0u32),
mint_limit: None,
total_minted_tokens: 0u32,
};
Ok(new_data)
}
Expand Down
4 changes: 2 additions & 2 deletions pallets/auction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,8 +1362,8 @@ pub mod pallet {
social_currency_id: FungibleTokenId,
) -> DispatchResult {
// Get royalty fee
let nft_details = T::NFTHandler::get_nft_detail((asset_id.0, asset_id.1))?;
let royalty_fee: Self::Balance = nft_details.royalty_fee * *high_bid_price;
let class_details = T::NFTHandler::get_nft_class_detail(asset_id.0)?;
let royalty_fee: Self::Balance = class_details.royalty_fee * *high_bid_price;
let class_fund = T::NFTHandler::get_class_fund(&asset_id.0);

// Transfer loyalty fee from winner to class fund pot
Expand Down
9 changes: 2 additions & 7 deletions pallets/estate/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,11 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
CLASS_FUND_ID
}

fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftClassData<Balance>, DispatchError> {
let new_data = NftClassData {
fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftAssetData<Balance>, DispatchError> {
let new_data = NftAssetData {
deposit: 0,
attributes: test_attributes(1),
token_type: TokenType::Transferable,
collection_type: CollectionType::Collectable,
is_locked: false,
royalty_fee: Perbill::from_percent(0u32),
mint_limit: None,
total_minted_tokens: 0u32,
};
Ok(new_data)
}
Expand Down
14 changes: 3 additions & 11 deletions pallets/governance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use sp_runtime::{
};
use sp_std::collections::btree_map::BTreeMap;

use metaverse_primitive::{
Attributes, CollectionType, MetaverseInfo as MetaversePrimitiveInfo, MetaverseLandTrait, MetaverseMetadata,
MetaverseTrait, NFTTrait, NftClassData, NftMetadata, TokenType,
};
use metaverse_primitive::{Attributes, CollectionType, MetaverseInfo as MetaversePrimitiveInfo, MetaverseLandTrait, MetaverseMetadata, MetaverseTrait, NFTTrait, NftClassData, NftMetadata, TokenType, NftAssetData};
use primitives::{Amount, ClassId, FungibleTokenId, GroupCollectionId, TokenId};
use sp_runtime::BuildStorage;

Expand Down Expand Up @@ -351,16 +348,11 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
CLASS_FUND_ID
}

fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftClassData<Balance>, DispatchError> {
let new_data = NftClassData {
fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftAssetData<Balance>, DispatchError> {
let new_data = NftAssetData {
deposit: 0,
attributes: test_attributes(1),
token_type: TokenType::Transferable,
collection_type: CollectionType::Collectable,
is_locked: false,
royalty_fee: Perbill::from_percent(0u32),
mint_limit: None,
total_minted_tokens: 0u32,
};
Ok(new_data)
}
Expand Down
9 changes: 2 additions & 7 deletions pallets/metaverse/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,11 @@ impl NFTTrait<AccountId, Balance> for MockNFTHandler {
CLASS_FUND_ID
}

fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftClassData<Balance>, DispatchError> {
let new_data = NftClassData {
fn get_nft_detail(_asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftAssetData<Balance>, DispatchError> {
let new_data = NftAssetData {
deposit: 0,
attributes: test_attributes(1),
token_type: TokenType::Transferable,
collection_type: CollectionType::Collectable,
is_locked: false,
royalty_fee: Perbill::from_percent(0u32),
mint_limit: None,
total_minted_tokens: 0u32,
};
Ok(new_data)
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/nft-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub mod pallet {
T::NFTSource::get_next_collection_id() == collection_id,
Error::<T>::InconsistentMigrationData
);
T::NFTSource::migrate_collection(collection_data);
T::NFTSource::migrate_collection(collection_data)?;
Ok(())
}

Expand Down
4 changes: 2 additions & 2 deletions pallets/nft-migration/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub type Extrinsic = TestXt<RuntimeCall, ()>;
pub const ALICE: AccountId = AccountId32::new([1; 32]);
pub const BOB: AccountId = AccountId32::new([5; 32]);
pub const COLLECTION_ID: GroupCollectionId = 0;
pub const CLASS_ID: ClassId = 1;
pub const CLASS_ID: ClassId = 0;

fn test_attributes(x: u8) -> Attributes {
let mut attr: Attributes = BTreeMap::new();
Expand Down Expand Up @@ -290,7 +290,7 @@ parameter_types! {
pub const StorageDepositFee: Balance = 1;
pub MaxBatchTransfer: u32 = 3;
pub MaxBatchMinting: u32 = 12;
pub MaxMetadata: u32 = 10;
pub MaxMetadata: u32 = 1024;
pub const MiningCurrencyId: FungibleTokenId = FungibleTokenId::MiningResource(0);
pub const MetaverseNetworkTreasuryPalletId: PalletId = PalletId(*b"bit/trsy");
pub NftPalletId: PalletId = PalletId(*b"bit/bNFT");
Expand Down
20 changes: 16 additions & 4 deletions pallets/nft-migration/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg(test)]

use core_primitives::NFTTrait;
use frame_support::{assert_err, assert_noop, assert_ok};
use sp_runtime::{traits::BadOrigin, Perbill};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -45,7 +46,7 @@ fn test_attributes(x: u8) -> core_primitives::Attributes {

fn get_test_class_data() -> NftClassData<Balance> {
NftClassData {
deposit: 1,
deposit: 5,
attributes: test_attributes(10),
token_type: TokenType::Transferable,
collection_type: CollectionType::Collectable,
Expand All @@ -58,7 +59,7 @@ fn get_test_class_data() -> NftClassData<Balance> {

fn get_test_token_data() -> NftAssetData<Balance> {
NftAssetData {
deposit: 1,
deposit: 2,
attributes: test_attributes(20),
is_locked: false,
}
Expand All @@ -84,14 +85,18 @@ fn start_migration_should_work() {
#[test]
fn migrating_single_collection_should_work() {
ExtBuilder::default().build().execute_with(|| {
init_test_collection();
let collection_id = Nft::get_next_collection_id();
assert_ok!(NftMigration::migrate_collection_unsigned(
RuntimeOrigin::none(),
collection_id,
get_test_collection_data()
));
//assert_eq!(Nft::get_group_collection(collection_id), Some(get_test_collection_data()));
//assert_eq!(Nft::get_next_collection_id(), collection_id + 1);
assert_eq!(Nft::get_next_collection_id(), collection_id + 1);
assert_eq!(
Nft::get_group_collection(collection_id),
Some(get_test_collection_data())
);
});
}

Expand Down Expand Up @@ -119,6 +124,10 @@ fn migrating_single_class_should_work() {
get_test_metadata(),
get_test_class_data(),
));
assert_eq!(Nft::get_next_class_id(), class_id + 1);
assert_eq!(Nft::get_nft_group_collection(&class_id), Ok(COLLECTION_ID));
assert_eq!(Nft::get_nft_class_detail(class_id), Ok(get_test_class_data()));
assert_eq!(Nft::get_total_issuance(class_id), Ok(0));
});
}

Expand Down Expand Up @@ -154,6 +163,9 @@ fn migrating_single_token_should_work() {
get_test_metadata(),
get_test_token_data(),
));
assert_eq!(Nft::get_next_token_id(CLASS_ID), token_id + 1);
assert_eq!(Nft::get_nft_detail((CLASS_ID, token_id)), Ok(get_test_token_data()));
assert_eq!(Nft::check_ownership(&ALICE, &(CLASS_ID, token_id)), Ok(true));
});
}

Expand Down
8 changes: 4 additions & 4 deletions pallets/nft/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,8 @@ impl<T: Config> NFTTrait<T::AccountId, BalanceOf<T>> for Pallet<T> {
Ok(who == &asset_info.owner)
}

fn get_nft_detail(asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftClassData<BalanceOf<T>>, DispatchError> {
let asset_info = NftModule::<T>::classes(asset_id.0).ok_or(Error::<T>::AssetInfoNotFound)?;
fn get_nft_detail(asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftAssetData<BalanceOf<T>>, DispatchError> {
let asset_info = NftModule::<T>::tokens(asset_id.0, asset_id.1).ok_or(Error::<T>::AssetInfoNotFound)?;

Ok(asset_info.data)
}
Expand Down Expand Up @@ -1820,12 +1820,12 @@ impl<T: Config> NFTMigrationTrait<T::AccountId, BalanceOf<T>> for Pallet<T> {
owner,
owner,
class_id,
Some(token_id),
None,
token_metadata,
token_data.attributes,
token_data.is_locked,
false,
);
)?;
// TODO: Transfer token minting fees back to owner
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion traits/core-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub trait NFTTrait<AccountId, Balance> {
/// Check the ownership of this nft asset
fn check_ownership(who: &AccountId, asset_id: &(Self::ClassId, Self::TokenId)) -> Result<bool, DispatchError>;
/// Get the detail of this nft
fn get_nft_detail(asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftClassData<Balance>, DispatchError>;
fn get_nft_detail(asset_id: (Self::ClassId, Self::TokenId)) -> Result<NftAssetData<Balance>, DispatchError>;
/// Get the detail of this nft
fn get_nft_group_collection(nft_collection: &Self::ClassId) -> Result<GroupCollectionId, DispatchError>;
/// Check if the asset is a stackable NFT
Expand Down

0 comments on commit dff52ad

Please sign in to comment.