feat(codec): impl codec for Bytes (#856)

This commit is contained in:
Matthias Seitz 2022-02-02 12:57:39 +01:00 committed by GitHub
parent dc1565c014
commit 8c07861b09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -3,7 +3,7 @@ use ethers_contract::{
}; };
use ethers_core::{ use ethers_core::{
abi::{AbiDecode, AbiEncode, RawLog, Tokenizable}, 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>() {} fn assert_tokenizeable<T: Tokenizable>() {}
@ -560,3 +560,15 @@ fn can_derive_abi_codec_two_field() {
assert_eq!(decoded_wrapped, tuple); 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>();
}

View File

@ -2,7 +2,7 @@ use crate::{
abi::{ abi::{
AbiArrayType, AbiError, AbiType, Detokenize, Token, Tokenizable, TokenizableItem, Tokenize, AbiArrayType, AbiError, AbiType, Detokenize, Token, Tokenizable, TokenizableItem, Tokenize,
}, },
types::{Address, H256, U128, U256}, types::{Address, Bytes, H256, U128, U256},
}; };
/// Trait for ABI encoding /// Trait for ABI encoding
@ -40,6 +40,7 @@ macro_rules! impl_abi_codec {
impl_abi_codec!( impl_abi_codec!(
Vec<u8>, Vec<u8>,
Bytes,
Address, Address,
bool, bool,
String, String,
@ -228,4 +229,11 @@ mod tests {
.collect::<String>() .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);
}
} }