difftreelog
CORE-386 Fix create item with public minting
in: master
4 files changed
pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -223,7 +223,7 @@
let weight = <CommonWeights<T>>::set_token_properties(properties.len() as u32);
with_weight(
- <Pallet<T>>::set_token_properties(self, &sender, token_id, properties),
+ <Pallet<T>>::set_token_properties(self, &sender, token_id, properties, false),
weight,
)
}
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -82,7 +82,7 @@
.map_err(|_| "key too long")?;
let value = value.try_into().map_err(|_| "value too long")?;
- <Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value })
+ <Pallet<T>>::set_token_property(self, &caller, TokenId(token_id), Property { key, value }, false)
.map_err(dispatch_to_evm::<T>)
}
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -447,8 +447,9 @@
sender: &T::CrossAccountId,
token_id: TokenId,
property: Property,
+ is_token_create: bool,
) -> DispatchResult {
- Self::check_token_change_permission(collection, sender, token_id, &property.key)?;
+ Self::check_token_change_permission(collection, sender, token_id, &property.key, is_token_create)?;
<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
let property = property.clone();
@@ -471,9 +472,10 @@
sender: &T::CrossAccountId,
token_id: TokenId,
properties: Vec<Property>,
+ is_token_create: bool,
) -> DispatchResult {
for property in properties {
- Self::set_token_property(collection, sender, token_id, property)?;
+ Self::set_token_property(collection, sender, token_id, property, is_token_create)?;
}
Ok(())
@@ -485,7 +487,7 @@
token_id: TokenId,
property_key: PropertyKey,
) -> DispatchResult {
- Self::check_token_change_permission(collection, sender, token_id, &property_key)?;
+ Self::check_token_change_permission(collection, sender, token_id, &property_key, false)?;
<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
properties.remove(&property_key)
@@ -506,6 +508,7 @@
sender: &T::CrossAccountId,
token_id: TokenId,
property_key: &PropertyKey,
+ is_token_create: bool,
) -> DispatchResult {
let permission = <PalletCommon<T>>::property_permissions(collection.id)
.get(property_key)
@@ -534,6 +537,10 @@
token_owner,
..
} => {
+ if is_token_create && (collection_admin || token_owner) {
+ return Ok(());
+ }
+
let mut check_result = Err(<CommonError<T>>::NoPermission.into());
if collection_admin {
@@ -772,6 +779,7 @@
sender,
TokenId(token),
data.properties.clone().into_inner(),
+ true,
) {
return TransactionOutcome::Rollback(Err(e));
}
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}) => {