feat(codec): impl codec for Bytes (#856)
This commit is contained in:
parent
dc1565c014
commit
8c07861b09
|
@ -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>() {}
|
||||
|
@ -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>();
|
||||
}
|
||||
|
|
|
@ -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<u8>,
|
||||
Bytes,
|
||||
Address,
|
||||
bool,
|
||||
String,
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue