difftreelog
transferFrom burnt token before&after approve test
in: master
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', decimalPoints: 0}});44 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');45 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);46 await transferFromExpectSuccess(reFungibleCollectionId,47 newReFungibleTokenId, Bob, Alice, Charlie, 1, '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', decimalPoints: 0}});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', decimalPoints: 0}});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', decimalPoints: 0}});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});1//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 burnItemExpectSuccess,19} from './util/helpers';2021chai.use(chaiAsPromised);22const expect = chai.expect;2324describe('Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {25 it('Execute the extrinsic and check nftItemList - owner of token', async () => {26 await usingApi(async (api: ApiPromise) => {27 const Alice = privateKey('//Alice');28 const Bob = privateKey('//Bob');29 const Charlie = privateKey('//CHARLIE');30 // nft31 const nftCollectionId = await createCollectionExpectSuccess();32 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');33 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);3435 await transferFromExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1, 'NFT');3637 // fungible38 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});39 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');40 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);41 await transferFromExpectSuccess(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1, 'Fungible');42 // reFungible43 const reFungibleCollectionId = await44 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});45 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');46 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);47 await transferFromExpectSuccess(reFungibleCollectionId,48 newReFungibleTokenId, Bob, Alice, Charlie, 1, 'ReFungible');49 });50 });51});5253describe('Negative Integration Test transferFrom(from, recipient, collection_id, item_id, value):', () => {54 it('transferFrom for a collection that does not exist', async () => {55 await usingApi(async (api: ApiPromise) => {56 const Alice = privateKey('//Alice');57 const Bob = privateKey('//Bob');58 const Charlie = privateKey('//CHARLIE');59 // nft60 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;61 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);6263 await transferFromExpectFail(nftCollectionCount + 1, 1, Bob, Alice, Charlie, 1);6465 // fungible66 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;67 await approveExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob);6869 await transferFromExpectFail(fungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);70 // reFungible71 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;72 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);7374 await transferFromExpectFail(reFungibleCollectionCount + 1, 1, Bob, Alice, Charlie, 1);75 });76 });7778 /* it('transferFrom for a collection that was destroyed', async () => {79 await usingApi(async (api: ApiPromise) => {80 this test copies approve negative test81 });82 }); */8384 /* it('transferFrom a token that does not exist', async () => {85 await usingApi(async (api: ApiPromise) => {86 this test copies approve negative test87 });88 }); */8990 /* it('transferFrom a token that was deleted', async () => {91 await usingApi(async (api: ApiPromise) => {92 this test copies approve negative test93 });94 }); */9596 it('transferFrom for not approved address', async () => {97 await usingApi(async (api: ApiPromise) => {98 const Alice = privateKey('//Alice');99 const Bob = privateKey('//Bob');100 const Charlie = privateKey('//CHARLIE');101 // nft102 const nftCollectionId = await createCollectionExpectSuccess();103 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');104105 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);106107 // fungible108 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});109 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');110 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);111 // reFungible112 const reFungibleCollectionId = await113 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});114 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');115 await transferFromExpectFail(reFungibleCollectionId,116 newReFungibleTokenId, Bob, Alice, Charlie, 1);117 });118 });119120 it('transferFrom incorrect token count', async () => {121 await usingApi(async (api: ApiPromise) => {122 const Alice = privateKey('//Alice');123 const Bob = privateKey('//Bob');124 const Charlie = privateKey('//CHARLIE');125 // nft126 const nftCollectionId = await createCollectionExpectSuccess();127 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');128 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);129130 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 2);131132 // fungible133 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});134 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');135 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);136 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 2);137 // reFungible138 const reFungibleCollectionId = await139 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});140 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');141 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);142 await transferFromExpectFail(reFungibleCollectionId,143 newReFungibleTokenId, Bob, Alice, Charlie, 2);144 });145 });146147 it('execute transferFrom from account that is not owner of collection', async () => {148 await usingApi(async (api: ApiPromise) => {149 const Alice = privateKey('//Alice');150 const Bob = privateKey('//Bob');151 const Charlie = privateKey('//CHARLIE');152 const Dave = privateKey('//DAVE');153 // nft154 const nftCollectionId = await createCollectionExpectSuccess();155 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');156 try {157 await approveExpectFail(nftCollectionId, newNftTokenId, Dave, Bob);158 await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);159 } catch (e) {160 // tslint:disable-next-line:no-unused-expression161 expect(e).to.be.exist;162 }163164 // await transferFromExpectFail(nftCollectionId, newNftTokenId, Dave, Alice, Charlie, 1);165166 // fungible167 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});168 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');169 try {170 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Bob);171 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Dave, Alice, Charlie, 1);172 } catch (e) {173 // tslint:disable-next-line:no-unused-expression174 expect(e).to.be.exist;175 }176 // reFungible177 const reFungibleCollectionId = await178 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});179 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');180 try {181 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Bob);182 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Dave, Alice, Charlie, 1);183 } catch (e) {184 // tslint:disable-next-line:no-unused-expression185 expect(e).to.be.exist;186 }187 });188 });189 it( 'transferFrom burnt token before approve NFT', async () => {190 await usingApi(async (api: ApiPromise) => {191 const Alice = privateKey('//Alice');192 const Bob = privateKey('//Bob');193 const Charlie = privateKey('//CHARLIE');194 // nft195 const nftCollectionId = await createCollectionExpectSuccess();196 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');197 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);198 await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);199 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1); 200 });201 });202 it( 'transferFrom burnt token before approve Fungible', async () => {203 await usingApi(async (api: ApiPromise) => {204 const Alice = privateKey('//Alice');205 const Bob = privateKey('//Bob');206 const Charlie = privateKey('//CHARLIE');207 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});208 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');209 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);210 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);211 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);212 213 });214 }); 215 it( 'transferFrom burnt token before approve ReFungible', async () => {216 await usingApi(async (api: ApiPromise) => {217 const Alice = privateKey('//Alice');218 const Bob = privateKey('//Bob');219 const Charlie = privateKey('//CHARLIE');220 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});221 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');222 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);223 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);224 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);225 226 });227 });228 229 it( 'transferFrom burnt token after approve NFT', async () => {230 await usingApi(async (api: ApiPromise) => {231 const Alice = privateKey('//Alice');232 const Bob = privateKey('//Bob');233 const Charlie = privateKey('//CHARLIE');234 // nft235 const nftCollectionId = await createCollectionExpectSuccess();236 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');237 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);238 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);239 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1); 240 });241 });242 it( 'transferFrom burnt token after approve Fungible', async () => {243 await usingApi(async (api: ApiPromise) => {244 const Alice = privateKey('//Alice');245 const Bob = privateKey('//Bob');246 const Charlie = privateKey('//CHARLIE');247 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});248 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');249 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);250 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);251 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);252 253 });254 }); 255 it( 'transferFrom burnt token after approve ReFungible', async () => {256 await usingApi(async (api: ApiPromise) => {257 const Alice = privateKey('//Alice');258 const Bob = privateKey('//Bob');259 const Charlie = privateKey('//CHARLIE');260 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});261 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');262 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);263 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);264 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);265 266 });267 }); 268});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -368,6 +368,7 @@
});
}
+
export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
await usingApi(async (api) => {
@@ -409,7 +410,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;
@@ -427,9 +428,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) => {