diff --git a/crates/sol-types/src/coder/decoder.rs b/crates/sol-types/src/coder/decoder.rs index 87bdf4c71e..7dc6efb706 100644 --- a/crates/sol-types/src/coder/decoder.rs +++ b/crates/sol-types/src/coder/decoder.rs @@ -268,7 +268,7 @@ pub fn decode_params<'de, T: TokenSeq<'de>>(data: &'de [u8], validate: bool) -> mod tests { use crate::{sol_data, utils::pad_u32, SolType}; use alloc::string::ToString; - use alloy_primitives::{Address, B256, U256}; + use alloy_primitives::{address, Address, B256, U256}; use hex_literal::hex; #[test] @@ -559,9 +559,9 @@ mod tests { assert_eq!( MyTy::decode_params(&encoded, false).unwrap(), ( - hex!("8497afefdc5ac170a664a231f6efb25526ef813f").into(), - B256::repeat_byte(0x01).into(), - [0x02; 4], + address!("8497afefdc5ac170a664a231f6efb25526ef813f"), + B256::repeat_byte(0x01), + [0x02; 4].into(), "0x0000001F".into(), ) ); diff --git a/crates/sol-types/src/coder/encoder.rs b/crates/sol-types/src/coder/encoder.rs index 6c5e0e26e9..1a30c90e38 100644 --- a/crates/sol-types/src/coder/encoder.rs +++ b/crates/sol-types/src/coder/encoder.rs @@ -538,12 +538,12 @@ mod tests { #[test] fn encode_fixed_bytes() { - let encoded = sol_data::FixedBytes::<2>::encode_single(&[0x12, 0x34]); + let encoded = sol_data::FixedBytes::<2>::encode_single(&[0x12, 0x34].into()); let expected = hex!("1234000000000000000000000000000000000000000000000000000000000000"); assert_eq!(encoded, expected); assert_eq!( encoded.len(), - sol_data::FixedBytes::<2>::encoded_size(&[0x12, 0x34]) + sol_data::FixedBytes::<2>::encoded_size(&[0x12, 0x34].into()) ); } diff --git a/crates/sol-types/src/eip712.rs b/crates/sol-types/src/eip712.rs index 42060407c2..7b962b7efa 100644 --- a/crates/sol-types/src/eip712.rs +++ b/crates/sol-types/src/eip712.rs @@ -132,23 +132,18 @@ impl Eip712Domain { self.salt, ) { (None, None, None, None, None) => vec![], - (None, None, None, None, Some(salt)) => { - <(sol_data::FixedBytes<32>,)>::encode(&(salt.0,)) - } + (None, None, None, None, Some(salt)) => <(sol_data::FixedBytes<32>,)>::encode(&(salt,)), (None, None, None, Some(verifying_contract), None) => { <(sol_data::Address,)>::encode(&(verifying_contract,)) } (None, None, None, Some(verifying_contract), Some(salt)) => { - <(sol_data::Address, sol_data::FixedBytes<32>)>::encode(&( - verifying_contract, - salt.0, - )) + <(sol_data::Address, sol_data::FixedBytes<32>)>::encode(&(verifying_contract, salt)) } (None, None, Some(chain_id), None, None) => { <(sol_data::Uint<256>,)>::encode(&(chain_id,)) } (None, None, Some(chain_id), None, Some(salt)) => { - <(sol_data::Uint<256>, sol_data::FixedBytes<32>)>::encode(&(chain_id, salt.0)) + <(sol_data::Uint<256>, sol_data::FixedBytes<32>)>::encode(&(chain_id, salt)) } (None, None, Some(chain_id), Some(verifying_contract), None) => { <(sol_data::Uint<256>, sol_data::Address)>::encode(&(chain_id, verifying_contract)) @@ -158,20 +153,20 @@ impl Eip712Domain { sol_data::Uint<256>, sol_data::Address, sol_data::FixedBytes<32>, - )>::encode(&(chain_id, verifying_contract, salt.0)) + )>::encode(&(chain_id, verifying_contract, salt)) } (None, Some(version), None, None, None) => { - <(sol_data::FixedBytes<32>,)>::encode(&(keccak256(version.as_bytes()).0,)) + <(sol_data::FixedBytes<32>,)>::encode(&(keccak256(version.as_bytes()),)) } (None, Some(version), None, None, Some(salt)) => { <(sol_data::FixedBytes<32>, sol_data::FixedBytes<32>)>::encode(&( - keccak256(version.as_bytes()).0, - salt.0, + keccak256(version.as_bytes()), + salt, )) } (None, Some(version), None, Some(verifying_contract), None) => { <(sol_data::FixedBytes<32>, sol_data::Address)>::encode(&( - keccak256(version.as_bytes()).0, + keccak256(version.as_bytes()), verifying_contract, )) } @@ -180,11 +175,11 @@ impl Eip712Domain { sol_data::Address, sol_data::FixedBytes<32>, )>::encode( - &(keccak256(version.as_bytes()).0, verifying_contract, salt.0), + &(keccak256(version.as_bytes()), verifying_contract, salt), ), (None, Some(version), Some(chain_id), None, None) => { <(sol_data::FixedBytes<32>, sol_data::Uint<256>)>::encode(&( - keccak256(version.as_bytes()).0, + keccak256(version.as_bytes()), chain_id, )) } @@ -193,19 +188,15 @@ impl Eip712Domain { sol_data::FixedBytes<32>, sol_data::Uint<256>, sol_data::FixedBytes<32>, - )>::encode(&(keccak256(version.as_bytes()).0, chain_id, salt.0)) - } - (None, Some(version), Some(chain_id), Some(verifying_contract), None) => { - <( - sol_data::FixedBytes<32>, - sol_data::Uint<256>, - sol_data::Address, - )>::encode(&( - keccak256(version.as_bytes()).0, - chain_id, - verifying_contract, - )) + )>::encode(&(keccak256(version.as_bytes()), chain_id, salt)) } + (None, Some(version), Some(chain_id), Some(verifying_contract), None) => <( + sol_data::FixedBytes<32>, + sol_data::Uint<256>, + sol_data::Address, + )>::encode( + &(keccak256(version.as_bytes()), chain_id, verifying_contract), + ), (None, Some(version), Some(chain_id), Some(verifying_contract), Some(salt)) => { <( sol_data::FixedBytes<32>, @@ -213,37 +204,37 @@ impl Eip712Domain { sol_data::Address, sol_data::FixedBytes<32>, )>::encode(&( - keccak256(version.as_bytes()).0, + keccak256(version.as_bytes()), chain_id, verifying_contract, - salt.0, + salt, )) } (Some(name), None, None, None, None) => { - <(sol_data::FixedBytes<32>,)>::encode(&(keccak256(name.as_bytes()).0,)) + <(sol_data::FixedBytes<32>,)>::encode(&(keccak256(name.as_bytes()),)) } (Some(name), None, None, None, Some(salt)) => { <(sol_data::FixedBytes<32>, sol_data::FixedBytes<32>)>::encode(&( - keccak256(name.as_bytes()).0, - salt.0, + keccak256(name.as_bytes()), + salt, )) } (Some(name), None, None, Some(verifying_contract), None) => { <(sol_data::FixedBytes<32>, sol_data::Address)>::encode(&( - keccak256(name.as_bytes()).0, + keccak256(name.as_bytes()), verifying_contract, )) } - (Some(name), None, None, Some(verifying_contract), Some(salt)) => <( - sol_data::FixedBytes<32>, - sol_data::Address, - sol_data::FixedBytes<32>, - )>::encode( - &(keccak256(name.as_bytes()).0, verifying_contract, salt.0), - ), + (Some(name), None, None, Some(verifying_contract), Some(salt)) => { + <( + sol_data::FixedBytes<32>, + sol_data::Address, + sol_data::FixedBytes<32>, + )>::encode(&(keccak256(name.as_bytes()), verifying_contract, salt)) + } (Some(name), None, Some(chain_id), None, None) => { <(sol_data::FixedBytes<32>, sol_data::Uint<256>)>::encode(&( - keccak256(name.as_bytes()).0, + keccak256(name.as_bytes()), chain_id, )) } @@ -252,14 +243,14 @@ impl Eip712Domain { sol_data::FixedBytes<32>, sol_data::Uint<256>, sol_data::FixedBytes<32>, - )>::encode(&(keccak256(name.as_bytes()).0, chain_id, salt.0)) + )>::encode(&(keccak256(name.as_bytes()), chain_id, salt)) } (Some(name), None, Some(chain_id), Some(verifying_contract), None) => <( sol_data::FixedBytes<32>, sol_data::Uint<256>, sol_data::Address, )>::encode( - &(keccak256(name.as_bytes()).0, chain_id, verifying_contract), + &(keccak256(name.as_bytes()), chain_id, verifying_contract), ), (Some(name), None, Some(chain_id), Some(verifying_contract), Some(salt)) => { <( @@ -268,16 +259,16 @@ impl Eip712Domain { sol_data::Address, sol_data::FixedBytes<32>, )>::encode(&( - keccak256(name.as_bytes()).0, + keccak256(name.as_bytes()), chain_id, verifying_contract, - salt.0, + salt, )) } (Some(name), Some(version), None, None, None) => { <(sol_data::FixedBytes<32>, sol_data::FixedBytes<32>)>::encode(&( - keccak256(name.as_bytes()).0, - keccak256(version.as_bytes()).0, + keccak256(name.as_bytes()), + keccak256(version.as_bytes()), )) } (Some(name), Some(version), None, None, Some(salt)) => <( @@ -285,9 +276,9 @@ impl Eip712Domain { sol_data::FixedBytes<32>, sol_data::FixedBytes<32>, )>::encode(&( - keccak256(name.as_bytes()).0, - keccak256(version.as_bytes()).0, - salt.0, + keccak256(name.as_bytes()), + keccak256(version.as_bytes()), + salt, )), (Some(name), Some(version), None, Some(verifying_contract), None) => { <( @@ -295,8 +286,8 @@ impl Eip712Domain { sol_data::FixedBytes<32>, sol_data::Address, )>::encode(&( - keccak256(name.as_bytes()).0, - keccak256(version.as_bytes()).0, + keccak256(name.as_bytes()), + keccak256(version.as_bytes()), verifying_contract, )) } @@ -307,10 +298,10 @@ impl Eip712Domain { sol_data::Address, sol_data::FixedBytes<32>, )>::encode(&( - keccak256(name.as_bytes()).0, - keccak256(version.as_bytes()).0, + keccak256(name.as_bytes()), + keccak256(version.as_bytes()), verifying_contract, - salt.0, + salt, )) } (Some(name), Some(version), Some(chain_id), None, None) => <( @@ -318,8 +309,8 @@ impl Eip712Domain { sol_data::FixedBytes<32>, sol_data::Uint<256>, )>::encode(&( - keccak256(name.as_bytes()).0, - keccak256(version.as_bytes()).0, + keccak256(name.as_bytes()), + keccak256(version.as_bytes()), chain_id, )), (Some(name), Some(version), Some(chain_id), None, Some(salt)) => { @@ -329,10 +320,10 @@ impl Eip712Domain { sol_data::Uint<256>, sol_data::FixedBytes<32>, )>::encode(&( - keccak256(name.as_bytes()).0, - keccak256(version.as_bytes()).0, + keccak256(name.as_bytes()), + keccak256(version.as_bytes()), chain_id, - salt.0, + salt, )) } (Some(name), Some(version), Some(chain_id), Some(verifying_contract), None) => { @@ -342,8 +333,8 @@ impl Eip712Domain { sol_data::Uint<256>, sol_data::Address, )>::encode(&( - keccak256(name.as_bytes()).0, - keccak256(version.as_bytes()).0, + keccak256(name.as_bytes()), + keccak256(version.as_bytes()), chain_id, verifying_contract, )) @@ -356,11 +347,11 @@ impl Eip712Domain { sol_data::Address, sol_data::FixedBytes<32>, )>::encode(&( - keccak256(name.as_bytes()).0, - keccak256(version.as_bytes()).0, + keccak256(name.as_bytes()), + keccak256(version.as_bytes()), chain_id, verifying_contract, - salt.0, + salt, )) } } diff --git a/crates/sol-types/src/types/data_type.rs b/crates/sol-types/src/types/data_type.rs index 182bb05e55..f45d055280 100644 --- a/crates/sol-types/src/types/data_type.rs +++ b/crates/sol-types/src/types/data_type.rs @@ -8,7 +8,10 @@ use crate::{token::*, utils, Encodable, Result, SolType, Word}; use alloc::{borrow::Cow, string::String as RustString, vec::Vec}; -use alloy_primitives::{keccak256, Address as RustAddress, Function as RustFunction, I256, U256}; +use alloy_primitives::{ + keccak256, Address as RustAddress, FixedBytes as RustFixedBytes, Function as RustFunction, + I256, U256, +}; use core::{borrow::Borrow, fmt::*, hash::Hash, marker::PhantomData, ops::*}; /// Bool - `bool` @@ -450,7 +453,7 @@ impl SolType for FixedBytes where ByteCount: SupportedFixedBytes, { - type RustType = [u8; N]; + type RustType = RustFixedBytes; type TokenType<'a> = WordToken; #[inline] @@ -480,7 +483,7 @@ where #[inline] fn encode_packed_to(rust: &Self::RustType, out: &mut Vec) { // write only the first n bytes - out.extend_from_slice(rust); + out.extend_from_slice(rust.as_slice()); } } diff --git a/crates/sol-types/tests/doctests/events.rs b/crates/sol-types/tests/doctests/events.rs index a6cf840a93..9dbc785aea 100644 --- a/crates/sol-types/tests/doctests/events.rs +++ b/crates/sol-types/tests/doctests/events.rs @@ -28,7 +28,7 @@ fn event() { assert_event_signature::("MyEvent(bytes32,uint256,string,bytes)"); assert!(!MyEvent::ANONYMOUS); let event = MyEvent { - a: [0x11; 32], + a: [0x11; 32].into(), b: U256::from(1u64), c: keccak256("Hello World").into(), d: Vec::new(), diff --git a/crates/sol-types/tests/doctests/types.rs b/crates/sol-types/tests/doctests/types.rs index 610d07f856..47c098fd93 100644 --- a/crates/sol-types/tests/doctests/types.rs +++ b/crates/sol-types/tests/doctests/types.rs @@ -17,7 +17,7 @@ type SolTuple = sol! { tuple(address, bytes, string) }; #[test] fn types() { let _ = ::encode_single(&true); - let _ = B32::encode_single(&[0; 32]); + let _ = B32::encode_single(&[0; 32].into()); let _ = SolArrayOf::::encode_single(&vec![true, false]); let _ = SolTuple::encode_single(&(Address::ZERO, vec![0; 32], "hello".to_string())); } diff --git a/crates/sol-types/tests/sol.rs b/crates/sol-types/tests/sol.rs index 4f80d56dca..67d77cfd43 100644 --- a/crates/sol-types/tests/sol.rs +++ b/crates/sol-types/tests/sol.rs @@ -41,18 +41,18 @@ fn e2e() { let a = MyStruct { a: U256::from(1), - b: [0; 32], + b: [0; 32].into(), c: Vec::new(), }; - MyTuple::hex_encode(&(a.clone(), [0; 32])); + MyTuple::hex_encode(&(a.clone(), [0; 32].into())); MyStruct::hex_encode(&a); LateBinding::::hex_encode(&(vec![a.clone(), a.clone()], Address::default())); MyStruct2::hex_encode(&MyStruct2 { a, - b: [0; 32], + b: [0; 32].into(), c: vec![], }); @@ -202,14 +202,14 @@ fn getters() { assert_eq!(data1Call::SIGNATURE, "data1(uint256,bool,uint256)"); let _ = data1Return { _0: U256::ZERO, - _1: [0, 0, 0], + _1: [0, 0, 0].into(), _2: vec![], }; assert_eq!(data2Call::SIGNATURE, "data2(uint256,bool)"); let _ = data2Return { _0: U256::ZERO, - _1: [0, 0, 0], + _1: [0, 0, 0].into(), _2: vec![], };