Skip to content

Commit

Permalink
Remove unused tests, fix imports, tidy up message verification tests
Browse files Browse the repository at this point in the history
  • Loading branch information
themicp committed Dec 5, 2023
1 parent 4793598 commit 88b5970
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 121 deletions.
64 changes: 10 additions & 54 deletions light-client/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mod execute {
let valid_block_root_proof = verify_merkle_proof(
&target_block_root,
block_root_proof.as_slice(),
&GeneralizedIndex(block_root_gindex as usize),
&GeneralizedIndex(block_root_gindex),
&block_summary_root,
);

Expand Down Expand Up @@ -362,67 +362,23 @@ mod tests {
}

#[test]
fn test_data() {
fn test_verification_with_historical_roots() {
let lightclient = init_lightclient();
let data = get_event_verification_data();
let data = get_verification_data_with_historical_roots();
let res = execute::process_verification_data(&lightclient, &data);
println!("{res:?}");
assert!(res.is_ok());
}

#[test]
fn test_verify() {
assert!(false);
fn test_verification_with_block_roots() {
let lightclient = init_lightclient();
let data = get_verification_data_with_block_roots();
let res = execute::process_verification_data(&lightclient, &data);
println!("{res:?}");
assert!(res.is_ok());
}

#[test]
fn test_topic_inclusion() {
let (mut app, addr) = deploy();
let mut request = get_topic_inclusion_query();
let mut resp = app
.execute_contract(
Addr::unchecked("owner"),
addr.to_owned(),
&ExecuteMsg::VerifyTopicInclusion {
receipt: request.receipt.clone(),
topic: request.topic.clone(),
},
&[],
)
.unwrap();

let wasm = resp.events.iter().find(|ev| ev.ty == "wasm").unwrap();
assert_eq!(
wasm.attributes
.iter()
.find(|attr| attr.key == "result")
.unwrap()
.value,
"true"
);

request.topic[0] = request.topic[0] + 1; // modify a random byte
resp = app
.execute_contract(
Addr::unchecked("owner"),
addr.to_owned(),
&ExecuteMsg::VerifyTopicInclusion {
receipt: request.receipt.clone(),
topic: request.topic.clone(),
},
&[],
)
.unwrap();

let wasm = resp.events.iter().find(|ev| ev.ty == "wasm").unwrap();
assert_eq!(
wasm.attributes
.iter()
.find(|attr| attr.key == "result")
.unwrap()
.value,
"false"
);
assert!(false);
}

#[test]
Expand Down
68 changes: 1 addition & 67 deletions light-client/src/lightclient/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub mod tests {
consensus_types::BeaconBlockHeader,
constants::{BlsPublicKey, BlsSignature},
};
use types::lightclient::{BlockVerificationData, LightClientState};
use types::lightclient::LightClientState;

pub fn init_lightclient() -> LightClient {
let bootstrap = get_bootstrap();
Expand Down Expand Up @@ -370,70 +370,4 @@ pub mod tests {
"finalized_header should be set after applying second update"
);
}

#[test]
fn test_verify_block_directly() {
let mut lightclient = init_lightclient();
let bootstrap = get_bootstrap();

let update = get_update(862);
let res = lightclient.apply_update(&update);
assert!(res.is_ok());

let file: File = File::open("testdata/verification/7061552-7061553.json").unwrap();
let data: BlockVerificationData = serde_json::from_reader(file).unwrap();
let sync_committee = bootstrap.current_sync_committee;

assert!(lightclient.verify_block(
&sync_committee,
&data.target_block,
&data.intermediate_chain,
&data.sync_aggregate,
data.sig_slot.into(),
));
}

#[test]
fn test_verify_block_with_intermediate_block() {
let mut lightclient = init_lightclient();
let bootstrap = get_bootstrap();

let update = get_update(862);
let res = lightclient.apply_update(&update);
assert!(res.is_ok());

let file: File = File::open("testdata/verification/7061551-7061553.json").unwrap();
let data: BlockVerificationData = serde_json::from_reader(file).unwrap();
let sync_committee = bootstrap.current_sync_committee;

assert!(lightclient.verify_block(
&sync_committee,
&data.target_block,
&data.intermediate_chain,
&data.sync_aggregate,
data.sig_slot.into(),
));
}

#[test]
fn test_verify_block_with_intermediate_chain() {
let mut lightclient = init_lightclient();
let bootstrap = get_bootstrap();

let update = get_update(862);
let res = lightclient.apply_update(&update);
assert!(res.is_ok());

let file: File = File::open("testdata/verification/7061551-7061555.json").unwrap();
let data: BlockVerificationData = serde_json::from_reader(file).unwrap();
let sync_committee = bootstrap.current_sync_committee;

assert!(lightclient.verify_block(
&sync_committee,
&data.target_block,
&data.intermediate_chain,
&data.sync_aggregate,
data.sig_slot.into(),
));
}
}

0 comments on commit 88b5970

Please sign in to comment.