--- 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); + + }); + }); }); --- 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) => {