Skip to content

Commit

Permalink
refactor: update aggregate verifier tests to utilize contract trait (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
maancham authored Feb 20, 2024
1 parent 671777b commit 6e5157f
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 90 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/aggregate-verifier/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ voting-verifier = { workspace = true, features = ["library"] }

[dev-dependencies]
cw-multi-test = "0.15.1"
integration-tests = { workspace = true }
136 changes: 46 additions & 90 deletions contracts/aggregate-verifier/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use aggregate_verifier::contract::*;
use aggregate_verifier::msg::{ExecuteMsg, InstantiateMsg};
use aggregate_verifier::msg::ExecuteMsg;
use axelar_wasm_std::VerificationStatus;
use connection_router::state::{CrossChainId, Message, ID_SEPARATOR};
use cosmwasm_std::from_binary;
use cosmwasm_std::Addr;
use cw_multi_test::{App, ContractWrapper, Executor};
use cw_multi_test::{App, Executor};

Check warning on line 6 in contracts/aggregate-verifier/tests/test.rs

View workflow job for this annotation

GitHub Actions / Test Suite

unused import: `Executor`
use integration_tests::contract::Contract;

use crate::mock::{make_mock_voting_verifier, mark_messages_as_verified};
pub mod mock;
mod test_utils;

fn generate_messages(count: usize) -> Vec<Message> {
let mut msgs = vec![];
Expand All @@ -33,28 +34,16 @@ fn verify_messages_empty() {
let mut app = App::default();
let voting_verifier_address = make_mock_voting_verifier(&mut app);

let code = ContractWrapper::new(execute, instantiate, query).with_reply(reply);
let code_id = app.store_code(Box::new(code));

let verifier_address = app
.instantiate_contract(
code_id,
Addr::unchecked("gateway"),
&InstantiateMsg {
verifier_address: voting_verifier_address.to_string(),
},
&[],
"Contract",
None,
)
.unwrap();
let aggregate_verifier = test_utils::AggregateVerifierContract::instantiate_contract(
&mut app,
voting_verifier_address.clone(),
);

let res = app
.execute_contract(
let res = aggregate_verifier
.execute(
&mut app,
Addr::unchecked("relayer"),
verifier_address.clone(),
&ExecuteMsg::VerifyMessages { messages: vec![] },
&[],
)
.unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_binary(&res.data.unwrap()).unwrap();
Expand All @@ -66,37 +55,26 @@ fn verify_messages_not_verified() {
let mut app = App::default();
let voting_verifier_address = make_mock_voting_verifier(&mut app);

let code = ContractWrapper::new(execute, instantiate, query).with_reply(reply);
let code_id = app.store_code(Box::new(code));

let verifier_address = app
.instantiate_contract(
code_id,
Addr::unchecked("gateway"),
&InstantiateMsg {
verifier_address: voting_verifier_address.to_string(),
},
&[],
"Contract",
None,
)
.unwrap();
let aggregate_verifier = test_utils::AggregateVerifierContract::instantiate_contract(
&mut app,
voting_verifier_address.clone(),
);

let msgs = generate_messages(10);
let res = app
.execute_contract(
let messages = generate_messages(10);
let res = aggregate_verifier
.execute(
&mut app,
Addr::unchecked("relayer"),
verifier_address.clone(),
&ExecuteMsg::VerifyMessages {
messages: msgs.clone(),
messages: messages.clone(),
},
&[],
)
.unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_binary(&res.data.unwrap()).unwrap();
assert_eq!(
ret,
msgs.iter()
messages
.iter()
.map(|msg| (msg.cc_id.clone(), VerificationStatus::None))
.collect::<Vec<(_, _)>>()
);
Expand All @@ -107,39 +85,28 @@ fn verify_messages_verified() {
let mut app = App::default();
let voting_verifier_address = make_mock_voting_verifier(&mut app);

let code = ContractWrapper::new(execute, instantiate, query).with_reply(reply);
let code_id = app.store_code(Box::new(code));

let verifier_address = app
.instantiate_contract(
code_id,
Addr::unchecked("gateway"),
&InstantiateMsg {
verifier_address: voting_verifier_address.to_string(),
},
&[],
"Contract",
None,
)
.unwrap();
let aggregate_verifier = test_utils::AggregateVerifierContract::instantiate_contract(
&mut app,
voting_verifier_address.clone(),
);

let msgs = generate_messages(10);
mark_messages_as_verified(&mut app, voting_verifier_address, msgs.clone());
let messages = generate_messages(10);
mark_messages_as_verified(&mut app, voting_verifier_address, messages.clone());

let res = app
.execute_contract(
let res = aggregate_verifier
.execute(
&mut app,
Addr::unchecked("relayer"),
verifier_address.clone(),
&ExecuteMsg::VerifyMessages {
messages: msgs.clone(),
messages: messages.clone(),
},
&[],
)
.unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_binary(&res.data.unwrap()).unwrap();
assert_eq!(
ret,
msgs.iter()
messages
.iter()
.map(|msg| (msg.cc_id.clone(), VerificationStatus::SucceededOnChain))
.collect::<Vec<(_, _)>>()
);
Expand All @@ -150,40 +117,29 @@ fn verify_messages_mixed_status() {
let mut app = App::default();
let voting_verifier_address = make_mock_voting_verifier(&mut app);

let code = ContractWrapper::new(execute, instantiate, query).with_reply(reply);
let code_id = app.store_code(Box::new(code));

let verifier_address = app
.instantiate_contract(
code_id,
Addr::unchecked("gateway"),
&InstantiateMsg {
verifier_address: voting_verifier_address.to_string(),
},
&[],
"Contract",
None,
)
.unwrap();
let aggregate_verifier = test_utils::AggregateVerifierContract::instantiate_contract(
&mut app,
voting_verifier_address.clone(),
);

let msgs = generate_messages(10);
let (verified, _) = msgs.split_at(5);
let messages = generate_messages(10);
let (verified, _) = messages.split_at(5);
mark_messages_as_verified(&mut app, voting_verifier_address, verified.to_vec());

let res = app
.execute_contract(
let res = aggregate_verifier
.execute(
&mut app,
Addr::unchecked("relayer"),
verifier_address.clone(),
&ExecuteMsg::VerifyMessages {
messages: msgs.clone(),
messages: messages.clone(),
},
&[],
)
.unwrap();
let ret: Vec<(CrossChainId, VerificationStatus)> = from_binary(&res.data.unwrap()).unwrap();
assert_eq!(
ret,
msgs.iter()
messages
.iter()
.map(|msg| {
if verified
.iter()
Expand Down
42 changes: 42 additions & 0 deletions contracts/aggregate-verifier/tests/test_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use aggregate_verifier::{
contract::*,
msg::{ExecuteMsg, InstantiateMsg, QueryMsg},
};
use cosmwasm_std::Addr;
use cw_multi_test::{App, ContractWrapper, Executor};
use integration_tests::contract::Contract;

pub struct AggregateVerifierContract {
pub contract_addr: Addr,
}

impl AggregateVerifierContract {
pub fn instantiate_contract(app: &mut App, voting_verifier_address: Addr) -> Self {
let code = ContractWrapper::new(execute, instantiate, query).with_reply(reply);
let code_id = app.store_code(Box::new(code));

let contract_addr = app
.instantiate_contract(
code_id,
Addr::unchecked("gateway"),
&InstantiateMsg {
verifier_address: voting_verifier_address.to_string(),
},
&[],
"Contract",
None,
)
.unwrap();

AggregateVerifierContract { contract_addr }
}
}

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

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

0 comments on commit 6e5157f

Please sign in to comment.