Skip to content

Commit

Permalink
WIP tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs committed Jan 6, 2023
1 parent ee54618 commit 16d8c6d
Show file tree
Hide file tree
Showing 36 changed files with 225 additions and 285 deletions.
2 changes: 1 addition & 1 deletion api/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async fn connect_submit_and_get_events<Call>(
call: Call,
) -> Result<Vec<state_chain_runtime::Event>>
where
Call: Into<state_chain_runtime::Call> + Clone + std::fmt::Debug + Send + Sync + 'static,
Call: Into<state_chain_runtime::RuntimeCall> + Clone + std::fmt::Debug + Send + Sync + 'static,
{
task_scope(|scope| {
async {
Expand Down
3 changes: 1 addition & 2 deletions engine/src/eth/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ pub mod mocks {
use super::*;

use mockall::mock;
use sp_core::H256;
use web3::types::{Block, Bytes, Filter, Log};
// use web3::types::{Block, Bytes, Filter, Log, H256};

mock!(
// becomes MockEthHttpRpcClient
Expand Down
2 changes: 1 addition & 1 deletion engine/src/eth/ws_safe_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ where
#[cfg(test)]
pub mod tests {

use sp_core::{H160, H256, U256};
use web::types::{H160, H256, U256};

use crate::logging::test_utils::new_test_logger;

Expand Down
4 changes: 2 additions & 2 deletions engine/src/state_chain_observer/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,15 @@ pub mod mocks {
logger: &slog::Logger,
) -> Result<H256>
where
Call: Into<state_chain_runtime::Call> + Clone + std::fmt::Debug + Send + Sync + 'static;
Call: Into<state_chain_runtime::RuntimeCall> + Clone + std::fmt::Debug + Send + Sync + 'static;

async fn submit_unsigned_extrinsic<Call>(
&self,
call: Call,
logger: &slog::Logger,
) -> Result<H256>
where
Call: Into<state_chain_runtime::Call> + Clone + std::fmt::Debug + Send + Sync + 'static;
Call: Into<state_chain_runtime::RuntimeCall> + Clone + std::fmt::Debug + Send + Sync + 'static;

async fn watch_submitted_extrinsic<BlockStream>(
&self,
Expand Down
4 changes: 2 additions & 2 deletions engine/src/state_chain_observer/sc_observer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,7 @@ where
C: CryptoScheme + Send + Sync,
I: 'static + Send + Sync,
state_chain_runtime::Runtime: pallet_cf_threshold_signature::Config<I>,
state_chain_runtime::Call:
state_chain_runtime::RuntimeCall:
std::convert::From<pallet_cf_threshold_signature::Call<state_chain_runtime::Runtime, I>>,
<<state_chain_runtime::Runtime as pallet_cf_threshold_signature::Config<I>>::TargetChain as ChainCrypto>::ThresholdSignature: std::convert::From<<C as CryptoScheme>::Signature>,
{
Expand Down Expand Up @@ -1472,7 +1472,7 @@ where
C: CryptoScheme<AggKey = <<state_chain_runtime::Runtime as pallet_cf_vaults::Config<I>>::Chain as ChainCrypto>::AggKey> + Send + Sync,
I: 'static + Send + Sync,
state_chain_runtime::Runtime: pallet_cf_vaults::Config<I>,
state_chain_runtime::Call:
state_chain_runtime::RuntimeCall:
std::convert::From<pallet_cf_vaults::Call<state_chain_runtime::Runtime, I>>,
{
let logger = new_test_logger();
Expand Down
3 changes: 2 additions & 1 deletion state-chain/cf-integration-tests/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ fn account_deletion_removes_relevant_storage_items() {
assert!(MappedPeers::<Runtime>::contains_key(peer_id));

network::Cli::activate_account(&backup_node);
Reputation::heartbeat(state_chain_runtime::Origin::signed(backup_node.clone())).unwrap();
Reputation::heartbeat(state_chain_runtime::RuntimeOrigin::signed(backup_node.clone()))
.unwrap();
assert!(Reputations::<Runtime>::get(backup_node.clone()).online_credits > 0);

let elon_vanity_name = "ElonShibMoonInu";
Expand Down
5 changes: 3 additions & 2 deletions state-chain/cf-integration-tests/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use pallet_transaction_payment::OnChargeTransaction;
// Governance is allowed to make free calls to governance gated extrinsics.
fn governance_members_pay_no_fees_for_governance_extrinsics() {
super::genesis::default().build().execute_with(|| {
let call: state_chain_runtime::Call = frame_system::Call::remark { remark: vec![] }.into();
let gov_call: state_chain_runtime::Call =
let call: state_chain_runtime::RuntimeCall =
frame_system::Call::remark { remark: vec![] }.into();
let gov_call: state_chain_runtime::RuntimeCall =
pallet_cf_governance::Call::approve { approved_id: 1 }.into();
// Expect a successful normal call to work
let ordinary = FlipTransactionPayment::<Runtime>::withdraw_fee(
Expand Down
4 changes: 2 additions & 2 deletions state-chain/cf-integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::crypto::{Pair, Public};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use state_chain_runtime::{
constants::common::*, opaque::SessionKeys, AccountId, Emissions, Flip, Governance, Origin,
Reputation, Runtime, Staking, System, Timestamp, Validator, Witnesser,
constants::common::*, opaque::SessionKeys, AccountId, Emissions, Flip, Governance, Reputation,
Runtime, RuntimeOrigin, Staking, System, Timestamp, Validator, Witnesser,
};

use cf_primitives::{AuthorityCount, BlockNumber, EpochIndex, FlipBalance};
Expand Down
36 changes: 20 additions & 16 deletions state-chain/cf-integration-tests/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ use frame_support::traits::{OnFinalize, OnIdle};
use pallet_cf_staking::{ClaimAmount, MinimumStake};
use pallet_cf_validator::RotationPhase;
use sp_std::collections::btree_set::BTreeSet;
use state_chain_runtime::{AccountRoles, Authorship, EthereumInstance, Event, Origin};
use state_chain_runtime::{
AccountRoles, Authorship, EthereumInstance, RuntimeEvent, RuntimeOrigin,
};
use std::{cell::RefCell, collections::HashMap, rc::Rc};

use crate::threshold_signing::KeyUtils;
Expand Down Expand Up @@ -105,16 +107,16 @@ pub struct Cli;

impl Cli {
pub fn activate_account(account: &NodeId) {
assert_ok!(Staking::activate_account(Origin::signed(account.clone())));
assert_ok!(Staking::activate_account(RuntimeOrigin::signed(account.clone())));
}

pub fn claim(account: &NodeId, amount: ClaimAmount<FlipBalance>, eth_address: EthereumAddress) {
assert_ok!(Staking::claim(Origin::signed(account.clone()), amount, eth_address));
assert_ok!(Staking::claim(RuntimeOrigin::signed(account.clone()), amount, eth_address));
}

pub fn set_vanity_name(account: &NodeId, name: &str) {
assert_ok!(Validator::set_vanity_name(
Origin::signed(account.clone()),
RuntimeOrigin::signed(account.clone()),
name.as_bytes().to_vec()
));
}
Expand Down Expand Up @@ -158,7 +160,7 @@ impl Engine {
match event {
ContractEvent::Staked { node_id: validator_id, amount, epoch, .. } => {
state_chain_runtime::Witnesser::witness_at_epoch(
Origin::signed(self.node_id.clone()),
RuntimeOrigin::signed(self.node_id.clone()),
Box::new(
pallet_cf_staking::Call::staked {
account_id: validator_id.clone(),
Expand All @@ -174,7 +176,7 @@ impl Engine {
},
ContractEvent::Claimed { node_id, amount, epoch } => {
state_chain_runtime::Witnesser::witness_at_epoch(
Origin::signed(self.node_id.clone()),
RuntimeOrigin::signed(self.node_id.clone()),
Box::new(
pallet_cf_staking::Call::claimed {
account_id: node_id.clone(),
Expand Down Expand Up @@ -217,7 +219,7 @@ impl Engine {
// if we unwrap on this, we'll panic, because we will have already succeeded
// on a previous submission (all nodes submit this)
let _result = state_chain_runtime::EthereumThresholdSigner::signature_success(
Origin::none(),
RuntimeOrigin::none(),
*ceremony_id,
self.eth_threshold_signer.borrow().sign_with_key(key_id.clone(), payload.as_fixed_bytes()),
);
Expand Down Expand Up @@ -245,7 +247,7 @@ impl Engine {
pallet_cf_validator::Event::RotationPhaseUpdated { new_phase: RotationPhase::ActivatingKeys(_) }) => {
// If we rotating let's witness the keys being rotated on the contract
let _result = state_chain_runtime::Witnesser::witness_at_epoch(
Origin::signed(self.node_id.clone()),
RuntimeOrigin::signed(self.node_id.clone()),
Box::new(pallet_cf_vaults::Call::<_, EthereumInstance>::vault_key_rotated {
new_public_key: self.eth_threshold_signer.borrow_mut().proposed_public_key(),
block_number: 100,
Expand All @@ -256,7 +258,7 @@ impl Engine {

#[cfg(feature = "ibiza")]
let _result = state_chain_runtime::Witnesser::witness_at_epoch(
Origin::signed(self.node_id.clone()),
RuntimeOrigin::signed(self.node_id.clone()),
Box::new(pallet_cf_vaults::Call::<_, PolkadotInstance>::vault_key_rotated {
new_public_key: self.dot_threshold_signer.borrow_mut().proposed_public_key(),
block_number: 100,
Expand Down Expand Up @@ -285,11 +287,12 @@ impl Engine {
threshold_signer: Rc<RefCell<ThresholdSigner<K, S>>>,
node_id: NodeId,
) where
<T as frame_system::Config>::Origin: From<state_chain_runtime::Origin>,
<T as frame_system::Config>::RuntimeOrigin:
From<state_chain_runtime::RuntimeOrigin>,
{
if authorities.contains(&node_id) {
pallet_cf_vaults::Pallet::<T, I>::report_keygen_outcome(
Origin::signed(node_id.clone()).into(),
RuntimeOrigin::signed(node_id.clone()).into(),
ceremony_id,
Ok(threshold_signer.borrow_mut().propose_new_key()),
)
Expand Down Expand Up @@ -327,7 +330,7 @@ pub(crate) fn setup_account(node_id: &NodeId) {
let seed = &node_id.clone().to_string();

assert_ok!(state_chain_runtime::Session::set_keys(
state_chain_runtime::Origin::signed(node_id.clone()),
state_chain_runtime::RuntimeOrigin::signed(node_id.clone()),
SessionKeys {
aura: get_from_seed::<AuraId>(seed),
grandpa: get_from_seed::<GrandpaId>(seed),
Expand All @@ -341,7 +344,7 @@ pub(crate) fn setup_peer_mapping(node_id: &NodeId) {
let peer_keypair = sp_core::ed25519::Pair::from_legacy_string(seed, None);

assert_ok!(state_chain_runtime::Validator::register_peer_id(
state_chain_runtime::Origin::signed(node_id.clone()),
state_chain_runtime::RuntimeOrigin::signed(node_id.clone()),
peer_keypair.public(),
0,
0,
Expand Down Expand Up @@ -425,8 +428,9 @@ impl Network {

pub fn submit_heartbeat_all_engines(&self) {
for engine in self.engines.values() {
let _result =
Reputation::heartbeat(state_chain_runtime::Origin::signed(engine.node_id.clone()));
let _result = Reputation::heartbeat(state_chain_runtime::RuntimeOrigin::signed(
engine.node_id.clone(),
));
}
}

Expand Down Expand Up @@ -465,7 +469,7 @@ impl Network {
.into_iter()
.map(|e| e.event)
.skip(self.last_event)
.collect::<Vec<Event>>();
.collect::<Vec<RuntimeEvent>>();

self.last_event += events.len();

Expand Down
6 changes: 3 additions & 3 deletions state-chain/cf-integration-tests/src/new_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ fn new_epoch_will_purge_stale_witnesser_storage() {
current_authorities_after_some_epochs.sort();
assert_eq!(nodes, current_authorities_after_some_epochs);

let call = Box::new(state_chain_runtime::Call::System(frame_system::Call::remark {
let call = Box::new(state_chain_runtime::RuntimeCall::System(frame_system::Call::remark {
remark: vec![],
}));
let call_hash = pallet_cf_witnesser::CallHash(frame_support::Hashable::blake2_256(&*call));

for node in &nodes {
assert_ok!(Witnesser::witness_at_epoch(
Origin::signed(node.clone()),
RuntimeOrigin::signed(node.clone()),
call.clone(),
storage_epoch
));
Expand Down Expand Up @@ -298,7 +298,7 @@ fn new_epoch_will_purge_stale_witnesser_storage() {
let _res = ext.commit_all();

ext.execute_with(|| {
let call = Box::new(state_chain_runtime::Call::System(frame_system::Call::remark {
let call = Box::new(state_chain_runtime::RuntimeCall::System(frame_system::Call::remark {
remark: vec![],
}));
let call_hash = pallet_cf_witnesser::CallHash(frame_support::Hashable::blake2_256(&*call));
Expand Down
10 changes: 7 additions & 3 deletions state-chain/cf-integration-tests/src/staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ fn cannot_claim_stake_out_of_claim_period() {

// We should be able to claim stake out of an auction
for node in &nodes {
assert_ok!(Staking::claim(Origin::signed(node.clone()), 1.into(), ETH_DUMMY_ADDR));
assert_ok!(Staking::claim(
RuntimeOrigin::signed(node.clone()),
1.into(),
ETH_DUMMY_ADDR
));
}

let end_of_claim_period = EPOCH_BLOCKS * PERCENT_OF_EPOCH_PERIOD_CLAIMABLE as u32 / 100;
Expand All @@ -55,7 +59,7 @@ fn cannot_claim_stake_out_of_claim_period() {
for node in &nodes {
assert_noop!(
Staking::claim(
Origin::signed(node.clone()),
RuntimeOrigin::signed(node.clone()),
stake_amount.into(),
ETH_DUMMY_ADDR
),
Expand All @@ -78,7 +82,7 @@ fn cannot_claim_stake_out_of_claim_period() {
// TODO implement Claims in Contract/Network
for node in &nodes {
assert_noop!(
Staking::claim(Origin::signed(node.clone()), 1.into(), ETH_DUMMY_ADDR),
Staking::claim(RuntimeOrigin::signed(node.clone()), 1.into(), ETH_DUMMY_ADDR),
Error::<Runtime>::PendingClaim
);
}
Expand Down
Loading

0 comments on commit 16d8c6d

Please sign in to comment.