git.delta.rocks / unique-network / refs/commits / d9e024859529

difftreelog

refactor remove "invalid" collection mode

Yaroslav Bolyukin2021-09-14parent: #d15a825.patch.diff
in: master

7 files changed

modifiedpallets/nft/src/eth/mod.rsdiffbeforeafterboth
103 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 })
deletedpallets/nft/src/eth/stubs/UniqueInvalid.rawdiffbeforeafterboth

no changes

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
1347 sender.clone(),1347 sender.clone(),
1348 recipient.clone(),1348 recipient.clone(),
1349 )?,1349 )?,
1350 _ => (),
1351 };1350 };
13521351
1353 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 };
14981496
1499 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 };
15391536
1540 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 };
16231619
1624 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 };
17301723
1731 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 }
20402032
2071 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 };
20762067
2077 ensure!(exists, Error::<T>::TokenNotFound);2068 ensure!(exists, Error::<T>::TokenNotFound);
modifiedpallets/nft/src/sponsorship.rsdiffbeforeafterboth
127127
128 sponsored128 sponsored
129 }129 }
130 _ => false,
131 };130 };
132 }131 }
133132
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
73#[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 points
79 Fungible(DecimalPoints),78 Fungible(DecimalPoints),
80 ReFungible,79 ReFungible,
81}80}
82
83impl Default for CollectionMode {
84 fn default() -> Self {
85 Self::Invalid
86 }
87}
8881
89impl 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,
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
33});33});
3434
35describe('(!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);
39
40 const badTransaction = async () => {
41 await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
42 };
43 await expect(badTransaction()).to.be.rejected;
44
45 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 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
224 return result;224 return result;
225}225}
226
227interface Invalid {
228 type: 'Invalid';
229}
230226
231interface Nft {227interface Nft {
232 type: 'NFT';228 type: 'NFT';
241 type: 'ReFungible';237 type: 'ReFungible';
242}238}
243239
244type CollectionMode = Nft | Fungible | ReFungible | Invalid;240type CollectionMode = Nft | Fungible | ReFungible;
245241
246export 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 }
281275
282 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 }
323315
324 await usingApi(async (api) => {316 await usingApi(async (api) => {
325 // Get number of collections before the transaction317 // Get number of collections before the transaction