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
--- a/pallets/nft/src/eth/mod.rs
+++ b/pallets/nft/src/eth/mod.rs
@@ -103,7 +103,6 @@
 					CollectionMode::ReFungible => {
 						include_bytes!("stubs/UniqueRefungible.raw") as &[u8]
 					}
-					CollectionMode::Invalid => include_bytes!("stubs/UniqueInvalid.raw") as &[u8],
 				}
 				.to_owned()
 			})
deletedpallets/nft/src/eth/stubs/UniqueInvalid.rawdiffbeforeafterboth
--- a/pallets/nft/src/eth/stubs/UniqueInvalid.raw
+++ /dev/null
@@ -1 +0,0 @@
-TODO
\ No newline at end of file
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -1347,7 +1347,6 @@
 				sender.clone(),
 				recipient.clone(),
 			)?,
-			_ => (),
 		};
 
 		Self::deposit_event(RawEvent::Transfer(
@@ -1493,7 +1492,6 @@
 				from.clone(),
 				recipient.clone(),
 			)?,
-			_ => (),
 		};
 
 		if matches!(collection.mode, CollectionMode::Fungible(_)) {
@@ -1534,7 +1532,6 @@
 				Self::set_re_fungible_variable_data(collection, item_id, data)?
 			}
 			CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),
-			_ => fail!(Error::<T>::UnexpectedCollectionType),
 		};
 
 		Ok(())
@@ -1618,7 +1615,6 @@
 			CollectionMode::NFT => Self::burn_nft_item(collection, item_id)?,
 			CollectionMode::Fungible(_) => Self::burn_fungible_item(sender, collection, value)?,
 			CollectionMode::ReFungible => Self::burn_refungible_item(collection, item_id, sender)?,
-			_ => (),
 		};
 
 		Ok(())
@@ -1723,9 +1719,6 @@
 					fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);
 				}
 			}
-			_ => {
-				fail!(Error::<T>::UnexpectedCollectionType);
-			}
 		};
 
 		Ok(())
@@ -2034,7 +2027,6 @@
 				.iter()
 				.find(|i| i.owner == *subject)
 				.map(|i| i.fraction),
-			CollectionMode::Invalid => None,
 		}
 	}
 
@@ -2071,7 +2063,6 @@
 			CollectionMode::ReFungible => {
 				<ReFungibleItemList<T>>::contains_key(collection_id, item_id)
 			}
-			_ => false,
 		};
 
 		ensure!(exists, Error::<T>::TokenNotFound);
modifiedpallets/nft/src/sponsorship.rsdiffbeforeafterboth
--- a/pallets/nft/src/sponsorship.rs
+++ b/pallets/nft/src/sponsorship.rs
@@ -127,7 +127,6 @@
 
 					sponsored
 				}
-				_ => false,
 			};
 		}
 
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -73,23 +73,15 @@
 #[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 pub enum CollectionMode {
-	Invalid,
 	NFT,
 	// decimal points
 	Fungible(DecimalPoints),
 	ReFungible,
-}
-
-impl Default for CollectionMode {
-	fn default() -> Self {
-		Self::Invalid
-	}
 }
 
 impl CollectionMode {
 	pub fn id(&self) -> u8 {
 		match self {
-			CollectionMode::Invalid => 0,
 			CollectionMode::NFT => 1,
 			CollectionMode::Fungible(_) => 2,
 			CollectionMode::ReFungible => 3,
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
before · tests/src/createCollection.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi } from './substrate/substrate-api';9import { createCollectionExpectFailure, createCollectionExpectSuccess } from './util/helpers';1011chai.use(chaiAsPromised);12const expect = chai.expect;1314describe('integration test: ext. createCollection():', () => {15  it('Create new NFT collection', async () => {16    await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});17  });18  it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {19    await createCollectionExpectSuccess({name: 'A'.repeat(64)});20  });21  it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {22    await createCollectionExpectSuccess({description: 'A'.repeat(256)});23  });24  it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {25    await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});26  });27  it('Create new Fungible collection', async () => {28    await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});29  });30  it('Create new ReFungible collection', async () => {31    await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});32  });33});3435describe('(!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 () => {50    await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});51  });52  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {53    await createCollectionExpectFailure({ description: 'A'.repeat(257), mode: { type: 'NFT' }});54  });55  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {56    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});57  });58});
after · tests/src/createCollection.test.ts
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import { default as usingApi } from './substrate/substrate-api';9import { createCollectionExpectFailure, createCollectionExpectSuccess } from './util/helpers';1011chai.use(chaiAsPromised);12const expect = chai.expect;1314describe('integration test: ext. createCollection():', () => {15  it('Create new NFT collection', async () => {16    await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});17  });18  it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {19    await createCollectionExpectSuccess({name: 'A'.repeat(64)});20  });21  it('Create new NFT collection whith collection_description of maximum length (256 bytes)', async () => {22    await createCollectionExpectSuccess({description: 'A'.repeat(256)});23  });24  it('Create new NFT collection whith token_prefix of maximum length (16 bytes)', async () => {25    await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});26  });27  it('Create new Fungible collection', async () => {28    await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});29  });30  it('Create new ReFungible collection', async () => {31    await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});32  });33});3435describe('(!negative test!) integration test: ext. createCollection():', () => {36  it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {37    await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});38  });39  it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {40    await createCollectionExpectFailure({ description: 'A'.repeat(257), mode: { type: 'NFT' }});41  });42  it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {43    await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});44  });45});
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -224,10 +224,6 @@
   return result;
 }
 
-interface Invalid {
-  type: 'Invalid';
-}
-
 interface Nft {
   type: 'NFT';
 }
@@ -241,7 +237,7 @@
   type: 'ReFungible';
 }
 
-type CollectionMode = Nft | Fungible | ReFungible | Invalid;
+type CollectionMode = Nft | Fungible | ReFungible;
 
 export type CreateCollectionParams = {
   mode: CollectionMode,
@@ -275,8 +271,6 @@
       modeprm = { fungible: mode.decimalPoints };
     } else if (mode.type === 'ReFungible') {
       modeprm = { refungible: null };
-    } else if (mode.type === 'Invalid') {
-      modeprm = { invalid: null };
     }
 
     const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);
@@ -317,8 +311,6 @@
     modeprm = { fungible: mode.decimalPoints };
   } else if (mode.type === 'ReFungible') {
     modeprm = { refungible: null };
-  } else if (mode.type === 'Invalid') {
-    modeprm = { invalid: null };
   }
 
   await usingApi(async (api) => {
@@ -528,23 +520,23 @@
 export async function setMetadataUpdatePermissionFlagExpectSuccess(sender: IKeyringPair, collectionId: number, flag: string) {
 
   await usingApi(async (api) => {
-    const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag); 
+    const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);
     const events = await submitTransactionAsync(sender, tx);
     const result = getGenericResult(events);
 
     expect(result.success).to.be.true;
-  }); 
+  });
 }
 
 export async function setMetadataUpdatePermissionFlagExpectFailure(sender: IKeyringPair, collectionId: number, flag: string) {
 
   await usingApi(async (api) => {
-    const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag); 
+    const tx = api.tx.nft.setMetaUpdatePermissionFlag(collectionId, flag);
     const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
     const result = getGenericResult(events);
 
     expect(result.success).to.be.false;
-  }); 
+  });
 }
 
 export async function enableContractSponsoringExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, enable: boolean) {
@@ -576,7 +568,7 @@
     const result = getGenericResult(events);
 
     expect(result.success).to.be.true;
-  }); 
+  });
 }
 
 export async function setTransferFlagExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {
@@ -588,7 +580,7 @@
     const result = getGenericResult(events);
 
     expect(result.success).to.be.false;
-  }); 
+  });
 }
 
 export async function setContractSponsoringRateLimitExpectSuccess(sender: IKeyringPair, contractAddress: AccountId | string, rateLimit: number) {
@@ -833,7 +825,7 @@
     const expectedBlockNumber = blockNumber + blockSchedule;
 
     expect(blockNumber).to.be.greaterThan(0);
-    const transferTx = await api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value); 
+    const transferTx = await api.tx.nft.transfer(normalizeAccountId(recipient.address), collectionId, tokenId, value);
     const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);
 
     await submitTransactionAsync(sender, scheduleTx);
@@ -1004,7 +996,7 @@
 export async function createItemExpectFailure(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = sender.address) {
   await usingApi(async (api) => {
     const tx = api.tx.nft.createItem(collectionId, normalizeAccountId(owner), createMode);
-    
+
     const events = await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;
     const result = getCreateItemResult(events);