difftreelog
fix account token ownership limit when transfer (#1080)
in: master
* fix: account token ownership limit when mint * fix: limit tests * fix: account token ownership limit rft mint * Revert "fix: account token ownership limit rft mint" This reverts commit 054110e015fd237fed77be1ef21bba6cea13fbea. * Revert "fix: limit tests" This reverts commit 75699574656bb0a34caddf3c9abdbffef79ba85d. * Revert "fix: account token ownership limit when mint" This reverts commit b89a3c86d3bf0888a636bc7da1949affa12d867d. * fix: account token ownership limit when transfer * test: account token ownership transfer tests ---------
3 files changed
js-packages/tests/limits.test.tsdiffbeforeafterboth191920describe('Number of tokens per address (NFT)', () => {20describe('Number of tokens per address (NFT)', () => {21 let alice: IKeyringPair;21 let alice: IKeyringPair;22 let bob: IKeyringPair;222323 before(async () => {24 before(async () => {24 await usingPlaygrounds(async (helper, privateKey) => {25 await usingPlaygrounds(async (helper, privateKey) => {25 const donor = await privateKey({url: import.meta.url});26 const donor = await privateKey({url: import.meta.url});26 [alice] = await helper.arrange.createAccounts([10n], donor);27 [alice, bob] = await helper.arrange.createAccounts([10n, 0n], donor);27 });28 });28 });29 });293052 await expect(collection.burn(alice)).to.be.not.rejected;53 await expect(collection.burn(alice)).to.be.not.rejected;53 });54 });5556 itSub('Can transfer tokens to address equal to accountTokenOwnershipLimit', async ({helper}) => {57 const collection = await helper.nft.mintCollection(alice, {});58 await collection.setLimits(alice, {accountTokenOwnershipLimit: 1});5960 // Limit 1 - can transfer #1 token61 const tkn1 = await collection.mintToken(alice);62 await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address});6364 // Limit 1 - cannot transfer #2 token65 const tkn2 = await collection.mintToken(alice);66 await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);6768 // Increase limit to 269 // Now can transfer token #270 await collection.setLimits(alice, {accountTokenOwnershipLimit: 2});71 await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address});7273 // But cannot transfer token #374 const tkn3 = await collection.mintToken(alice);75 await expect(collection.transferToken(alice, tkn3.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);76 });54});77});557856describe('Number of tokens per address (ReFungible)', () => {79describe('Number of tokens per address (ReFungible)', () => {57 let alice: IKeyringPair;80 let alice: IKeyringPair;81 let bob: IKeyringPair;588259 before(async function() {83 before(async function() {60 await usingPlaygrounds(async (helper, privateKey) => {84 await usingPlaygrounds(async (helper, privateKey) => {61 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);85 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);628663 const donor = await privateKey({url: import.meta.url});87 const donor = await privateKey({url: import.meta.url});64 [alice] = await helper.arrange.createAccounts([10n], donor);88 [alice, bob] = await helper.arrange.createAccounts([10n, 0n], donor);65 });89 });66 });90 });679190 await expect(collection.burn(alice)).to.be.not.rejected;114 await expect(collection.burn(alice)).to.be.not.rejected;91 });115 });116117 itSub('Can transfer tokens to address equal to accountTokenOwnershipLimit', async ({helper}) => {118 const collection = await helper.rft.mintCollection(alice, {});119 await collection.setLimits(alice, {accountTokenOwnershipLimit: 1});120121 // Limit 1 - can transfer #1 token122 const tkn1 = await collection.mintToken(alice);123 await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address});124125 // Limit 1 - cannot transfer #2 token126 const tkn2 = await collection.mintToken(alice);127 await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);128129 // Increase limit to 2130 // Now can transfer token #2131 await collection.setLimits(alice, {accountTokenOwnershipLimit: 2});132 await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address});133134 // But cannot transfer token #3135 const tkn3 = await collection.mintToken(alice);136 await expect(collection.transferToken(alice, tkn3.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);137 });92});138});9313994// todo:playgrounds skipped ~ postponed140// todo:playgrounds skipped ~ postponedpallets/nonfungible/src/lib.rsdiffbeforeafterboth746 .ok_or(ArithmeticError::Overflow)?;746 .ok_or(ArithmeticError::Overflow)?;747747748 ensure!(748 ensure!(749 balance_to < collection.limits.account_token_ownership_limit(),749 balance_to <= collection.limits.account_token_ownership_limit(),750 <CommonError<T>>::AccountTokenLimitExceeded,750 <CommonError<T>>::AccountTokenLimitExceeded,751 );751 );752752pallets/refungible/src/lib.rsdiffbeforeafterboth679 .checked_add(1)679 .checked_add(1)680 .ok_or(ArithmeticError::Overflow)?;680 .ok_or(ArithmeticError::Overflow)?;681 ensure!(681 ensure!(682 account_balance_to < collection.limits.account_token_ownership_limit(),682 account_balance_to <= collection.limits.account_token_ownership_limit(),683 <CommonError<T>>::AccountTokenLimitExceeded,683 <CommonError<T>>::AccountTokenLimitExceeded,684 );684 );685685