Skip to content

Commit

Permalink
refactor: contract trait voting verifier (#276)
Browse files Browse the repository at this point in the history
* refactor: base voting verifier tests template

* refactor: finish voting verifier tests migration

* fix: handle lint issue

* refactor: change config name to fixture

* refactor: handle TestFixture name typo
  • Loading branch information
maancham authored Feb 21, 2024
1 parent 70f6283 commit 2644fba
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 320 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.

1 change: 1 addition & 0 deletions contracts/voting-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ thiserror = { workspace = true }

[dev-dependencies]
cw-multi-test = "0.15.1"
integration-tests = { workspace = true }
65 changes: 65 additions & 0 deletions contracts/voting-verifier/tests/test_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use crate::{source_chain, POLL_BLOCK_EXPIRY};
use axelar_wasm_std::{nonempty, Threshold};
use cosmwasm_std::Addr;
use cw_multi_test::{App, ContractWrapper, Executor};
use integration_tests::contract::Contract;
use voting_verifier::{
contract::*,
msg::{ExecuteMsg, InstantiateMsg, QueryMsg},
};

pub struct VotingVerifierContract {
pub contract_addr: Addr,
}

impl VotingVerifierContract {
pub fn instantiate_contract(
app: &mut App,
service_registry_address: nonempty::String,
rewards_address: String,
) -> 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("sender"),
&InstantiateMsg {
service_registry_address,
service_name: "service_name".parse().unwrap(),
voting_threshold: Threshold::try_from((2u64, 3u64))
.unwrap()
.try_into()
.unwrap(),
block_expiry: POLL_BLOCK_EXPIRY,
confirmation_height: 100,
source_gateway_address: "gateway_address".parse().unwrap(),
source_chain: source_chain(),
rewards_address,
},
&[],
"voting-verifier",
None,
)
.unwrap();

VotingVerifierContract { contract_addr }
}
}

impl Contract for VotingVerifierContract {
type QMsg = QueryMsg;
type ExMsg = ExecuteMsg;

fn contract_address(&self) -> Addr {
self.contract_addr.clone()
}
}

pub fn are_contract_err_strings_equal(
actual: impl Into<axelar_wasm_std::ContractError>,
expected: impl Into<axelar_wasm_std::ContractError>,
) {
assert_eq!(actual.into().to_string(), expected.into().to_string());
}
Loading

0 comments on commit 2644fba

Please sign in to comment.