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

no syntactic changes

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
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
258 });258 });
259}259}
260260
261export async function createItemExpectSuccess(collectionId: number, createMode: string, senderSeed: string = '//Alice') {261export async function createItemExpectSuccess(collectionId: number, createMode: string, owner: string = '', senderSeed: string = '//Alice') {
262 let newItemId: number = 0;262 let newItemId: number = 0;
263 await usingApi(async (api) => {263 await usingApi(async (api) => {
264 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());264 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());
265265
266 const sender = privateKey(senderSeed);266 const sender = privateKey(senderSeed);
267 if (owner === '') owner = sender.address;
267 const tx = api.tx.nft.createItem(collectionId, sender.address, createMode);268 const tx = api.tx.nft.createItem(collectionId, owner, createMode);
268 const events = await submitTransactionAsync(sender, tx);269 const events = await submitTransactionAsync(sender, tx);
269 const result = getCreateItemResult(events);270 const result = getCreateItemResult(events);
270 271