Skip to content

Commit 6554ca0

Browse files
committed
Fixed mina and mina_account tests and moved test files
1 parent 7d89a32 commit 6554ca0

15 files changed

Lines changed: 50 additions & 36 deletions
-47.2 KB
Binary file not shown.
-1.03 KB
Binary file not shown.
-4.09 KB
Binary file not shown.
-4.09 KB
Binary file not shown.

operator/mina/lib/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

operator/mina/lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bs58 = "0.5.1"
2626
lazy_static = "1.5.0"
2727
blake2 = "0.10.6"
2828
once_cell = "1.19.0"
29-
mina_bridge_core = { git = "https://github.com/lambdaclass/mina_bridge", branch = "relative_finalization" }
29+
mina_bridge_core = { git = "https://github.com/lambdaclass/mina_bridge", branch = "new_account_proof" }
3030
bincode = "1.3.3"
3131

3232
[patch.crates-io]

operator/mina/lib/src/consensus_state.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const GRACE_PERIOD_END: u32 = 1440;
1313
const SUB_WINDOWS_PER_WINDOW: u32 = 11;
1414
const SLOTS_PER_SUB_WINDOW: u32 = 7;
1515

16-
#[derive(PartialEq)]
16+
#[derive(Debug, PartialEq)]
1717
pub enum ChainResult {
1818
Bridge,
1919
Candidate,
@@ -138,3 +138,37 @@ fn hash_last_vrf(chain: &MinaProtocolState) -> String {
138138
fn hash_state(chain: &MinaProtocolState) -> String {
139139
MinaHash::hash(chain).to_hex()
140140
}
141+
142+
#[cfg(test)]
143+
mod test {
144+
use mina_bridge_core::proof::state_proof::MinaStateProof;
145+
146+
use super::*;
147+
148+
const PROOF_BYTES: &[u8] =
149+
include_bytes!("../../../../scripts/test_files/mina/mina_state.proof");
150+
151+
#[test]
152+
fn new_mina_state_passes_consensus_checks() {
153+
let valid_proof: MinaStateProof = bincode::deserialize(PROOF_BYTES).unwrap();
154+
let old_tip = valid_proof.bridge_tip_state;
155+
let new_tip = valid_proof.candidate_chain_states.last().unwrap();
156+
157+
assert_eq!(
158+
select_secure_chain(new_tip, &old_tip).unwrap(),
159+
ChainResult::Candidate
160+
);
161+
}
162+
163+
#[test]
164+
fn old_mina_state_fails_consensus_checks() {
165+
let valid_proof: MinaStateProof = bincode::deserialize(PROOF_BYTES).unwrap();
166+
let old_tip = valid_proof.bridge_tip_state;
167+
let new_tip = valid_proof.candidate_chain_states.last().unwrap();
168+
169+
assert_eq!(
170+
select_secure_chain(&old_tip, new_tip).unwrap(),
171+
ChainResult::Bridge
172+
);
173+
}
174+
}

operator/mina/lib/src/lib.rs

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,14 @@ mod test {
195195
use super::*;
196196

197197
const PROOF_BYTES: &[u8] =
198-
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state.proof");
198+
include_bytes!("../../../../scripts/test_files/mina/mina_state.proof");
199199
const PUB_INPUT_BYTES: &[u8] =
200-
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state.pub");
201-
const PROTOCOL_STATE_BAD_HASH_PUB_BYTES: &[u8] =
202-
include_bytes!("../../../../batcher/aligned/test_files/mina/protocol_state_bad_hash.pub");
203-
const PROTOCOL_STATE_BAD_CONSENSUS_PUB_BYTES: &[u8] = include_bytes!(
204-
"../../../../batcher/aligned/test_files/mina/protocol_state_bad_consensus.pub"
205-
);
200+
include_bytes!("../../../../scripts/test_files/mina/mina_state.pub");
201+
const BAD_HASH_PUB_INPUT_BYTES: &[u8] =
202+
include_bytes!("../../../../scripts/test_files/mina/mina_state_bad_hash.pub");
206203

207204
#[test]
208-
fn protocol_state_proof_verifies() {
205+
fn valid_mina_state_proof_verifies() {
209206
let mut proof_buffer = [0u8; super::MAX_PROOF_SIZE];
210207
let proof_size = PROOF_BYTES.len();
211208
assert!(proof_size <= proof_buffer.len());
@@ -222,33 +219,16 @@ mod test {
222219
}
223220

224221
#[test]
225-
fn proof_of_protocol_state_with_bad_hash_does_not_verify() {
222+
fn mina_state_proof_with_bad_bridge_tip_hash_does_not_verify() {
226223
let mut proof_buffer = [0u8; super::MAX_PROOF_SIZE];
227224
let proof_size = PROOF_BYTES.len();
228225
assert!(proof_size <= proof_buffer.len());
229226
proof_buffer[..proof_size].clone_from_slice(PROOF_BYTES);
230227

231228
let mut pub_input_buffer = [0u8; super::MAX_PUB_INPUT_SIZE];
232-
let pub_input_size = PROTOCOL_STATE_BAD_HASH_PUB_BYTES.len();
229+
let pub_input_size = BAD_HASH_PUB_INPUT_BYTES.len();
233230
assert!(pub_input_size <= pub_input_buffer.len());
234-
pub_input_buffer[..pub_input_size].clone_from_slice(PROTOCOL_STATE_BAD_HASH_PUB_BYTES);
235-
236-
let result =
237-
verify_mina_state_ffi(&proof_buffer, proof_size, &pub_input_buffer, pub_input_size);
238-
assert!(!result);
239-
}
240-
241-
#[test]
242-
fn proof_of_protocol_state_with_bad_consensus_does_not_verify() {
243-
let mut proof_buffer = [0u8; super::MAX_PROOF_SIZE];
244-
let proof_size = PROOF_BYTES.len();
245-
assert!(proof_size <= proof_buffer.len());
246-
proof_buffer[..proof_size].clone_from_slice(PROOF_BYTES);
247-
248-
let mut pub_input_buffer = [0u8; super::MAX_PUB_INPUT_SIZE];
249-
let pub_input_size = PROTOCOL_STATE_BAD_CONSENSUS_PUB_BYTES.len();
250-
assert!(pub_input_size <= pub_input_buffer.len());
251-
pub_input_buffer[..pub_input_size].clone_from_slice(PROTOCOL_STATE_BAD_CONSENSUS_PUB_BYTES);
231+
pub_input_buffer[..pub_input_size].clone_from_slice(BAD_HASH_PUB_INPUT_BYTES);
252232

253233
let result =
254234
verify_mina_state_ffi(&proof_buffer, proof_size, &pub_input_buffer, pub_input_size);

operator/mina/mina_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestMinaStateProofVerifies(t *testing.T) {
1212
fmt.Println(os.Getwd())
13-
proofFile, err := os.Open("../../batcher/aligned/test_files/mina/protocol_state.proof")
13+
proofFile, err := os.Open("../../scripts/test_files/mina/mina_state.proof")
1414
if err != nil {
1515
t.Errorf("could not open mina state proof file")
1616
}
@@ -21,7 +21,7 @@ func TestMinaStateProofVerifies(t *testing.T) {
2121
t.Errorf("could not read bytes from mina state proof file")
2222
}
2323

24-
pubInputFile, err := os.Open("../../batcher/aligned/test_files/mina/protocol_state.pub")
24+
pubInputFile, err := os.Open("../../scripts/test_files/mina/mina_state.pub")
2525
if err != nil {
2626
t.Errorf("could not open mina state hash file")
2727
}

operator/mina_account/mina_account_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
func TestMinaStateProofVerifies(t *testing.T) {
1212
fmt.Println(os.Getwd())
13-
proofFile, err := os.Open("../../batcher/aligned/test_files/mina/account_B62qrQKS9ghd91shs73TCmBJRW9GzvTJK443DPx2YbqcyoLc56g1ny9.proof")
13+
proofFile, err := os.Open("../../scripts/test_files/mina_account/account_B62qrQKS9ghd91shs73TCmBJRW9GzvTJK443DPx2YbqcyoLc56g1ny9.proof")
1414
if err != nil {
1515
t.Errorf("could not open mina account proof file")
1616
}
@@ -21,7 +21,7 @@ func TestMinaStateProofVerifies(t *testing.T) {
2121
t.Errorf("could not read bytes from mina account proof file")
2222
}
2323

24-
pubInputFile, err := os.Open("../../batcher/aligned/test_files/mina/account_B62qrQKS9ghd91shs73TCmBJRW9GzvTJK443DPx2YbqcyoLc56g1ny9.pub")
24+
pubInputFile, err := os.Open("../../scripts/test_files/mina_account/account_B62qrQKS9ghd91shs73TCmBJRW9GzvTJK443DPx2YbqcyoLc56g1ny9.pub")
2525
if err != nil {
2626
t.Errorf("could not open mina account pub inputs file")
2727
}

0 commit comments

Comments
 (0)