Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat(codec): impl codec for Bytes #856

Merged
merged 1 commit into from
Feb 2, 2022
Merged
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
14 changes: 13 additions & 1 deletion ethers-contract/tests/common/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use ethers_contract::{
};
use ethers_core::{
abi::{AbiDecode, AbiEncode, RawLog, Tokenizable},
types::{Address, H160, H256, I256, U128, U256},
types::{Address, Bytes, H160, H256, I256, U128, U256},
};

fn assert_tokenizeable<T: Tokenizable>() {}
Expand Down Expand Up @@ -560,3 +560,15 @@ fn can_derive_abi_codec_two_field() {

assert_eq!(decoded_wrapped, tuple);
}

#[test]
fn can_derive_ethcall_for_bytes() {
#[derive(Clone, Debug, Default, Eq, PartialEq, EthCall, EthDisplay)]
#[ethcall(name = "batch", abi = "batch(bytes[],bool)")]
pub struct BatchCall {
pub calls: Vec<Bytes>,
pub revert_on_fail: bool,
}

assert_ethcall::<BatchCall>();
}
10 changes: 9 additions & 1 deletion ethers-core/src/abi/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
abi::{
AbiArrayType, AbiError, AbiType, Detokenize, Token, Tokenizable, TokenizableItem, Tokenize,
},
types::{Address, H256, U128, U256},
types::{Address, Bytes, H256, U128, U256},
};

/// Trait for ABI encoding
Expand Down Expand Up @@ -40,6 +40,7 @@ macro_rules! impl_abi_codec {

impl_abi_codec!(
Vec<u8>,
Bytes,
Address,
bool,
String,
Expand Down Expand Up @@ -228,4 +229,11 @@ mod tests {
.collect::<String>()
};
}

#[test]
fn bytes_codec() {
let bytes: Bytes = std::iter::repeat_with(random::<u8>).take(10).collect::<Vec<_>>().into();
let v = vec![bytes];
assert_codec(v);
}
}