git.delta.rocks / unique-network / refs/commits / 4fc0eb51c33a

difftreelog

Merge pull request #90 from usetech-llc/feature/transferfromtests

Greg Zaitsev2021-02-09parents: #337b8d4 #2e2d3bf.patch.diff
in: master
transferFrom burnt token before&after approve test

2 files changed

modifiedtests/src/transferFrom.test.tsdiffbeforeafterboth
15 destroyCollectionExpectSuccess,15 destroyCollectionExpectSuccess,
16 transferFromExpectFail,16 transferFromExpectFail,
17 transferFromExpectSuccess,17 transferFromExpectSuccess,
18 burnItemExpectSuccess,
18} from './util/helpers';19} from './util/helpers';
1920
20chai.use(chaiAsPromised);21chai.use(chaiAsPromised);
185 }186 }
186 });187 });
187 });188 });
189 it( 'transferFrom burnt token before approve NFT', async () => {
190 await usingApi(async (api: ApiPromise) => {
191 const Alice = privateKey('//Alice');
192 const Bob = privateKey('//Bob');
193 const Charlie = privateKey('//Charlie');
194 // nft
195 const nftCollectionId = await createCollectionExpectSuccess();
196 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
197 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
198 await approveExpectFail(nftCollectionId, newNftTokenId, Alice, Bob);
199 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);
200 });
201 });
202 it( 'transferFrom burnt token before approve Fungible', async () => {
203 await usingApi(async (api: ApiPromise) => {
204 const Alice = privateKey('//Alice');
205 const Bob = privateKey('//Bob');
206 const Charlie = privateKey('//Charlie');
207 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
208 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
209 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
210 await approveExpectFail(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
211 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
212
213 });
214 });
215 it( 'transferFrom burnt token before approve ReFungible', async () => {
216 await usingApi(async (api: ApiPromise) => {
217 const Alice = privateKey('//Alice');
218 const Bob = privateKey('//Bob');
219 const Charlie = privateKey('//Charlie');
220 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
221 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
222 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
223 await approveExpectFail(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
224 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
225
226 });
227 });
228
229 it( 'transferFrom burnt token after approve NFT', async () => {
230 await usingApi(async (api: ApiPromise) => {
231 const Alice = privateKey('//Alice');
232 const Bob = privateKey('//Bob');
233 const Charlie = privateKey('//Charlie');
234 // nft
235 const nftCollectionId = await createCollectionExpectSuccess();
236 const newNftTokenId = await createItemExpectSuccess(Alice, nftCollectionId, 'NFT');
237 await approveExpectSuccess(nftCollectionId, newNftTokenId, Alice, Bob);
238 await burnItemExpectSuccess(Alice, nftCollectionId, newNftTokenId, 1);
239 await transferFromExpectFail(nftCollectionId, newNftTokenId, Bob, Alice, Charlie, 1);
240 });
241 });
242 it( 'transferFrom burnt token after approve Fungible', async () => {
243 await usingApi(async (api: ApiPromise) => {
244 const Alice = privateKey('//Alice');
245 const Bob = privateKey('//Bob');
246 const Charlie = privateKey('//Charlie');
247 const fungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
248 const newFungibleTokenId = await createItemExpectSuccess(Alice, fungibleCollectionId, 'Fungible');
249 await approveExpectSuccess(fungibleCollectionId, newFungibleTokenId, Alice, Bob);
250 await burnItemExpectSuccess(Alice, fungibleCollectionId, 1, 10);
251 await transferFromExpectFail(fungibleCollectionId, newFungibleTokenId, Bob, Alice, Charlie, 1);
252
253 });
254 });
255 it( 'transferFrom burnt token after approve ReFungible', async () => {
256 await usingApi(async (api: ApiPromise) => {
257 const Alice = privateKey('//Alice');
258 const Bob = privateKey('//Bob');
259 const Charlie = privateKey('//Charlie');
260 const reFungibleCollectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
261 const newReFungibleTokenId = await createItemExpectSuccess(Alice, reFungibleCollectionId, 'ReFungible');
262 await approveExpectSuccess(reFungibleCollectionId, newReFungibleTokenId, Alice, Bob);
263 await burnItemExpectSuccess(Alice, reFungibleCollectionId, newReFungibleTokenId, 1);
264 await transferFromExpectFail(reFungibleCollectionId, newReFungibleTokenId, Bob, Alice, Charlie, 1);
265
266 });
267 });
188});268});
189269
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -359,6 +359,7 @@
   });
 }
 
+
 export async function confirmSponsorshipExpectFailure(collectionId: number, senderSeed: string = '//Alice') {
   await usingApi(async (api) => {
 
@@ -505,7 +506,7 @@
 
 export async function
 approveExpectSuccess(collectionId: number,
-                     tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
+                     tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) { //alice,bob
   await usingApi(async (api: ApiPromise) => {
     const allowanceBefore =
       await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;
@@ -523,9 +524,9 @@
 export async function
 transferFromExpectSuccess(collectionId: number,
                           tokenId: number,
-                          accountApproved: IKeyringPair,
-                          accountFrom: IKeyringPair,
-                          accountTo: IKeyringPair,
+                          accountApproved: IKeyringPair, //bob
+                          accountFrom: IKeyringPair, //alice
+                          accountTo: IKeyringPair, //charlie
                           value: number = 1,
                           type: string = 'NFT') {
   await usingApi(async (api: ApiPromise) => {