git.delta.rocks / unique-network / refs/commits / 4fc0eb51c33a

difftreelog

Merge pull request #90 from usetech-llc/feature/transferfromtests

Greg Zaitsev2021-02-09parents: #337b8d4 #2e2d3bf.patch.diff
in: master
transferFrom burnt token before&after approve test

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
505506
506export async function507export async function
507approveExpectSuccess(collectionId: number,508approveExpectSuccess(collectionId: number,
508 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {509 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) { //alice,bob
509 await usingApi(async (api: ApiPromise) => {510 await usingApi(async (api: ApiPromise) => {
510 const allowanceBefore =511 const allowanceBefore =
511 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;512 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;
523export async function524export async function
524transferFromExpectSuccess(collectionId: number,525transferFromExpectSuccess(collectionId: number,
525 tokenId: number,526 tokenId: number,
526 accountApproved: IKeyringPair,527 accountApproved: IKeyringPair, //bob
527 accountFrom: IKeyringPair,528 accountFrom: IKeyringPair, //alice
528 accountTo: IKeyringPair,529 accountTo: IKeyringPair, //charlie
529 value: number = 1,530 value: number = 1,
530 type: string = 'NFT') {531 type: string = 'NFT') {
531 await usingApi(async (api: ApiPromise) => {532 await usingApi(async (api: ApiPromise) => {