--- a/tests/src/confirmSponsorship.test.ts +++ b/tests/src/confirmSponsorship.test.ts @@ -89,7 +89,7 @@ }); it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => { - const collectionId = await createCollectionExpectSuccess(); + const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'}); await setCollectionSponsorExpectSuccess(collectionId, bob.address); await confirmSponsorshipExpectSuccess(collectionId, '//Bob'); @@ -115,7 +115,7 @@ }); it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => { - const collectionId = await createCollectionExpectSuccess(); + const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'}); await setCollectionSponsorExpectSuccess(collectionId, bob.address); await confirmSponsorshipExpectSuccess(collectionId, '//Bob'); @@ -210,7 +210,7 @@ }); it('Fungible: Sponsoring is rate limited', async () => { - const collectionId = await createCollectionExpectSuccess(); + const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'}); await setCollectionSponsorExpectSuccess(collectionId, bob.address); await confirmSponsorshipExpectSuccess(collectionId, '//Bob'); @@ -247,7 +247,7 @@ }); it('ReFungible: Sponsoring is rate limited', async () => { - const collectionId = await createCollectionExpectSuccess(); + const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'}); await setCollectionSponsorExpectSuccess(collectionId, bob.address); await confirmSponsorshipExpectSuccess(collectionId, '//Bob'); --- a/tests/src/creditFeesToTreasury.test.ts +++ b/tests/src/creditFeesToTreasury.test.ts @@ -5,7 +5,7 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; -import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api"; +import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api"; import { alicesPublicKey, bobsPublicKey } from "./accounts"; import privateKey from "./substrate/privateKey"; import { BigNumber } from 'bignumber.js'; @@ -63,14 +63,13 @@ const bobBalanceBefore = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString()); const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0); - const result = getGenericResult(await submitTransactionAsync(bobPrivateKey, badTx)); + await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected; const treasuryBalanceAfter = new BigNumber((await api.query.system.account(Treasury)).data.free.toString()); const bobBalanceAfter = new BigNumber((await api.query.system.account(bobsPublicKey)).data.free.toString()); const fee = bobBalanceBefore.minus(bobBalanceAfter); const treasuryIncrease = treasuryBalanceAfter.minus(treasuryBalanceBefore); - expect(result.success).to.be.false; expect(treasuryIncrease.toFixed()).to.be.equal(fee.toFixed()); }); }); --- a/tests/src/substrate/substrate-api.ts +++ b/tests/src/substrate/substrate-api.ts @@ -68,7 +68,7 @@ resolve(events); } else if (transactionStatus == TransactionStatus.Fail) { console.log(`Something went wrong with transaction. Status: ${status}`); - reject("Transaction failed"); + reject(events); } }); } catch (e) { @@ -107,7 +107,7 @@ if (transactionStatus == TransactionStatus.Success) { resolve(events); } else if (transactionStatus == TransactionStatus.Fail) { - reject("Transaction failed"); + reject(events); } }); } catch (e) { --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -7,7 +7,7 @@ import chaiAsPromised from 'chai-as-promised'; import type { AccountId, EventRecord } from '@polkadot/types/interfaces'; import { ApiPromise, Keyring } from "@polkadot/api"; -import { default as usingApi, submitTransactionAsync } from "../substrate/substrate-api"; +import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "../substrate/substrate-api"; import privateKey from '../substrate/privateKey'; import { alicesPublicKey, nullPublicKey } from "../accounts"; import { strToUTF16, utf16ToStr, hexToStr } from '../util/util'; @@ -147,7 +147,7 @@ // Run the CreateCollection transaction const alicePrivateKey = privateKey('//Alice'); const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), mode); - const events = await submitTransactionAsync(alicePrivateKey, tx); + const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected; const result = getCreateCollectionResult(events); // Get number of collections after the transaction @@ -187,11 +187,7 @@ // Run the DestroyCollection transaction const alicePrivateKey = privateKey(senderSeed); const tx = api.tx.nft.destroyCollection(collectionId); - const events = await submitTransactionAsync(alicePrivateKey, tx); - const result = getDestroyResult(events); - - // What to expect - expect(result).to.be.false; + await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected; }); } @@ -257,11 +253,7 @@ // Run the transaction const alicePrivateKey = privateKey('//Alice'); const tx = api.tx.nft.removeCollectionSponsor(collectionId); - const events = await submitTransactionAsync(alicePrivateKey, tx); - const result = getGenericResult(events); - - // What to expect - expect(result.success).to.be.false; + await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected; }); } @@ -271,11 +263,7 @@ // Run the transaction const alicePrivateKey = privateKey(senderSeed); const tx = api.tx.nft.setCollectionSponsor(collectionId, sponsor); - const events = await submitTransactionAsync(alicePrivateKey, tx); - const result = getGenericResult(events); - - // What to expect - expect(result.success).to.be.false; + await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected; }); } @@ -304,11 +292,7 @@ // Run the transaction const sender = privateKey(senderSeed); const tx = api.tx.nft.confirmSponsorship(collectionId); - const events = await submitTransactionAsync(sender, tx); - const result = getGenericResult(events); - - // What to expect - expect(result.success).to.be.false; + await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected; }); }