From 0fa24baaac296a6e5de2b3766e54c1184001e7ba Mon Sep 17 00:00:00 2001 From: Heemank Verma Date: Sat, 17 Aug 2024 10:44:31 +0530 Subject: [PATCH] update: PR reviews fixes --- .../ethereum/src/conversion.rs | 25 +- crates/settlement-clients/ethereum/src/lib.rs | 2 +- .../test_data/ABI/starknet_core_contract.json | 681 ------------------ .../ethereum/src/tests/mod.rs | 2 +- 4 files changed, 10 insertions(+), 700 deletions(-) delete mode 100644 crates/settlement-clients/ethereum/src/test_data/ABI/starknet_core_contract.json diff --git a/crates/settlement-clients/ethereum/src/conversion.rs b/crates/settlement-clients/ethereum/src/conversion.rs index 509a8493..04543c27 100644 --- a/crates/settlement-clients/ethereum/src/conversion.rs +++ b/crates/settlement-clients/ethereum/src/conversion.rs @@ -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] @@ -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); } @@ -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")] diff --git a/crates/settlement-clients/ethereum/src/lib.rs b/crates/settlement-clients/ethereum/src/lib.rs index 374ef8f2..8978b6f7 100644 --- a/crates/settlement-clients/ethereum/src/lib.rs +++ b/crates/settlement-clients/ethereum/src/lib.rs @@ -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. diff --git a/crates/settlement-clients/ethereum/src/test_data/ABI/starknet_core_contract.json b/crates/settlement-clients/ethereum/src/test_data/ABI/starknet_core_contract.json deleted file mode 100644 index 99362827..00000000 --- a/crates/settlement-clients/ethereum/src/test_data/ABI/starknet_core_contract.json +++ /dev/null @@ -1,681 +0,0 @@ -[ - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "changedBy", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "oldConfigHash", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "newConfigHash", - "type": "uint256" - } - ], - "name": "ConfigHashChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "fromAddress", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "toAddress", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256[]", - "name": "payload", - "type": "uint256[]" - } - ], - "name": "ConsumedMessageToL1", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "fromAddress", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "toAddress", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "selector", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256[]", - "name": "payload", - "type": "uint256[]" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - } - ], - "name": "ConsumedMessageToL2", - "type": "event" - }, - { "anonymous": false, "inputs": [], "name": "Finalized", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "fromAddress", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "toAddress", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256[]", - "name": "payload", - "type": "uint256[]" - } - ], - "name": "LogMessageToL1", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "fromAddress", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "toAddress", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "selector", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256[]", - "name": "payload", - "type": "uint256[]" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "fee", - "type": "uint256" - } - ], - "name": "LogMessageToL2", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "acceptedGovernor", - "type": "address" - } - ], - "name": "LogNewGovernorAccepted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "nominatedGovernor", - "type": "address" - } - ], - "name": "LogNominatedGovernor", - "type": "event" - }, - { - "anonymous": false, - "inputs": [], - "name": "LogNominationCancelled", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "operator", - "type": "address" - } - ], - "name": "LogOperatorAdded", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "operator", - "type": "address" - } - ], - "name": "LogOperatorRemoved", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "removedGovernor", - "type": "address" - } - ], - "name": "LogRemovedGovernor", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "bytes32", - "name": "stateTransitionFact", - "type": "bytes32" - } - ], - "name": "LogStateTransitionFact", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "globalRoot", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "int256", - "name": "blockNumber", - "type": "int256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "blockHash", - "type": "uint256" - } - ], - "name": "LogStateUpdate", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "fromAddress", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "toAddress", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "selector", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256[]", - "name": "payload", - "type": "uint256[]" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - } - ], - "name": "MessageToL2Canceled", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "fromAddress", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "toAddress", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "selector", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256[]", - "name": "payload", - "type": "uint256[]" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "nonce", - "type": "uint256" - } - ], - "name": "MessageToL2CancellationStarted", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "changedBy", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "oldProgramHash", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "newProgramHash", - "type": "uint256" - } - ], - "name": "ProgramHashChanged", - "type": "event" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "toAddress", "type": "uint256" }, - { "internalType": "uint256", "name": "selector", "type": "uint256" }, - { "internalType": "uint256[]", "name": "payload", "type": "uint256[]" }, - { "internalType": "uint256", "name": "nonce", "type": "uint256" } - ], - "name": "cancelL1ToL2Message", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "configHash", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "fromAddress", "type": "uint256" }, - { "internalType": "uint256[]", "name": "payload", "type": "uint256[]" } - ], - "name": "consumeMessageFromL2", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "finalize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "getMaxL1MsgFee", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [], - "name": "identify", - "outputs": [{ "internalType": "string", "name": "", "type": "string" }], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [{ "internalType": "bytes", "name": "data", "type": "bytes" }], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "isFinalized", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "isFrozen", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "isOperator", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "msgHash", "type": "bytes32" } - ], - "name": "l1ToL2MessageCancellations", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "l1ToL2MessageNonce", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "msgHash", "type": "bytes32" } - ], - "name": "l1ToL2Messages", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "msgHash", "type": "bytes32" } - ], - "name": "l2ToL1Messages", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "messageCancellationDelay", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "programHash", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "newOperator", "type": "address" } - ], - "name": "registerOperator", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "toAddress", "type": "uint256" }, - { "internalType": "uint256", "name": "selector", "type": "uint256" }, - { "internalType": "uint256[]", "name": "payload", "type": "uint256[]" } - ], - "name": "sendMessageToL2", - "outputs": [ - { "internalType": "bytes32", "name": "", "type": "bytes32" }, - { "internalType": "uint256", "name": "", "type": "uint256" } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "newConfigHash", "type": "uint256" } - ], - "name": "setConfigHash", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "delayInSeconds", "type": "uint256" } - ], - "name": "setMessageCancellationDelay", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "newProgramHash", "type": "uint256" } - ], - "name": "setProgramHash", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "starknetAcceptGovernance", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "starknetCancelNomination", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "user", "type": "address" } - ], - "name": "starknetIsGovernor", - "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "address", "name": "newGovernor", "type": "address" } - ], - "name": "starknetNominateNewGovernor", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "governorForRemoval", - "type": "address" - } - ], - "name": "starknetRemoveGovernor", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { "internalType": "uint256", "name": "toAddress", "type": "uint256" }, - { "internalType": "uint256", "name": "selector", "type": "uint256" }, - { "internalType": "uint256[]", "name": "payload", "type": "uint256[]" }, - { "internalType": "uint256", "name": "nonce", "type": "uint256" } - ], - "name": "startL1ToL2MessageCancellation", - "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "stateBlockHash", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { "internalType": "bytes32", "name": "msgHash", "type": "bytes32" } - ], - "name": "l1ToL2Messages", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "stateBlockNumber", - "outputs": [{ "internalType": "int256", "name": "", "type": "int256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "stateRoot", - "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "removedOperator", - "type": "address" - } - ], - "name": "unregisterOperator", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256[]", - "name": "programOutput", - "type": "uint256[]" - }, - { - "internalType": "uint256", - "name": "onchainDataHash", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "onchainDataSize", - "type": "uint256" - } - ], - "name": "updateState", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256[]", - "name": "programOutput", - "type": "uint256[]" - }, - { "internalType": "bytes", "name": "kzgProof", "type": "bytes" } - ], - "name": "updateStateKzgDA", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - } -] diff --git a/crates/settlement-clients/ethereum/src/tests/mod.rs b/crates/settlement-clients/ethereum/src/tests/mod.rs index 274967c0..68c081b3 100644 --- a/crates/settlement-clients/ethereum/src/tests/mod.rs +++ b/crates/settlement-clients/ethereum/src/tests/mod.rs @@ -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! {