From 6badb6c738ffff2c2c4305e424e53a505f0b82aa Mon Sep 17 00:00:00 2001 From: glihm Date: Wed, 27 Sep 2023 20:01:46 -0600 Subject: [PATCH] fix no-std --- starknet-core/src/types/messaging.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/starknet-core/src/types/messaging.rs b/starknet-core/src/types/messaging.rs index de40dbdd..0b87382f 100644 --- a/starknet-core/src/types/messaging.rs +++ b/starknet-core/src/types/messaging.rs @@ -39,12 +39,15 @@ impl MsgL1ToL2 { let high = FieldElement::from_byte_slice_be(&high.to_bytes_be()).unwrap(); let low = FieldElement::from_byte_slice_be(&low.to_bytes_be()).unwrap(); - vec![low, high] + let mut u256 = Vec::new(); + u256.push(low); + u256.push(high); + u256 } /// Computes the message hash. pub fn hash(&self) -> BigUint { - let mut buf: Vec = vec![]; + let mut buf: Vec = Vec::new(); // As EthAddress is only 20 bytes, we do want the 32 bytes // to compute the hash as done in solidity `uint256(uint160(fromAddress))`. @@ -94,12 +97,18 @@ impl L1HandlerTransaction { #[cfg(test)] mod test { + use alloc::vec::Vec; + use super::*; use crate::types::EthAddress; #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] fn test_message_hash_compute() { + let mut payload = Vec::new(); + payload.push(FieldElement::ONE); + payload.push(FieldElement::TWO); + // Tx used for this test on goerli: // 0x46144b600db00853c57a8cf003030ffaa51a810758ef5bfe1bb42bf55b7af38. let msg = MsgL1ToL2 { @@ -113,7 +122,7 @@ mod test { "0x02f15cff7b0eed8b9beb162696cf4e3e0e35fa7032af69cd1b7d2ac67a13f40f", ) .unwrap(), - payload: vec![FieldElement::ONE, FieldElement::TWO], + payload, nonce: 782870_u128.into(), }; @@ -132,6 +141,10 @@ mod test { fn test_message_from_l1_handler_tx() { // Tx used for this test on goerli: // 0x46144b600db00853c57a8cf003030ffaa51a810758ef5bfe1bb42bf55b7af38. + let mut calldata = Vec::new(); + calldata.push(FieldElement::from_hex_be("0xbe3c44c09bc1a3566f3e1ca12e5aba0fa4ca72be").unwrap()); + calldata.push(FieldElement::ONE); + calldata.push(FieldElement::TWO); let tx = L1HandlerTransaction { transaction_hash: FieldElement::from_hex_be( @@ -148,11 +161,7 @@ mod test { "0x2f15cff7b0eed8b9beb162696cf4e3e0e35fa7032af69cd1b7d2ac67a13f40f", ) .unwrap(), - calldata: vec![ - FieldElement::from_hex_be("0xbe3c44c09bc1a3566f3e1ca12e5aba0fa4ca72be").unwrap(), - FieldElement::ONE, - FieldElement::TWO, - ], + calldata, }; let msg = tx.parse_msg_l1_to_l2();