Skip to content

Commit

Permalink
Update verification testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
themicp committed Jan 30, 2024
1 parent 08b7154 commit a74e9d0
Show file tree
Hide file tree
Showing 7 changed files with 1,058 additions and 1,201 deletions.
18 changes: 8 additions & 10 deletions contracts/light-client/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,9 @@ mod tests {
assert_eq!(
result,
vec![
(String::from("message:ethereum:0x302c20e77610ecff3e2dbd7ca7f422dd790efedbfec67a0330d9c705a77e9cc1:0"), String::from("OK")),
(String::from("workersetmessage:0x9d3cf63d98fd73dcc7d2a325e104f29af16909a88725bdd94e88c3e0441b74d5:0"), String::from("OK")),
(String::from("workersetmessage:0xd190fddcf5ff9246ef2d267ca0746e1300f18120d31c48be2dd587468979f130:2"), String::from("OK")),
(String::from("message:ethereum:0xd190fddcf5ff9246ef2d267ca0746e1300f18120d31c48be2dd587468979f130:0"), String::from("OK"))
(String::from("message:ethereum:0x9b7b2617eef7734bbb6e83464e955c205838790c1806ecf2a864d0c16395fe20:0"), String::from("OK")),
(String::from("workersetmessage:0x9b7b2617eef7734bbb6e83464e955c205838790c1806ecf2a864d0c16395fe20:2"), String::from("OK")),
(String::from("message:ethereum:0xabdb1b254e1f6b779611ae699e1c48188cb1f58013f51474e58a1842fe9d782e:0"), String::from("OK")),
]
);
for content in contents {
Expand Down Expand Up @@ -380,10 +379,9 @@ mod tests {
assert_eq!(
result,
vec![
(String::from("message:ethereum:0x302c20e77610ecff3e2dbd7ca7f422dd790efedbfec67a0330d9c705a77e9cc1:0"), String::from("Invalid transaction proof")),
(String::from("workersetmessage:0x9d3cf63d98fd73dcc7d2a325e104f29af16909a88725bdd94e88c3e0441b74d5:0"), String::from("OK")),
(String::from("workersetmessage:0xd190fddcf5ff9246ef2d267ca0746e1300f18120d31c48be2dd587468979f130:2"), String::from("OK")),
(String::from("message:ethereum:0xd190fddcf5ff9246ef2d267ca0746e1300f18120d31c48be2dd587468979f130:0"), String::from("OK"))
(String::from("message:ethereum:0x9b7b2617eef7734bbb6e83464e955c205838790c1806ecf2a864d0c16395fe20:0"), String::from("Invalid transaction proof")),
(String::from("workersetmessage:0x9b7b2617eef7734bbb6e83464e955c205838790c1806ecf2a864d0c16395fe20:2"), String::from("Invalid transaction proof")),
(String::from("message:ethereum:0xabdb1b254e1f6b779611ae699e1c48188cb1f58013f51474e58a1842fe9d782e:0"), String::from("OK")),
]
);
for (_index, content) in contents.iter().enumerate() {
Expand All @@ -398,7 +396,7 @@ mod tests {
},
)
.unwrap();
assert_eq!(res, vec![(m.clone(), m.key() != "message:ethereum:0x302c20e77610ecff3e2dbd7ca7f422dd790efedbfec67a0330d9c705a77e9cc1:0")]);
assert_eq!(res, vec![(m.clone(), m.key() == "message:ethereum:0xabdb1b254e1f6b779611ae699e1c48188cb1f58013f51474e58a1842fe9d782e:0")]);
}
ContentVariant::WorkerSet(m) => {
let res: bool = app
Expand All @@ -408,7 +406,7 @@ mod tests {
&QueryMsg::IsWorkerSetVerified { message: m.clone() },
)
.unwrap();
assert!(res);
assert_eq!(res, m.key() != "workersetmessage:0x9b7b2617eef7734bbb6e83464e955c205838790c1806ecf2a864d0c16395fe20:2");
}
};
}
Expand Down
13 changes: 9 additions & 4 deletions contracts/light-client/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub mod tests {
fn test_verify_workerset_message() {
let gateway_address = String::from("0xAba4D993188008F665C972d79fc59AB2381eCe94");
let verification_data = get_batched_data(false, "finality").1;
let target_block_proofs = verification_data.target_blocks.get(1).unwrap();
let target_block_proofs = verification_data.target_blocks.get(0).unwrap();
let proofs = target_block_proofs.transactions_proofs.get(0).unwrap();

let messages = filter_workerset_variants(proofs);
Expand Down Expand Up @@ -443,8 +443,13 @@ pub mod tests {

// test error from content
let mut corrupted_proofs = transaction_proofs.clone();
let (_, mut messages) = filter_variants_as_mutref(&mut corrupted_proofs);
messages[0].cc_id.id = "invalid".to_string().try_into().unwrap();
let (workerset_messages, messages) = filter_variants_as_mutref(&mut corrupted_proofs);
for message in messages {
message.cc_id.id = "invalid".to_string().try_into().unwrap();
}
for message in workerset_messages {
message.message_id = "invalid".to_string().try_into().unwrap();
}
let res =
process_transaction_proofs(&corrupted_proofs, &target_block_root, &gateway_address);
assert_invalid_contents(&corrupted_proofs.content, &res);
Expand Down Expand Up @@ -556,7 +561,7 @@ pub mod tests {
.flat_map(|target_block| extract_content_from_block(target_block))
.collect::<Vec<ContentVariant>>();

println!("{:?}", res);
println!("{}, {}", historical, finalization);
assert!(res.is_ok());
assert_valid_contents(&contents, &res.unwrap());
for content in contents {
Expand Down
Loading

0 comments on commit a74e9d0

Please sign in to comment.