Skip to content

Commit

Permalink
feat: Bytes maps to Bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
rachel-bousfield committed Feb 29, 2024
1 parent 761c296 commit 3d080d0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/sol-macro/src/expand/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub(crate) fn rec_expand_rust_type(ty: &Type, crates: &ExternCrates, tokens: &mu
Type::Address(span, _) => quote_spanned! {span=> #alloy_sol_types::private::Address },
Type::Bool(span) => return Ident::new("bool", span).to_tokens(tokens),
Type::String(span) => quote_spanned! {span=> #alloy_sol_types::private::String },
Type::Bytes(span) => quote_spanned! {span=> #alloy_sol_types::private::Vec<u8> },
Type::Bytes(span) => quote_spanned! {span=> #alloy_sol_types::private::Bytes },

Type::FixedBytes(span, size) => {
assert!(size.get() <= 32);
Expand Down
10 changes: 5 additions & 5 deletions crates/sol-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ mod json;
/// ```ignore
#[cfg_attr(doc, doc = include_str!("../doctests/structs.rs"))]
/// ```
///
///
/// ### UDVT and type aliases
///
/// User defined value types (UDVT) generate a tuple struct with the type as
Expand All @@ -159,7 +159,7 @@ mod json;
/// ```ignore
#[cfg_attr(doc, doc = include_str!("../doctests/types.rs"))]
/// ```
///
///
/// ### State variables
///
/// Public and external state variables will generate a getter function just like in Solidity.
Expand All @@ -182,7 +182,7 @@ mod json;
/// ```ignore
#[cfg_attr(doc, doc = include_str!("../doctests/function_like.rs"))]
/// ```
///
///
/// ### Events
///
/// Events generate a struct that implements `SolEvent`.
Expand All @@ -194,7 +194,7 @@ mod json;
/// ```ignore
#[cfg_attr(doc, doc = include_str!("../doctests/events.rs"))]
/// ```
///
///
/// ### Contracts/interfaces
///
/// Contracts generate a module with the same name, which contains all the items.
Expand All @@ -206,7 +206,7 @@ mod json;
/// ```ignore
#[cfg_attr(doc, doc = include_str!("../doctests/contracts.rs"))]
/// ```
///
///
/// ## JSON ABI
///
/// Contracts can also be generated from ABI JSON strings and files, similar to
Expand Down
6 changes: 3 additions & 3 deletions crates/sol-types/src/abi/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ mod tests {

let ty = Ty {
arr: [[0x11u8; 32].into(), [0x22u8; 32].into(), [0x33u8; 32].into()],
r#dyn: vec![0x44u8; 4],
r#dyn: vec![0x44u8; 4].into(),
};
let encoded = hex!(
"0000000000000000000000000000000000000000000000000000000000000020"
Expand Down Expand Up @@ -757,8 +757,8 @@ mod tests {
}

let ty = Ty {
arr: [vec![0x11u8; 32], vec![0x22u8; 32], vec![0x33u8; 32]],
r#dyn: vec![0x44u8; 4],
arr: [vec![0x11u8; 32].into(), vec![0x22u8; 32].into(), vec![0x33u8; 32].into()],
r#dyn: vec![0x44u8; 4].into(),
};
let encoded = hex!(
"0000000000000000000000000000000000000000000000000000000000000020" // struct offset
Expand Down
8 changes: 4 additions & 4 deletions crates/sol-types/src/types/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use crate::{abi::token::*, private::SolTypeValue, utils, SolType, Word};
use alloc::{string::String as RustString, vec::Vec};
use alloy_primitives::{
keccak256, Address as RustAddress, FixedBytes as RustFixedBytes, Function as RustFunction,
I256, U256,
keccak256, Address as RustAddress, Bytes as RustBytes, FixedBytes as RustFixedBytes,
Function as RustFunction, I256, U256,
};
use core::{borrow::Borrow, fmt::*, hash::Hash, marker::PhantomData, ops::*};

Expand Down Expand Up @@ -309,7 +309,7 @@ impl<T: ?Sized + AsRef<[u8]>> SolTypeValue<Bytes> for T {
}

impl SolType for Bytes {
type RustType = Vec<u8>;
type RustType = RustBytes;
type Token<'a> = PackedSeqToken<'a>;

const SOL_NAME: &'static str = "bytes";
Expand All @@ -322,7 +322,7 @@ impl SolType for Bytes {

#[inline]
fn detokenize(token: Self::Token<'_>) -> Self::RustType {
token.into_vec()
token.into_vec().into()
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/sol-types/tests/doctests/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::assertions_on_constants)]

use alloy_primitives::{hex, keccak256, B256, U256};
use alloy_primitives::{hex, keccak256, Bytes, B256, U256};
use alloy_sol_types::{abi::token::WordToken, sol, SolEvent};

sol! {
Expand Down Expand Up @@ -30,7 +30,7 @@ fn event() {
a: [0x11; 32].into(),
b: U256::from(1u64),
c: keccak256("Hello World"),
d: Vec::new(),
d: Bytes::default(),
};
// topics are `(SELECTOR, a, keccak256(c))`
assert_eq!(
Expand Down
12 changes: 6 additions & 6 deletions crates/sol-types/tests/macros/sol/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use alloy_primitives::{b256, hex, keccak256, Address, I256, U256};
use alloy_primitives::{b256, hex, keccak256, Address, Bytes, I256, U256};
use alloy_sol_types::{sol, SolCall, SolError, SolEvent, SolStruct, SolType};
use serde::Serialize;
use serde_json::Value;
Expand Down Expand Up @@ -93,7 +93,7 @@ fn function() {
let call = someFunctionCall {
basic: U256::from(1),
string_: "Hello World".to_owned(),
longBytes: vec![0; 36],
longBytes: vec![0; 36].into(),
array: vec![Address::ZERO, Address::ZERO, Address::ZERO],
fixedArray: [true, false],
struct_: CustomStruct { a: Address::ZERO, b: 2 },
Expand Down Expand Up @@ -226,10 +226,10 @@ fn getters() {
}

assert_eq!(data1Call::SIGNATURE, "data1(uint256,bool,uint256)");
let _ = data1Return { _0: U256::ZERO, _1: [0, 0, 0].into(), _2: vec![] };
let _ = data1Return { _0: U256::ZERO, _1: [0, 0, 0].into(), _2: Bytes::default() };

assert_eq!(data2Call::SIGNATURE, "data2(uint256,bool)");
let _ = data2Return { _0: U256::ZERO, _1: [0, 0, 0].into(), _2: vec![] };
let _ = data2Return { _0: U256::ZERO, _1: [0, 0, 0].into(), _2: Bytes::default() };

assert_eq!(
nestedMapArrayCall::SIGNATURE,
Expand Down Expand Up @@ -413,8 +413,8 @@ fn nested_items() {
}
use nested::{InterfaceTest::*, *};

let _ = FilAddress { data: vec![] };
let _ = BigInt { val: vec![], neg: false };
let _ = FilAddress { data: Bytes::default() };
let _ = BigInt { val: Bytes::default(), neg: false };
assert_eq!(f1Call::SIGNATURE, "f1((bytes),uint256)");
assert_eq!(f2Call::SIGNATURE, "f2((bytes,bool))");
}
Expand Down

0 comments on commit 3d080d0

Please sign in to comment.