Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Sep 11, 2023
1 parent ad6c662 commit beb68a0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 58 deletions.
43 changes: 19 additions & 24 deletions apps/src/lib/node/ledger/ethereum_oracle/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,35 +340,30 @@ pub mod eth_events {
/// Test decoding a "Transfer to Namada" Ethereum event.
#[test]
fn test_transfer_to_namada_decode() {
// XXX: this is gonna fail :D
let data = vec![
170, 156, 23, 249, 166, 216, 156, 37, 67, 204, 150, 161, 103,
163, 161, 122, 243, 66, 109, 149, 141, 194, 27, 80, 238, 109,
40, 128, 254, 233, 54, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 160, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95, 189, 178, 49, 86,
120, 175, 236, 179, 103, 240, 50, 217, 63, 100, 47, 100, 24,
10, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 95, 189,
178, 49, 86, 120, 175, 236, 179, 103, 240, 50, 217, 63, 100,
47, 100, 24, 10, 163, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 96, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84,
97, 116, 101, 115, 116, 49, 118, 52, 101, 104, 103, 119, 51,
54, 120, 117, 117, 110, 119, 100, 54, 57, 56, 57, 112, 114,
119, 100, 102, 107, 120, 113, 109, 110, 118, 115, 102, 106,
120, 115, 54, 110, 118, 118, 54, 120, 120, 117, 99, 114, 115,
51, 102, 51, 120, 99, 109, 110, 115, 51, 102, 99, 120, 100,
122, 114, 118, 118, 122, 57, 120, 118, 101, 114, 122, 118, 122,
114, 53, 54, 108, 101, 56, 102, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1,
0, 0, 0, 84, 97, 116, 101, 115, 116, 49, 118, 52, 101, 104,
103, 119, 51, 54, 120, 117, 117, 110, 119, 100, 54, 57, 56, 57,
112, 114, 119, 100, 102, 107, 120, 113, 109, 110, 118, 115,
102, 106, 120, 115, 54, 110, 118, 118, 54, 120, 120, 117, 99,
114, 115, 51, 102, 51, 120, 99, 109, 110, 115, 51, 102, 99,
120, 100, 122, 114, 118, 118, 122, 57, 120, 118, 101, 114, 122,
118, 122, 114, 53, 54, 108, 101, 56, 102, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
];

let raw: TransferToChainFilter = TRANSFER_TO_CHAIN_CODEC
Expand Down
43 changes: 19 additions & 24 deletions apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,22 +524,6 @@ mod test_vote_extensions {
transfers: vec![],
})
.expect_err("Test failed");

// either kind of transfer with different validity map and transfer
// array length are invalid
shell
.validate_eth_event(&EthereumEvent::TransfersToEthereum {
nonce,
transfers: vec![],
relayer: gen_established_address(),
})
.expect_err("Test failed");
shell
.validate_eth_event(&EthereumEvent::TransfersToNamada {
nonce,
transfers: vec![],
})
.expect_err("Test failed");
}

/// Test that we successfully receive ethereum events
Expand Down Expand Up @@ -580,22 +564,33 @@ mod test_vote_extensions {
.expect("Test failed");
tokio_test::block_on(oracle.send(event_3.clone()))
.expect("Test failed");
let [event_first, event_second]: [EthereumEvent; 2] =

let got_events: [EthereumEvent; 2] =
shell.new_ethereum_events().try_into().expect("Test failed");
let expected_events: Vec<_> = std::collections::BTreeSet::from([
event_1.clone(),
event_3.clone(),
])
.into_iter()
.collect();
assert_eq!(expected_events, got_events);

assert_eq!(event_first, event_1);
assert_eq!(event_second, event_3);
// check that we queue and de-duplicate events
tokio_test::block_on(oracle.send(event_2.clone()))
.expect("Test failed");
tokio_test::block_on(oracle.send(event_3.clone()))
.expect("Test failed");
let [event_first, event_second, event_third]: [EthereumEvent; 3] =
shell.new_ethereum_events().try_into().expect("Test failed");

assert_eq!(event_first, event_1);
assert_eq!(event_second, event_2);
assert_eq!(event_third, event_3);
let got_events: [EthereumEvent; 3] =
shell.new_ethereum_events().try_into().expect("Test failed");
let expected_events: Vec<_> = std::collections::BTreeSet::from([
event_1.clone(),
event_2.clone(),
event_3.clone(),
])
.into_iter()
.collect();
assert_eq!(expected_events, got_events);
}

/// Test that ethereum events are added to vote extensions.
Expand Down
12 changes: 6 additions & 6 deletions core/src/types/eth_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ mod tests {
};
let encoded = valset_update.encode().into_inner();
let encoded = HEXLOWER.encode(&encoded);
let expected = "00000000000000000000000000000000000000000000000000000000000000200000\
00000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000\
000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000\
00000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000\
241d37b7cf5233b3b0b204321420a86e8f7bfdb50000000000000000000000000000000000000000000000000000\
000000000001000000000000000000000000000000000000000000000000000000000086b58b";
let expected = "000000000000000000000000000000000000000000000000000000000000002\
000000000000000000000000000000000000000000000000000000000000000\
400000000000000000000000000000000000000000000000000000000000000\
000000000000000000000000000000000000000000000000000000000000000\
0001241d37b7cf5233b3b0b204321420a86e8f7bfdb50000000000000000008\
6b58b";
assert_eq!(expected, encoded);
}
}
6 changes: 3 additions & 3 deletions core/src/types/vote_extensions/ethereum_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ mod tests {
assert_eq!(
hash,
Hash([
237, 76, 45, 220, 228, 238, 146, 153, 170, 10, 70, 130, 32, 16,
67, 66, 231, 34, 223, 166, 173, 203, 204, 195, 54, 19, 165,
119, 63, 252, 187, 132
94, 131, 116, 129, 41, 204, 178, 144, 24, 8, 185, 16, 103, 236,
209, 191, 20, 89, 145, 17, 41, 233, 31, 98, 185, 6, 217, 204,
80, 38, 224, 23
])
);
}
Expand Down
2 changes: 1 addition & 1 deletion ethereum_bridge/src/storage/vote_tallies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ mod test {
nonce: 0.into(),
transfers: vec![],
},
"9E1736C43D19118E6CE4302118AF337109491ECC52757DFB949BAD6A7940B0C2"
"AB24A95F44CECA5D2AED4B6D056ADDDD8539F44C6CD6CA506534E830C82EA8A8"
.to_owned(),
)
}
Expand Down

0 comments on commit beb68a0

Please sign in to comment.