Skip to content

Commit

Permalink
test: add rust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RomarQ committed Jan 14, 2025
1 parent bdf5101 commit 8520cfb
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 3 deletions.
71 changes: 71 additions & 0 deletions runtime/moonbase/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use moonbase_runtime::{
RuntimeBlockWeights,
RuntimeCall,
RuntimeEvent,
Sudo,
System,
TransactionPayment,
TransactionPaymentAsGasPrice,
Expand Down Expand Up @@ -2973,6 +2974,76 @@ fn validate_transaction_fails_on_filtered_call() {
});
}

#[test]
fn test_treasury_spend_local() {
ExtBuilder::default()
.with_balances(vec![
(AccountId::from(ALICE), 2_000 * UNIT),
(AccountId::from(BOB), 1_000 * UNIT),
])
.build()
.execute_with(|| {
assert_ok!(moonbase_runtime::Sudo::sudo(
root_origin(),
Box::new(RuntimeCall::Treasury(pallet_treasury::Call::spend_local {
amount: 100u128,
beneficiary: AccountId::from(BOB),
}))
));

assert_eq!(
System::events()
.into_iter()
.filter(|r| {
match r.event {
RuntimeEvent::Treasury(pallet_treasury::Event::SpendApproved {
..
}) => true,
_ => false,
}
})
.count(),
1
)
});
}

#[test]
fn test_treasury_spend() {
ExtBuilder::default()
.with_balances(vec![
(AccountId::from(ALICE), 2_000 * UNIT),
(AccountId::from(BOB), 1_000 * UNIT),
])
.build()
.execute_with(|| {
assert_ok!(moonbase_runtime::Sudo::sudo(
root_origin(),
Box::new(RuntimeCall::Treasury(pallet_treasury::Call::spend {
asset_kind: Box::new(()),
amount: 100u128,
beneficiary: Box::new(AccountId::from(BOB)),
valid_from: None
}))
));

assert_eq!(
System::events()
.into_iter()
.filter(|r| {
match r.event {
RuntimeEvent::Treasury(
pallet_treasury::Event::AssetSpendApproved { .. },
) => true,
_ => false,
}
})
.count(),
1
)
});
}

#[cfg(test)]
mod fee_tests {
use super::*;
Expand Down
14 changes: 11 additions & 3 deletions test/suites/dev/moonbase/test-treasury/test-treasury-pallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "@moonbeam-network/api-augment";
import { beforeAll, describeSuite, expect } from "@moonwall/cli";
import type { ApiPromise } from "@polkadot/api";
import { alith, baltathar, ethan } from "@moonwall/util";
import { expectSubstrateEvent } from "../../../../helpers";

describeSuite({
id: "D013801",
Expand All @@ -24,26 +25,33 @@ describeSuite({
const proposal_value = 1000000000n;
const tx = api.tx.treasury.spendLocal(proposal_value, ethan.address);
const signedTx = await tx.signAsync(baltathar);
await context.createBlock(signedTx, { allowFailures: false });
const blockResult = await context.createBlock(signedTx);

expectSubstrateEvent(blockResult, "system", "ExtrinsicFailed");

expect((await api.query.treasury.proposalCount()).toNumber()).to.equal(0);
expect((await api.query.treasury.spendCount()).toNumber()).to.equal(0);
},
});

it({
id: "T02",
title: "Root should be able to spend (local) and approve a proposal",
timeout: -1,
test: async function () {
const spendPeriod = api.consts.treasury.spendPeriod.toNumber();

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;
const tx = api.tx.treasury.spendLocal(proposal_value, ethan.address);
const signedTx = await api.tx.sudo.sudo(tx).signAsync(alith);
await context.createBlock(signedTx, { allowFailures: false });
const blockResult = await context.createBlock(signedTx, { allowFailures: false });

expect((await api.query.treasury.spendCount()).toNumber()).to.equal(1);
expectSubstrateEvent(blockResult, "treasury", "SpendApproved");
expect((await api.query.treasury.proposalCount()).toNumber()).to.equal(1);
},
});
},
Expand Down

0 comments on commit 8520cfb

Please sign in to comment.