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

difftreelog

rename to lowerCase

Igor Kozyrev2021-11-22parent: #714868d.patch.diff
in: master

1 file changed

modifiedtests/src/approve.test.tsdiffbeforeafterboth
26const expect = chai.expect;26const expect = chai.expect;
2727
28describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {28describe('Integration Test approve(spender, collection_id, item_id, amount):', () => {
29 let Alice: IKeyringPair;29 let alice: IKeyringPair;
30 let Bob: IKeyringPair;30 let bob: IKeyringPair;
31 let Charlie: IKeyringPair;31 let charlie: IKeyringPair;
3232
33 before(async () => {33 before(async () => {
34 await usingApi(async () => {34 await usingApi(async () => {
35 Alice = privateKey('//Alice');35 alice = privateKey('//Alice');
36 Bob = privateKey('//Bob');36 bob = privateKey('//Bob');
37 Charlie = privateKey('//Charlie');37 charlie = privateKey('//Charlie');
38 });38 });
39 });39 });
4040
41 it('Execute the extrinsic and check approvedList', async () => {41 it('Execute the extrinsic and check approvedList', async () => {
42 const nftCollectionId = await createCollectionExpectSuccess();42 const nftCollectionId = await createCollectionExpectSuccess();
43 // nft43 // nft
44 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');44 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
45 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address);45 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address);
46 // fungible46 // fungible
47 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});47 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
48 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');48 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
49 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address);49 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address);
50 // reFungible50 // reFungible
51 const reFungibleCollectionId =51 const reFungibleCollectionId =
52 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});52 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
53 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');53 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
54 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address);54 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address);
55 });55 });
5656
57 it('Remove approval by using 0 amount', async () => {57 it('Remove approval by using 0 amount', async () => {
58 const nftCollectionId = await createCollectionExpectSuccess();58 const nftCollectionId = await createCollectionExpectSuccess();
59 // nft59 // nft
60 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');60 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
61 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address, 1);61 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 1);
62 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob.address, 0);62 await approveExpectSuccess(nftCollectionId, newNftTokenId, alice, bob.address, 0);
63 // fungible63 // fungible
64 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});64 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
65 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');65 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
66 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 1);66 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);
67 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 0);67 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);
68 // reFungible68 // reFungible
69 const reFungibleCollectionId =69 const reFungibleCollectionId =
70 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});70 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
71 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');71 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
72 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 1);72 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);
73 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 0);73 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);
74 });74 });
7575
76 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {76 it('can be called by collection owner on non-owned item when OwnerCanTransfer == true', async () => {
77 const collectionId = await createCollectionExpectSuccess();77 const collectionId = await createCollectionExpectSuccess();
78 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);78 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
7979
80 await adminApproveFromExpectSuccess(collectionId, itemId, Alice, Bob.address, Charlie.address);80 await adminApproveFromExpectSuccess(collectionId, itemId, alice, bob.address, charlie.address);
81 });81 });
82});82});
8383
84describe('Normal user can approve other users to transfer:', () => {84describe('Normal user can approve other users to transfer:', () => {
85 let Alice: IKeyringPair;85 let alice: IKeyringPair;
86 let Bob: IKeyringPair;86 let bob: IKeyringPair;
87 let Charlie: IKeyringPair;87 let charlie: IKeyringPair;
8888
89 before(async () => {89 before(async () => {
90 await usingApi(async () => {90 await usingApi(async () => {
91 Alice = privateKey('//Alice');91 alice = privateKey('//Alice');
92 Bob = privateKey('//Bob');92 bob = privateKey('//Bob');
93 Charlie = privateKey('//Charlie');93 charlie = privateKey('//Charlie');
94 });94 });
95 }); 95 });
9696
97 it('NFT', async () => {97 it('NFT', async () => {
98 const collectionId = await createCollectionExpectSuccess();98 const collectionId = await createCollectionExpectSuccess();
99 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);99 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
100 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);100 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
101 });101 });
102102
103 it('Fungible up to an approved amount', async () => {103 it('Fungible up to an approved amount', async () => {
104 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});104 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
105 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address); 105 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address);
106 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);106 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
107 });107 });
108108
109 it('ReFungible up to an approved amount', async () => {109 it('ReFungible up to an approved amount', async () => {
110 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });110 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
111 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address);111 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);
112 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);112 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
113 });113 });
114});114});
115115
116describe('Approved users can transferFrom up to approved amount:', () => {116describe('Approved users can transferFrom up to approved amount:', () => {
117 let Alice: IKeyringPair;117 let alice: IKeyringPair;
118 let Bob: IKeyringPair;118 let bob: IKeyringPair;
119 let Charlie: IKeyringPair;119 let charlie: IKeyringPair;
120120
121 before(async () => {121 before(async () => {
122 await usingApi(async () => {122 await usingApi(async () => {
123 Alice = privateKey('//Alice');123 alice = privateKey('//Alice');
124 Bob = privateKey('//Bob');124 bob = privateKey('//Bob');
125 Charlie = privateKey('//Charlie');125 charlie = privateKey('//Charlie');
126 });126 });
127 }); 127 });
128128
129 it('NFT', async () => {129 it('NFT', async () => {
130 const collectionId = await createCollectionExpectSuccess();130 const collectionId = await createCollectionExpectSuccess();
131 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);131 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
132 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);132 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
133 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'NFT');133 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');
134 });134 });
135135
136 it('Fungible up to an approved amount', async () => {136 it('Fungible up to an approved amount', async () => {
137 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});137 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
138 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address); 138 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address);
139 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);139 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
140 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'Fungible');140 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');
141 });141 });
142142
143 it('ReFungible up to an approved amount', async () => {143 it('ReFungible up to an approved amount', async () => {
144 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });144 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
145 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address);145 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);
146 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);146 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
147 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'ReFungible');147 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');
148 });148 });
149});149});
150150
151describe('Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:', () => {151describe('Approved users cannot use transferFrom to repeat transfers if approved amount was already transferred:', () => {
152 let Alice: IKeyringPair;152 let alice: IKeyringPair;
153 let Bob: IKeyringPair;153 let bob: IKeyringPair;
154 let Charlie: IKeyringPair;154 let charlie: IKeyringPair;
155155
156 before(async () => {156 before(async () => {
157 await usingApi(async () => {157 await usingApi(async () => {
158 Alice = privateKey('//Alice');158 alice = privateKey('//Alice');
159 Bob = privateKey('//Bob');159 bob = privateKey('//Bob');
160 Charlie = privateKey('//Charlie');160 charlie = privateKey('//Charlie');
161 });161 });
162 }); 162 });
163163
164 it('NFT', async () => {164 it('NFT', async () => {
165 const collectionId = await createCollectionExpectSuccess();165 const collectionId = await createCollectionExpectSuccess();
166 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);166 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
167 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);167 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
168 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'NFT');168 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'NFT');
169 await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1);169 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);
170 });170 });
171171
172 it('Fungible up to an approved amount', async () => {172 it('Fungible up to an approved amount', async () => {
173 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});173 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
174 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Bob.address); 174 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', bob.address);
175 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);175 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
176 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'Fungible');176 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'Fungible');
177 await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1);177 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);
178 });178 });
179179
180 it('ReFungible up to an approved amount', async () => {180 it('ReFungible up to an approved amount', async () => {
181 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });181 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
182 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Bob.address);182 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', bob.address);
183 await approveExpectSuccess(collectionId, itemId, Bob, Charlie.address);183 await approveExpectSuccess(collectionId, itemId, bob, charlie.address);
184 await transferFromExpectSuccess(collectionId, itemId, Charlie, Bob, Alice, 1, 'ReFungible');184 await transferFromExpectSuccess(collectionId, itemId, charlie, bob, alice, 1, 'ReFungible');
185 await transferFromExpectFail(collectionId, itemId, Charlie, Bob, Alice, 1);185 await transferFromExpectFail(collectionId, itemId, charlie, bob, alice, 1);
186 });186 });
187});187});
188188
189describe('Approved amount decreases by the transferred amount.:', () => {189describe('Approved amount decreases by the transferred amount.:', () => {
190 let Alice: IKeyringPair;190 let alice: IKeyringPair;
191 let Bob: IKeyringPair;191 let bob: IKeyringPair;
192 let Charlie: IKeyringPair;192 let charlie: IKeyringPair;
193 let Dave: IKeyringPair;193 let dave: IKeyringPair;
194194
195 before(async () => {195 before(async () => {
196 await usingApi(async () => {196 await usingApi(async () => {
197 Alice = privateKey('//Alice');197 alice = privateKey('//Alice');
198 Bob = privateKey('//Bob');198 bob = privateKey('//Bob');
199 Charlie = privateKey('//Charlie');199 charlie = privateKey('//Charlie');
200 Dave = privateKey('//Dave');200 dave = privateKey('//Dave');
201 });201 });
202 }); 202 });
203203
204 it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {204 it('If a user B is approved to transfer 10 Fungible tokens from user A, they can transfer 2 tokens to user C, which will result in decreasing approval from 10 to 8. Then user B can transfer 8 tokens to user D.', async () => {
205 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});205 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
206 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Alice.address); 206 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address);
207 await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 10);207 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 10);
208 await transferFromExpectSuccess(collectionId, itemId, Bob, Alice, Charlie, 2, 'Fungible');208 await transferFromExpectSuccess(collectionId, itemId, bob, alice, charlie, 2, 'Fungible');
209 await transferFromExpectSuccess(collectionId, itemId, Bob, Alice, Dave, 8, 'Fungible');209 await transferFromExpectSuccess(collectionId, itemId, bob, alice, dave, 8, 'Fungible');
210 });210 });
211});211});
212212
213describe('User may clear the approvals to approving for 0 amount:', () => {213describe('User may clear the approvals to approving for 0 amount:', () => {
214 let Alice: IKeyringPair;214 let alice: IKeyringPair;
215 let Bob: IKeyringPair;215 let bob: IKeyringPair;
216 let Charlie: IKeyringPair;216 let charlie: IKeyringPair;
217217
218 before(async () => {218 before(async () => {
219 await usingApi(async () => {219 await usingApi(async () => {
220 Alice = privateKey('//Alice');220 alice = privateKey('//Alice');
221 Bob = privateKey('//Bob');221 bob = privateKey('//Bob');
222 Charlie = privateKey('//Charlie');222 charlie = privateKey('//Charlie');
223 });223 });
224 });224 });
225225
226 it('NFT', async () => {226 it('NFT', async () => {
227 const collectionId = await createCollectionExpectSuccess();227 const collectionId = await createCollectionExpectSuccess();
228 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT');228 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT');
229 await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 1);229 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1);
230 await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 0);230 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 0);
231 await transferFromExpectFail(collectionId, itemId, Bob, Bob, Charlie, 1);231 await transferFromExpectFail(collectionId, itemId, bob, bob, charlie, 1);
232 });232 });
233233
234 it('Fungible', async () => {234 it('Fungible', async () => {
235 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});235 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
236 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');236 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
237 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 1);237 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 1);
238 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob.address, 0);238 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, alice, bob.address, 0);
239 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Bob, Charlie, 1);239 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, bob, bob, charlie, 1);
240 });240 });
241241
242 it('ReFungible', async () => {242 it('ReFungible', async () => {
243 const reFungibleCollectionId =243 const reFungibleCollectionId =
244 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});244 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
245 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');245 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
246 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 1);246 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 1);
247 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob.address, 0);247 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, alice, bob.address, 0);
248 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Bob, Charlie, 1);248 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, bob, charlie, 1);
249 });249 });
250});250});
251251
252describe('User cannot approve for the amount greater than they own:', () => {252describe('User cannot approve for the amount greater than they own:', () => {
253 let Alice: IKeyringPair;253 let alice: IKeyringPair;
254 let Bob: IKeyringPair;254 let bob: IKeyringPair;
255 let Charlie: IKeyringPair;255 let charlie: IKeyringPair;
256256
257 before(async () => {257 before(async () => {
258 await usingApi(async () => {258 await usingApi(async () => {
259 Alice = privateKey('//Alice');259 alice = privateKey('//Alice');
260 Bob = privateKey('//Bob');260 bob = privateKey('//Bob');
261 Charlie = privateKey('//Charlie');261 charlie = privateKey('//Charlie');
262 });262 });
263 });263 });
264264
265 it('1 for NFT', async () => {265 it('1 for NFT', async () => {
266 const collectionId = await createCollectionExpectSuccess();266 const collectionId = await createCollectionExpectSuccess();
267 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);267 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
268 await approveExpectFail(collectionId, itemId, Bob, Charlie, 2);268 await approveExpectFail(collectionId, itemId, bob, charlie, 2);
269 });269 });
270270
271 it('Fungible', async () => {271 it('Fungible', async () => {
272 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});272 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
273 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');273 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
274 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Charlie, 11);274 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, charlie, 11);
275 });275 });
276276
277 it('ReFungible', async () => {277 it('ReFungible', async () => {
278 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});278 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
279 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');279 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
280 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Charlie, 101);280 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, charlie, 101);
281 });281 });
282});282});
283283
284describe('Administrator and collection owner do not need approval in order to execute TransferFrom:', () => {284describe('Administrator and collection owner do not need approval in order to execute TransferFrom:', () => {
285 let Alice: IKeyringPair;285 let alice: IKeyringPair;
286 let Bob: IKeyringPair;286 let bob: IKeyringPair;
287 let Charlie: IKeyringPair;287 let charlie: IKeyringPair;
288 let Dave: IKeyringPair;288 let dave: IKeyringPair;
289289
290 before(async () => {290 before(async () => {
291 await usingApi(async () => {291 await usingApi(async () => {
292 Alice = privateKey('//Alice');292 alice = privateKey('//Alice');
293 Bob = privateKey('//Bob');293 bob = privateKey('//Bob');
294 Charlie = privateKey('//Charlie');294 charlie = privateKey('//Charlie');
295 Dave = privateKey('//Dave');295 dave = privateKey('//Dave');
296 });296 });
297 }); 297 });
298298
299 it('NFT', async () => {299 it('NFT', async () => {
300 const collectionId = await createCollectionExpectSuccess();300 const collectionId = await createCollectionExpectSuccess();
301 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Charlie.address);301 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', charlie.address);
302 await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'NFT');302 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'NFT');
303 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address);303 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
304 await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'NFT');304 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'NFT');
305 });305 });
306306
307 it('Fungible up to an approved amount', async () => {307 it('Fungible up to an approved amount', async () => {
308 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});308 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
309 const itemId = await createItemExpectSuccess(Alice, collectionId, 'Fungible', Charlie.address); 309 const itemId = await createItemExpectSuccess(alice, collectionId, 'Fungible', charlie.address);
310 await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'Fungible');310 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'Fungible');
311 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address);311 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
312 await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'Fungible');312 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'Fungible');
313 });313 });
314314
315 it('ReFungible up to an approved amount', async () => {315 it('ReFungible up to an approved amount', async () => {
316 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });316 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
317 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Charlie.address);317 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', charlie.address);
318 await transferFromExpectSuccess(collectionId, itemId, Alice, Charlie, Dave, 1, 'ReFungible');318 await transferFromExpectSuccess(collectionId, itemId, alice, charlie, dave, 1, 'ReFungible');
319 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address);319 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
320 await transferFromExpectSuccess(collectionId, itemId, Bob, Dave, Alice, 1, 'ReFungible');320 await transferFromExpectSuccess(collectionId, itemId, bob, dave, alice, 1, 'ReFungible');
321 });321 });
322});322});
323323
324describe('Repeated approvals add up', () => {324describe('Repeated approvals add up', () => {
325 let Alice: IKeyringPair;325 let alice: IKeyringPair;
326 let Bob: IKeyringPair;326 let bob: IKeyringPair;
327 let Charlie: IKeyringPair;327 let charlie: IKeyringPair;
328 let Dave: IKeyringPair;328 let dave: IKeyringPair;
329329
330 before(async () => {330 before(async () => {
331 await usingApi(async () => {331 await usingApi(async () => {
332 Alice = privateKey('//Alice');332 alice = privateKey('//Alice');
333 Bob = privateKey('//Bob');333 bob = privateKey('//Bob');
334 Charlie = privateKey('//Charlie');334 charlie = privateKey('//Charlie');
335 Dave = privateKey('//Dave');335 dave = privateKey('//Dave');
336 });336 });
337 }); 337 });
338338
339 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {339 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. Fungible', async () => {
340 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});340 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
341 await createItemExpectSuccess(Alice, collectionId, 'Fungible', Alice.address);341 await createItemExpectSuccess(alice, collectionId, 'Fungible', alice.address);
342 await approveExpectSuccess(collectionId, 0, Alice, Bob.address, 1);342 await approveExpectSuccess(collectionId, 0, alice, bob.address, 1);
343 await approveExpectSuccess(collectionId, 0, Alice, Charlie.address, 1);343 await approveExpectSuccess(collectionId, 0, alice, charlie.address, 1);
344 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);344 // const allowances1 = await getAllowance(collectionId, 0, Alice.address, Bob.address);
345 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);345 // const allowances2 = await getAllowance(collectionId, 0, Alice.address, Charlie.address);
346 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));346 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));
347 });347 });
348348
349 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async () => {349 it.skip('Owned 10, approval 1: 1, approval 2: 1, resulting approved value: 2. ReFungible', async () => {
350 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });350 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
351 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Alice.address);351 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', alice.address);
352 await approveExpectSuccess(collectionId, itemId, Alice, Bob.address, 1);352 await approveExpectSuccess(collectionId, itemId, alice, bob.address, 1);
353 await approveExpectSuccess(collectionId, itemId, Alice, Charlie.address, 1);353 await approveExpectSuccess(collectionId, itemId, alice, charlie.address, 1);
354 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);354 // const allowances1 = await getAllowance(collectionId, itemId, Alice.address, Bob.address);
355 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);355 // const allowances2 = await getAllowance(collectionId, itemId, Alice.address, Charlie.address);
356 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));356 // expect(allowances1 + allowances2).to.be.eq(BigInt(2));
359 // Canceled by changing approve logic359 // Canceled by changing approve logic
360 it.skip('Cannot approve for more than total user`s amount (owned: 10, approval 1: 5 - should succeed, approval 2: 6 - should fail). Fungible', async () => {360 it.skip('Cannot approve for more than total user`s amount (owned: 10, approval 1: 5 - should succeed, approval 2: 6 - should fail). Fungible', async () => {
361 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});361 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'Fungible', decimalPoints: 0 }});
362 await createItemExpectSuccess(Alice, collectionId, 'Fungible', Dave.address);362 await createItemExpectSuccess(alice, collectionId, 'Fungible', dave.address);
363 await approveExpectSuccess(collectionId, 0, Dave, Bob.address, 5);363 await approveExpectSuccess(collectionId, 0, dave, bob.address, 5);
364 await approveExpectFail(collectionId, 0, Dave, Charlie, 6);364 await approveExpectFail(collectionId, 0, dave, charlie, 6);
365 });365 });
366366
367 // Canceled by changing approve logic367 // Canceled by changing approve logic
368 it.skip('Cannot approve for more than total users amount (owned: 100, approval 1: 50 - should succeed, approval 2: 51 - should fail). ReFungible', async () => {368 it.skip('Cannot approve for more than total users amount (owned: 100, approval 1: 50 - should succeed, approval 2: 51 - should fail). ReFungible', async () => {
369 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });369 const collectionId = await createCollectionExpectSuccess({ mode:{ type: 'ReFungible' } });
370 const itemId = await createItemExpectSuccess(Alice, collectionId, 'ReFungible', Dave.address);370 const itemId = await createItemExpectSuccess(alice, collectionId, 'ReFungible', dave.address);
371 await approveExpectSuccess(collectionId, itemId, Dave, Bob.address, 50);371 await approveExpectSuccess(collectionId, itemId, dave, bob.address, 50);
372 await approveExpectFail(collectionId, itemId, Dave, Charlie, 51);372 await approveExpectFail(collectionId, itemId, dave, charlie, 51);
373 });373 });
374});374});
375375
376describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {376describe('Integration Test approve(spender, collection_id, item_id, amount) with collection admin permissions:', () => {
377 let Alice: IKeyringPair;377 let alice: IKeyringPair;
378 let Bob: IKeyringPair;378 let bob: IKeyringPair;
379 let Charlie: IKeyringPair;379 let charlie: IKeyringPair;
380380
381 before(async () => {381 before(async () => {
382 await usingApi(async () => {382 await usingApi(async () => {
383 Alice = privateKey('//Alice');383 alice = privateKey('//Alice');
384 Bob = privateKey('//Bob');384 bob = privateKey('//Bob');
385 Charlie = privateKey('//Charlie');385 charlie = privateKey('//Charlie');
386 });386 });
387 });387 });
388388
389 it('can be called by collection admin on non-owned item', async () => {389 it('can be called by collection admin on non-owned item', async () => {
390 const collectionId = await createCollectionExpectSuccess();390 const collectionId = await createCollectionExpectSuccess();
391 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Alice.address);391 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', alice.address);
392392
393 await addCollectionAdminExpectSuccess(Alice, collectionId, Bob.address);393 await addCollectionAdminExpectSuccess(alice, collectionId, bob.address);
394 await adminApproveFromExpectSuccess(collectionId, itemId, Bob, Alice.address, Charlie.address);394 await adminApproveFromExpectSuccess(collectionId, itemId, bob, alice.address, charlie.address);
395 });395 });
396});396});
397397
398describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {398describe('Negative Integration Test approve(spender, collection_id, item_id, amount):', () => {
399 let Alice: IKeyringPair;399 let alice: IKeyringPair;
400 let Bob: IKeyringPair;400 let bob: IKeyringPair;
401 let Charlie: IKeyringPair;401 let charlie: IKeyringPair;
402402
403 before(async () => {403 before(async () => {
404 await usingApi(async () => {404 await usingApi(async () => {
405 Alice = privateKey('//Alice');405 alice = privateKey('//Alice');
406 Bob = privateKey('//Bob');406 bob = privateKey('//Bob');
407 Charlie = privateKey('//Charlie');407 charlie = privateKey('//Charlie');
408 });408 });
409 });409 });
410410
411 it('Approve for a collection that does not exist', async () => {411 it('Approve for a collection that does not exist', async () => {
412 await usingApi(async (api: ApiPromise) => {412 await usingApi(async (api: ApiPromise) => {
413 // nft413 // nft
414 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();414 const nftCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
415 await approveExpectFail(nftCollectionCount + 1, 1, Alice, Bob);415 await approveExpectFail(nftCollectionCount + 1, 1, alice, bob);
416 // fungible416 // fungible
417 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();417 const fungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
418 await approveExpectFail(fungibleCollectionCount + 1, 0, Alice, Bob);418 await approveExpectFail(fungibleCollectionCount + 1, 0, alice, bob);
419 // reFungible419 // reFungible
420 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();420 const reFungibleCollectionCount = (await api.query.common.createdCollectionCount()).toNumber();
421 await approveExpectFail(reFungibleCollectionCount + 1, 1, Alice, Bob);421 await approveExpectFail(reFungibleCollectionCount + 1, 1, alice, bob);
422 });422 });
423 });423 });
424424
425 it('Approve for a collection that was destroyed', async () => {425 it('Approve for a collection that was destroyed', async () => {
426 // nft426 // nft
427 const nftCollectionId = await createCollectionExpectSuccess();427 const nftCollectionId = await createCollectionExpectSuccess();
428 await destroyCollectionExpectSuccess(nftCollectionId);428 await destroyCollectionExpectSuccess(nftCollectionId);
429 await approveExpectFail(nftCollectionId, 1, Alice, Bob);429 await approveExpectFail(nftCollectionId, 1, alice, bob);
430 // fungible430 // fungible
431 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});431 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
432 await destroyCollectionExpectSuccess(fungibleCollectionId);432 await destroyCollectionExpectSuccess(fungibleCollectionId);
433 await approveExpectFail(fungibleCollectionId, 0, Alice, Bob);433 await approveExpectFail(fungibleCollectionId, 0, alice, bob);
434 // reFungible434 // reFungible
435 const reFungibleCollectionId =435 const reFungibleCollectionId =
436 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});436 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
437 await destroyCollectionExpectSuccess(reFungibleCollectionId);437 await destroyCollectionExpectSuccess(reFungibleCollectionId);
438 await approveExpectFail(reFungibleCollectionId, 1, Alice, Bob);438 await approveExpectFail(reFungibleCollectionId, 1, alice, bob);
439 });439 });
440440
441 it('Approve transfer of a token that does not exist', async () => {441 it('Approve transfer of a token that does not exist', async () => {
442 // nft442 // nft
443 const nftCollectionId = await createCollectionExpectSuccess();443 const nftCollectionId = await createCollectionExpectSuccess();
444 await approveExpectFail(nftCollectionId, 2, Alice, Bob);444 await approveExpectFail(nftCollectionId, 2, alice, bob);
445 // reFungible445 // reFungible
446 const reFungibleCollectionId =446 const reFungibleCollectionId =
447 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});447 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
448 await approveExpectFail(reFungibleCollectionId, 2, Alice, Bob);448 await approveExpectFail(reFungibleCollectionId, 2, alice, bob);
449 });449 });
450450
451 it('Approve using the address that does not own the approved token', async () => {451 it('Approve using the address that does not own the approved token', async () => {
452 const nftCollectionId = await createCollectionExpectSuccess();452 const nftCollectionId = await createCollectionExpectSuccess();
453 // nft453 // nft
454 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');454 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'NFT');
455 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice);455 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice);
456 // fungible456 // fungible
457 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});457 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
458 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');458 const newFungibleTokenId = await createItemExpectSuccess(alice, fungibleCollectionId, 'Fungible');
459 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice);459 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, bob, alice);
460 // reFungible460 // reFungible
461 const reFungibleCollectionId =461 const reFungibleCollectionId =
462 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});462 await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
463 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');463 const newReFungibleTokenId = await createItemExpectSuccess(alice, reFungibleCollectionId, 'ReFungible');
464 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice);464 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, bob, alice);
465 });465 });
466466
467 it('should fail if approved more ReFungibles than owned', async () => {467 it('should fail if approved more ReFungibles than owned', async () => {
468 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});468 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible'}});
469 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'ReFungible');469 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'ReFungible');
470 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 100, 'ReFungible');470 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 100, 'ReFungible');
471 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice.address, 100);471 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 100);
472 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 101);472 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 101);
473 });473 });
474474
475 it('should fail if approved more Fungibles than owned', async () => {475 it('should fail if approved more Fungibles than owned', async () => {
476 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});476 const nftCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
477 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'Fungible');477 const newNftTokenId = await createItemExpectSuccess(alice, nftCollectionId, 'Fungible');
478 await transferExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob, 10, 'Fungible');478 await transferExpectSuccess(nftCollectionId, newNftTokenId, alice, bob, 10, 'Fungible');
479 await approveExpectSuccess(nftCollectionId, newNftTokenId, Bob, Alice.address, 10);479 await approveExpectSuccess(nftCollectionId, newNftTokenId, bob, alice.address, 10);
480 await approveExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, 11);480 await approveExpectFail(nftCollectionId, newNftTokenId, bob, alice, 11);
481 });481 });
482482
483 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {483 it('fails when called by collection owner on non-owned item when OwnerCanTransfer == false', async () => {
484 const collectionId = await createCollectionExpectSuccess();484 const collectionId = await createCollectionExpectSuccess();
485 const itemId = await createItemExpectSuccess(Alice, collectionId, 'NFT', Bob.address);485 const itemId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
486 await setCollectionLimitsExpectSuccess(Alice, collectionId, {ownerCanTransfer: false});486 await setCollectionLimitsExpectSuccess(alice, collectionId, {ownerCanTransfer: false});
487487
488 await approveExpectFail(collectionId, itemId, Alice, Charlie);488 await approveExpectFail(collectionId, itemId, alice, charlie);
489 });489 });
490});490});
491491