Skip to content

Commit

Permalink
feat(minor-multisig-prover): next verifier set query (#452)
Browse files Browse the repository at this point in the history
* feat(minor-multisig-prover): next verifier set query

* rename GetVerifierSet to CurrentVerifierSet
  • Loading branch information
haiyizxx authored Jun 13, 2024
1 parent 47cc8f6 commit 6fd3612
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
5 changes: 3 additions & 2 deletions contracts/multisig-prover/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ pub fn query(
QueryMsg::GetProof {
multisig_session_id,
} => to_json_binary(&query::get_proof(deps, multisig_session_id)?),
QueryMsg::GetVerifierSet {} => to_json_binary(&query::get_verifier_set(deps)?),
QueryMsg::CurrentVerifierSet {} => to_json_binary(&query::current_verifier_set(deps)?),
QueryMsg::NextVerifierSet {} => to_json_binary(&query::next_verifier_set(deps)?),
}
.change_context(ContractError::SerializeResponse)
.map_err(axelar_wasm_std::ContractError::from)
Expand Down Expand Up @@ -299,7 +300,7 @@ mod tests {
fn query_get_verifier_set(
deps: Deps,
) -> Result<Option<VerifierSet>, axelar_wasm_std::ContractError> {
query(deps, mock_env(), QueryMsg::GetVerifierSet {}).map(|res| from_json(res).unwrap())
query(deps, mock_env(), QueryMsg::CurrentVerifierSet {}).map(|res| from_json(res).unwrap())
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion contracts/multisig-prover/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ pub enum QueryMsg {
GetProof { multisig_session_id: Uint64 },

#[returns(Option<multisig::verifier_set::VerifierSet>)]
GetVerifierSet,
CurrentVerifierSet,

#[returns(Option<multisig::verifier_set::VerifierSet>)]
NextVerifierSet,
}

#[cw_serde]
Expand Down
31 changes: 29 additions & 2 deletions contracts/multisig-prover/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use multisig::{multisig::Multisig, types::MultisigState, verifier_set::VerifierS
use crate::{
error::ContractError,
msg::{GetProofResponse, ProofStatus},
state::{CONFIG, CURRENT_VERIFIER_SET, MULTISIG_SESSION_PAYLOAD, PAYLOAD},
state::{CONFIG, CURRENT_VERIFIER_SET, MULTISIG_SESSION_PAYLOAD, NEXT_VERIFIER_SET, PAYLOAD},
};

pub fn get_proof(
Expand Down Expand Up @@ -57,6 +57,33 @@ pub fn get_proof(
})
}

pub fn get_verifier_set(deps: Deps) -> StdResult<Option<VerifierSet>> {
pub fn current_verifier_set(deps: Deps) -> StdResult<Option<VerifierSet>> {
CURRENT_VERIFIER_SET.may_load(deps.storage)
}

pub fn next_verifier_set(deps: Deps) -> StdResult<Option<VerifierSet>> {
NEXT_VERIFIER_SET.may_load(deps.storage)
}

#[cfg(test)]
mod test {
use cosmwasm_std::testing::mock_dependencies;

use crate::{state, test::test_data::new_verifier_set};

#[test]
fn next_verifier_set() {
let mut deps = mock_dependencies();

assert_eq!(None, super::next_verifier_set(deps.as_ref()).unwrap());

state::NEXT_VERIFIER_SET
.save(deps.as_mut().storage, &new_verifier_set())
.unwrap();

assert_eq!(
Some(new_verifier_set()),
super::next_verifier_set(deps.as_ref()).unwrap()
);
}
}
2 changes: 1 addition & 1 deletion integration-tests/tests/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub fn get_verifier_set_from_prover(
multisig_prover_contract: &MultisigProverContract,
) -> VerifierSet {
let query_response: Result<VerifierSet, StdError> =
multisig_prover_contract.query(app, &multisig_prover::msg::QueryMsg::GetVerifierSet);
multisig_prover_contract.query(app, &multisig_prover::msg::QueryMsg::CurrentVerifierSet);
assert!(query_response.is_ok());

query_response.unwrap()
Expand Down

0 comments on commit 6fd3612

Please sign in to comment.