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.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.tsdiffbeforeafterboth505506506export async function507export async function507approveExpectSuccess(collectionId: number,508approveExpectSuccess(collectionId: number,508 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {509 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) { //alice,bob509 await usingApi(async (api: ApiPromise) => {510 await usingApi(async (api: ApiPromise) => {510 const allowanceBefore =511 const allowanceBefore =511 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;512 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;523export async function524export async function524transferFromExpectSuccess(collectionId: number,525transferFromExpectSuccess(collectionId: number,525 tokenId: number,526 tokenId: number,526 accountApproved: IKeyringPair,527 accountApproved: IKeyringPair, //bob527 accountFrom: IKeyringPair,528 accountFrom: IKeyringPair, //alice528 accountTo: IKeyringPair,529 accountTo: IKeyringPair, //charlie529 value: number = 1,530 value: number = 1,530 type: string = 'NFT') {531 type: string = 'NFT') {531 await usingApi(async (api: ApiPromise) => {532 await usingApi(async (api: ApiPromise) => {