difftreelog
add amount to approveToken in unique playgrounds
in: master
2 files changed
tests/src/approve.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {ApiPromise} from '@polkadot/api';19import chai from 'chai';18import chai from 'chai';20import chaiAsPromised from 'chai-as-promised';19import chaiAsPromised from 'chai-as-promised';21import {default as usingApi} from './substrate/substrate-api';22import {20import {23 approveExpectFail,21 approveExpectFail,24 approveExpectSuccess,22 approveExpectSuccess,25 createCollectionExpectSuccess,23 createCollectionExpectSuccess,26 createItemExpectSuccess,24 createItemExpectSuccess,27 destroyCollectionExpectSuccess,28 setCollectionLimitsExpectSuccess,29 transferExpectSuccess,30 addCollectionAdminExpectSuccess,31 adminApproveFromExpectFail,32 getCreatedCollectionCount,33 transferFromExpectSuccess,34 transferFromExpectFail,35 requirePallets,36 Pallets,37} from './util/helpers';25} from './util/helpers';38import { usingPlaygrounds } from './util/playgrounds';26import {usingPlaygrounds} from './util/playgrounds';392740let donor: IKeyringPair;28let donor: IKeyringPair;412942before(async () => {30before(async () => {43 await usingPlaygrounds(async (_, privateKeyWrapper) => {31 await usingPlaygrounds(async (_, privateKey) => {44 donor = privateKeyWrapper('//Alice');32 donor = privateKey('//Alice');45 });33 });46});34});473595 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});83 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});96 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});84 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});97 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;85 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;98 await helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0).signAndSend(alice);86 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 0n);99 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;87 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;100 });88 });101 });89 });333 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});321 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});334 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});322 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});335 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;323 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;336 await helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0).signAndSend(alice);324 await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address}, undefined, 0n);337 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;325 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;338 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});326 const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});339 await expect(transferTokenFromTx()).to.be.rejected;327 await expect(transferTokenFromTx()).to.be.rejected;391 await usingPlaygrounds(async (helper) => {379 await usingPlaygrounds(async (helper) => {392 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});380 const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});393 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});381 const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});394 await helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2).signAndSend(bob);382 const approveTx = async () => helper.nft.approveToken(bob, collectionId, tokenId, {Substrate: charlie.address}, undefined, 2n);383 await expect(approveTx()).to.be.rejected;395 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;384 expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;396 });385 });397 });386 });tests/src/util/playgrounds/unique.tsdiffbeforeafterboth1419 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1419 * @example approveToken(aliceKeyring, 10, 5, {Substrate: "5DyN4Y92vZCjv38fg..."})1420 * @returns ```true``` if extrinsic success, otherwise ```false```1420 * @returns ```true``` if extrinsic success, otherwise ```false```1421 */1421 */1422 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string) {1422 async approveToken(signer: IKeyringPair, collectionId: number, tokenId: number, toAddressObj: ICrossAccountId, label?: string, amount=1n) {1423 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, 1n);1423 return super.approveToken(signer, collectionId, tokenId, toAddressObj, label, amount);1424 }1424 }1425}1425}14261426