difftreelog
transferFrom burnt token before&after approve test
in: master
2 files changed
tests/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);
+
+ });
+ });
});
tests/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) => {