Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests setup #947

Merged
merged 8 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/base_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:

- name: Check EVM tracing features compilation
run: cargo check --verbose --features evm-tracing --locked

- name: Runtime integration tests
run: make test-runtimes
18 changes: 18 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"runtime/shiden",
"runtime/shibuya",
"tests/xcm-simulator",
"tests/integration",
]

exclude = ["vendor"]
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@
runtime-upgrade-test:
cargo build -p $(runtime)-runtime --release --locked
cd tests/e2e && yarn --frozen-lockfile && yarn test:runtime-upgrade-$(runtime)

.PHONY: test-runtimes
test-runtimes:
SKIP_WASM_BUILD= cargo test -p integration-tests --features=shibuya
SKIP_WASM_BUILD= cargo test -p integration-tests --features=shiden
SKIP_WASM_BUILD= cargo test -p integration-tests --features=astar
254 changes: 0 additions & 254 deletions runtime/shibuya/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1950,257 +1950,3 @@ cumulus_pallet_parachain_system::register_validate_block! {
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
CheckInherents = CheckInherents,
}

#[cfg(test)]
mod proxy_test {
use super::*;
use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Hooks;
use frame_support::*;
use pallet_balances::Call as BalancesCall;
use pallet_dapps_staking as DappStakingCall;
use pallet_proxy::Event as ProxyEvent;
use pallet_utility::{Call as UtilityCall, Event as UtilityEvent};
use sp_runtime::AccountId32;

type SystemError = frame_system::Error<Runtime>;

const INITIAL_AMOUNT: u128 = 100_000 * SBY;
const ALICE: AccountId32 = AccountId32::new([1_u8; 32]);
const BOB: AccountId32 = AccountId32::new([2_u8; 32]);
const CAT: AccountId32 = AccountId32::new([3_u8; 32]);

pub fn new_test_ext() -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default()
.build_storage::<Runtime>()
.unwrap();
pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(ALICE, INITIAL_AMOUNT),
(BOB, INITIAL_AMOUNT),
(CAT, INITIAL_AMOUNT),
],
}
.assimilate_storage(&mut t)
.unwrap();
let mut ext = sp_io::TestExternalities::new(t);
ext.execute_with(|| System::set_block_number(1));
ext
}

fn last_events(n: usize) -> Vec<RuntimeEvent> {
frame_system::Pallet::<Runtime>::events()
.into_iter()
.rev()
.take(n)
.rev()
.map(|e| e.event)
.collect()
}

fn expect_events(e: Vec<RuntimeEvent>) {
assert_eq!(last_events(e.len()), e);
}

pub fn run_to_block(n: u32) {
while System::block_number() < n {
<pallet_dapps_staking::Pallet<Runtime> as Hooks<BlockNumber>>::on_finalize(
System::block_number(),
);
System::set_block_number(System::block_number() + 1);
<pallet_dapps_staking::Pallet<Runtime> as Hooks<BlockNumber>>::on_initialize(
System::block_number(),
);
}
}

#[test]
fn test_utility_call_pass_for_any() {
new_test_ext().execute_with(|| {
// Any proxy should be allowed to make balance transfer call
assert_ok!(Proxy::add_proxy(
RuntimeOrigin::signed(ALICE),
sp_runtime::MultiAddress::Id(BOB),
ProxyType::Any,
0
));

// Preparing Utility call
let transfer_call = RuntimeCall::Balances(BalancesCall::transfer {
dest: sp_runtime::MultiAddress::Id(CAT),
value: 100_000_000_000,
});
let inner = Box::new(transfer_call);
let call = Box::new(RuntimeCall::Utility(UtilityCall::batch {
calls: vec![*inner],
}));

// Utility call passed through filter
assert_ok!(Proxy::proxy(
RuntimeOrigin::signed(BOB),
sp_runtime::MultiAddress::Id(ALICE),
None,
call.clone()
));
expect_events(vec![
UtilityEvent::BatchCompleted.into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
});
}
#[test]
fn test_utility_call_pass_for_balances() {
new_test_ext().execute_with(|| {
// Balances proxy should be allowed to make balance transfer call
assert_ok!(Proxy::add_proxy(
RuntimeOrigin::signed(ALICE),
sp_runtime::MultiAddress::Id(BOB),
ProxyType::Balances,
0
));

// Preparing Utility call
let transfer_call = RuntimeCall::Balances(BalancesCall::transfer {
dest: sp_runtime::MultiAddress::Id(CAT),
value: 100_000_000_000,
});
let inner = Box::new(transfer_call);
let call = Box::new(RuntimeCall::Utility(UtilityCall::batch {
calls: vec![*inner],
}));

// Utility call passed through filter
assert_ok!(Proxy::proxy(
RuntimeOrigin::signed(BOB),
sp_runtime::MultiAddress::Id(ALICE),
None,
call.clone()
));
expect_events(vec![
UtilityEvent::BatchCompleted.into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
});
}

#[test]
fn test_utility_call_fail_non_transfer() {
new_test_ext().execute_with(|| {
// NonTransfer proxy shouldn't be allowed to make balance transfer call
assert_ok!(Proxy::add_proxy(
RuntimeOrigin::signed(ALICE),
sp_runtime::MultiAddress::Id(BOB),
ProxyType::NonTransfer,
0
));

// Preparing Utility call
let transfer_call = RuntimeCall::Balances(BalancesCall::transfer {
dest: sp_runtime::MultiAddress::Id(CAT),
value: 100_000_000_000,
});
let inner = Box::new(transfer_call);
let call = Box::new(RuntimeCall::Utility(UtilityCall::batch {
calls: vec![*inner],
}));

assert_ok!(Proxy::proxy(
RuntimeOrigin::signed(BOB),
sp_runtime::MultiAddress::Id(ALICE),
None,
call.clone()
));

// Utility call filtered out
expect_events(vec![
UtilityEvent::BatchInterrupted {
index: 0,
error: SystemError::CallFiltered.into(),
}
.into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
});
}
#[test]
fn test_utility_call_fail_for_dappstaking() {
new_test_ext().execute_with(|| {
// Dappstaking proxy shouldn't be allowed to make balance transfer call
assert_ok!(Proxy::add_proxy(
RuntimeOrigin::signed(ALICE),
sp_runtime::MultiAddress::Id(BOB),
ProxyType::DappsStaking,
0
));

// Preparing Utility call
let transfer_call = RuntimeCall::Balances(BalancesCall::transfer {
dest: sp_runtime::MultiAddress::Id(CAT),
value: 100_000_000_000,
});
let inner = Box::new(transfer_call);
let call = Box::new(RuntimeCall::Utility(UtilityCall::batch {
calls: vec![*inner],
}));

assert_ok!(Proxy::proxy(
RuntimeOrigin::signed(BOB),
sp_runtime::MultiAddress::Id(ALICE),
None,
call.clone()
));
// Utility call filtered out
expect_events(vec![
UtilityEvent::BatchInterrupted {
index: 0,
error: SystemError::CallFiltered.into(),
}
.into(),
ProxyEvent::ProxyExecuted { result: Ok(()) }.into(),
]);
});
}
#[test]
fn test_staker_reward_claim_proxy_works() {
new_test_ext().execute_with(|| {
// Make CAT delegate for StakerRewardClaim proxy
assert_ok!(Proxy::add_proxy(
RuntimeOrigin::signed(BOB),
sp_runtime::MultiAddress::Id(CAT),
ProxyType::StakerRewardClaim,
0
));

let contract = SmartContract::Evm(H160::repeat_byte(0x01));
let staker_reward_claim_call =
RuntimeCall::DappsStaking(DappStakingCall::Call::claim_staker {
contract_id: contract.clone(),
});
let call = Box::new(staker_reward_claim_call);

// contract must be registered
assert_ok!(DappsStaking::register(
RuntimeOrigin::root(),
ALICE.clone(),
contract.clone()
));

// some amount must be staked
assert_ok!(DappsStaking::bond_and_stake(
RuntimeOrigin::signed(BOB),
contract.clone(),
20 * SBY
));
run_to_block(10);

// CAT making proxy call on behalf of staker (BOB)
assert_ok!(Proxy::proxy(
RuntimeOrigin::signed(CAT),
sp_runtime::MultiAddress::Id(BOB),
None,
call.clone()
));

expect_events(vec![ProxyEvent::ProxyExecuted { result: Ok(()) }.into()]);
})
}
}
Loading