git.delta.rocks / unique-network / refs/commits / 0ceea0af66a9

difftreelog

fix account token ownership limit when transfer (#1080)

Daniel Shiposha2024-06-25parent: #347f218.patch.diff
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

modifiedjs-packages/tests/limits.test.tsdiffbeforeafterboth
1919
20describe('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;
2223
23 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 });
2930
52 await expect(collection.burn(alice)).to.be.not.rejected;53 await expect(collection.burn(alice)).to.be.not.rejected;
53 });54 });
55
56 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});
59
60 // Limit 1 - can transfer #1 token
61 const tkn1 = await collection.mintToken(alice);
62 await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address});
63
64 // Limit 1 - cannot transfer #2 token
65 const tkn2 = await collection.mintToken(alice);
66 await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);
67
68 // Increase limit to 2
69 // Now can transfer token #2
70 await collection.setLimits(alice, {accountTokenOwnershipLimit: 2});
71 await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address});
72
73 // But cannot transfer token #3
74 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});
5578
56describe('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;
5882
59 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]);
6286
63 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 });
6791
90 await expect(collection.burn(alice)).to.be.not.rejected;114 await expect(collection.burn(alice)).to.be.not.rejected;
91 });115 });
116
117 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});
120
121 // Limit 1 - can transfer #1 token
122 const tkn1 = await collection.mintToken(alice);
123 await collection.transferToken(alice, tkn1.tokenId, {Substrate: bob.address});
124
125 // Limit 1 - cannot transfer #2 token
126 const tkn2 = await collection.mintToken(alice);
127 await expect(collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address})).to.be.rejectedWith(/common\.AccountTokenLimitExceeded/);
128
129 // Increase limit to 2
130 // Now can transfer token #2
131 await collection.setLimits(alice, {accountTokenOwnershipLimit: 2});
132 await collection.transferToken(alice, tkn2.tokenId, {Substrate: bob.address});
133
134 // But cannot transfer token #3
135 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});
93139
94// todo:playgrounds skipped ~ postponed140// todo:playgrounds skipped ~ postponed
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
746 .ok_or(ArithmeticError::Overflow)?;746 .ok_or(ArithmeticError::Overflow)?;
747747
748 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 );
752752
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
679 .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