difftreelog
transferSuccess
in: master
3 files changed
tests/src/burnItem.test.tsdiffbeforeafterboth1import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';2import { Keyring } from "@polkadot/api";3import { IKeyringPair } from "@polkadot/types/types";4import { 5 createCollectionExpectSuccess, 6 createItemExpectSuccess,7 getGenericResult,8 destroyCollectionExpectSuccess9} from './util/helpers';10import { nullPublicKey } from "./accounts";1112import chai from 'chai';13import chaiAsPromised from 'chai-as-promised';14chai.use(chaiAsPromised);15const expect = chai.expect;1617let alice: IKeyringPair;18let bob: IKeyringPair;1920describe('integration test: ext. burnItem():', () => {21 before(async () => {22 await usingApi(async (api) => {23 const keyring = new Keyring({ type: 'sr25519' });24 alice = keyring.addFromUri(`//Alice`);25 bob = keyring.addFromUri(`//Bob`);26 });27 });2829 it('Burn item in NFT collection', async () => {30 const createMode = 'NFT';31 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});32 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);3334 await usingApi(async (api) => {35 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);36 const events = await submitTransactionAsync(alice, tx);37 const result = getGenericResult(events);38 39 // Get the item 40 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();41 42 // What to expect43 expect(result.success).to.be.true;44 expect(item).to.be.not.null;45 expect(item.Owner).to.be.equal(nullPublicKey);46 });47 48 });49 it('Burn item in Fungible collection', async () => {50 const createMode = 'Fungible';51 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});52 await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens53 const tokenId = 0; // ignored5455 await usingApi(async (api) => {56 // Destroy 1 of 1057 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);58 const events = await submitTransactionAsync(alice, tx);59 const result = getGenericResult(events);60 61 // Get alice balance 62 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();63 64 // What to expect65 expect(result.success).to.be.true;66 expect(balance).to.be.not.null;67 expect(balance.Value).to.be.equal(9);68 });6970 });71 it('Burn item in ReFungible collection', async () => {72 const createMode = 'ReFungible';73 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});74 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);7576 await usingApi(async (api) => {77 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);78 const events = await submitTransactionAsync(alice, tx);79 const result = getGenericResult(events);80 81 // Get alice balance 82 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();83 84 // What to expect85 expect(result.success).to.be.true;86 expect(balance).to.be.not.null;87 expect(balance.Owner.length).to.be.equal(0);88 });8990 });9192 it('Burn owned portion of item in ReFungible collection', async () => {93 const createMode = 'ReFungible';94 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});95 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);9697 await usingApi(async (api) => {98 // Transfer 1/100 of the token to Bob99 const transfertx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 1);100 const events1 = await submitTransactionAsync(alice, transfertx);101 const result1 = getGenericResult(events1);102103 // Get balances104 const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();105106 // Bob burns his portion107 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);108 const events2 = await submitTransactionAsync(bob, tx);109 const result2 = getGenericResult(events2);110 111 // Get balances 112 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();113 // console.log(balance);114 115 // What to expect before burning116 expect(result1.success).to.be.true;117 expect(balanceBefore).to.be.not.null;118 expect(balanceBefore.Owner.length).to.be.equal(2);119 expect(balanceBefore.Owner[0].Owner).to.be.equal(alice.address);120 expect(balanceBefore.Owner[0].Fraction).to.be.equal(99);121 expect(balanceBefore.Owner[1].Owner).to.be.equal(bob.address);122 expect(balanceBefore.Owner[1].Fraction).to.be.equal(1);123124 // What to expect after burning125 expect(result2.success).to.be.true;126 expect(balance).to.be.not.null;127 expect(balance.Owner.length).to.be.equal(1);128 expect(balance.Owner[0].Fraction).to.be.equal(99);129 expect(balance.Owner[0].Owner).to.be.equal(alice.address);130 });131132 });133134});135136describe('Negative integration test: ext. burnItem():', () => {137 before(async () => {138 await usingApi(async (api) => {139 const keyring = new Keyring({ type: 'sr25519' });140 alice = keyring.addFromUri(`//Alice`);141 bob = keyring.addFromUri(`//Bob`);142 });143 });144145 it('Burn a token in a destroyed collection', async () => {146 const createMode = 'NFT';147 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});148 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);149 await destroyCollectionExpectSuccess(collectionId);150151 await usingApi(async (api) => {152 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);153 const badTransaction = async function () { 154 await submitTransactionExpectFailAsync(alice, tx);155 };156 await expect(badTransaction()).to.be.rejected;157 });158159 });160161 it('Burn a token that was never created', async () => {162 const createMode = 'NFT';163 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});164 const tokenId = 10;165166 await usingApi(async (api) => {167 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);168 const badTransaction = async function () { 169 await submitTransactionExpectFailAsync(alice, tx);170 };171 await expect(badTransaction()).to.be.rejected;172 });173174 });175176 it('Burn a token using the address that does not own it', async () => {177 const createMode = 'NFT';178 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});179 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);180181 await usingApi(async (api) => {182 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);183 const badTransaction = async function () { 184 await submitTransactionExpectFailAsync(bob, tx);185 };186 await expect(badTransaction()).to.be.rejected;187 });188189 });190191 it('Transfer a burned a token', async () => {192 const createMode = 'NFT';193 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});194 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);195196 await usingApi(async (api) => {197198 const burntx = api.tx.nft.burnItem(collectionId, tokenId, 0);199 const events1 = await submitTransactionAsync(alice, burntx);200 const result1 = getGenericResult(events1);201 expect(result1.success).to.be.true;202 203 const tx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 0);204 const badTransaction = async function () { 205 await submitTransactionExpectFailAsync(alice, tx);206 };207 await expect(badTransaction()).to.be.rejected;208 });209210 });211212 it('Burn more than owned in Fungible collection', async () => {213 const createMode = 'Fungible';214 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});215 // Helper creates 10 fungible tokens216 await createItemExpectSuccess(alice, collectionId, createMode);217 const tokenId = 0; // ignored218219 await usingApi(async (api) => {220 // Destroy 11 of 10221 const tx = api.tx.nft.burnItem(collectionId, tokenId, 11);222 const badTransaction = async function () { 223 await submitTransactionExpectFailAsync(alice, tx);224 };225 await expect(badTransaction()).to.be.rejected;226 227 // Get alice balance 228 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();229 230 // What to expect231 expect(balance).to.be.not.null;232 expect(balance.Value).to.be.equal(10);233 });234235 });236237});1import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';2import { Keyring } from "@polkadot/api";3import { IKeyringPair } from "@polkadot/types/types";4import { 5 createCollectionExpectSuccess, 6 createItemExpectSuccess,7 getGenericResult,8 destroyCollectionExpectSuccess9} from './util/helpers';10import { nullPublicKey } from "./accounts";1112import chai from 'chai';13import chaiAsPromised from 'chai-as-promised';14chai.use(chaiAsPromised);15const expect = chai.expect;1617let alice: IKeyringPair;18let bob: IKeyringPair;1920describe('integration test: ext. burnItem():', () => {21 before(async () => {22 await usingApi(async (api) => {23 const keyring = new Keyring({ type: 'sr25519' });24 alice = keyring.addFromUri(`//Alice`);25 bob = keyring.addFromUri(`//Bob`);26 });27 });2829 it('Burn item in NFT collection', async () => {30 const createMode = 'NFT';31 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});32 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);3334 await usingApi(async (api) => {35 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);36 const events = await submitTransactionAsync(alice, tx);37 const result = getGenericResult(events);38 // Get the item39 const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();40 // What to expect41 // tslint:disable-next-line:no-unused-expression42 expect(result.success).to.be.true;43 // tslint:disable-next-line:no-unused-expression44 expect(item).to.be.not.null;45 expect(item.Owner).to.be.equal(nullPublicKey);46 });4748 });49 it('Burn item in Fungible collection', async () => {50 const createMode = 'Fungible';51 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});52 await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens53 const tokenId = 0; // ignored5455 await usingApi(async (api) => {56 // Destroy 1 of 1057 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);58 const events = await submitTransactionAsync(alice, tx);59 const result = getGenericResult(events);60 61 // Get alice balance 62 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();63 64 // What to expect65 expect(result.success).to.be.true;66 expect(balance).to.be.not.null;67 expect(balance.Value).to.be.equal(9);68 });6970 });71 it('Burn item in ReFungible collection', async () => {72 const createMode = 'ReFungible';73 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});74 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);7576 await usingApi(async (api) => {77 const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);78 const events = await submitTransactionAsync(alice, tx);79 const result = getGenericResult(events);80 81 // Get alice balance 82 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();83 84 // What to expect85 expect(result.success).to.be.true;86 expect(balance).to.be.not.null;87 expect(balance.Owner.length).to.be.equal(0);88 });8990 });9192 it('Burn owned portion of item in ReFungible collection', async () => {93 const createMode = 'ReFungible';94 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});95 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);9697 await usingApi(async (api) => {98 // Transfer 1/100 of the token to Bob99 const transfertx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 1);100 const events1 = await submitTransactionAsync(alice, transfertx);101 const result1 = getGenericResult(events1);102103 // Get balances104 const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();105106 // Bob burns his portion107 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);108 const events2 = await submitTransactionAsync(bob, tx);109 const result2 = getGenericResult(events2);110 111 // Get balances 112 const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();113 // console.log(balance);114 115 // What to expect before burning116 expect(result1.success).to.be.true;117 expect(balanceBefore).to.be.not.null;118 expect(balanceBefore.Owner.length).to.be.equal(2);119 expect(balanceBefore.Owner[0].Owner).to.be.equal(alice.address);120 expect(balanceBefore.Owner[0].Fraction).to.be.equal(99);121 expect(balanceBefore.Owner[1].Owner).to.be.equal(bob.address);122 expect(balanceBefore.Owner[1].Fraction).to.be.equal(1);123124 // What to expect after burning125 expect(result2.success).to.be.true;126 expect(balance).to.be.not.null;127 expect(balance.Owner.length).to.be.equal(1);128 expect(balance.Owner[0].Fraction).to.be.equal(99);129 expect(balance.Owner[0].Owner).to.be.equal(alice.address);130 });131132 });133134});135136describe('Negative integration test: ext. burnItem():', () => {137 before(async () => {138 await usingApi(async (api) => {139 const keyring = new Keyring({ type: 'sr25519' });140 alice = keyring.addFromUri(`//Alice`);141 bob = keyring.addFromUri(`//Bob`);142 });143 });144145 it('Burn a token in a destroyed collection', async () => {146 const createMode = 'NFT';147 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});148 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);149 await destroyCollectionExpectSuccess(collectionId);150151 await usingApi(async (api) => {152 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);153 const badTransaction = async function () { 154 await submitTransactionExpectFailAsync(alice, tx);155 };156 await expect(badTransaction()).to.be.rejected;157 });158159 });160161 it('Burn a token that was never created', async () => {162 const createMode = 'NFT';163 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});164 const tokenId = 10;165166 await usingApi(async (api) => {167 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);168 const badTransaction = async function () { 169 await submitTransactionExpectFailAsync(alice, tx);170 };171 await expect(badTransaction()).to.be.rejected;172 });173174 });175176 it('Burn a token using the address that does not own it', async () => {177 const createMode = 'NFT';178 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});179 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);180181 await usingApi(async (api) => {182 const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);183 const badTransaction = async function () { 184 await submitTransactionExpectFailAsync(bob, tx);185 };186 await expect(badTransaction()).to.be.rejected;187 });188189 });190191 it('Transfer a burned a token', async () => {192 const createMode = 'NFT';193 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});194 const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);195196 await usingApi(async (api) => {197198 const burntx = api.tx.nft.burnItem(collectionId, tokenId, 0);199 const events1 = await submitTransactionAsync(alice, burntx);200 const result1 = getGenericResult(events1);201 expect(result1.success).to.be.true;202 203 const tx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 0);204 const badTransaction = async function () { 205 await submitTransactionExpectFailAsync(alice, tx);206 };207 await expect(badTransaction()).to.be.rejected;208 });209210 });211212 it('Burn more than owned in Fungible collection', async () => {213 const createMode = 'Fungible';214 const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});215 // Helper creates 10 fungible tokens216 await createItemExpectSuccess(alice, collectionId, createMode);217 const tokenId = 0; // ignored218219 await usingApi(async (api) => {220 // Destroy 11 of 10221 const tx = api.tx.nft.burnItem(collectionId, tokenId, 11);222 const badTransaction = async function () { 223 await submitTransactionExpectFailAsync(alice, tx);224 };225 await expect(badTransaction()).to.be.rejected;226 227 // Get alice balance 228 const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();229 230 // What to expect231 expect(balance).to.be.not.null;232 expect(balance.Value).to.be.equal(10);233 });234235 });236237});tests/src/transfer.test.tsdiffbeforeafterboth--- a/tests/src/transfer.test.ts
+++ b/tests/src/transfer.test.ts
@@ -8,17 +8,18 @@
import { alicesPublicKey, bobsPublicKey } from './accounts';
import getBalance from './substrate/get-balance';
import privateKey from './substrate/privateKey';
-import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';
+import { default as usingApi, submitTransactionAsync } from './substrate/substrate-api';
import {
- approveExpectSuccess,
- createCollectionExpectSuccess, createItemExpectSuccess,
+ burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess,
+ destroyCollectionExpectSuccess,
findUnusedAddress,
getCreateCollectionResult,
getCreateItemResult,
+ transferExpectFail,
transferExpectSuccess,
} from './util/helpers';
-describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
+/*describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
it('Balance transfers and check balance', async () => {
await usingApi(async (api: ApiPromise) => {
const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
@@ -58,44 +59,125 @@
});
it('Create collection, balance transfers and check balance', async () => {
- 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 transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
-
- // fungible
- const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
- const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
- await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
- await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
- // reFungible
- const reFungibleCollectionId = await
- createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
- const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
- await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
- await transferExpectSuccess(reFungibleCollectionId,
- newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
+ await usingApi(async (api) => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
+ // fungible
+ const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+ await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
+ // reFungible
+ const reFungibleCollectionId = await
+ createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
+ const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ await transferExpectSuccess(reFungibleCollectionId,
+ newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
+ });
});
-});
+});*/
describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
- it('Transfer with not existed collection_id', async () => {
-
+ /*it('Transfer with not existed collection_id', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ // nft
+ const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
+ await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);
+ // fungible
+ const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
+ await transferExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob, 1);
+ // reFungible
+ const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
+ await transferExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);
+ });
});
it('Transfer with deleted collection_id', async () => {
-
+ await usingApi(async (api: ApiPromise) => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await destroyCollectionExpectSuccess(nftCollectionId);
+ await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
+ // fungible
+ const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+ await destroyCollectionExpectSuccess(fungibleCollectionId);
+ await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
+ // reFungible
+ const reFungibleCollectionId = await
+ createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
+ const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ await destroyCollectionExpectSuccess(reFungibleCollectionId);
+ await transferExpectFail(reFungibleCollectionId,
+ newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
+ });
});
it('Transfer with not existed item_id', async () => {
-
+ await usingApi(async (api: ApiPromise) => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');
+ // fungible
+ const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');
+ // reFungible
+ const reFungibleCollectionId = await
+ createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
+ await transferExpectFail(reFungibleCollectionId,
+ 2, Alice, Bob, 1, 'ReFungible');
+ });
});
it('Transfer with deleted item_id', async () => {
-
- });
+ await usingApi(async (api: ApiPromise) => {
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ // nft
+ const nftCollectionId = await createCollectionExpectSuccess();
+ const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
+ await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
+ await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
+ // fungible
+ const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+ await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 1);
+ await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
+ // reFungible
+ const reFungibleCollectionId = await
+ createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
+ const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
+ await transferExpectFail(reFungibleCollectionId,
+ newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
+ });
+ });*/
it('Transfer with recipient that is not owner', 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 transferExpectFail(nftCollectionId, newNftTokenId, Charlie, Bob, 1, 'NFT');
+ // fungible
+ const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
+ const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
+ await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1, 'Fungible');
+ // reFungible
+ const reFungibleCollectionId = await
+ createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
+ const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
+ await transferExpectFail(reFungibleCollectionId,
+ newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');
+ });
});
});
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -391,6 +391,22 @@
ReFungible: CreateReFungibleData;
}
+export async function burnItemExpectSuccess(owner: IKeyringPair, collectionId: number, tokenId: number, value = 0) {
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const events = await submitTransactionAsync(owner, tx);
+ const result = getGenericResult(events);
+ // Get the item
+ const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
+ // What to expect
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.true;
+ // tslint:disable-next-line:no-unused-expression
+ expect(item).to.be.not.null;
+ expect(item.Owner).to.be.equal(nullPublicKey);
+ });
+}
+
export async function
approveExpectSuccess(collectionId: number,
tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
@@ -496,6 +512,22 @@
}
export async function
+transferExpectFail(collectionId: number,
+ tokenId: number,
+ sender: IKeyringPair,
+ recipient: IKeyringPair,
+ value: number = 1,
+ type: string = 'NFT') {
+ await usingApi(async (api: ApiPromise) => {
+ const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);
+ const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;
+ const result = getCreateCollectionResult(events);
+ // tslint:disable-next-line:no-unused-expression
+ expect(result.success).to.be.false;
+ });
+}
+
+export async function
approveExpectFail(collectionId: number,
tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
await usingApi(async (api: ApiPromise) => {
@@ -507,7 +539,8 @@
});
}
-export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {
+export async function createItemExpectSuccess(
+ sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {
let newItemId: number = 0;
await usingApi(async (api) => {
const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);
@@ -559,6 +592,7 @@
const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
// What to expect
+ // tslint:disable-next-line:no-unused-expression
expect(result.success).to.be.true;
expect(collection.Access).to.be.equal('WhiteList');
});