difftreelog
transferFrom burnt token before&after approve test
in: master
2 files changed
tests/src/transferFrom.test.tsdiffbeforeafterboth15 destroyCollectionExpectSuccess,15 destroyCollectionExpectSuccess,16 transferFromExpectFail,16 transferFromExpectFail,17 transferFromExpectSuccess,17 transferFromExpectSuccess,18 burnItemExpectSuccess,18} from './util/helpers';19} from './util/helpers';192020chai.use(chaiAsPromised);21chai.use(chaiAsPromised);185 }186 }186 });187 });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 }); 188});268});189269tests/src/util/helpers.tsdiffbeforeafterboth409410410export async function411export async function411approveExpectSuccess(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,bob413 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 function428transferFromExpectSuccess(collectionId: number,429transferFromExpectSuccess(collectionId: number,429 tokenId: number,430 tokenId: number,430 accountApproved: IKeyringPair,431 accountApproved: IKeyringPair, //bob431 accountFrom: IKeyringPair,432 accountFrom: IKeyringPair, //alice432 accountTo: IKeyringPair,433 accountTo: IKeyringPair, //charlie433 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) => {