Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alloy 0.8.3 #163

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 54 additions & 51 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ repository = "https://github.com/OffchainLabs/stylus-sdk-rs"
rust-version = "1.71.0"

[workspace.dependencies]
alloy-primitives = { version = "=0.7.7", default-features = false , features = ["native-keccak"] }
alloy-sol-types = { version = "=0.7.7", default-features = false }
alloy-primitives = { version = "=0.8.3", default-features = false , features = ["native-keccak"] }
alloy-sol-types = { version = "=0.8.3", default-features = false }
cfg-if = "1.0.0"
derivative = { version = "2.2.0", features = ["use_core"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
Expand Down
88 changes: 88 additions & 0 deletions stylus-sdk/src/abi/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,91 @@ impl AbiType for Bytes {

const EXPORT_ABI_RET: ConstString = Self::ABI.concat(ConstString::new(" memory"));
}

#[cfg(test)]
mod tests {
use alloy_primitives::hex;

use super::*;
use crate::abi;

#[test]
fn bytes_sol_type() {
assert_eq!(Bytes::ABI.as_str(), "bytes");
assert_eq!(Bytes::EXPORT_ABI_ARG.as_str(), "bytes calldata");
assert_eq!(Bytes::EXPORT_ABI_RET.as_str(), "bytes memory");
}

#[test]
fn bytes_abi() {
assert_eq!(Bytes::SOL_NAME, "bytes");
assert_eq!(Bytes::ENCODED_SIZE, None);
assert!(Bytes::DYNAMIC);
assert_eq!(
<Bytes as SolType>::abi_encoded_size(&Bytes(vec![1, 2, 3, 4])),
64
);
}

#[test]
fn encode_decode_empty_bytes() {
abi::test_encode_decode_params(
(Bytes(vec![]),),
hex!(
"0000000000000000000000000000000000000000000000000000000000000020"
"0000000000000000000000000000000000000000000000000000000000000000"
),
);
}

#[test]
fn encode_decode_one_byte() {
abi::test_encode_decode_params(
(Bytes(vec![100]),),
hex!(
"0000000000000000000000000000000000000000000000000000000000000020"
"0000000000000000000000000000000000000000000000000000000000000001"
"6400000000000000000000000000000000000000000000000000000000000000"
),
);
}

#[test]
fn encode_decode_several_bytes() {
let mut input = Vec::with_capacity(40);
input.extend([1, 2, 3, 4]);
input.extend([0u8; 32]);
input.extend([5, 6, 7, 8]);
let value = (Bytes(input),);
let encoded = hex!(
"0000000000000000000000000000000000000000000000000000000000000020"
"0000000000000000000000000000000000000000000000000000000000000028"
"0102030400000000000000000000000000000000000000000000000000000000"
"0000000005060708000000000000000000000000000000000000000000000000"
);
abi::test_encode_decode_params(value, encoded);
}

#[test]
fn encode_decode_bytes_tuple() {
let mut input = Vec::with_capacity(40);
input.extend([1, 2, 3, 4]);
input.extend([0u8; 32]);
input.extend([5, 6, 7, 8]);
let value = (Bytes(input), Bytes(vec![]), Bytes(vec![1, 2, 3, 4]));

let encoded = hex!(
"0000000000000000000000000000000000000000000000000000000000000060"
"00000000000000000000000000000000000000000000000000000000000000C0"
"00000000000000000000000000000000000000000000000000000000000000E0"
"0000000000000000000000000000000000000000000000000000000000000028"
"0102030400000000000000000000000000000000000000000000000000000000"
"0000000005060708000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000000"
"0000000000000000000000000000000000000000000000000000000000000004"
"0102030400000000000000000000000000000000000000000000000000000000"
);

abi::test_encode_decode_params(value, encoded)
}
}
18 changes: 14 additions & 4 deletions stylus-sdk/src/abi/const_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,19 @@ impl Debug for ConstString {
}
}

#[test]
fn test_from_decimal() {
for i in (0..=100).chain(1000..=1001) {
assert_eq!(ConstString::from_decimal_number(i).as_str(), i.to_string());
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_from_decimal() {
for i in (0..=100).chain(1000..=1001) {
assert_eq!(ConstString::from_decimal_number(i).as_str(), i.to_string());
}
}

#[test]
fn test_concat() {
assert_eq!(ConstString::new("foo").concat(ConstString::new("bar")).as_str(), "foobar");
}
}
Loading
Loading