From 1e1ca965ce7467d4e726083dce0f3e43db269926 Mon Sep 17 00:00:00 2001 From: Houmaan Chamani Date: Mon, 11 Mar 2024 22:18:46 -0400 Subject: [PATCH] refactor: contract trait for integration tests (#297) * feat: migrate service registry executions to contract trait * feat: add connection router trait * feat: add rewards implementation * feat: add multisig implementation * feat: add multisig_prover implementation * feat: add gateway implementation * feat: add voting-verifier implementation * fix: add unwrap to query_response and check for errors * fix: update based on incoming main changes * refactor: change organization of traits into single files based on contract * refactor: rename trait files, move under src directory * fix: address lint issue with cargo clippy --- .../src/connection_router_contract.rs | 45 ++ integration-tests/src/gateway_contract.rs | 48 ++ integration-tests/src/lib.rs | 7 + integration-tests/src/multisig_contract.rs | 50 ++ .../src/multisig_prover_contract.rs | 66 ++ integration-tests/src/rewards_contract.rs | 50 ++ .../src/service_registry_contract.rs | 40 ++ .../src/voting_verifier_contract.rs | 61 ++ integration-tests/tests/message_routing.rs | 36 +- integration-tests/tests/test_utils/mod.rs | 633 ++++++------------ integration-tests/tests/update_worker_set.rs | 117 +--- 11 files changed, 595 insertions(+), 558 deletions(-) create mode 100644 integration-tests/src/connection_router_contract.rs create mode 100644 integration-tests/src/gateway_contract.rs create mode 100644 integration-tests/src/multisig_contract.rs create mode 100644 integration-tests/src/multisig_prover_contract.rs create mode 100644 integration-tests/src/rewards_contract.rs create mode 100644 integration-tests/src/service_registry_contract.rs create mode 100644 integration-tests/src/voting_verifier_contract.rs diff --git a/integration-tests/src/connection_router_contract.rs b/integration-tests/src/connection_router_contract.rs new file mode 100644 index 000000000..996ceaf28 --- /dev/null +++ b/integration-tests/src/connection_router_contract.rs @@ -0,0 +1,45 @@ +use crate::contract::Contract; +use cosmwasm_std::Addr; +use cw_multi_test::{App, ContractWrapper, Executor}; + +#[derive(Clone)] +pub struct ConnectionRouterContract { + pub contract_addr: Addr, +} + +impl ConnectionRouterContract { + pub fn instantiate_contract(app: &mut App, admin: Addr, governance: Addr, nexus: Addr) -> Self { + let code = ContractWrapper::new( + connection_router::contract::execute, + connection_router::contract::instantiate, + connection_router::contract::query, + ); + let code_id = app.store_code(Box::new(code)); + + let contract_addr = app + .instantiate_contract( + code_id, + Addr::unchecked("router"), + &connection_router::msg::InstantiateMsg { + admin_address: admin.to_string(), + governance_address: governance.to_string(), + nexus_gateway: nexus.to_string(), + }, + &[], + "connection_router", + None, + ) + .unwrap(); + + ConnectionRouterContract { contract_addr } + } +} + +impl Contract for ConnectionRouterContract { + type QMsg = connection_router_api::msg::QueryMsg; + type ExMsg = connection_router_api::msg::ExecuteMsg; + + fn contract_address(&self) -> Addr { + self.contract_addr.clone() + } +} diff --git a/integration-tests/src/gateway_contract.rs b/integration-tests/src/gateway_contract.rs new file mode 100644 index 000000000..7ed4b8585 --- /dev/null +++ b/integration-tests/src/gateway_contract.rs @@ -0,0 +1,48 @@ +use crate::contract::Contract; +use cosmwasm_std::Addr; +use cw_multi_test::{App, ContractWrapper, Executor}; + +#[derive(Clone)] +pub struct GatewayContract { + pub contract_addr: Addr, +} + +impl GatewayContract { + pub fn instantiate_contract( + app: &mut App, + router_address: Addr, + verifier_address: Addr, + ) -> Self { + let code = ContractWrapper::new( + gateway::contract::execute, + gateway::contract::instantiate, + gateway::contract::query, + ); + let code_id = app.store_code(Box::new(code)); + + let contract_addr = app + .instantiate_contract( + code_id, + Addr::unchecked("anyone"), + &gateway::msg::InstantiateMsg { + router_address: router_address.to_string(), + verifier_address: verifier_address.to_string(), + }, + &[], + "gateway", + None, + ) + .unwrap(); + + GatewayContract { contract_addr } + } +} + +impl Contract for GatewayContract { + type QMsg = gateway_api::msg::QueryMsg; + type ExMsg = gateway_api::msg::ExecuteMsg; + + fn contract_address(&self) -> Addr { + self.contract_addr.clone() + } +} diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 2943dbb50..182eed44b 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -1 +1,8 @@ +pub mod connection_router_contract; pub mod contract; +pub mod gateway_contract; +pub mod multisig_contract; +pub mod multisig_prover_contract; +pub mod rewards_contract; +pub mod service_registry_contract; +pub mod voting_verifier_contract; diff --git a/integration-tests/src/multisig_contract.rs b/integration-tests/src/multisig_contract.rs new file mode 100644 index 000000000..63d35b0d0 --- /dev/null +++ b/integration-tests/src/multisig_contract.rs @@ -0,0 +1,50 @@ +use crate::contract::Contract; +use cosmwasm_std::Addr; +use cw_multi_test::{App, ContractWrapper, Executor}; + +#[derive(Clone)] +pub struct MultisigContract { + pub contract_addr: Addr, +} + +impl MultisigContract { + pub fn instantiate_contract( + app: &mut App, + governance: Addr, + rewards_address: Addr, + block_expiry: u64, + ) -> Self { + let code = ContractWrapper::new( + multisig::contract::execute, + multisig::contract::instantiate, + multisig::contract::query, + ); + let code_id = app.store_code(Box::new(code)); + + let contract_addr = app + .instantiate_contract( + code_id, + Addr::unchecked("anyone"), + &multisig::msg::InstantiateMsg { + rewards_address: rewards_address.to_string(), + governance_address: governance.to_string(), + block_expiry, + }, + &[], + "multisig", + None, + ) + .unwrap(); + + MultisigContract { contract_addr } + } +} + +impl Contract for MultisigContract { + type QMsg = multisig::msg::QueryMsg; + type ExMsg = multisig::msg::ExecuteMsg; + + fn contract_address(&self) -> Addr { + self.contract_addr.clone() + } +} diff --git a/integration-tests/src/multisig_prover_contract.rs b/integration-tests/src/multisig_prover_contract.rs new file mode 100644 index 000000000..c841119a3 --- /dev/null +++ b/integration-tests/src/multisig_prover_contract.rs @@ -0,0 +1,66 @@ +use crate::contract::Contract; +use axelar_wasm_std::Threshold; +use cosmwasm_std::{Addr, Uint256}; +use cw_multi_test::{App, ContractWrapper, Executor}; +use multisig::key::KeyType; +use multisig_prover::encoding::Encoder; + +#[derive(Clone)] +pub struct MultisigProverContract { + pub contract_addr: Addr, +} + +impl MultisigProverContract { + pub fn instantiate_contract( + app: &mut App, + gateway_address: Addr, + multisig_address: Addr, + service_registry_address: Addr, + voting_verifier_address: Addr, + service_name: String, + chain_name: String, + ) -> Self { + let code = ContractWrapper::new( + multisig_prover::contract::execute, + multisig_prover::contract::instantiate, + multisig_prover::contract::query, + ) + .with_reply(multisig_prover::contract::reply); + let code_id = app.store_code(Box::new(code)); + + let contract_addr = app + .instantiate_contract( + code_id, + Addr::unchecked("anyone"), + &multisig_prover::msg::InstantiateMsg { + admin_address: Addr::unchecked("doesn't matter").to_string(), + gateway_address: gateway_address.to_string(), + multisig_address: multisig_address.to_string(), + service_registry_address: service_registry_address.to_string(), + voting_verifier_address: voting_verifier_address.to_string(), + destination_chain_id: Uint256::zero(), + signing_threshold: Threshold::try_from((2, 3)).unwrap().try_into().unwrap(), + service_name: service_name.to_string(), + chain_name: chain_name.to_string(), + worker_set_diff_threshold: 0, + encoder: Encoder::Abi, + key_type: KeyType::Ecdsa, + }, + &[], + "multisig_prover", + None, + ) + .unwrap(); + + MultisigProverContract { contract_addr } + } +} + +impl Contract for MultisigProverContract { + type QMsg = multisig_prover::msg::QueryMsg; + type ExMsg = multisig_prover::msg::ExecuteMsg; + + fn contract_address(&self) -> Addr { + self.contract_addr.clone() + } +} diff --git a/integration-tests/src/rewards_contract.rs b/integration-tests/src/rewards_contract.rs new file mode 100644 index 000000000..48f1f02dc --- /dev/null +++ b/integration-tests/src/rewards_contract.rs @@ -0,0 +1,50 @@ +use crate::contract::Contract; +use cosmwasm_std::{Addr, Binary, Deps, Env, StdResult}; +use cw_multi_test::{App, ContractWrapper, Executor}; + +#[derive(Clone)] +pub struct RewardsContract { + pub contract_addr: Addr, +} + +impl RewardsContract { + pub fn instantiate_contract( + app: &mut App, + governance: Addr, + rewards_denom: String, + params: rewards::msg::Params, + ) -> Self { + let code = ContractWrapper::new( + rewards::contract::execute, + rewards::contract::instantiate, + |_: Deps, _: Env, _: rewards::msg::QueryMsg| -> StdResult { todo!() }, + ); + let code_id = app.store_code(Box::new(code)); + + let contract_addr = app + .instantiate_contract( + code_id, + Addr::unchecked("anyone"), + &rewards::msg::InstantiateMsg { + governance_address: governance.to_string(), + rewards_denom, + params, + }, + &[], + "rewards", + None, + ) + .unwrap(); + + RewardsContract { contract_addr } + } +} + +impl Contract for RewardsContract { + type QMsg = rewards::msg::QueryMsg; + type ExMsg = rewards::msg::ExecuteMsg; + + fn contract_address(&self) -> Addr { + self.contract_addr.clone() + } +} diff --git a/integration-tests/src/service_registry_contract.rs b/integration-tests/src/service_registry_contract.rs new file mode 100644 index 000000000..34d79c477 --- /dev/null +++ b/integration-tests/src/service_registry_contract.rs @@ -0,0 +1,40 @@ +use crate::contract::Contract; +use cosmwasm_std::Addr; +use cw_multi_test::{App, ContractWrapper, Executor}; +use service_registry::contract::{execute, instantiate, query}; + +#[derive(Clone)] +pub struct ServiceRegistryContract { + pub contract_addr: Addr, +} + +impl ServiceRegistryContract { + pub fn instantiate_contract(app: &mut App, governance: Addr) -> Self { + let code = ContractWrapper::new(execute, instantiate, query); + let code_id = app.store_code(Box::new(code)); + + let contract_addr = app + .instantiate_contract( + code_id, + Addr::unchecked("anyone"), + &service_registry::msg::InstantiateMsg { + governance_account: governance.clone().into(), + }, + &[], + "service_registry", + None, + ) + .unwrap(); + + ServiceRegistryContract { contract_addr } + } +} + +impl Contract for ServiceRegistryContract { + type QMsg = service_registry::msg::QueryMsg; + type ExMsg = service_registry::msg::ExecuteMsg; + + fn contract_address(&self) -> Addr { + self.contract_addr.clone() + } +} diff --git a/integration-tests/src/voting_verifier_contract.rs b/integration-tests/src/voting_verifier_contract.rs new file mode 100644 index 000000000..9d061a23e --- /dev/null +++ b/integration-tests/src/voting_verifier_contract.rs @@ -0,0 +1,61 @@ +use crate::contract::Contract; +use axelar_wasm_std::nonempty; +use axelar_wasm_std::MajorityThreshold; +use connection_router_api::ChainName; +use cosmwasm_std::Addr; +use cw_multi_test::{App, ContractWrapper, Executor}; + +#[derive(Clone)] +pub struct VotingVerifierContract { + pub contract_addr: Addr, +} + +impl VotingVerifierContract { + pub fn instantiate_contract( + app: &mut App, + service_registry_address: nonempty::String, + service_name: nonempty::String, + source_gateway_address: nonempty::String, + voting_threshold: MajorityThreshold, + source_chain: ChainName, + rewards_address: Addr, + ) -> Self { + let code = ContractWrapper::new( + voting_verifier::contract::execute, + voting_verifier::contract::instantiate, + voting_verifier::contract::query, + ); + let code_id = app.store_code(Box::new(code)); + + let contract_addr = app + .instantiate_contract( + code_id, + Addr::unchecked("anyone"), + &voting_verifier::msg::InstantiateMsg { + service_registry_address, + service_name, + source_gateway_address, + voting_threshold, + block_expiry: 10, + confirmation_height: 5, + source_chain, + rewards_address: rewards_address.to_string(), + }, + &[], + "voting_verifier", + None, + ) + .unwrap(); + + VotingVerifierContract { contract_addr } + } +} + +impl Contract for VotingVerifierContract { + type QMsg = voting_verifier::msg::QueryMsg; + type ExMsg = voting_verifier::msg::ExecuteMsg; + + fn contract_address(&self) -> Addr { + self.contract_addr.clone() + } +} diff --git a/integration-tests/tests/message_routing.rs b/integration-tests/tests/message_routing.rs index f85a994da..87968c117 100644 --- a/integration-tests/tests/message_routing.rs +++ b/integration-tests/tests/message_routing.rs @@ -39,13 +39,12 @@ fn single_message_can_be_verified_and_routed_and_proven_and_rewards_are_distribu let msg_ids: Vec = msgs.iter().map(|msg| msg.cc_id.clone()).collect(); // start the flow by submitting the message to the gateway - let (poll_id, expiry) = - test_utils::verify_messages(&mut protocol.app, &chain1.gateway_address, &msgs); + let (poll_id, expiry) = test_utils::verify_messages(&mut protocol.app, &chain1.gateway, &msgs); // do voting test_utils::vote_success_for_all_messages( &mut protocol.app, - &chain1.voting_verifier_address, + &chain1.voting_verifier, &msgs, &workers, poll_id, @@ -53,30 +52,25 @@ fn single_message_can_be_verified_and_routed_and_proven_and_rewards_are_distribu test_utils::advance_at_least_to_height(&mut protocol.app, expiry); - test_utils::end_poll(&mut protocol.app, &chain1.voting_verifier_address, poll_id); + test_utils::end_poll(&mut protocol.app, &chain1.voting_verifier, poll_id); // should be verified, now route - test_utils::route_messages(&mut protocol.app, &chain1.gateway_address, &msgs); + test_utils::route_messages(&mut protocol.app, &chain1.gateway, &msgs); // check that the message can be found at the outgoing gateway let found_msgs = - test_utils::get_messages_from_gateway(&mut protocol.app, &chain2.gateway_address, &msg_ids); + test_utils::get_messages_from_gateway(&mut protocol.app, &chain2.gateway, &msg_ids); assert_eq!(found_msgs, msgs); // trigger signing and submit all necessary signatures let session_id = test_utils::construct_proof_and_sign( - &mut protocol.app, - &chain2.multisig_prover_address, - &protocol.multisig_address, + &mut protocol, + &chain2.multisig_prover, &msgs, &workers, ); - let proof = test_utils::get_proof( - &mut protocol.app, - &chain2.multisig_prover_address, - &session_id, - ); + let proof = test_utils::get_proof(&mut protocol.app, &chain2.multisig_prover, &session_id); // proof should be complete by now assert!(matches!( @@ -92,18 +86,14 @@ fn single_message_can_be_verified_and_routed_and_proven_and_rewards_are_distribu ); test_utils::distribute_rewards( - &mut protocol.app, - &protocol.rewards_address, + &mut protocol, &chain1.chain_name, - &chain1.voting_verifier_address, - ); - test_utils::distribute_rewards( - &mut protocol.app, - &protocol.rewards_address, - &chain2.chain_name, - &protocol.multisig_address, + chain1.voting_verifier.contract_addr.clone(), ); + let protocol_multisig_address = protocol.multisig.contract_addr.clone(); + test_utils::distribute_rewards(&mut protocol, &chain2.chain_name, protocol_multisig_address); + // rewards split evenly amongst all workers, but there are two contracts that rewards should have been distributed for let expected_rewards = Uint128::from(protocol.rewards_params.rewards_per_epoch) / Uint128::from(workers.len() as u64) diff --git a/integration-tests/tests/test_utils/mod.rs b/integration-tests/tests/test_utils/mod.rs index 647e6aa38..2d1222c85 100644 --- a/integration-tests/tests/test_utils/mod.rs +++ b/integration-tests/tests/test_utils/mod.rs @@ -5,10 +5,19 @@ use axelar_wasm_std::{ }; use connection_router_api::{ChainName, CrossChainId, Message}; use cosmwasm_std::{ - coins, Addr, Attribute, Binary, BlockInfo, Deps, Env, Event, HexBinary, StdResult, Uint128, - Uint256, Uint64, + coins, Addr, Attribute, BlockInfo, Event, HexBinary, StdError, Uint128, Uint256, Uint64, }; -use cw_multi_test::{App, AppResponse, ContractWrapper, Executor}; +use cw_multi_test::{App, AppResponse, Executor}; + +use integration_tests::connection_router_contract::ConnectionRouterContract; +use integration_tests::contract::Contract; +use integration_tests::gateway_contract::GatewayContract; +use integration_tests::multisig_contract::MultisigContract; +use integration_tests::multisig_prover_contract::MultisigProverContract; +use integration_tests::rewards_contract::RewardsContract; +use integration_tests::service_registry_contract::ServiceRegistryContract; +use integration_tests::voting_verifier_contract::VotingVerifierContract; + use k256::ecdsa; use sha3::{Digest, Keccak256}; @@ -18,6 +27,7 @@ use multisig::{ }; use multisig_prover::encoding::{make_operators, Encoder}; use rewards::state::PoolId; +use service_registry::msg::ExecuteMsg; use tofn::ecdsa::KeyPair; pub const AXL_DENOMINATION: &str = "uaxl"; @@ -41,16 +51,16 @@ type PollExpiryBlock = u64; pub fn verify_messages( app: &mut App, - gateway_address: &Addr, + gateway: &GatewayContract, msgs: &[Message], ) -> (PollId, PollExpiryBlock) { - let response = app.execute_contract( + let response = gateway.execute( + app, Addr::unchecked("relayer"), - gateway_address.clone(), &gateway_api::msg::ExecuteMsg::VerifyMessages(msgs.to_vec()), - &[], ); assert!(response.is_ok()); + let response = response.unwrap(); let poll_id = get_event_attribute(&response.events, "wasm-messages_poll_started", "poll_id") @@ -62,33 +72,30 @@ pub fn verify_messages( (poll_id, expiry) } -pub fn route_messages(app: &mut App, gateway_address: &Addr, msgs: &[Message]) { - let response = app.execute_contract( +pub fn route_messages(app: &mut App, gateway: &GatewayContract, msgs: &[Message]) { + let response = gateway.execute( + app, Addr::unchecked("relayer"), - gateway_address.clone(), &gateway_api::msg::ExecuteMsg::RouteMessages(msgs.to_vec()), - &[], ); - assert!(response.is_ok()); } pub fn vote_success_for_all_messages( app: &mut App, - voting_verifier_address: &Addr, + voting_verifier: &VotingVerifierContract, messages: &Vec, workers: &Vec, poll_id: PollId, ) { for worker in workers { - let response = app.execute_contract( + let response = voting_verifier.execute( + app, worker.addr.clone(), - voting_verifier_address.clone(), &voting_verifier::msg::ExecuteMsg::Vote { poll_id, votes: vec![Vote::SucceededOnChain; messages.len()], }, - &[], ); assert!(response.is_ok()); } @@ -96,62 +103,52 @@ pub fn vote_success_for_all_messages( pub fn vote_true_for_worker_set( app: &mut App, - voting_verifier_address: &Addr, + voting_verifier: &VotingVerifierContract, workers: &Vec, poll_id: PollId, ) { for worker in workers { - let response = app.execute_contract( + let response = voting_verifier.execute( + app, worker.addr.clone(), - voting_verifier_address.clone(), &voting_verifier::msg::ExecuteMsg::Vote { poll_id, votes: vec![Vote::SucceededOnChain; 1], }, - &[], ); - assert!(response.is_ok()); + assert!(response.is_ok()) } } /// Ends the poll. Be sure the current block height has advanced at least to the poll expiration, else this will fail -pub fn end_poll(app: &mut App, voting_verifier_address: &Addr, poll_id: PollId) { - let response = app.execute_contract( +pub fn end_poll(app: &mut App, voting_verifier: &VotingVerifierContract, poll_id: PollId) { + let response = voting_verifier.execute( + app, Addr::unchecked("relayer"), - voting_verifier_address.clone(), &voting_verifier::msg::ExecuteMsg::EndPoll { poll_id }, - &[], ); - assert!(response.is_ok()); } pub fn construct_proof_and_sign( - app: &mut App, - multisig_prover_address: &Addr, - multisig_address: &Addr, + protocol: &mut Protocol, + multisig_prover: &MultisigProverContract, messages: &[Message], workers: &Vec, ) -> Uint64 { - let response = app.execute_contract( + let response = multisig_prover.execute( + &mut protocol.app, Addr::unchecked("relayer"), - multisig_prover_address.clone(), &multisig_prover::msg::ExecuteMsg::ConstructProof { message_ids: messages.iter().map(|msg| msg.cc_id.clone()).collect(), }, - &[], ); assert!(response.is_ok()); - sign_proof(app, multisig_address, workers, response.unwrap()) + sign_proof(protocol, workers, response.unwrap()) } -pub fn sign_proof( - app: &mut App, - multisig_address: &Addr, - workers: &Vec, - response: AppResponse, -) -> Uint64 { +pub fn sign_proof(protocol: &mut Protocol, workers: &Vec, response: AppResponse) -> Uint64 { let msg_to_sign = get_event_attribute(&response.events, "wasm-signing_started", "msg") .map(|attr| attr.value.clone()) .expect("couldn't find message to sign"); @@ -173,83 +170,79 @@ pub fn sign_proof( let sig = ecdsa::Signature::from_der(&signature).unwrap(); - let response = app.execute_contract( + let response = protocol.multisig.execute( + &mut protocol.app, worker.addr.clone(), - multisig_address.clone(), &multisig::msg::ExecuteMsg::SubmitSignature { session_id, signature: HexBinary::from(sig.to_vec()), }, - &[], ); - assert!(response.is_ok()); } session_id } -pub fn register_service( - app: &mut App, - service_registry: Addr, - governance_addr: Addr, - service_name: nonempty::String, - min_worker_bond: Uint128, -) { - let response = app.execute_contract( - governance_addr, - service_registry, - &service_registry::msg::ExecuteMsg::RegisterService { - service_name: service_name.to_string(), +pub fn register_service(protocol: &mut Protocol, min_worker_bond: Uint128) { + let response = protocol.service_registry.execute( + &mut protocol.app, + protocol.governance_address.clone(), + &ExecuteMsg::RegisterService { + service_name: protocol.service_name.to_string(), service_contract: Addr::unchecked("nowhere"), min_num_workers: 0, max_num_workers: Some(100), - min_worker_bond: min_worker_bond, + min_worker_bond, bond_denom: AXL_DENOMINATION.into(), unbonding_period_days: 10, description: "Some service".into(), }, - &[], ); assert!(response.is_ok()); } pub fn get_messages_from_gateway( app: &mut App, - gateway_address: &Addr, + gateway: &GatewayContract, message_ids: &[CrossChainId], ) -> Vec { - let query_response = app.wrap().query_wasm_smart( - gateway_address, + let query_response: Result, StdError> = gateway.query( + &app, &gateway_api::msg::QueryMsg::GetOutgoingMessages { message_ids: message_ids.to_owned(), }, ); assert!(query_response.is_ok()); + query_response.unwrap() } pub fn get_proof( app: &mut App, - multisig_prover_address: &Addr, + multisig_prover: &MultisigProverContract, multisig_session_id: &Uint64, ) -> multisig_prover::msg::GetProofResponse { - let query_response = app.wrap().query_wasm_smart( - multisig_prover_address, - &multisig_prover::msg::QueryMsg::GetProof { - multisig_session_id: *multisig_session_id, - }, - ); + let query_response: Result = multisig_prover + .query( + &app, + &multisig_prover::msg::QueryMsg::GetProof { + multisig_session_id: *multisig_session_id, + }, + ); assert!(query_response.is_ok()); + query_response.unwrap() } -pub fn get_worker_set(app: &mut App, multisig_prover_address: &Addr) -> WorkerSet { - let query_response = app.wrap().query_wasm_smart( - multisig_prover_address, - &multisig_prover::msg::QueryMsg::GetWorkerSet, - ); +pub fn get_worker_set( + app: &mut App, + multisig_prover_contract: &MultisigProverContract, +) -> WorkerSet { + let query_response: Result = + multisig_prover_contract.query(&app, &multisig_prover::msg::QueryMsg::GetWorkerSet); assert!(query_response.is_ok()); + query_response.unwrap() } @@ -271,23 +264,17 @@ pub fn advance_at_least_to_height(app: &mut App, desired_height: u64) { } } -pub fn distribute_rewards( - app: &mut App, - rewards_address: &Addr, - chain_name: &ChainName, - contract_address: &Addr, -) { - let response = app.execute_contract( +pub fn distribute_rewards(protocol: &mut Protocol, chain_name: &ChainName, contract_address: Addr) { + let response = protocol.rewards.execute( + &mut protocol.app, Addr::unchecked("relayer"), - rewards_address.clone(), &rewards::msg::ExecuteMsg::DistributeRewards { pool_id: PoolId { chain_name: chain_name.clone(), - contract: contract_address.clone(), + contract: contract_address, }, epoch_count: None, }, - &[], ); assert!(response.is_ok()); } @@ -295,12 +282,12 @@ pub fn distribute_rewards( pub struct Protocol { pub genesis_address: Addr, // holds u128::max coins, can use to send coins to other addresses pub governance_address: Addr, - pub router_address: Addr, + pub connection_router: ConnectionRouterContract, pub router_admin_address: Addr, - pub multisig_address: Addr, - pub service_registry_address: Addr, + pub multisig: MultisigContract, + pub service_registry: ServiceRegistryContract, pub service_name: nonempty::String, - pub rewards_address: Addr, + pub rewards: RewardsContract, pub rewards_params: rewards::msg::Params, pub app: App, } @@ -317,13 +304,11 @@ pub fn setup_protocol(service_name: nonempty::String) -> Protocol { let governance_address = Addr::unchecked("governance"); let nexus_gateway = Addr::unchecked("nexus_gateway"); - let router_address = instantiate_connection_router( + let connection_router = ConnectionRouterContract::instantiate_contract( &mut app, - connection_router::msg::InstantiateMsg { - admin_address: router_admin_address.to_string(), - governance_address: governance_address.to_string(), - nexus_gateway: nexus_gateway.to_string(), - }, + router_admin_address.clone(), + governance_address.clone(), + nexus_gateway.clone(), ); let rewards_params = rewards::msg::Params { @@ -331,38 +316,32 @@ pub fn setup_protocol(service_name: nonempty::String) -> Protocol { rewards_per_epoch: Uint128::from(100u128).try_into().unwrap(), participation_threshold: (1, 2).try_into().unwrap(), }; - let rewards_address = instantiate_rewards( + let rewards = RewardsContract::instantiate_contract( &mut app, - rewards::msg::InstantiateMsg { - governance_address: governance_address.to_string(), - rewards_denom: AXL_DENOMINATION.to_string(), - params: rewards_params.clone(), - }, + governance_address.clone(), + AXL_DENOMINATION.to_string(), + rewards_params.clone(), ); - let multisig_address = instantiate_multisig( + + let multisig = MultisigContract::instantiate_contract( &mut app, - multisig::msg::InstantiateMsg { - rewards_address: rewards_address.to_string(), - governance_address: governance_address.to_string(), - block_expiry: SIGNATURE_BLOCK_EXPIRY, - }, - ); - let service_registry_address = instantiate_service_registry( - &mut app, - service_registry::msg::InstantiateMsg { - governance_account: governance_address.to_string(), - }, + governance_address.clone(), + rewards.contract_addr.clone(), + SIGNATURE_BLOCK_EXPIRY, ); + let service_registry = + ServiceRegistryContract::instantiate_contract(&mut app, governance_address.clone()); + Protocol { genesis_address: genesis, governance_address, - router_address, + connection_router, router_admin_address, - multisig_address, - service_registry_address, + multisig, + service_registry, service_name, - rewards_address, + rewards, rewards_params, app, } @@ -383,55 +362,45 @@ pub struct Worker { pub key_pair: KeyPair, } -pub fn register_workers( - app: &mut App, - service_registry: Addr, - multisig: Addr, - governance_addr: Addr, - genesis: Addr, - workers: &Vec, - service_name: nonempty::String, - min_worker_bond: Uint128, -) { - let response = app.execute_contract( - governance_addr, - service_registry.clone(), - &service_registry::msg::ExecuteMsg::AuthorizeWorkers { +pub fn register_workers(protocol: &mut Protocol, workers: &Vec, min_worker_bond: Uint128) { + let response = protocol.service_registry.execute( + &mut protocol.app, + protocol.governance_address.clone(), + &ExecuteMsg::AuthorizeWorkers { workers: workers .iter() .map(|worker| worker.addr.to_string()) .collect(), - service_name: service_name.to_string(), + service_name: protocol.service_name.to_string(), }, - &[], ); assert!(response.is_ok()); for worker in workers { - let response = app.send_tokens( - genesis.clone(), + let response = protocol.app.send_tokens( + protocol.genesis_address.clone(), worker.addr.clone(), &coins(min_worker_bond.u128(), AXL_DENOMINATION), ); assert!(response.is_ok()); - let response = app.execute_contract( + + let response = protocol.service_registry.execute_with_funds( + &mut protocol.app, worker.addr.clone(), - service_registry.clone(), - &service_registry::msg::ExecuteMsg::BondWorker { - service_name: service_name.to_string(), + &ExecuteMsg::BondWorker { + service_name: protocol.service_name.to_string(), }, &coins(min_worker_bond.u128(), AXL_DENOMINATION), ); assert!(response.is_ok()); - let response = app.execute_contract( + let response = protocol.service_registry.execute( + &mut protocol.app, worker.addr.clone(), - service_registry.clone(), - &service_registry::msg::ExecuteMsg::RegisterChainSupport { - service_name: service_name.to_string(), + &ExecuteMsg::RegisterChainSupport { + service_name: protocol.service_name.to_string(), chains: worker.supported_chains.clone(), }, - &[], ); assert!(response.is_ok()); @@ -444,61 +413,55 @@ pub fn register_workers( .unwrap(); let sig = ecdsa::Signature::from_der(&sig).unwrap(); - let response = app.execute_contract( + let response = protocol.multisig.execute( + &mut protocol.app, worker.addr.clone(), - multisig.clone(), &multisig::msg::ExecuteMsg::RegisterPublicKey { public_key: PublicKey::Ecdsa(HexBinary::from( worker.key_pair.encoded_verifying_key(), )), signed_sender_address: HexBinary::from(sig.to_vec()), }, - &[], ); assert!(response.is_ok()); } } -pub fn deregister_workers( - app: &mut App, - service_registry: Addr, - governance_addr: Addr, - workers: &Vec, - service_name: nonempty::String, -) { - let response = app.execute_contract( - governance_addr, - service_registry.clone(), - &service_registry::msg::ExecuteMsg::UnauthorizeWorkers { +pub fn deregister_workers(protocol: &mut Protocol, workers: &Vec) { + let response = protocol.service_registry.execute( + &mut protocol.app, + protocol.governance_address.clone(), + &ExecuteMsg::UnauthorizeWorkers { workers: workers .iter() .map(|worker| worker.addr.to_string()) .collect(), - service_name: service_name.to_string(), + service_name: protocol.service_name.to_string(), }, - &[], ); assert!(response.is_ok()); for worker in workers { - let response = app.execute_contract( + let response = protocol.service_registry.execute( + &mut protocol.app, worker.addr.clone(), - service_registry.clone(), - &service_registry::msg::ExecuteMsg::UnbondWorker { - service_name: service_name.to_string(), + &ExecuteMsg::UnbondWorker { + service_name: protocol.service_name.to_string(), }, - &[], ); assert!(response.is_ok()); } } -pub fn confirm_worker_set(app: &mut App, relayer_addr: Addr, multisig_prover: Addr) { - let response = app.execute_contract( +pub fn confirm_worker_set( + app: &mut App, + relayer_addr: Addr, + multisig_prover: &MultisigProverContract, +) { + let response = multisig_prover.execute( + app, relayer_addr.clone(), - multisig_prover.clone(), &multisig_prover::msg::ExecuteMsg::ConfirmWorkerSet, - &[], ); assert!(response.is_ok()); } @@ -520,17 +483,16 @@ fn get_worker_set_poll_id_and_expiry(response: AppResponse) -> (PollId, PollExpi pub fn create_worker_set_poll( app: &mut App, relayer_addr: Addr, - voting_verifier: Addr, + voting_verifier: &VotingVerifierContract, worker_set: WorkerSet, ) -> (PollId, PollExpiryBlock) { - let response = app.execute_contract( + let response = voting_verifier.execute( + app, relayer_addr.clone(), - voting_verifier.clone(), &voting_verifier::msg::ExecuteMsg::VerifyWorkerSet { message_id: "ethereum:00".parse().unwrap(), new_operators: make_operators(worker_set.clone(), Encoder::Abi), }, - &[], ); assert!(response.is_ok()); @@ -586,52 +548,28 @@ pub fn update_registry_and_construct_worker_set_update_proof( new_workers: &Vec, workers_to_remove: &Vec, current_workers: &Vec, - chain_multisig_prover_address: &Addr, + chain_multisig_prover: &MultisigProverContract, min_worker_bond: Uint128, ) -> Uint64 { // Register new workers - register_workers( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.multisig_address.clone(), - protocol.governance_address.clone(), - protocol.genesis_address.clone(), - new_workers, - protocol.service_name.clone(), - min_worker_bond, - ); + register_workers(protocol, new_workers, min_worker_bond); // Deregister old workers - deregister_workers( + deregister_workers(protocol, workers_to_remove); + + let response = chain_multisig_prover.execute( &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.governance_address.clone(), - workers_to_remove, - protocol.service_name.clone(), + Addr::unchecked("relayer"), + &multisig_prover::msg::ExecuteMsg::UpdateWorkerSet, ); - let response = protocol - .app - .execute_contract( - Addr::unchecked("relayer"), - chain_multisig_prover_address.clone(), - &multisig_prover::msg::ExecuteMsg::UpdateWorkerSet, - &[], - ) - .unwrap(); - - sign_proof( - &mut protocol.app, - &protocol.multisig_address, - current_workers, - response, - ) + sign_proof(protocol, current_workers, response.unwrap()) } pub fn execute_worker_set_poll( protocol: &mut Protocol, relayer_addr: &Addr, - verifier_address: &Addr, + voting_verifier: &VotingVerifierContract, new_workers: &Vec, ) { // Create worker set @@ -641,118 +579,106 @@ pub fn execute_worker_set_poll( let (poll_id, expiry) = create_worker_set_poll( &mut protocol.app, relayer_addr.clone(), - verifier_address.clone(), + voting_verifier, new_worker_set.clone(), ); // Vote for the worker set - vote_true_for_worker_set(&mut protocol.app, verifier_address, new_workers, poll_id); + vote_true_for_worker_set(&mut protocol.app, voting_verifier, new_workers, poll_id); // Advance to expiration height advance_at_least_to_height(&mut protocol.app, expiry); // End the poll - end_poll(&mut protocol.app, verifier_address, poll_id); + end_poll(&mut protocol.app, voting_verifier, poll_id); } #[derive(Clone)] pub struct Chain { - pub gateway_address: Addr, - pub voting_verifier_address: Addr, - pub multisig_prover_address: Addr, + pub gateway: GatewayContract, + pub voting_verifier: VotingVerifierContract, + pub multisig_prover: MultisigProverContract, pub chain_name: ChainName, } pub fn setup_chain(protocol: &mut Protocol, chain_name: ChainName) -> Chain { - let voting_verifier_address = instantiate_voting_verifier( + let voting_verifier = VotingVerifierContract::instantiate_contract( &mut protocol.app, - voting_verifier::msg::InstantiateMsg { - service_registry_address: protocol - .service_registry_address - .to_string() - .try_into() - .unwrap(), - service_name: protocol.service_name.clone(), - source_gateway_address: "doesn't matter".to_string().try_into().unwrap(), - voting_threshold: Threshold::try_from((9, 10)).unwrap().try_into().unwrap(), - block_expiry: 10, - confirmation_height: 5, - source_chain: chain_name.clone(), - rewards_address: protocol.rewards_address.to_string(), - }, + protocol + .service_registry + .contract_addr + .to_string() + .try_into() + .unwrap(), + protocol.service_name.clone(), + "doesn't matter".to_string().try_into().unwrap(), + Threshold::try_from((9, 10)).unwrap().try_into().unwrap(), + chain_name.clone(), + protocol.rewards.contract_addr.clone(), ); - let gateway_address = instantiate_gateway( + + let gateway = GatewayContract::instantiate_contract( &mut protocol.app, - gateway::msg::InstantiateMsg { - router_address: protocol.router_address.to_string(), - verifier_address: voting_verifier_address.to_string(), - }, + protocol.connection_router.contract_address().clone(), + voting_verifier.contract_addr.clone(), ); - let multisig_prover_address = instantiate_multisig_prover( + + let multisig_prover = MultisigProverContract::instantiate_contract( &mut protocol.app, - multisig_prover::msg::InstantiateMsg { - admin_address: Addr::unchecked("doesn't matter").to_string(), - gateway_address: gateway_address.to_string(), - multisig_address: protocol.multisig_address.to_string(), - service_registry_address: protocol.service_registry_address.to_string(), - voting_verifier_address: voting_verifier_address.to_string(), - destination_chain_id: Uint256::zero(), - signing_threshold: Threshold::try_from((2, 3)).unwrap().try_into().unwrap(), - service_name: protocol.service_name.to_string(), - chain_name: chain_name.to_string(), - worker_set_diff_threshold: 0, - encoder: Encoder::Abi, - key_type: KeyType::Ecdsa, - }, + gateway.contract_addr.clone(), + protocol.multisig.contract_addr.clone(), + protocol.service_registry.contract_addr.clone(), + voting_verifier.contract_addr.clone(), + protocol.service_name.to_string(), + chain_name.to_string(), ); - let response = protocol.app.execute_contract( + + let response = multisig_prover.execute( + &mut protocol.app, Addr::unchecked("doesn't matter"), - multisig_prover_address.clone(), &multisig_prover::msg::ExecuteMsg::UpdateWorkerSet, - &[], ); assert!(response.is_ok()); - let response = protocol.app.execute_contract( + + let response = protocol.multisig.execute( + &mut protocol.app, protocol.governance_address.clone(), - protocol.multisig_address.clone(), &multisig::msg::ExecuteMsg::AuthorizeCaller { - contract_address: multisig_prover_address.clone(), + contract_address: multisig_prover.contract_addr.clone(), }, - &[], ); assert!(response.is_ok()); - let response = protocol.app.execute_contract( + let response = protocol.connection_router.execute( + &mut protocol.app, protocol.governance_address.clone(), - protocol.router_address.clone(), &connection_router_api::msg::ExecuteMsg::RegisterChain { chain: chain_name.clone(), - gateway_address: gateway_address.to_string().try_into().unwrap(), + gateway_address: gateway.contract_addr.to_string().try_into().unwrap(), }, - &[], ); assert!(response.is_ok()); - let response = protocol.app.execute_contract( + let response = protocol.rewards.execute_with_funds( + &mut protocol.app, protocol.genesis_address.clone(), - protocol.rewards_address.clone(), &rewards::msg::ExecuteMsg::AddRewards { pool_id: PoolId { chain_name: chain_name.clone(), - contract: voting_verifier_address.clone(), + contract: voting_verifier.contract_addr.clone(), }, }, &coins(1000, AXL_DENOMINATION), ); assert!(response.is_ok()); - let response = protocol.app.execute_contract( + let response = protocol.rewards.execute_with_funds( + &mut protocol.app, protocol.genesis_address.clone(), - protocol.rewards_address.clone(), &rewards::msg::ExecuteMsg::AddRewards { pool_id: PoolId { chain_name: chain_name.clone(), - contract: protocol.multisig_address.clone(), + contract: protocol.multisig.contract_addr.clone(), }, }, &coins(1000, AXL_DENOMINATION), @@ -760,173 +686,13 @@ pub fn setup_chain(protocol: &mut Protocol, chain_name: ChainName) -> Chain { assert!(response.is_ok()); Chain { - gateway_address, - voting_verifier_address, - multisig_prover_address, + gateway, + voting_verifier, + multisig_prover, chain_name, } } -pub fn instantiate_connection_router( - app: &mut App, - instantiate_msg: connection_router::msg::InstantiateMsg, -) -> Addr { - let code = ContractWrapper::new( - connection_router::contract::execute, - connection_router::contract::instantiate, - connection_router::contract::query, - ); - let code_id = app.store_code(Box::new(code)); - - let contract_addr = app.instantiate_contract( - code_id, - Addr::unchecked("anyone"), - &instantiate_msg, - &[], - "connection_router", - None, - ); - - assert!(contract_addr.is_ok()); - contract_addr.unwrap() -} - -pub fn instantiate_multisig(app: &mut App, instantiate_msg: multisig::msg::InstantiateMsg) -> Addr { - let code = ContractWrapper::new( - multisig::contract::execute, - multisig::contract::instantiate, - multisig::contract::query, - ); - let code_id = app.store_code(Box::new(code)); - - let contract_addr = app.instantiate_contract( - code_id, - Addr::unchecked("anyone"), - &instantiate_msg, - &[], - "multisig", - None, - ); - - assert!(contract_addr.is_ok()); - contract_addr.unwrap() -} - -pub fn instantiate_rewards(app: &mut App, instantiate_msg: rewards::msg::InstantiateMsg) -> Addr { - let code = ContractWrapper::new( - rewards::contract::execute, - rewards::contract::instantiate, - |_: Deps, _: Env, _: rewards::msg::QueryMsg| -> StdResult { todo!() }, - ); - let code_id = app.store_code(Box::new(code)); - - let contract_addr = app.instantiate_contract( - code_id, - Addr::unchecked("anyone"), - &instantiate_msg, - &[], - "rewards", - None, - ); - - assert!(contract_addr.is_ok()); - contract_addr.unwrap() -} - -pub fn instantiate_voting_verifier( - app: &mut App, - instantiate_msg: voting_verifier::msg::InstantiateMsg, -) -> Addr { - let code = ContractWrapper::new( - voting_verifier::contract::execute, - voting_verifier::contract::instantiate, - voting_verifier::contract::query, - ); - let code_id = app.store_code(Box::new(code)); - - let contract_addr = app.instantiate_contract( - code_id, - Addr::unchecked("anyone"), - &instantiate_msg, - &[], - "voting_verifier", - None, - ); - - assert!(contract_addr.is_ok()); - contract_addr.unwrap() -} - -pub fn instantiate_gateway(app: &mut App, instantiate_msg: gateway::msg::InstantiateMsg) -> Addr { - let code = ContractWrapper::new( - gateway::contract::execute, - gateway::contract::instantiate, - gateway::contract::query, - ); - let code_id = app.store_code(Box::new(code)); - - let contract_addr = app.instantiate_contract( - code_id, - Addr::unchecked("anyone"), - &instantiate_msg, - &[], - "gateway", - None, - ); - - assert!(contract_addr.is_ok()); - contract_addr.unwrap() -} - -pub fn instantiate_service_registry( - app: &mut App, - instantiate_msg: service_registry::msg::InstantiateMsg, -) -> Addr { - let code = ContractWrapper::new( - service_registry::contract::execute, - service_registry::contract::instantiate, - service_registry::contract::query, - ); - let code_id = app.store_code(Box::new(code)); - - let contract_addr = app.instantiate_contract( - code_id, - Addr::unchecked("anyone"), - &instantiate_msg, - &[], - "service_registry", - None, - ); - - assert!(contract_addr.is_ok()); - contract_addr.unwrap() -} - -pub fn instantiate_multisig_prover( - app: &mut App, - instantiate_msg: multisig_prover::msg::InstantiateMsg, -) -> Addr { - let code = ContractWrapper::new( - multisig_prover::contract::execute, - multisig_prover::contract::instantiate, - multisig_prover::contract::query, - ) - .with_reply(multisig_prover::contract::reply); - let code_id = app.store_code(Box::new(code)); - - let contract_addr = app.instantiate_contract( - code_id, - Addr::unchecked("anyone"), - &instantiate_msg, - &[], - "multisig_prover", - None, - ); - - assert!(contract_addr.is_ok()); - contract_addr.unwrap() -} - // Creates an instance of Axelar Amplifier with an initial worker set registered, and returns the instance, the chains, the workers, and the minimum worker bond. pub fn setup_test_case() -> (Protocol, Chain, Chain, Vec, Uint128) { let mut protocol = setup_protocol("validators".to_string().try_into().unwrap()); @@ -947,24 +713,9 @@ pub fn setup_test_case() -> (Protocol, Chain, Chain, Vec, Uint128) { }, ]; let min_worker_bond = Uint128::new(100); - register_service( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.governance_address.clone(), - protocol.service_name.clone(), - min_worker_bond.clone(), - ); + register_service(&mut protocol, min_worker_bond.clone()); - register_workers( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.multisig_address.clone(), - protocol.governance_address.clone(), - protocol.genesis_address.clone(), - &workers, - protocol.service_name.clone(), - min_worker_bond, - ); + register_workers(&mut protocol, &workers, min_worker_bond); let chain1 = setup_chain(&mut protocol, chains.get(0).unwrap().clone()); let chain2 = setup_chain(&mut protocol, chains.get(1).unwrap().clone()); (protocol, chain1, chain2, workers, min_worker_bond) diff --git a/integration-tests/tests/update_worker_set.rs b/integration-tests/tests/update_worker_set.rs index 014df7f44..d75cab6d8 100644 --- a/integration-tests/tests/update_worker_set.rs +++ b/integration-tests/tests/update_worker_set.rs @@ -1,5 +1,6 @@ use cosmwasm_std::Addr; use cw_multi_test::Executor; +use integration_tests::contract::Contract; use test_utils::Worker; mod test_utils; @@ -15,8 +16,7 @@ fn worker_set_can_be_initialized_and_then_manually_updated() { let simulated_worker_set = test_utils::workers_to_worker_set(&mut protocol, &initial_workers); - let worker_set = - test_utils::get_worker_set(&mut protocol.app, ðereum.multisig_prover_address); + let worker_set = test_utils::get_worker_set(&mut protocol.app, ðereum.multisig_prover); assert_eq!(worker_set, simulated_worker_set); @@ -37,49 +37,25 @@ fn worker_set_can_be_initialized_and_then_manually_updated() { let expected_new_worker_set = test_utils::workers_to_worker_set(&mut protocol, &new_workers); - test_utils::register_workers( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.multisig_address.clone(), - protocol.governance_address.clone(), - protocol.genesis_address.clone(), - &new_workers, - protocol.service_name.clone(), - min_worker_bond, - ); + test_utils::register_workers(&mut protocol, &new_workers, min_worker_bond); // remove old workers - test_utils::deregister_workers( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.governance_address.clone(), - &initial_workers, - protocol.service_name.clone(), - ); + test_utils::deregister_workers(&mut protocol, &initial_workers); let response = protocol .app .execute_contract( Addr::unchecked("relayer"), - ethereum.multisig_prover_address.clone(), + ethereum.multisig_prover.contract_addr.clone(), &multisig_prover::msg::ExecuteMsg::UpdateWorkerSet, &[], ) .unwrap(); // sign with old workers - let session_id = test_utils::sign_proof( - &mut protocol.app, - &protocol.multisig_address, - &initial_workers, - response, - ); + let session_id = test_utils::sign_proof(&mut protocol, &initial_workers, response); - let proof = test_utils::get_proof( - &mut protocol.app, - ðereum.multisig_prover_address, - &session_id, - ); + let proof = test_utils::get_proof(&mut protocol.app, ðereum.multisig_prover, &session_id); assert!(matches!( proof.status, multisig_prover::msg::ProofStatus::Completed { .. } @@ -90,34 +66,29 @@ fn worker_set_can_be_initialized_and_then_manually_updated() { let (poll_id, expiry) = test_utils::create_worker_set_poll( &mut protocol.app, Addr::unchecked("relayer"), - ethereum.voting_verifier_address.clone(), + ðereum.voting_verifier, expected_new_worker_set.clone(), ); // do voting test_utils::vote_true_for_worker_set( &mut protocol.app, - ðereum.voting_verifier_address, + ðereum.voting_verifier, &new_workers, poll_id, ); test_utils::advance_at_least_to_height(&mut protocol.app, expiry); - test_utils::end_poll( - &mut protocol.app, - ðereum.voting_verifier_address, - poll_id, - ); + test_utils::end_poll(&mut protocol.app, ðereum.voting_verifier, poll_id); test_utils::confirm_worker_set( &mut protocol.app, Addr::unchecked("relayer"), - ethereum.multisig_prover_address.clone(), + ðereum.multisig_prover, ); - let new_worker_set = - test_utils::get_worker_set(&mut protocol.app, ðereum.multisig_prover_address); + let new_worker_set = test_utils::get_worker_set(&mut protocol.app, ðereum.multisig_prover); assert_eq!(new_worker_set, expected_new_worker_set); } @@ -133,8 +104,7 @@ fn worker_set_cannot_be_updated_again_while_pending_worker_is_not_yet_confirmed( let simulated_worker_set = test_utils::workers_to_worker_set(&mut protocol, &initial_workers); - let worker_set = - test_utils::get_worker_set(&mut protocol.app, ðereum.multisig_prover_address); + let worker_set = test_utils::get_worker_set(&mut protocol.app, ðereum.multisig_prover); assert_eq!(worker_set, simulated_worker_set); @@ -144,48 +114,24 @@ fn worker_set_cannot_be_updated_again_while_pending_worker_is_not_yet_confirmed( vec![("worker3".to_string(), 2), ("worker4".to_string(), 3)], ); - test_utils::register_workers( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.multisig_address.clone(), - protocol.governance_address.clone(), - protocol.genesis_address.clone(), - &first_wave_of_new_workers, - protocol.service_name.clone(), - min_worker_bond, - ); + test_utils::register_workers(&mut protocol, &first_wave_of_new_workers, min_worker_bond); // Deregister old workers - test_utils::deregister_workers( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.governance_address.clone(), - &initial_workers, - protocol.service_name.clone(), - ); + test_utils::deregister_workers(&mut protocol, &initial_workers); let response = protocol .app .execute_contract( Addr::unchecked("relayer"), - ethereum.multisig_prover_address.clone(), + ethereum.multisig_prover.contract_addr.clone(), &multisig_prover::msg::ExecuteMsg::UpdateWorkerSet, &[], ) .unwrap(); - let session_id = test_utils::sign_proof( - &mut protocol.app, - &protocol.multisig_address, - &initial_workers, - response, - ); + let session_id = test_utils::sign_proof(&mut protocol, &initial_workers, response); - let proof = test_utils::get_proof( - &mut protocol.app, - ðereum.multisig_prover_address, - &session_id, - ); + let proof = test_utils::get_proof(&mut protocol.app, ðereum.multisig_prover, &session_id); // proof must be completed assert!(matches!( @@ -198,7 +144,7 @@ fn worker_set_cannot_be_updated_again_while_pending_worker_is_not_yet_confirmed( test_utils::execute_worker_set_poll( &mut protocol, &Addr::unchecked("relayer"), - ðereum.voting_verifier_address, + ðereum.voting_verifier, &first_wave_of_new_workers, ); @@ -206,32 +152,15 @@ fn worker_set_cannot_be_updated_again_while_pending_worker_is_not_yet_confirmed( let second_wave_of_new_workers = test_utils::create_new_workers_vec(chains.clone(), vec![("worker5".to_string(), 5)]); - test_utils::register_workers( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.multisig_address.clone(), - protocol.governance_address.clone(), - protocol.genesis_address.clone(), - &second_wave_of_new_workers, - protocol.service_name.clone(), - min_worker_bond, - ); + test_utils::register_workers(&mut protocol, &second_wave_of_new_workers, min_worker_bond); // Deregister old workers - test_utils::deregister_workers( - &mut protocol.app, - protocol.service_registry_address.clone(), - protocol.governance_address.clone(), - &first_wave_of_new_workers, - protocol.service_name.clone(), - ); + test_utils::deregister_workers(&mut protocol, &first_wave_of_new_workers); - let response = protocol.app.execute_contract( + let response = ethereum.multisig_prover.execute( + &mut protocol.app, Addr::unchecked("relayer"), - ethereum.multisig_prover_address.clone(), &multisig_prover::msg::ExecuteMsg::UpdateWorkerSet, - &[], ); - assert!(response.is_err()); }