Skip to content

Commit

Permalink
Fix: slashing test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Lacy committed Sep 24, 2024
1 parent 543e639 commit 4bdc93a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions contracts/btc-finality/src/multitest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ mod slashing {

// Call the begin-block sudo handler at the next height, for completeness
let next_height = initial_height + 1;
suite.app.advance_blocks(next_height - initial_height);
suite
.call_begin_block(&add_finality_signature.block_app_hash, next_height)
.unwrap();
Expand Down Expand Up @@ -364,14 +365,20 @@ mod slashing {

// Assert the double signing evidence is proper
let btc_pk = hex::decode(pk_hex.clone()).unwrap();
let evidence = suite.get_double_signing_evidence(&pk_hex, submit_height);
let evidence = suite
.get_double_signing_evidence(&pk_hex, submit_height)
.evidence
.unwrap();
assert_eq!(evidence.block_height, submit_height);
assert_eq!(evidence.fp_btc_pk, btc_pk);

// Assert the slashing event is there
assert_eq!(1, res.events.len());
// Assert the slashing event is proper
assert_eq!(res.events[0].ty, "slashed_finality_provider".to_string());
assert_eq!(4, res.events.len());
// Assert the slashing event is proper (slashing is the 2nd event in the list)
assert_eq!(
res.events[1].ty,
"wasm-slashed_finality_provider".to_string()
);

// Call the end-block sudo handler for completeness / realism
suite
Expand All @@ -380,6 +387,7 @@ mod slashing {

// Call the next (final) block begin blocker, to compute the active FP set
let final_height = next_height + 1;
suite.app.advance_blocks(final_height - next_height);
suite
.call_begin_block("deadbeef02".as_bytes(), final_height)
.unwrap();
Expand All @@ -402,6 +410,6 @@ mod slashing {

// Assert the finality provider has been slashed
let fp = suite.get_finality_provider(&pk_hex);
assert_eq!(fp.slashed_height, submit_height);
assert_eq!(fp.slashed_height, next_height);
}
}
6 changes: 3 additions & 3 deletions contracts/btc-finality/src/multitest/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use cosmwasm_std::Addr;
use cw_multi_test::{AppResponse, Contract, ContractWrapper, Executor};

use babylon_apis::btc_staking_api::{ActiveBtcDelegation, FinalityProvider, NewFinalityProvider};
use babylon_apis::finality_api::{Evidence, IndexedBlock, PubRandCommit};
use babylon_apis::finality_api::{IndexedBlock, PubRandCommit};
use babylon_apis::{btc_staking_api, finality_api};
use babylon_bindings::BabylonMsg;
use babylon_bindings_test::BabylonApp;
use babylon_bitcoin::chain_params::Network;
use btc_staking::msg::{ActivatedHeightResponse, FinalityProviderInfo};

use crate::msg::FinalitySignatureResponse;
use crate::msg::{EvidenceResponse, FinalitySignatureResponse};
use crate::multitest::{CONTRACT1_ADDR, CONTRACT2_ADDR};

fn contract_btc_staking() -> Box<dyn Contract<BabylonMsg>> {
Expand Down Expand Up @@ -228,7 +228,7 @@ impl Suite {
}

#[track_caller]
pub fn get_double_signing_evidence(&self, pk_hex: &str, height: u64) -> Evidence {
pub fn get_double_signing_evidence(&self, pk_hex: &str, height: u64) -> EvidenceResponse {
self.app
.wrap()
.query_wasm_smart(
Expand Down

0 comments on commit 4bdc93a

Please sign in to comment.