Skip to content

Commit

Permalink
update: PR reviews fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
heemankv committed Aug 17, 2024
1 parent d0ddfde commit e2dba9a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ MONGODB_CONNECTION_STRING="mongodb://localhost:27017"
# Ethereum Settlement
DEFAULT_SETTLEMENT_CLIENT_RPC="http://localhost:3000"
DEFAULT_L1_CORE_CONTRACT_ADDRESS="0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4"
ETHEREUM_BLAST_RPC_URL="https://eth-mainnet.blastapi.io/5b0a8479-6b45-49dc-b3b2-18a0c3b8a94e"
TEST_IMPERSONATE_OPERATOR="1"
TEST_DUMMY_CONTRACT_ADDRESS="0xE5b6F5e695BA6E4aeD92B68c4CC8Df1160D69A81"
25 changes: 8 additions & 17 deletions crates/settlement-clients/ethereum/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,10 @@ mod tests {
#[case::maximum(&[0xFF; 32], U256::MAX)]
#[case::short(&[0xFF; 16], U256::from_be_slice(&[0xFF; 16]))]
#[case::empty(&[], U256::ZERO)]
fn slice_u8_to_u256_works(#[case] slice: &[u8], #[case] expected: U256) {
assert_eq!(slice_u8_to_u256(slice).expect("slice_u8_to_u256 failed"), expected)
}

#[rstest]
#[should_panic(expected = "could not convert &[u8] to U256")]
#[case::over(&[0xFF; 33])]
fn slice_u8_to_u256_panics(#[case] slice: &[u8]) {
let _ = slice_u8_to_u256(slice).unwrap();
#[case::over(&[0xFF; 33],U256::from_be_slice(&[0xFF;32]))]
fn slice_u8_to_u256_all_working_and_failing_cases(#[case] slice: &[u8], #[case] expected: U256) {
assert_eq!(slice_u8_to_u256(slice).expect("slice_u8_to_u256 failed"), expected)
}

#[rstest]
Expand Down Expand Up @@ -198,17 +193,11 @@ mod tests {
#[case::empty(&[], "0".repeat(64))]
#[case::typical(&[0xFF,0xFF,0xFF,0xFF], format!("{}{}", "ff".repeat(4), "0".repeat(56)))]
#[case::big(&[0xFF; 32], format!("{}", "ff".repeat(32)))]
fn to_hex_string_works(#[case] slice: &[u8], #[case] expected: String) {
let result = to_padded_hex(slice);
assert_eq!(result, expected);
assert!(expected.len() == 64);
}

#[rstest]
#[should_panic(expected = "Slice length must not exceed 32")]
#[case::exceeding(&[0xFF; 40], format!("{}", "ff".repeat(32)))]
fn to_hex_string_panics(#[case] slice: &[u8], #[case] expected: String) {
let _ = to_padded_hex(slice);
fn to_hex_string_working_and_failing_cases(#[case] slice: &[u8], #[case] expected: String) {
let result = to_padded_hex(slice);
assert_eq!(result, expected);
assert!(expected.len() == 64);
}

Expand Down Expand Up @@ -250,6 +239,8 @@ mod tests {

// block_no here are Ethereum(mainnet) blocks, we are creating sidecar and validating
// the function by matching pre-existing commitments against computed.
// https://etherscan.io/tx/0x4e012b119391bdc192653bfee9758c432ea6f35ff23f8af60a7dca4664383dfc
// https://etherscan.io/tx/0x96470b890833c5ae51622bd6efca98d8eec3b4a66402c34be3cdcacf006eb9a0
#[rstest]
#[case("20462788")]
#[case("20462818")]
Expand Down
2 changes: 1 addition & 1 deletion crates/settlement-clients/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub mod conversion;
// IMPORTANT to understand #[cfg(test)], #[cfg(not(test))] and SHOULD_IMPERSONATE_ACCOUNT
// Two tests : `update_state_blob_with_dummy_contract_works` & `update_state_blob_with_impersonation_works` use a env var `TEST_IMPERSONATE_OPERATOR` to inform the function `update_state_with_blobs` about the kind of testing,
// `TEST_IMPERSONATE_OPERATOR` can have any of "0" or "1" value :
// - if "0" then : Testing against Dummy Contract.
// - if "0" then : Testing via default Anvil address.
// - if "1" then : Testing via impersonating `Starknet Operator Address`.
// Note : changing between "0" and "1" is handled automatically by each test function, `no` manual change in `env.test` is needed.

Expand Down
2 changes: 1 addition & 1 deletion crates/settlement-clients/ethereum/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ sol!(
#[allow(missing_docs)]
#[sol(rpc)]
STARKNET_CORE_CONTRACT,
"src/test_data/ABI/starknet_core_contract.json"
"src/test_data/contract_abi/starknet_core_contract.json"
);

sol! {
Expand Down

0 comments on commit e2dba9a

Please sign in to comment.