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
--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -33,19 +33,6 @@
 });
 
 describe('(!negative test!) integration test: ext. createCollection():', () => {
-  it('(!negative test!) create new NFT collection whith incorrect data (mode)', async () => {
-    await usingApi(async (api) => {
-      const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
-
-      const badTransaction = async () => {
-        await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
-      };
-      await expect(badTransaction()).to.be.rejected;
-
-      const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
-      expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Incorrect collection created.');
-    });
-  });
   it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {
     await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});
   });
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