diff --git a/test/scripts/print-failed-tests.ts b/test/scripts/print-failed-tests.ts new file mode 100755 index 0000000000..ca1fa11454 --- /dev/null +++ b/test/scripts/print-failed-tests.ts @@ -0,0 +1,29 @@ +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.resolve(path.dirname(__filename), ".."); + +["Moonbeam", "Moonriver", "Moonbase"].forEach((runtime) => { + const outputPath = `${__dirname}/tmp/testResults${runtime}.json`; + if (!fs.existsSync(outputPath)) { + return; + } + + const fileContent = fs.readFileSync(outputPath, { encoding: "utf-8" }); + const { testResults } = JSON.parse(fileContent); + + const failedSuites = testResults.filter((suite) => suite.status !== "passed"); + const failedTests = failedSuites + .flatMap((suite) => { + const file = suite.name.replaceAll(__dirname, ""); + const fails = suite.assertionResults.map((test) => `\n\t\t> ${test.title.trim()}`).join(""); + return `\t- ${file}${fails}`; + }) + .join("\n"); + + if (failedTests) { + console.log(`Failed tests for ${runtime}:\n`, failedTests); + } +}); diff --git a/test/suites/dev/moonbase/test-treasury/test-treasury-pallet.ts b/test/suites/dev/moonbase/test-treasury/test-treasury-pallet.ts index 8690e97fde..92ccf5d0e7 100644 --- a/test/suites/dev/moonbase/test-treasury/test-treasury-pallet.ts +++ b/test/suites/dev/moonbase/test-treasury/test-treasury-pallet.ts @@ -3,21 +3,26 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import type { ApiPromise } from "@polkadot/api"; import { alith, baltathar, ethan } from "@moonwall/util"; import { expectSubstrateEvent } from "../../../../helpers"; +import type { FrameSupportPalletId } from "@polkadot/types/lookup"; describeSuite({ id: "D013801", title: "Treasury pallet tests", foundationMethods: "dev", testCases: ({ context, log, it }) => { + let treasuryPalletId: FrameSupportPalletId; + let treasuryAddress: string; let api: ApiPromise; beforeAll(async function () { api = context.polkadotJs(); + treasuryPalletId = api.consts.treasury.palletId; + treasuryAddress = `0x6d6f646C${treasuryPalletId.toString().slice(2)}0000000000000000`; }); it({ id: "T01", - title: "Non root cannot spend (local)", + title: "Origins that are not Root or members of treasury council cannot spend treasury funds", test: async function () { expect((await api.query.treasury.spendCount()).toNumber()).to.equal(0); @@ -25,9 +30,9 @@ describeSuite({ const proposal_value = 1000000000n; const tx = api.tx.treasury.spendLocal(proposal_value, ethan.address); const signedTx = await tx.signAsync(baltathar); - const blockResult = await context.createBlock(signedTx); - - expectSubstrateEvent(blockResult, "system", "ExtrinsicFailed"); + await context.createBlock(signedTx, { + expectEvents: [api.events.system.ExtrinsicFailed], + }); expect((await api.query.treasury.proposalCount()).toNumber()).to.equal(0); expect((await api.query.treasury.spendCount()).toNumber()).to.equal(0); @@ -36,22 +41,76 @@ describeSuite({ it({ id: "T02", - title: "Root should be able to spend (local) and approve a proposal", - timeout: -1, + title: "Root can spend treasury funds", test: async function () { - const spendPeriod = api.consts.treasury.spendPeriod.toNumber(); + // Fund treasury + const treasuryPot = 2_000_000_000_000_000n; + await context.createBlock( + await api.tx.balances.transferAllowDeath(treasuryAddress, treasuryPot), + { allowFailures: false } + ); + await context.createBlock(); + expect((await api.query.treasury.deactivated()).toBigInt()).toBeGreaterThan(treasuryPot); - expect((await api.query.treasury.spendCount()).toNumber()).to.equal(0); - // Creates a proposal - // Value needs to be higher than the transaction fee paid by ethan, - // but lower than the total treasury pot - const proposal_value = 1000000000n; + // Pre-checks + expect((await api.query.treasury.proposalCount()).toNumber()).to.equal(0); + expect((await api.query.treasury.approvals()).length).to.equal(0); + + // Approve treasury spend to Ethan + const proposal_value = 1_000_000_000_000_000n; const tx = api.tx.treasury.spendLocal(proposal_value, ethan.address); const signedTx = await api.tx.sudo.sudo(tx).signAsync(alith); - const blockResult = await context.createBlock(signedTx, { allowFailures: false }); + await context.createBlock(signedTx, { + allowFailures: false, + expectEvents: [api.events.treasury.SpendApproved], + }); + + // Spending was successfully approved + expect((await api.query.treasury.proposalCount()).toNumber()).to.equal(1); + expect((await api.query.treasury.approvals()).length).to.equal(1); + }, + }); + + it({ + id: "T03", + title: "Members of the treasury council can spend treasury funds", + test: async function () { + // Set Alith as member of the treasury council + const setMembersTX = api.tx.treasuryCouncilCollective.setMembers( + [alith.address], + alith.address, + 3 + ); + await context.createBlock(await api.tx.sudo.sudo(setMembersTX).signAsync(alith), { + allowFailures: false, + }); + + // Fund treasury + const treasuryPot = 2_000_000_000_000_000n; + await context.createBlock( + await api.tx.balances.transferAllowDeath(treasuryAddress, treasuryPot), + { allowFailures: false } + ); + await context.createBlock(); + expect((await api.query.treasury.deactivated()).toBigInt()).toBeGreaterThan(treasuryPot); + + // Pre-checks + expect((await api.query.treasury.proposalCount()).toNumber()).to.equal(0); + expect((await api.query.treasury.approvals()).length).to.equal(0); + + // Approve treasury spend to Ethan + const proposal_value = 1_000_000_000_000_000n; + const tx = api.tx.treasury.spendLocal(proposal_value, ethan.address); + const signedTx = api.tx.treasuryCouncilCollective.propose(1, tx, 1_000).signAsync(alith); + + await context.createBlock(signedTx, { + allowFailures: false, + expectEvents: [api.events.treasury.SpendApproved], + }); - expectSubstrateEvent(blockResult, "treasury", "SpendApproved"); + // Spending was successfully approved expect((await api.query.treasury.proposalCount()).toNumber()).to.equal(1); + expect((await api.query.treasury.approvals()).length).to.equal(1); }, }); },