git.delta.rocks / unique-network / refs/commits / 427c943f97f4

difftreelog

Add tests for sponsorship

Greg Zaitsev2020-12-23parent: #298277a.patch.diff
in: master

4 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -2356,6 +2356,7 @@
                 
                 let mut sponsor_transfer = false;
                 if <Collection<T>>::get(collection_id).sponsor_confirmed {
+
                     let collection_limits = <Collection<T>>::get(collection_id).limits;
                     let collection_mode = <Collection<T>>::get(collection_id).mode;
     
modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -58,33 +58,41 @@
     await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
   });
 
-  it.only('Transfer fees are paid by the sponsor after confirmation', async () => {
+  it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {
     const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
     await setCollectionSponsorExpectSuccess(collectionId, bob.address);
     await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
-    const itemId = await createItemExpectSuccess(collectionId, 'NFT', '//Alice');
 
     await usingApi(async (api) => {
-      const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).toString());
+      const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
 
       // Find unused address
       const zeroBalance = await findUnusedAddress(api);
-      
-      const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
-      await submitTransactionAsync(alice, aliceToZero);
 
+      // Mint token for unused address
+      const itemId = await createItemExpectSuccess(collectionId, 'NFT', zeroBalance.address, '//Alice');
+
+      // Transfer this token from unused address to Alice
       const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
       const events = await submitTransactionAsync(zeroBalance, zeroToAlice);
       const result = getGenericResult(events);
 
-      const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).toString());
+      const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
 
       expect(result.success).to.be.true;
-      expect(BsponsorBalance.toNumber()).to.be.lessThan(AsponsorBalance.toNumber());
+      expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
     });
 
   });
 
+  it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {
+    expect(false).to.be.true;
+  });
+
+  it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {
+    expect(false).to.be.true;
+  });
+
   it.skip('CreateItem fees are paid by the sponsor after confirmation', async () => {
     // const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
     // await setCollectionSponsorExpectSuccess(collectionId, bob.address);
@@ -92,6 +100,18 @@
     expect(false).to.be.true;
   });
 
+  it('NFT: Sponsoring is rate limited', async () => {
+    expect(false).to.be.true;
+  });
+
+  it('Fungible: Sponsoring is rate limited', async () => {
+    expect(false).to.be.true;
+  });
+
+  it('ReFungible: Sponsoring is rate limited', async () => {
+    expect(false).to.be.true;
+  });
+
 });
 
 describe('(!negative test!) integration test: ext. setCollectionSponsor():', () => {
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
12 it('Create new item in NFT collection', async () => { 12 it('Create new item in NFT collection', async () => {
13 const createMode = 'NFT'; 13 const createMode = 'NFT';
14 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode); 14 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
15 await createItemExpectSuccess(newCollectionID, createMode, '//Alice'); 15 await createItemExpectSuccess(newCollectionID, createMode);
16 }); 16 });
17 it('Create new item in Fungible collection', async () => { 17 it('Create new item in Fungible collection', async () => {
18 const createMode = 'Fungible'; 18 const createMode = 'Fungible';
19 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode); 19 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
20 await createItemExpectSuccess(newCollectionID, createMode, '//Alice'); 20 await createItemExpectSuccess(newCollectionID, createMode);
21 }); 21 });
22 it('Create new item in ReFungible collection', async () => { 22 it('Create new item in ReFungible collection', async () => {
23 const createMode = 'ReFungible'; 23 const createMode = 'ReFungible';
24 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode); 24 const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
25 await createItemExpectSuccess(newCollectionID, createMode, '//Alice'); 25 await createItemExpectSuccess(newCollectionID, createMode);
26 }); 26 });
27}); 27});
2828
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -258,13 +258,14 @@
   });
 }
 
-export async function createItemExpectSuccess(collectionId: number, createMode: string, senderSeed: string = '//Alice') {
+export async function createItemExpectSuccess(collectionId: number, createMode: string, owner: string = '', senderSeed: string = '//Alice') {
   let newItemId: number = 0;
   await usingApi(async (api) => {
     const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());
 
     const sender = privateKey(senderSeed);
-    const tx = api.tx.nft.createItem(collectionId, sender.address, createMode);
+    if (owner === '') owner = sender.address;
+    const tx = api.tx.nft.createItem(collectionId, owner, createMode);
     const events = await submitTransactionAsync(sender, tx);
     const result = getCreateItemResult(events);