difftreelog
CORE-386 Fix create item with public minting
in: master
4 files changed
pallets/nonfungible/src/common.rsdiffbeforeafterboth223 let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);223 let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);224224225 with_weight(225 with_weight(226 <Pallet<T>>::set_token_properties(self, &sender, token_id, properties),226 <Pallet<T>>::set_token_properties(self, &sender, token_id, properties, false),227 weight,227 weight,228 )228 )229 }229 }pallets/nonfungible/src/erc.rsdiffbeforeafterboth82 .map_err(|_| "key too long")?;82 .map_err(|_| "key too long")?;83 let value = value.try_into().map_err(|_| "value too long")?;83 let value = value.try_into().map_err(|_| "value too long")?;848485 <Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value })85 <Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value }, false)86 .map_err(dispatch_to_evm::<T>)86 .map_err(dispatch_to_evm::<T>)87 }87 }8888pallets/nonfungible/src/lib.rsdiffbeforeafterboth447 sender: &T::CrossAccountId,447 sender: &T::CrossAccountId,448 token_id: TokenId,448 token_id: TokenId,449 property: Property,449 property: Property,450 is_token_create: bool,450 ) -> DispatchResult {451 ) -> DispatchResult {451 Self::check_token_change_permission(collection, sender, token_id, &property.key)?;452 Self::check_token_change_permission(collection, sender, token_id, &property.key, is_token_create)?;452453453 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {454 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {454 let property = property.clone();455 let property = property.clone();471 sender: &T::CrossAccountId,472 sender: &T::CrossAccountId,472 token_id: TokenId,473 token_id: TokenId,473 properties: Vec<Property>,474 properties: Vec<Property>,475 is_token_create: bool,474 ) -> DispatchResult {476 ) -> DispatchResult {475 for property in properties {477 for property in properties {476 Self::set_token_property(collection, sender, token_id, property)?;478 Self::set_token_property(collection, sender, token_id, property, is_token_create)?;477 }479 }478480479 Ok(())481 Ok(())485 token_id: TokenId,487 token_id: TokenId,486 property_key: PropertyKey,488 property_key: PropertyKey,487 ) -> DispatchResult {489 ) -> DispatchResult {488 Self::check_token_change_permission(collection, sender, token_id, &property_key)?;490 Self::check_token_change_permission(collection, sender, token_id, &property_key, false)?;489491490 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {492 <TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {491 properties.remove(&property_key)493 properties.remove(&property_key)506 sender: &T::CrossAccountId,508 sender: &T::CrossAccountId,507 token_id: TokenId,509 token_id: TokenId,508 property_key: &PropertyKey,510 property_key: &PropertyKey,511 is_token_create: bool,509 ) -> DispatchResult {512 ) -> DispatchResult {510 let permission = <PalletCommon<T>>::property_permissions(collection.id)513 let permission = <PalletCommon<T>>::property_permissions(collection.id)511 .get(property_key)514 .get(property_key)534 token_owner,537 token_owner,535 ..538 ..536 } => {539 } => {540 if is_token_create && (collection_admin || token_owner) {541 return Ok(());542 }543537 let mut check_result = Err(<CommonError<T>>::NoPermission.into());544 let mut check_result = Err(<CommonError<T>>::NoPermission.into());538545772 sender,779 sender,773 TokenId(token),780 TokenId(token),774 data.properties.clone().into_inner(),781 data.properties.clone().into_inner(),782 true,775 ) {783 ) {776 return TransactionOutcome::Rollback(Err(e));784 return TransactionOutcome::Rollback(Err(e));777 }785 }tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth221 expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');221 expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');222 });222 });223223224 //TODO: CORE-302 add eth methods225 itWeb3.skip('Sponsoring collection from evm address via access list', async ({api, web3}) => {224 itWeb3('Sponsoring collection from evm address via access list', async ({api, web3}) => {226 const owner = await createEthAccountWithBalance(api, web3);225 const owner = await createEthAccountWithBalance(api, web3);227 const collectionHelpers = evmCollectionHelpers(web3, owner);226 const collectionHelpers = evmCollectionHelpers(web3, owner);228 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();227 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();229 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);228 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);230 const sponsor = await createEthAccountWithBalance(api, web3);229 const sponsor = await createEthAccountWithBalance(api, web3);231 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);230 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);232 result = await collectionEvm.methods.ethSetSponsor(sponsor).send({from: owner});231 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});233 let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;232 let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;234 expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;233 expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;235 expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));234 expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));236 await expect(collectionEvm.methods.ethConfirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');235 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');237236238 await collectionEvm.methods.ethConfirmSponsorship().send({from: sponsor});237 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});239 collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;238 collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;240 expect(collectionSub.sponsorship.isConfirmed).to.be.true;239 expect(collectionSub.sponsorship.isConfirmed).to.be.true;241 expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));240 expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));242241243 const user = createEthAccount(web3);242 const user = createEthAccount(web3);244 const nextTokenId = await collectionEvm.methods.nextTokenId().call();243 let nextTokenId = await collectionEvm.methods.nextTokenId().call();245 expect(nextTokenId).to.be.equal('1');244 expect(nextTokenId).to.be.equal('1');246245247 const oldPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();246 const oldPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();248 expect(oldPermissions.mintMode).to.be.false;247 expect(oldPermissions.mintMode).to.be.false;249 expect(oldPermissions.access).to.be.equal('Normal');248 expect(oldPermissions.access).to.be.equal('Normal');250249251 await collectionEvm.methods.setAccess('AllowList').send({from: owner});250 await collectionEvm.methods.setCollectionAccess('AllowList').send({from: owner});252 await collectionEvm.methods.addToAllowList(user).send({from: owner});251 await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});253 await collectionEvm.methods.setMintMode(true).send({from: owner});252 await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});254253255 const newPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();254 const newPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();256 expect(newPermissions.mintMode).to.be.true;255 expect(newPermissions.mintMode).to.be.true;257 expect(newPermissions.access).to.be.equal('AllowList');256 expect(newPermissions.access).to.be.equal('AllowList');258257259 // const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);260261 {262 const nextTokenId = await collectionEvm.methods.nextTokenId().call();258 const ownerBalanceBefore = await ethBalanceViaSub(api, owner);259 const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);260261 nextTokenId = await collectionEvm.methods.nextTokenId().call({from: user});263 expect(nextTokenId).to.be.equal('1');262 expect(nextTokenId).to.be.equal('1');264 const result = await collectionEvm.methods.mintWithTokenURI(263 result = await collectionEvm.methods.mintWithTokenURI(265 user,264 user,266 nextTokenId,265 nextTokenId,267 'Test URI',266 'Test URI',268 ).call({from: user});267 ).send({from: user});269 console.log(result);270 const events = normalizeEvents(result.events);268 const events = normalizeEvents(result.events);269 events[0].address = events[0].address.toLocaleLowerCase();271270272 expect(events).to.be.deep.equal([271 expect(events).to.be.deep.equal([273 {272 {274 collectionIdAddress,273 address: collectionIdAddress.toLocaleLowerCase(),275 event: 'Transfer',274 event: 'Transfer',276 args: {275 args: {277 from: '0x0000000000000000000000000000000000000000',276 from: '0x0000000000000000000000000000000000000000',282 ]);281 ]);283282284 expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');283 expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');285 }284285 const ownerBalanceAfter = await ethBalanceViaSub(api, owner);286 expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);287 const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);288 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;286 });289 });287290288 itWeb3('Check that transaction via EVM spend money from sponsor address', async ({api, web3}) => {291 itWeb3('Check that transaction via EVM spend money from sponsor address', async ({api, web3}) => {