difftreelog
Confirm sponsorship tests in progress
in: master
3 files changed
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -13,10 +13,14 @@
setCollectionSponsorExpectFailure,
confirmSponsorshipExpectSuccess,
confirmSponsorshipExpectFailure,
+ createItemExpectSuccess,
+ findUnusedAddress,
+ getGenericResult,
} from "./util/helpers";
import { Keyring } from "@polkadot/api";
import { IKeyringPair } from "@polkadot/types/types";
import type { AccountId } from '@polkadot/types/interfaces';
+import { BigNumber } from 'bignumber.js';
chai.use(chaiAsPromised);
const expect = chai.expect;
@@ -30,6 +34,7 @@
before(async () => {
await usingApi(async (api) => {
const keyring = new Keyring({ type: 'sr25519' });
+ alice = keyring.addFromUri(`//Alice`);
bob = keyring.addFromUri(`//Bob`);
charlie = keyring.addFromUri(`//Charlie`);
});
@@ -53,11 +58,31 @@
await setCollectionSponsorExpectSuccess(collectionId, charlie.address);
});
- it.skip('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');
- expect(false).to.be.true;
+ it.only('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());
+
+ // Find unused address
+ const zeroBalance = await findUnusedAddress(api);
+
+ const aliceToZero = api.tx.nft.transfer(zeroBalance.address, collectionId, itemId, 0);
+ await submitTransactionAsync(alice, aliceToZero);
+
+ 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());
+
+ expect(result.success).to.be.true;
+ expect(BsponsorBalance.toNumber()).to.be.lessThan(AsponsorBalance.toNumber());
+ });
+
});
it.skip('CreateItem fees are paid by the sponsor after confirmation', async () => {
tests/src/createItem.test.tsdiffbeforeafterbothno changes
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -26,6 +26,12 @@
collectionId: number
};
+type CreateItemResult = {
+ success: boolean,
+ collectionId: number,
+ itemId: number
+};
+
export function getGenericResult(events: EventRecord[]): GenericResult {
let result: GenericResult = {
success: false
@@ -57,6 +63,27 @@
return result;
}
+function getCreateItemResult(events: EventRecord[]): CreateItemResult {
+ let success = false;
+ let collectionId: number = 0;
+ let itemId: number = 0;
+ events.forEach(({ phase, event: { data, method, section } }) => {
+ // console.log(` ${phase}: ${section}.${method}:: ${data}`);
+ if (method == 'ExtrinsicSuccess') {
+ success = true;
+ } else if ((section == 'nft') && (method == 'ItemCreated')) {
+ collectionId = parseInt(data[0].toString());
+ itemId = parseInt(data[1].toString());
+ }
+ });
+ let result: CreateItemResult = {
+ success,
+ collectionId,
+ itemId
+ }
+ return result;
+}
+
export async function createCollectionExpectSuccess(name: string, description: string, tokenPrefix: string, mode: string): Promise<number> {
let collectionId: number = 0;
await usingApi(async (api) => {
@@ -231,3 +258,24 @@
});
}
+export async function createItemExpectSuccess(collectionId: number, createMode: 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);
+ const events = await submitTransactionAsync(sender, tx);
+ const result = getCreateItemResult(events);
+
+ const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());
+
+ // What to expect
+ expect(result.success).to.be.true;
+ expect(BItemCount).to.be.equal(AItemCount+1);
+ expect(collectionId).to.be.equal(result.collectionId);
+ expect(BItemCount).to.be.equal(result.itemId);
+ newItemId = result.itemId;
+ });
+ return newItemId;
+}