Skip to content

Commit

Permalink
refactor: contract trait for integration tests (#297)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
maancham authored Mar 12, 2024
1 parent c179252 commit 1e1ca96
Show file tree
Hide file tree
Showing 11 changed files with 595 additions and 558 deletions.
45 changes: 45 additions & 0 deletions integration-tests/src/connection_router_contract.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
48 changes: 48 additions & 0 deletions integration-tests/src/gateway_contract.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
7 changes: 7 additions & 0 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
50 changes: 50 additions & 0 deletions integration-tests/src/multisig_contract.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
66 changes: 66 additions & 0 deletions integration-tests/src/multisig_prover_contract.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
50 changes: 50 additions & 0 deletions integration-tests/src/rewards_contract.rs
Original file line number Diff line number Diff line change
@@ -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<Binary> { 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()
}
}
40 changes: 40 additions & 0 deletions integration-tests/src/service_registry_contract.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
61 changes: 61 additions & 0 deletions integration-tests/src/voting_verifier_contract.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
Loading

0 comments on commit 1e1ca96

Please sign in to comment.