Skip to content

Commit

Permalink
Finish integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinonard committed Jun 27, 2024
1 parent 1217806 commit 4d21b40
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ sp-runtime = { workspace = true }
# astar dependencies
assets-chain-extension-types = { workspace = true }
pallet-collator-selection = { workspace = true }
pallet-collective-proxy = { workspace = true }
pallet-dapp-staking-v3 = { workspace = true }
pallet-ethereum-checked = { workspace = true }
pallet-evm-precompile-assets-erc20 = { workspace = true }
Expand Down Expand Up @@ -68,6 +69,7 @@ std = [
"astar-primitives/std",
"astar-test-utils/std",
"assets-chain-extension-types/std",
"pallet-collective-proxy/std",
"ethereum?/std",
"fp-evm/std",
"fp-rpc?/std",
Expand Down
70 changes: 62 additions & 8 deletions tests/integration/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

use crate::setup::*;

use frame_support::{dispatch::GetDispatchInfo, traits::StorePreimage};
use frame_support::{
dispatch::GetDispatchInfo,
traits::{Currency, StorePreimage},
};
use parity_scale_codec::Encode;
use sp_runtime::traits::{BlakeTwo256, Hash};

Expand All @@ -31,7 +34,7 @@ fn external_proposals_work() {
let remark_call_bounded = Preimage::bound(remark_call).unwrap();

let external_propose_call =
RuntimeCall::Democracy(pallet_democracy::Call::external_propose {
RuntimeCall::Democracy(pallet_democracy::Call::external_propose_majority {
proposal: remark_call_bounded.clone(),
});
let external_propose_call_hash = BlakeTwo256::hash_of(&external_propose_call);
Expand Down Expand Up @@ -79,26 +82,26 @@ fn external_proposals_work() {
let fast_track_call_hash = BlakeTwo256::hash_of(&fast_track_call);

// Tech committee should be able to fast-track external proposals
assert_ok!(Council::propose(
assert_ok!(TechnicalCommittee::propose(
RuntimeOrigin::signed(ALICE.clone()),
2,
Box::new(fast_track_call.clone()),
fast_track_call.encode().len() as u32
));

for signer in &[BOB, CAT] {
assert_ok!(Council::vote(
for signer in &[ALICE, BOB, CAT] {
assert_ok!(TechnicalCommittee::vote(
RuntimeOrigin::signed(signer.clone()),
fast_track_call_hash,
1,
0,
true
));
}

assert_ok!(Council::close(
assert_ok!(TechnicalCommittee::close(
RuntimeOrigin::signed(ALICE.clone()),
fast_track_call_hash,
1,
0,
fast_track_call.get_dispatch_info().weight,
fast_track_call.encode().len() as u32,
));
Expand All @@ -113,3 +116,54 @@ fn external_proposals_work() {
);
})
}

#[test]
fn community_council_can_execute_dapp_staking_calls() {
new_test_ext().execute_with(|| {
// Fund the proxy account
let proxy_account = <Runtime as pallet_collective_proxy::Config>::ProxyAccountId::get();
let lock_amount = 10_000_000_000_000_000_000_000;
Balances::make_free_balance_be(&proxy_account, lock_amount);

// Prepare the wrapped dApp staking lock call
let lock_call = RuntimeCall::DappStaking(pallet_dapp_staking_v3::Call::lock {
amount: lock_amount,
});
let collective_proxy_call =
RuntimeCall::CollectiveProxy(pallet_collective_proxy::Call::execute_call {
call: Box::new(lock_call),
});
let collective_proxy_call_hash = BlakeTwo256::hash_of(&collective_proxy_call);

// Community council should be able to execute dApp staking calls
assert_ok!(CommunityCouncil::propose(
RuntimeOrigin::signed(ALICE.clone()),
2,
Box::new(collective_proxy_call.clone()),
collective_proxy_call.encode().len() as u32
));

for signer in &[BOB, CAT] {
assert_ok!(CommunityCouncil::vote(
RuntimeOrigin::signed(signer.clone()),
collective_proxy_call_hash,
0,
true
));
}

assert_ok!(CommunityCouncil::close(
RuntimeOrigin::signed(ALICE.clone()),
collective_proxy_call_hash,
0,
collective_proxy_call.get_dispatch_info().weight,
collective_proxy_call.encode().len() as u32,
));

// Check that the lock was successful
assert_eq!(
pallet_dapp_staking_v3::Ledger::<Runtime>::get(&proxy_account).locked,
lock_amount
);
})
}

0 comments on commit 4d21b40

Please sign in to comment.