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

difftreelog

CORE-386 Fix PR

Trubnikov Sergey2022-06-10parent: #fd95478.patch.diff
in: master

5 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -22,7 +22,10 @@
 pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};
 use pallet_evm_coder_substrate::dispatch_to_evm;
 use sp_std::vec::Vec;
-use up_data_structs::{Property, SponsoringRateLimit, NestingRule, OwnerRestrictedSet, AccessMode};
+use up_data_structs::{
+	Property, SponsoringRateLimit, NestingRule, OwnerRestrictedSet, AccessMode,
+	CollectionPermissions,
+};
 use alloc::format;
 
 use crate::{Pallet, CollectionHandle, Config, CollectionProperties};
@@ -211,10 +214,20 @@
 	#[solidity(rename_selector = "setNesting")]
 	fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {
 		check_is_owner_or_admin(caller, self)?;
-		self.collection.permissions.nesting = Some(match enable {
-			false => NestingRule::Disabled,
-			true => NestingRule::Owner,
-		});
+		let permissions = CollectionPermissions {
+			nesting: Some(match enable {
+				false => NestingRule::Disabled,
+				true => NestingRule::Owner,
+			}),
+			..Default::default()
+		};
+		self.collection.permissions = <Pallet<T>>::clamp_permissions(
+			self.collection.mode.clone(),
+			&self.collection.permissions,
+			permissions,
+		)
+		.map_err(dispatch_to_evm::<T>)?;
+
 		save(self)?;
 		Ok(())
 	}
@@ -237,19 +250,29 @@
 			)));
 		}
 		check_is_owner_or_admin(caller, self)?;
-		self.collection.permissions.nesting = Some(match enable {
-			false => NestingRule::Disabled,
-			true => {
-				let mut bv = OwnerRestrictedSet::new();
-				for i in collections {
-					bv.try_insert(crate::eth::map_eth_to_id(&i).ok_or_else(|| {
-						Error::Revert("Can't convert address into collection id".into())
-					})?)
-					.map_err(|e| Error::Revert(format!("{:?}", e)))?;
+		let permissions = CollectionPermissions {
+			nesting: Some(match enable {
+				false => NestingRule::Disabled,
+				true => {
+					let mut bv = OwnerRestrictedSet::new();
+					for i in collections {
+						bv.try_insert(crate::eth::map_eth_to_id(&i).ok_or_else(|| {
+							Error::Revert("Can't convert address into collection id".into())
+						})?)
+						.map_err(|e| Error::Revert(format!("{:?}", e)))?;
+					}
+					NestingRule::OwnerRestricted(bv)
 				}
-				NestingRule::OwnerRestricted(bv)
-			}
-		});
+			}),
+			..Default::default()
+		};
+		self.collection.permissions = <Pallet<T>>::clamp_permissions(
+			self.collection.mode.clone(),
+			&self.collection.permissions,
+			permissions,
+		)
+		.map_err(dispatch_to_evm::<T>)?;
+		
 		save(self)?;
 		Ok(())
 	}
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -46,6 +46,7 @@
   before(async () => {
     await usingApi(async (api, privateKeyWrapper) => {
       alice = privateKeyWrapper('//Alice');
+      bob = privateKeyWrapper('//Bob');
       collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
     });
   });
@@ -115,6 +116,21 @@
     });
   });
 
+  it('execute setCollectionLimits from admin collection', async () => {
+    await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
+    await usingApi(async (api: ApiPromise) => {
+      tx = api.tx.unique.setCollectionLimits(
+        collectionIdForTesting,
+        {
+          accountTokenOwnershipLimit,
+          sponsoredDataSize,
+          // sponsoredMintSize,
+          tokenLimit,
+        },
+      );
+      await expect(submitTransactionAsync(bob, tx)).to.be.not.rejected;
+    });
+  });
 });
 
 describe('setCollectionLimits negative', () => {
@@ -143,21 +159,6 @@
     });
   });
   it('execute setCollectionLimits from user who is not owner of this collection', async () => {
-    await usingApi(async (api: ApiPromise) => {
-      tx = api.tx.unique.setCollectionLimits(
-        collectionIdForTesting,
-        {
-          accountTokenOwnershipLimit,
-          sponsoredDataSize,
-          // sponsoredMintSize,
-          tokenLimit,
-        },
-      );
-      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
-    });
-  });
-  it('execute setCollectionLimits from admin collection', async () => {
-    await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
     await usingApi(async (api: ApiPromise) => {
       tx = api.tx.unique.setCollectionLimits(
         collectionIdForTesting,
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
before · tests/src/setCollectionSponsor.test.ts
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import chai from 'chai';18import chaiAsPromised from 'chai-as-promised';19import {default as usingApi} from './substrate/substrate-api';20import {createCollectionExpectSuccess,21  setCollectionSponsorExpectSuccess,22  destroyCollectionExpectSuccess,23  setCollectionSponsorExpectFailure,24  addCollectionAdminExpectSuccess,25  getCreatedCollectionCount,26} from './util/helpers';27import {IKeyringPair} from '@polkadot/types/types';2829chai.use(chaiAsPromised);3031let alice: IKeyringPair;32let bob: IKeyringPair;33let charlie: IKeyringPair;3435describe('integration test: ext. setCollectionSponsor():', () => {3637  before(async () => {38    await usingApi(async (api, privateKeyWrapper) => {39      alice = privateKeyWrapper('//Alice');40      bob = privateKeyWrapper('//Bob');41      charlie = privateKeyWrapper('//Charlie');42    });43  });4445  it('Set NFT collection sponsor', async () => {46    const collectionId = await createCollectionExpectSuccess();47    await setCollectionSponsorExpectSuccess(collectionId, bob.address);48  });49  it('Set Fungible collection sponsor', async () => {50    const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});51    await setCollectionSponsorExpectSuccess(collectionId, bob.address);52  });53  it('Set ReFungible collection sponsor', async () => {54    const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});55    await setCollectionSponsorExpectSuccess(collectionId, bob.address);56  });5758  it('Set the same sponsor repeatedly', async () => {59    const collectionId = await createCollectionExpectSuccess();60    await setCollectionSponsorExpectSuccess(collectionId, bob.address);61    await setCollectionSponsorExpectSuccess(collectionId, bob.address);62  });63  it('Replace collection sponsor', async () => {64    const collectionId = await createCollectionExpectSuccess();65    await setCollectionSponsorExpectSuccess(collectionId, bob.address);66    await setCollectionSponsorExpectSuccess(collectionId, charlie.address);67  });68});6970describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {71  before(async () => {72    await usingApi(async (api, privateKeyWrapper) => {73      alice = privateKeyWrapper('//Alice');74      bob = privateKeyWrapper('//Bob');75      charlie = privateKeyWrapper('//Charlie');76    });77  });7879  it('(!negative test!) Add sponsor with a non-owner', async () => {80    const collectionId = await createCollectionExpectSuccess();81    await setCollectionSponsorExpectFailure(collectionId, bob.address, '//Bob');82  });83  it('(!negative test!) Add sponsor to a collection that never existed', async () => {84    // Find the collection that never existed85    let collectionId = 0;86    await usingApi(async (api) => {87      collectionId = await getCreatedCollectionCount(api) + 1;88    });8990    await setCollectionSponsorExpectFailure(collectionId, bob.address);91  });92  it('(!negative test!) Add sponsor to a collection that was destroyed', async () => {93    const collectionId = await createCollectionExpectSuccess();94    await destroyCollectionExpectSuccess(collectionId);95    await setCollectionSponsorExpectFailure(collectionId, bob.address);96  });97  it('(!negative test!) Collection admin add sponsor', async () => {98    const collectionId = await createCollectionExpectSuccess();99    await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);100    await setCollectionSponsorExpectFailure(collectionId, charlie.address, '//Bob');101  });102});
modifiedtests/src/setMintPermission.test.tsdiffbeforeafterboth
--- a/tests/src/setMintPermission.test.ts
+++ b/tests/src/setMintPermission.test.ts
@@ -67,6 +67,14 @@
       await setMintPermissionExpectSuccess(alice, collectionId, false);
     });
   });
+
+  it('Collection admin success on set', async () => {
+    await usingApi(async () => {
+      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
+      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
+      await setMintPermissionExpectSuccess(bob, collectionId, true);
+    });
+  });
 });
 
 describe('Negative Integration Test setMintPermission', () => {
@@ -100,14 +108,6 @@
     const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
     await enableAllowListExpectSuccess(alice, collectionId);
     await setMintPermissionExpectFailure(bob, collectionId, true);
-  });
-
-  it('Collection admin fails on set', async () => {
-    await usingApi(async () => {
-      const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
-      await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
-      await setMintPermissionExpectFailure(bob, collectionId, true);
-    });
   });
 
   it('ensure non-allow-listed non-privileged address can\'t mint tokens', async () => {
modifiedtests/src/setPublicAccessMode.test.tsdiffbeforeafterboth
--- a/tests/src/setPublicAccessMode.test.ts
+++ b/tests/src/setPublicAccessMode.test.ts
@@ -103,22 +103,23 @@
       await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
     });
   });
-});
 
-describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {
-  before(async () => {
-    await usingApi(async (api, privateKeyWrapper) => {
-      alice = privateKeyWrapper('//Alice');
-      bob = privateKeyWrapper('//Bob');
-    });
-  });
   it('setPublicAccessMode by collection admin', async () => {
     await usingApi(async (api: ApiPromise) => {
       // tslint:disable-next-line: no-bitwise
       const collectionId = await createCollectionExpectSuccess();
       await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
       const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: 'AllowList'});
-      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
+      await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.not.rejected;
+    });
+  });
+});
+
+describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {
+  before(async () => {
+    await usingApi(async (api, privateKeyWrapper) => {
+      alice = privateKeyWrapper('//Alice');
+      bob = privateKeyWrapper('//Bob');
     });
   });
 });