difftreelog
Merge pull request #90 from usetech-llc/feature/transferfromtests
in: master
transferFrom burnt token before&after approve test
2 files changed
tests/src/transferFrom.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//5import { ApiPromise } from '@polkadot/api';6import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import privateKey from './substrate/privateKey';9import { default as usingApi } from './substrate/substrate-api';10import {11 approveExpectFail,12 approveExpectSuccess,13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 destroyCollectionExpectSuccess,16 transferFromExpectFail,17 transferFromExpectSuccess,18} from './util/helpers';1920chai.use(chaiAsPromised);21const expect = chai.expect;2223describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {24 it('Execute the extrinsic and check nftItemList - owner of token', async () => {25 await usingApi(async (api: ApiPromise) => {26 const Alice = privateKey('//Alice');27 const Bob = privateKey('//Bob');28 const Charlie = privateKey('//Charlie');29 // nft30 const nftCollectionId = await createCollectionExpectSuccess();31 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');32 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);3334 await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');3536 // fungible37 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});38 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');39 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);40 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');41 // reFungible42 const reFungibleCollectionId = await43 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});44 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');45 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob, 100);46 await transferFromExpectSuccess(reFungibleCollectionId,47 newReFungibleTokenId, Bob, Alice, Charlie, 100, 'ReFungible');48 });49 });50});5152describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {53 it('transferFrom for a collection that does not exist', async () => {54 await usingApi(async (api: ApiPromise) => {55 const Alice = privateKey('//Alice');56 const Bob = privateKey('//Bob');57 const Charlie = privateKey('//Charlie');58 // nft59 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;60 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);6162 await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);6364 // fungible65 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;66 await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);6768 await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);69 // reFungible70 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;71 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);7273 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);74 });75 });7677 /* it('transferFrom for a collection that was destroyed', async () => {78 await usingApi(async (api: ApiPromise) => {79 this test copies approve negative test80 });81 }); */8283 /* it('transferFrom a token that does not exist', async () => {84 await usingApi(async (api: ApiPromise) => {85 this test copies approve negative test86 });87 }); */8889 /* it('transferFrom a token that was deleted', async () => {90 await usingApi(async (api: ApiPromise) => {91 this test copies approve negative test92 });93 }); */9495 it('transferFrom for not approved address', async () => {96 await usingApi(async (api: ApiPromise) => {97 const Alice = privateKey('//Alice');98 const Bob = privateKey('//Bob');99 const Charlie = privateKey('//Charlie');100 // nft101 const nftCollectionId = await createCollectionExpectSuccess();102 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');103104 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);105106 // fungible107 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});108 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');109 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);110 // reFungible111 const reFungibleCollectionId = await112 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});113 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');114 await transferFromExpectFail(reFungibleCollectionId,115 newReFungibleTokenId, Bob, Alice, Charlie, 1);116 });117 });118119 it('transferFrom incorrect token count', async () => {120 await usingApi(async (api: ApiPromise) => {121 const Alice = privateKey('//Alice');122 const Bob = privateKey('//Bob');123 const Charlie = privateKey('//Charlie');124 // nft125 const nftCollectionId = await createCollectionExpectSuccess();126 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');127 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);128129 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);130131 // fungible132 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});133 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');134 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);135 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);136 // reFungible137 const reFungibleCollectionId = await138 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});139 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');140 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);141 await transferFromExpectFail(reFungibleCollectionId,142 newReFungibleTokenId, Bob, Alice, Charlie, 2);143 });144 });145146 it('execute transferFrom from account that is not owner of collection', async () => {147 await usingApi(async (api: ApiPromise) => {148 const Alice = privateKey('//Alice');149 const Bob = privateKey('//Bob');150 const Charlie = privateKey('//Charlie');151 const Dave = privateKey('//Dave');152 // nft153 const nftCollectionId = await createCollectionExpectSuccess();154 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');155 try {156 await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);157 await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);158 } catch (e) {159 // tslint:disable-next-line:no-unused-expression160 expect(e).to.be.exist;161 }162163 // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);164165 // fungible166 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});167 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');168 try {169 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);170 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);171 } catch (e) {172 // tslint:disable-next-line:no-unused-expression173 expect(e).to.be.exist;174 }175 // reFungible176 const reFungibleCollectionId = await177 createCollectionExpectSuccess({mode: {type: 'ReFungible'}});178 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');179 try {180 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);181 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);182 } catch (e) {183 // tslint:disable-next-line:no-unused-expression184 expect(e).to.be.exist;185 }186 });187 });188});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -359,6 +359,7 @@
});
}
+
export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
await usingApi(async (api) => {
@@ -505,7 +506,7 @@
export async function
approveExpectSuccess(collectionId: number,
- tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
+ tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) { //alice,bob
await usingApi(async (api: ApiPromise) => {
const allowanceBefore =
await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;
@@ -523,9 +524,9 @@
export async function
transferFromExpectSuccess(collectionId: number,
tokenId: number,
- accountApproved: IKeyringPair,
- accountFrom: IKeyringPair,
- accountTo: IKeyringPair,
+ accountApproved: IKeyringPair, //bob
+ accountFrom: IKeyringPair, //alice
+ accountTo: IKeyringPair, //charlie
value: number = 1,
type: string = 'NFT') {
await usingApi(async (api: ApiPromise) => {