From 8c07861b0937ebb68f258ff6fc532c46f5d27fd5 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 2 Feb 2022 12:57:39 +0100 Subject: [PATCH] feat(codec): impl codec for Bytes (#856) --- ethers-contract/tests/common/derive.rs | 14 +++++++++++++- ethers-core/src/abi/codec.rs | 10 +++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ethers-contract/tests/common/derive.rs b/ethers-contract/tests/common/derive.rs index 58c0aa83..a18879d3 100644 --- a/ethers-contract/tests/common/derive.rs +++ b/ethers-contract/tests/common/derive.rs @@ -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() {} @@ -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, + pub revert_on_fail: bool, + } + + assert_ethcall::(); +} diff --git a/ethers-core/src/abi/codec.rs b/ethers-core/src/abi/codec.rs index f4de400c..fef30f18 100644 --- a/ethers-core/src/abi/codec.rs +++ b/ethers-core/src/abi/codec.rs @@ -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 @@ -40,6 +40,7 @@ macro_rules! impl_abi_codec { impl_abi_codec!( Vec, + Bytes, Address, bool, String, @@ -228,4 +229,11 @@ mod tests { .collect::() }; } + + #[test] + fn bytes_codec() { + let bytes: Bytes = std::iter::repeat_with(random::).take(10).collect::>().into(); + let v = vec![bytes]; + assert_codec(v); + } }