difftreelog
refactor remove "invalid" collection mode
in: master
7 files changed
pallets/nft/src/eth/mod.rsdiffbeforeafterboth103 CollectionMode::ReFungible => {103 CollectionMode::ReFungible => {104 include_bytes!("stubs/UniqueRefungible.raw") as &[u8]104 include_bytes!("stubs/UniqueRefungible.raw") as &[u8]105 }105 }106 CollectionMode::Invalid => include_bytes!("stubs/UniqueInvalid.raw") as &[u8],107 }106 }108 .to_owned()107 .to_owned()109 })108 })pallets/nft/src/eth/stubs/UniqueInvalid.rawdiffbeforeafterbothno changes
pallets/nft/src/lib.rsdiffbeforeafterboth1347 sender.clone(),1347 sender.clone(),1348 recipient.clone(),1348 recipient.clone(),1349 )?,1349 )?,1350 _ => (),1351 };1350 };135213511353 Self::deposit_event(RawEvent::Transfer(1352 Self::deposit_event(RawEvent::Transfer(1493 from.clone(),1492 from.clone(),1494 recipient.clone(),1493 recipient.clone(),1495 )?,1494 )?,1496 _ => (),1497 };1495 };149814961499 if matches!(collection.mode, CollectionMode::Fungible(_)) {1497 if matches!(collection.mode, CollectionMode::Fungible(_)) {1534 Self::set_re_fungible_variable_data(collection, item_id, data)?1532 Self::set_re_fungible_variable_data(collection, item_id, data)?1535 }1533 }1536 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1534 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1537 _ => fail!(Error::<T>::UnexpectedCollectionType),1538 };1535 };153915361540 Ok(())1537 Ok(())1618 CollectionMode::NFT => Self::burn_nft_item(collection, item_id)?,1615 CollectionMode::NFT => Self::burn_nft_item(collection, item_id)?,1619 CollectionMode::Fungible(_) => Self::burn_fungible_item(sender, collection, value)?,1616 CollectionMode::Fungible(_) => Self::burn_fungible_item(sender, collection, value)?,1620 CollectionMode::ReFungible => Self::burn_refungible_item(collection, item_id, sender)?,1617 CollectionMode::ReFungible => Self::burn_refungible_item(collection, item_id, sender)?,1621 _ => (),1622 };1618 };162316191624 Ok(())1620 Ok(())1723 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1719 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1724 }1720 }1725 }1721 }1726 _ => {1727 fail!(Error::<T>::UnexpectedCollectionType);1728 }1729 };1722 };173017231731 Ok(())1724 Ok(())2034 .iter()2027 .iter()2035 .find(|i| i.owner == *subject)2028 .find(|i| i.owner == *subject)2036 .map(|i| i.fraction),2029 .map(|i| i.fraction),2037 CollectionMode::Invalid => None,2038 }2030 }2039 }2031 }204020322071 CollectionMode::ReFungible => {2063 CollectionMode::ReFungible => {2072 <ReFungibleItemList<T>>::contains_key(collection_id, item_id)2064 <ReFungibleItemList<T>>::contains_key(collection_id, item_id)2073 }2065 }2074 _ => false,2075 };2066 };207620672077 ensure!(exists, Error::<T>::TokenNotFound);2068 ensure!(exists, Error::<T>::TokenNotFound);pallets/nft/src/sponsorship.rsdiffbeforeafterboth127127128 sponsored128 sponsored129 }129 }130 _ => false,131 };130 };132 }131 }133132primitives/nft/src/lib.rsdiffbeforeafterboth73#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]73#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]74#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]74#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]75pub enum CollectionMode {75pub enum CollectionMode {76 Invalid,77 NFT,76 NFT,78 // decimal points77 // decimal points79 Fungible(DecimalPoints),78 Fungible(DecimalPoints),80 ReFungible,79 ReFungible,81}80}8283impl Default for CollectionMode {84 fn default() -> Self {85 Self::Invalid86 }87}888189impl CollectionMode {82impl CollectionMode {90 pub fn id(&self) -> u8 {83 pub fn id(&self) -> u8 {91 match self {84 match self {92 CollectionMode::Invalid => 0,93 CollectionMode::NFT => 1,85 CollectionMode::NFT => 1,94 CollectionMode::Fungible(_) => 2,86 CollectionMode::Fungible(_) => 2,95 CollectionMode::ReFungible => 3,87 CollectionMode::ReFungible => 3,tests/src/createCollection.test.tsdiffbeforeafterboth33});33});343435describe('(!negative test!) integration test: ext. createCollection():', () => {35describe('(!negative test!) integration test: ext. createCollection():', () => {36 it('(!negative test!) create new NFT collection whith incorrect data (mode)', async () => {37 await usingApi(async (api) => {38 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);3940 const badTransaction = async () => {41 await createCollectionExpectSuccess({mode: {type: 'Invalid'}});42 };43 await expect(badTransaction()).to.be.rejected;4445 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);46 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Incorrect collection created.');47 });48 });49 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {36 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {50 await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});37 await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});51 });38 });tests/src/util/helpers.tsdiffbeforeafterboth224 return result;224 return result;225}225}226227interface Invalid {228 type: 'Invalid';229}230226231interface Nft {227interface Nft {232 type: 'NFT';228 type: 'NFT';241 type: 'ReFungible';237 type: 'ReFungible';242}238}243239244type CollectionMode = Nft | Fungible | ReFungible | Invalid;240type CollectionMode = Nft | Fungible | ReFungible;245241246export type CreateCollectionParams = {242export type CreateCollectionParams = {247 mode: CollectionMode,243 mode: CollectionMode,275 modeprm = { fungible: mode.decimalPoints };271 modeprm = { fungible: mode.decimalPoints };276 } else if (mode.type === 'ReFungible') {272 } else if (mode.type === 'ReFungible') {277 modeprm = { refungible: null };273 modeprm = { refungible: null };278 } else if (mode.type === 'Invalid') {274 }279 modeprm = { invalid: null };280 }281275282 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);276 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);283 const events = await submitTransactionAsync(alicePrivateKey, tx);277 const events = await submitTransactionAsync(alicePrivateKey, tx);317 modeprm = { fungible: mode.decimalPoints };311 modeprm = { fungible: mode.decimalPoints };318 } else if (mode.type === 'ReFungible') {312 } else if (mode.type === 'ReFungible') {319 modeprm = { refungible: null };313 modeprm = { refungible: null };320 } else if (mode.type === 'Invalid') {314 }321 modeprm = { invalid: null };322 }323315324 await usingApi(async (api) => {316 await usingApi(async (api) => {325 // Get number of collections before the transaction317 // Get number of collections before the transaction