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

difftreelog

transferFail

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

2 files changed

modifiedtests/src/transfer.test.tsdiffbeforeafterboth
19 transferExpectSuccess,19 transferExpectSuccess,
20} from './util/helpers';20} from './util/helpers';
2121
22/*describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {22describe('Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
23 it('Balance transfers and check balance', async () => {23 it('Balance transfers and check balance', async () => {
24 await usingApi(async (api: ApiPromise) => {24 await usingApi(async (api: ApiPromise) => {
25 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);25 const [alicesBalanceBefore, bobsBalanceBefore] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
2626
27 const alicePrivateKey = privateKey('//Alice');27 const alicePrivateKey = privateKey('//Alice');
2828
29 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);29 const transfer = api.tx.balances.transfer(bobsPublicKey, 1n);
30 const events = await submitTransactionAsync(alicePrivateKey, transfer);30 const events = await submitTransactionAsync(alicePrivateKey, transfer);
31 const result = getCreateItemResult(events);31 const result = getCreateItemResult(events);
32 // tslint:disable-next-line:no-unused-expression32 // tslint:disable-next-line:no-unused-expression
33 expect(result.success).to.be.true;33 expect(result.success).to.be.true;
3434
35 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);35 const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);
3636
37 // tslint:disable-next-line:no-unused-expression37 // tslint:disable-next-line:no-unused-expression
38 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;38 expect(alicesBalanceAfter < alicesBalanceBefore).to.be.true;
39 // tslint:disable-next-line:no-unused-expression39 // tslint:disable-next-line:no-unused-expression
40 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;40 expect(bobsBalanceAfter > bobsBalanceBefore).to.be.true;
41 });41 });
42 });42 });
4343
44 it('Inability to pay fees error message is correct', async () => {44 it('Inability to pay fees error message is correct', async () => {
45 await usingApi(async (api) => {45 await usingApi(async (api) => {
46 // Find unused address46 // Find unused address
47 const pk = await findUnusedAddress(api);47 const pk = await findUnusedAddress(api);
4848
49 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);49 const badTransfer = api.tx.balances.transfer(bobsPublicKey, 1n);
50 // const events = await submitTransactionAsync(pk, badTransfer);50 // const events = await submitTransactionAsync(pk, badTransfer);
51 const badTransaction = async () => {51 const badTransaction = async () => {
52 const events = await submitTransactionAsync(pk, badTransfer);52 const events = await submitTransactionAsync(pk, badTransfer);
53 const result = getCreateCollectionResult(events);53 const result = getCreateCollectionResult(events);
54 // tslint:disable-next-line:no-unused-expression54 // tslint:disable-next-line:no-unused-expression
55 expect(result.success).to.be.false;55 expect(result.success).to.be.false;
56 };56 };
57 expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');57 expect(badTransaction()).to.be.rejectedWith('Inability to pay some fees , e.g. account balance too low');
58 });58 });
59 });59 });
6060
61 it('Create collection, balance transfers and check balance', async () => {61 it('Create collection, balance transfers and check balance', async () => {
62 await usingApi(async (api) => {62 await usingApi(async (api) => {
63 const Alice = privateKey('//Alice');63 const Alice = privateKey('//Alice');
64 const Bob = privateKey('//Bob');64 const Bob = privateKey('//Bob');
65 // nft65 // nft
66 const nftCollectionId = await createCollectionExpectSuccess();66 const nftCollectionId = await createCollectionExpectSuccess();
67 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');67 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
68 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');68 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
69 // fungible69 // fungible
70 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});70 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
71 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');71 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
72 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');72 await transferExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
73 // reFungible73 // reFungible
74 const reFungibleCollectionId = await74 const reFungibleCollectionId = await
75 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});75 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
76 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');76 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
77 await transferExpectSuccess(reFungibleCollectionId,77 await transferExpectSuccess(reFungibleCollectionId,
78 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');78 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
79 });79 });
80 });80 });
81});*/81});
8282
83describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {83describe('Negative Integration Test Transfer(recipient, collection_id, item_id, value)', () => {
84 /*it('Transfer with not existed collection_id', async () => {84 it('Transfer with not existed collection_id', async () => {
85 await usingApi(async (api: ApiPromise) => {85 await usingApi(async (api: ApiPromise) => {
86 const Alice = privateKey('//Alice');86 const Alice = privateKey('//Alice');
87 const Bob = privateKey('//Bob');87 const Bob = privateKey('//Bob');
88 // nft88 // nft
89 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;89 const nftCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
90 await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);90 await transferExpectFail(nftCollectionCount + 1, 1, Alice, Bob, 1);
91 // fungible91 // fungible
92 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;92 const fungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
93 await transferExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob, 1);93 await transferExpectFail(fungibleCollectionCount + 1, 1, Alice, Bob, 1);
94 // reFungible94 // reFungible
95 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;95 const reFungibleCollectionCount = await api.query.nft.createdCollectionCount() as unknown as number;
96 await transferExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);96 await transferExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob, 1);
97 });97 });
98 });98 });
99 it('Transfer with deleted collection_id', async () => {99 it('Transfer with deleted collection_id', async () => {
100 await usingApi(async (api: ApiPromise) => {100 await usingApi(async (api: ApiPromise) => {
101 const Alice = privateKey('//Alice');101 const Alice = privateKey('//Alice');
102 const Bob = privateKey('//Bob');102 const Bob = privateKey('//Bob');
103 // nft103 // nft
104 const nftCollectionId = await createCollectionExpectSuccess();104 const nftCollectionId = await createCollectionExpectSuccess();
105 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');105 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
106 await destroyCollectionExpectSuccess(nftCollectionId);106 await destroyCollectionExpectSuccess(nftCollectionId);
107 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');107 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
108 // fungible108 // fungible
109 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});109 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
110 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');110 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
111 await destroyCollectionExpectSuccess(fungibleCollectionId);111 await destroyCollectionExpectSuccess(fungibleCollectionId);
112 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');112 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
113 // reFungible113 // reFungible
114 const reFungibleCollectionId = await114 const reFungibleCollectionId = await
115 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});115 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
116 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');116 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
117 await destroyCollectionExpectSuccess(reFungibleCollectionId);117 await destroyCollectionExpectSuccess(reFungibleCollectionId);
118 await transferExpectFail(reFungibleCollectionId,118 await transferExpectFail(reFungibleCollectionId,
119 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');119 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
120 });120 });
121 });121 });
122 it('Transfer with not existed item_id', async () => {122 it('Transfer with not existed item_id', async () => {
123 await usingApi(async (api: ApiPromise) => {123 await usingApi(async (api: ApiPromise) => {
124 const Alice = privateKey('//Alice');124 const Alice = privateKey('//Alice');
125 const Bob = privateKey('//Bob');125 const Bob = privateKey('//Bob');
126 // nft126 // nft
127 const nftCollectionId = await createCollectionExpectSuccess();127 const nftCollectionId = await createCollectionExpectSuccess();
128 await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');128 await transferExpectFail(nftCollectionId, 2, Alice, Bob, 1, 'NFT');
129 // fungible129 // fungible
130 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});130 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
131 await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');131 await transferExpectFail(fungibleCollectionId, 2, Alice, Bob, 1, 'Fungible');
132 // reFungible132 // reFungible
133 const reFungibleCollectionId = await133 const reFungibleCollectionId = await
134 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});134 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
135 await transferExpectFail(reFungibleCollectionId,135 await transferExpectFail(reFungibleCollectionId,
136 2, Alice, Bob, 1, 'ReFungible');136 2, Alice, Bob, 1, 'ReFungible');
137 });137 });
138 });138 });
139 it('Transfer with deleted item_id', async () => {139 it('Transfer with deleted item_id', async () => {
140 await usingApi(async (api: ApiPromise) => {140 await usingApi(async (api: ApiPromise) => {
141 const Alice = privateKey('//Alice');141 const Alice = privateKey('//Alice');
142 const Bob = privateKey('//Bob');142 const Bob = privateKey('//Bob');
143 // nft143 // nft
144 const nftCollectionId = await createCollectionExpectSuccess();144 const nftCollectionId = await createCollectionExpectSuccess();
145 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');145 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
146 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);146 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
147 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');147 await transferExpectFail(nftCollectionId, newNftTokenId, Alice, Bob, 1, 'NFT');
148 // fungible148 // fungible
149 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});149 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
150 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');150 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
151 await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 1);151 await burnItemExpectSuccess(Alice, fungibleCollectionId, newFungibleTokenId, 1);
152 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');152 await transferExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob, 1, 'Fungible');
153 // reFungible153 // reFungible
154 const reFungibleCollectionId = await154 const reFungibleCollectionId = await
155 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});155 createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
156 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');156 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
157 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);157 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
158 await transferExpectFail(reFungibleCollectionId,158 await transferExpectFail(reFungibleCollectionId,
159 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');159 newReFungibleTokenId, Alice, Bob, 1, 'ReFungible');
160 });160 });
161 });*/161 });
162 it('Transfer with recipient that is not owner', async () => {162 it('Transfer with recipient that is not owner', async () => {
163 await usingApi(async (api: ApiPromise) => {163 await usingApi(async (api: ApiPromise) => {
164 const Alice = privateKey('//Alice');164 const Alice = privateKey('//Alice');
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
521 await usingApi(async (api: ApiPromise) => {521 await usingApi(async (api: ApiPromise) => {
522 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);522 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);
523 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;523 const events = await expect(submitTransactionExpectFailAsync(sender, transferTx)).to.be.rejected;
524 if (events && Array.isArray(events)) {
524 const result = getCreateCollectionResult(events);525 const result = getCreateCollectionResult(events);
525 // tslint:disable-next-line:no-unused-expression526 // tslint:disable-next-line:no-unused-expression
526 expect(result.success).to.be.false;527 expect(result.success).to.be.false;
528 }
527 });529 });
528}530}
529531
627 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();629 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
628630
629 // What to expect631 // What to expect
632 // tslint:disable-next-line:no-unused-expression
630 expect(result.success).to.be.true;633 expect(result.success).to.be.true;
631 expect(collection.MintMode).to.be.equal(true);634 expect(collection.MintMode).to.be.equal(true);
632 });635 });