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
58 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);58 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
59 });59 });
6060
61 it.only('Transfer fees are paid by the sponsor after confirmation', async () => {61 it('NFT: Transfer fees are paid by the sponsor after confirmation', async () => {
62 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');62 const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
63 await setCollectionSponsorExpectSuccess(collectionId, bob.address);63 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
64 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');64 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
65 const itemId = await createItemExpectSuccess(collectionId, 'NFT', '//Alice');
6665
67 await usingApi(async (api) => {66 await usingApi(async (api) => {
68 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).toString());67 const AsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
6968
70 // Find unused address69 // Find unused address
71 const zeroBalance = await findUnusedAddress(api);70 const zeroBalance = await findUnusedAddress(api);
72 71
72 // Mint token for unused address
73 const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);73 const itemId = await createItemExpectSuccess(collectionId, 'NFT', zeroBalance.address, '//Alice');
74 await submitTransactionAsync(alice, aliceToZero);74
7575 // Transfer this token from unused address to Alice
76 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);76 const zeroToAlice = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
77 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);77 const events = await submitTransactionAsync(zeroBalance, zeroToAlice);
78 const result = getGenericResult(events);78 const result = getGenericResult(events);
7979
80 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).toString());80 const BsponsorBalance = new BigNumber((await api.query.system.account(bob.address)).data.free.toString());
8181
82 expect(result.success).to.be.true;82 expect(result.success).to.be.true;
83 expect(BsponsorBalance.toNumber()).to.be.lessThan(AsponsorBalance.toNumber());83 expect(BsponsorBalance.lt(AsponsorBalance)).to.be.true;
84 });84 });
8585
86 });86 });
87
88 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {
89 expect(false).to.be.true;
90 });
91
92 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {
93 expect(false).to.be.true;
94 });
8795
88 it.skip('CreateItem fees are paid by the sponsor after confirmation', async () => {96 it.skip('CreateItem fees are paid by the sponsor after confirmation', async () => {
89 // const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');97 // const collectionId = await createCollectionExpectSuccess('A', 'B', 'C', 'NFT');
92 expect(false).to.be.true;100 expect(false).to.be.true;
93 });101 });
102
103 it('NFT: Sponsoring is rate limited', async () => {
104 expect(false).to.be.true;
105 });
106
107 it('Fungible: Sponsoring is rate limited', async () => {
108 expect(false).to.be.true;
109 });
110
111 it('ReFungible: Sponsoring is rate limited', async () => {
112 expect(false).to.be.true;
113 });
94114
95});115});
96116
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -12,16 +12,16 @@
   it('Create new item in NFT collection', async () => {
     const createMode = 'NFT';
     const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
-    await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
+    await createItemExpectSuccess(newCollectionID, createMode);
   });
   it('Create new item in Fungible collection', async () => {
     const createMode = 'Fungible';
     const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
-    await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
+    await createItemExpectSuccess(newCollectionID, createMode);
   });
   it('Create new item in ReFungible collection', async () => {
     const createMode = 'ReFungible';
     const newCollectionID = await createCollectionExpectSuccess('0', '0', '0', createMode);
-    await createItemExpectSuccess(newCollectionID, createMode, '//Alice');
+    await createItemExpectSuccess(newCollectionID, createMode);
   });
 });
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);