difftreelog
Add tests for sponsorship
in: master
4 files changed
pallets/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;
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth58 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);58 await setCollectionSponsorExpectSuccess(collectionId, charlie.address);59 });59 });606061 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');666567 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());696870 // Find unused address69 // Find unused address71 const zeroBalance = await findUnusedAddress(api);70 const zeroBalance = await findUnusedAddress(api);72 7172 // Mint token for unused address73 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);747575 // Transfer this token from unused address to Alice76 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);797980 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());818182 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 });858586 });86 });8788 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {89 expect(false).to.be.true;90 });9192 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {93 expect(false).to.be.true;94 });879588 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 });102103 it('NFT: Sponsoring is rate limited', async () => {104 expect(false).to.be.true;105 });106107 it('Fungible: Sponsoring is rate limited', async () => {108 expect(false).to.be.true;109 });110111 it('ReFungible: Sponsoring is rate limited', async () => {112 expect(false).to.be.true;113 });9411495});115});96116tests/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);
});
});
tests/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);