Skip to content

Commit

Permalink
add substrate based tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TarekkMA committed Nov 13, 2024
1 parent 7f17edf commit 2841fc9
Showing 1 changed file with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describeSuite, expect, TransactionTypes } from "@moonwall/cli";
import {
alith,
baltathar,
BALTATHAR_ADDRESS,
createRawTransfer,
extractFee,
Expand All @@ -18,7 +19,9 @@ describeSuite({
for (const txnType of TransactionTypes) {
it({
id: `T${++testCounter}`,
title: `should send 0% of fees to treasury for ${txnType} transfers`,
title:
`Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` +
` Ethereum ${txnType} transfers`,
test: async () => {
const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0);
await context.createBlock(
Expand Down Expand Up @@ -53,5 +56,89 @@ describeSuite({
},
});
}

it({
id: `T${++testCounter}`,
title:
`Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` +
` Substrate based transactions with no tip`,
test: async () => {
const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0);
await context.createBlock(
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a()))
.signAsync(alith),
{ allowFailures: false }
);

const balanceBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT });
const issuanceBefore = (
await context.polkadotJs().query.balances.totalIssuance()
).toBigInt();

const { result } = await context.createBlock(
context
.polkadotJs()
.tx.balances.transfer(alith.address, 128)
.signAsync(baltathar, { tip: 0 }),
{ allowFailures: false }
);

const balanceAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT });
const issuanceAfter = (
await context.polkadotJs().query.balances.totalIssuance()
).toBigInt();

const treasuryIncrease = balanceAfter - balanceBefore;
const fee = extractFee(result?.events)!.amount.toBigInt();
expect(treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n);

const issuanceDecrease = issuanceBefore - issuanceAfter;
expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal(100n);
},
});

it({
id: `T${++testCounter}`,
title:
`Changing FeesTreasuryProportion to zero should send 0% of fees to treasury for` +
` Substrate based transactions with tip`,
test: async () => {
const param = parameterType(context, "RuntimeConfig", "FeesTreasuryProportion", 0);
await context.createBlock(
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param.toU8a()))
.signAsync(alith),
{ allowFailures: false }
);

const balanceBefore = await context.viem().getBalance({ address: TREASURY_ACCOUNT });
const issuanceBefore = (
await context.polkadotJs().query.balances.totalIssuance()
).toBigInt();

const { result } = await context.createBlock(
context
.polkadotJs()
.tx.balances.transfer(alith.address, 128)
.signAsync(baltathar, { tip: 128 }),
{ allowFailures: false }
);

const balanceAfter = await context.viem().getBalance({ address: TREASURY_ACCOUNT });
const issuanceAfter = (
await context.polkadotJs().query.balances.totalIssuance()
).toBigInt();

const treasuryIncrease = balanceAfter - balanceBefore;
const fee = extractFee(result?.events)!.amount.toBigInt();
expect(treasuryIncrease, "0% of the fees should go to treasury").to.equal(0n);

const issuanceDecrease = issuanceBefore - issuanceAfter;
expect((fee * 100n) / issuanceDecrease, "100% of the fees should be burned").to.equal(100n);
},
});
},
});

0 comments on commit 2841fc9

Please sign in to comment.