git.delta.rocks / unique-network / refs/commits / 31d864f5958b

difftreelog

transferFrom burnt token before&after approve test

Vadim Danilov2021-02-08parent: #0379d3a.patch.diff
in: master

2 files changed

modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
--- a/tests/src/transferFrom.test.ts
+++ b/tests/src/transferFrom.test.ts
@@ -15,6 +15,7 @@
   destroyCollectionExpectSuccess,
   transferFromExpectFail,
   transferFromExpectSuccess,
+  burnItemExpectSuccess,
 } from './util/helpers';
 
 chai.use(chaiAsPromised);
@@ -185,4 +186,83 @@
       }
     });
   });
+  it( 'transferFrom burnt token before approve NFT', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const Charlie = privateKey('//CHARLIE');
+      // nft
+      const nftCollectionId = await createCollectionExpectSuccess();
+      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
+      await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);
+      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      
+    });
+  });
+  it( 'transferFrom burnt token before approve Fungible', async () => {
+    await usingApi(async (api: ApiPromise) => {
+    const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const Charlie = privateKey('//CHARLIE');
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
+      await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
+      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
+          
+    });
+  }); 
+  it( 'transferFrom burnt token before approve ReFungible', async () => {
+    await usingApi(async (api: ApiPromise) => {
+    const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const Charlie = privateKey('//CHARLIE');
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
+      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
+      await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
+      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
+          
+    });
+  });
+  
+  it( 'transferFrom burnt token after approve NFT', async () => {
+    await usingApi(async (api: ApiPromise) => {
+      const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const Charlie = privateKey('//CHARLIE');
+      // nft
+      const nftCollectionId = await createCollectionExpectSuccess();
+      const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+      await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
+      await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
+      await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);      
+    });
+  });
+  it( 'transferFrom burnt token after approve Fungible', async () => {
+    await usingApi(async (api: ApiPromise) => {
+    const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const Charlie = privateKey('//CHARLIE');
+      const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+      const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+      await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
+      await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
+      await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
+          
+    });
+  }); 
+  it( 'transferFrom burnt token after approve ReFungible', async () => {
+    await usingApi(async (api: ApiPromise) => {
+    const Alice = privateKey('//Alice');
+      const Bob = privateKey('//Bob');
+      const Charlie = privateKey('//CHARLIE');
+      const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
+      const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+      await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
+      await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
+      await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
+          
+    });
+  }); 
 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
409410
410export async function411export async function
411approveExpectSuccess(collectionId: number,412approveExpectSuccess(collectionId: number,
412 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {413 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) { //alice,bob
413 await usingApi(async (api: ApiPromise) => {414 await usingApi(async (api: ApiPromise) => {
414 const allowanceBefore =415 const allowanceBefore =
415 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;416 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;
427export async function428export async function
428transferFromExpectSuccess(collectionId: number,429transferFromExpectSuccess(collectionId: number,
429 tokenId: number,430 tokenId: number,
430 accountApproved: IKeyringPair,431 accountApproved: IKeyringPair, //bob
431 accountFrom: IKeyringPair,432 accountFrom: IKeyringPair, //alice
432 accountTo: IKeyringPair,433 accountTo: IKeyringPair, //charlie
433 value: number = 1,434 value: number = 1,
434 type: string = 'NFT') {435 type: string = 'NFT') {
435 await usingApi(async (api: ApiPromise) => {436 await usingApi(async (api: ApiPromise) => {