git.delta.rocks / unique-network / refs/commits / a24084d50f85

difftreelog

transferSuccess

kpozdnikin2021-01-19parent: #8154d7d.patch.diff
in: master

3 files changed

modifiedtests/src/burnItem.test.tsdiffbeforeafterboth
--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -35,16 +35,16 @@
       const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
       const events = await submitTransactionAsync(alice, tx);
       const result = getGenericResult(events);
-  
-      // Get the item 
+      // 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);
     });
-  
+
   });
   it('Burn item in Fungible collection', async () => {
     const createMode = 'Fungible';
modifiedtests/src/transfer.test.tsdiffbeforeafterboth
8import { alicesPublicKey, bobsPublicKey } from './accounts';8import { alicesPublicKey, bobsPublicKey } from './accounts';
9import getBalance from './substrate/get-balance';9import getBalance from './substrate/get-balance';
10import privateKey from './substrate/privateKey';10import privateKey from './substrate/privateKey';
11import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';11import { default as usingApi, submitTransactionAsync } from './substrate/substrate-api';
12import {12import {
13 approveExpectSuccess,13 burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess,
14 createCollectionExpectSuccess, createItemExpectSuccess,14 destroyCollectionExpectSuccess,
15 findUnusedAddress,15 findUnusedAddress,
16 getCreateCollectionResult,16 getCreateCollectionResult,
17 getCreateItemResult,17 getCreateItemResult,
18 transferExpectFail,
18 transferExpectSuccess,19 transferExpectSuccess,
19} from './util/helpers';20} from './util/helpers';
21
22/*describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
23 it('Balance transfers and check balance', async () => {
24 await usingApi(async (api: ApiPromise) => {
25 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
26
27 const alicePrivateKey = privateKey('//Alice');
28
29 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);
30 const events = await submitTransactionAsync(alicePrivateKey, transfer);
31 const result = getCreateItemResult(events);
32 // tslint:disable-next-line:no-unused-expression
33 expect(result.success).to.be.true;
34
35 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
36
37 // tslint:disable-next-line:no-unused-expression
38 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
39 // tslint:disable-next-line:no-unused-expression
40 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;
41 });
42 });
43
44 it('Inability to pay fees error message is correct', async () => {
45 await usingApi(async (api) => {
46 // Find unused address
47 const pk = await findUnusedAddress(api);
48
49 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);
50 // const events = await submitTransactionAsync(pk, badTransfer);
51 const badTransaction = async () => {
52 const events = await submitTransactionAsync(pk, badTransfer);
53 const result = getCreateCollectionResult(events);
54 // tslint:disable-next-line:no-unused-expression
55 expect(result.success).to.be.false;
56 };
57 expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');
58 });
59 });
60
61 it('Create collection, balance transfers and check balance', async () => {
62 await usingApi(async (api) => {
63 const Alice = privateKey('//Alice');
64 const Bob = privateKey('//Bob');
65 // nft
66 const nftCollectionId = await createCollectionExpectSuccess();
67 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
68 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
69 // fungible
70 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
71 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
72 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
73 // reFungible
74 const reFungibleCollectionId = await
75 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
76 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
77 await transferExpectSuccess(reFungibleCollectionId,
78 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
79 });
80 });
81});*/
2082
21describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {83describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
22 it('Balance transfers and check balance', async () => {84 /*it('Transfer with not existed collection_id', async () => {
23 await usingApi(async (api: ApiPromise) => {85 await usingApi(async (api: ApiPromise) => {
24 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);86 const Alice = privateKey('//Alice');
2587 const Bob = privateKey('//Bob');
26 const alicePrivateKey = privateKey('//Alice');88 // nft
2789 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
28 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);90 await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);
29 const events = await submitTransactionAsync(alicePrivateKey, transfer);91 // fungible
30 const result = getCreateItemResult(events);92 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
31 // tslint:disable-next-line:no-unused-expression93 await transferExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob, 1);
32 expect(result.success).to.be.true;94 // reFungible
3395 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
34 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);96 await transferExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);
3597 });
36 // tslint:disable-next-line:no-unused-expression98 });
37 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;99 it('Transfer with deleted collection_id', async () => {
38 // tslint:disable-next-line:no-unused-expression100 await usingApi(async (api: ApiPromise) => {
39 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;101 const Alice = privateKey('//Alice');
40 });102 const Bob = privateKey('//Bob');
41 });103 // nft
42104 const nftCollectionId = await createCollectionExpectSuccess();
43 it('Inability to pay fees error message is correct', async () => {105 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
44 await usingApi(async (api) => {106 await destroyCollectionExpectSuccess(nftCollectionId);
45 // Find unused address107 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
46 const pk = await findUnusedAddress(api);108 // fungible
47109 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
48 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);110 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
49 // const events = await submitTransactionAsync(pk, badTransfer);111 await destroyCollectionExpectSuccess(fungibleCollectionId);
50 const badTransaction = async () => {112 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
51 const events = await submitTransactionAsync(pk, badTransfer);113 // reFungible
52 const result = getCreateCollectionResult(events);114 const reFungibleCollectionId = await
53 // tslint:disable-next-line:no-unused-expression115 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
54 expect(result.success).to.be.false;116 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
55 };117 await destroyCollectionExpectSuccess(reFungibleCollectionId);
56 expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');118 await transferExpectFail(reFungibleCollectionId,
57 });119 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
58 });120 });
59121 });
122 it('Transfer with not existed item_id', async () => {
123 await usingApi(async (api: ApiPromise) => {
124 const Alice = privateKey('//Alice');
125 const Bob = privateKey('//Bob');
126 // nft
127 const nftCollectionId = await createCollectionExpectSuccess();
128 await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');
129 // fungible
130 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
131 await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');
132 // reFungible
133 const reFungibleCollectionId = await
134 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
135 await transferExpectFail(reFungibleCollectionId,
136 2, Alice, Bob, 1, 'ReFungible');
137 });
138 });
139 it('Transfer with deleted item_id', async () => {
140 await usingApi(async (api: ApiPromise) => {
141 const Alice = privateKey('//Alice');
142 const Bob = privateKey('//Bob');
143 // nft
144 const nftCollectionId = await createCollectionExpectSuccess();
145 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
146 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
147 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
148 // fungible
149 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
150 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
151 await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 1);
152 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
153 // reFungible
154 const reFungibleCollectionId = await
155 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
156 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
157 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
158 await transferExpectFail(reFungibleCollectionId,
159 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
160 });
161 });*/
60 it('Create collection, balance transfers and check balance', async () => {162 it('Transfer with recipient that is not owner', async () => {
163 await usingApi(async (api: ApiPromise) => {
61 const Alice = privateKey('//Alice');164 const Alice = privateKey('//Alice');
62 const Bob = privateKey('//Bob');165 const Bob = privateKey('//Bob');
63 const Charlie = privateKey('//CHARLIE');166 const Charlie = privateKey('//CHARLIE');
64 // nft167 // nft
65 const nftCollectionId = await createCollectionExpectSuccess();168 const nftCollectionId = await createCollectionExpectSuccess();
66 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');169 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
67
68 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');170 await transferExpectFail(nftCollectionId, newNftTokenId, Charlie, Bob, 1, 'NFT');
69
70 // fungible171 // fungible
71 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});172 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
72 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');173 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
73 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
74 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');174 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Charlie, Bob, 1, 'Fungible');
75 // reFungible175 // reFungible
76 const reFungibleCollectionId = await176 const reFungibleCollectionId = await
77 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});177 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
78 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');178 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
79 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
80 await transferExpectSuccess(reFungibleCollectionId,179 await transferExpectFail(reFungibleCollectionId,
81 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');180 newReFungibleTokenId, Charlie, Bob, 1, 'ReFungible');
181 });
82 });182 });
83});183});
84
85describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
86 it('Transfer with not existed collection_id', async () => {
87
88 });
89 it('Transfer with deleted collection_id', async () => {
90
91 });
92 it('Transfer with not existed item_id', async () => {
93
94 });
95 it('Transfer with deleted item_id', async () => {
96
97 });
98 it('Transfer with recipient that is not owner', async () => {
99
100 });
101});
102184
modifiedtests/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');
   });