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
23use pallet_evm_coder_substrate::dispatch_to_evm;23use pallet_evm_coder_substrate::dispatch_to_evm;
24use sp_std::vec::Vec;24use sp_std::vec::Vec;
25use up_data_structs::{Property, SponsoringRateLimit, NestingRule, OwnerRestrictedSet, AccessMode};25use up_data_structs::{
26 Property, SponsoringRateLimit, NestingRule, OwnerRestrictedSet, AccessMode,
27 CollectionPermissions,
28};
26use alloc::format;29use alloc::format;
2730
211 #[solidity(rename_selector = "setNesting")]214 #[solidity(rename_selector = "setNesting")]
212 fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {215 fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {
213 check_is_owner_or_admin(caller, self)?;216 check_is_owner_or_admin(caller, self)?;
214 self.collection.permissions.nesting = Some(match enable {217 let permissions = CollectionPermissions {
218 nesting: Some(match enable {
215 false => NestingRule::Disabled,219 false => NestingRule::Disabled,
216 true => NestingRule::Owner,220 true => NestingRule::Owner,
217 });221 }),
222 ..Default::default()
223 };
224 self.collection.permissions = <Pallet<T>>::clamp_permissions(
225 self.collection.mode.clone(),
226 &self.collection.permissions,
227 permissions,
228 )
229 .map_err(dispatch_to_evm::<T>)?;
230
218 save(self)?;231 save(self)?;
219 Ok(())232 Ok(())
237 )));250 )));
238 }251 }
239 check_is_owner_or_admin(caller, self)?;252 check_is_owner_or_admin(caller, self)?;
240 self.collection.permissions.nesting = Some(match enable {253 let permissions = CollectionPermissions {
254 nesting: Some(match enable {
241 false => NestingRule::Disabled,255 false => NestingRule::Disabled,
242 true => {256 true => {
243 let mut bv = OwnerRestrictedSet::new();257 let mut bv = OwnerRestrictedSet::new();
249 }263 }
250 NestingRule::OwnerRestricted(bv)264 NestingRule::OwnerRestricted(bv)
251 }265 }
252 });266 }),
267 ..Default::default()
268 };
269 self.collection.permissions = <Pallet<T>>::clamp_permissions(
270 self.collection.mode.clone(),
271 &self.collection.permissions,
272 permissions,
273 )
274 .map_err(dispatch_to_evm::<T>)?;
275
253 save(self)?;276 save(self)?;
254 Ok(())277 Ok(())
modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
46 before(async () => {46 before(async () => {
47 await usingApi(async (api, privateKeyWrapper) => {47 await usingApi(async (api, privateKeyWrapper) => {
48 alice = privateKeyWrapper('//Alice');48 alice = privateKeyWrapper('//Alice');
49 bob = privateKeyWrapper('//Bob');
49 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});50 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
50 });51 });
51 });52 });
115 });116 });
116 });117 });
117118
119 it('execute setCollectionLimits from admin collection', async () => {
120 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
121 await usingApi(async (api: ApiPromise) => {
122 tx = api.tx.unique.setCollectionLimits(
123 collectionIdForTesting,
124 {
125 accountTokenOwnershipLimit,
126 sponsoredDataSize,
127 // sponsoredMintSize,
128 tokenLimit,
129 },
130 );
131 await expect(submitTransactionAsync(bob, tx)).to.be.not.rejected;
132 });
133 });
118});134});
119135
120describe('setCollectionLimits negative', () => {136describe('setCollectionLimits negative', () => {
156 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;172 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
157 });173 });
158 });174 });
159 it('execute setCollectionLimits from admin collection', async () => {
160 await addCollectionAdminExpectSuccess(alice, collectionIdForTesting, bob.address);
161 await usingApi(async (api: ApiPromise) => {
162 tx = api.tx.unique.setCollectionLimits(
163 collectionIdForTesting,
164 {
165 accountTokenOwnershipLimit,
166 sponsoredDataSize,
167 // sponsoredMintSize,
168 tokenLimit,
169 },
170 );
171 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
172 });
173 });
174175
175 it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {176 it('fails when trying to enable OwnerCanTransfer after it was disabled', async () => {
176 const collectionId = await createCollectionExpectSuccess();177 const collectionId = await createCollectionExpectSuccess();
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
65 await setCollectionSponsorExpectSuccess(collectionId, bob.address);65 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
66 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);66 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
67 });67 });
68 it('Collection admin add sponsor', async () => {
69 const collectionId = await createCollectionExpectSuccess();
70 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
71 await setCollectionSponsorExpectSuccess(collectionId, charlie.address, '//Bob');
72 });
68});73});
6974
70describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {75describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
94 await destroyCollectionExpectSuccess(collectionId);99 await destroyCollectionExpectSuccess(collectionId);
95 await setCollectionSponsorExpectFailure(collectionId, bob.address);100 await setCollectionSponsorExpectFailure(collectionId, bob.address);
96 });101 });
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});102});
103103
modifiedtests/src/setMintPermission.test.tsdiffbeforeafterboth
68 });68 });
69 });69 });
70
71 it('Collection admin success on set', async () => {
72 await usingApi(async () => {
73 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
74 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
75 await setMintPermissionExpectSuccess(bob, collectionId, true);
76 });
77 });
70});78});
7179
72describe('Negative Integration Test setMintPermission', () => {80describe('Negative Integration Test setMintPermission', () => {
102 await setMintPermissionExpectFailure(bob, collectionId, true);110 await setMintPermissionExpectFailure(bob, collectionId, true);
103 });111 });
104
105 it('Collection admin fails on set', async () => {
106 await usingApi(async () => {
107 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
108 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
109 await setMintPermissionExpectFailure(bob, collectionId, true);
110 });
111 });
112112
113 it('ensure non-allow-listed non-privileged address can\'t mint tokens', async () => {113 it('ensure non-allow-listed non-privileged address can\'t mint tokens', async () => {
114 await usingApi(async () => {114 await usingApi(async () => {
modifiedtests/src/setPublicAccessMode.test.tsdiffbeforeafterboth
104 });104 });
105 });105 });
106
107 it('setPublicAccessMode by collection admin', async () => {
108 await usingApi(async (api: ApiPromise) => {
109 // tslint:disable-next-line: no-bitwise
110 const collectionId = await createCollectionExpectSuccess();
111 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
112 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: 'AllowList'});
113 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.not.rejected;
114 });
115 });
106});116});
107117
108describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {118describe('Negative Integration Test ext. collection admin setPublicAccessMode(): ', () => {
112 bob = privateKeyWrapper('//Bob');122 bob = privateKeyWrapper('//Bob');
113 });123 });
114 });124 });
115 it('setPublicAccessMode by collection admin', async () => {
116 await usingApi(async (api: ApiPromise) => {
117 // tslint:disable-next-line: no-bitwise
118 const collectionId = await createCollectionExpectSuccess();
119 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
120 const tx = api.tx.unique.setCollectionPermissions(collectionId, {access: 'AllowList'});
121 await expect(submitTransactionExpectFailAsync(bob, tx)).to.be.rejected;
122 });
123 });
124});125});
125126