From bc34424a5e3c7eebc3a1911a950a2b05df349097 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:34:05 +0200 Subject: [PATCH] fix(sol-macro): correct `SolCall::abi_decode_returns` (#367) --- crates/sol-macro/src/expand/function.rs | 2 +- crates/sol-types/tests/sol.rs | 47 ++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/crates/sol-macro/src/expand/function.rs b/crates/sol-macro/src/expand/function.rs index 3523b894e..8f275c2b4 100644 --- a/crates/sol-macro/src/expand/function.rs +++ b/crates/sol-macro/src/expand/function.rs @@ -125,7 +125,7 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, function: &ItemFunction) -> Result ::alloy_sol_types::Result { - as ::alloy_sol_types::SolType>::abi_decode(data, validate).map(Into::into) + as ::alloy_sol_types::SolType>::abi_decode_sequence(data, validate).map(Into::into) } } }; diff --git a/crates/sol-types/tests/sol.rs b/crates/sol-types/tests/sol.rs index 379ea8dd5..29f16f62a 100644 --- a/crates/sol-types/tests/sol.rs +++ b/crates/sol-types/tests/sol.rs @@ -1,4 +1,4 @@ -use alloy_primitives::{keccak256, Address, B256, I256, U256}; +use alloy_primitives::{hex, keccak256, Address, B256, I256, U256}; use alloy_sol_types::{eip712_domain, sol, SolCall, SolError, SolStruct, SolType}; use serde::Serialize; use serde_json::Value; @@ -130,6 +130,51 @@ fn function() { ); } +#[test] +fn function_returns() { + sol! { + #[derive(Debug, PartialEq)] + function test() returns (uint256[]); + } + assert_eq!( + testCall::abi_decode_returns( + &hex!( + "0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000000" + ), + true, + ), + Ok(testReturn { _0: vec![] }) + ); + assert_eq!( + testCall::abi_decode_returns( + &hex!( + "0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000001 + 0000000000000000000000000000000000000000000000000000000000000002" + ), + true, + ), + Ok(testReturn { + _0: vec![U256::from(2)] + }) + ); + assert_eq!( + testCall::abi_decode_returns( + &hex!( + "0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000000000000000000000000000000000000000000042 + 0000000000000000000000000000000000000000000000000000000000000069" + ), + true, + ), + Ok(testReturn { + _0: vec![U256::from(0x42), U256::from(0x69)] + }) + ); +} + #[test] fn error() { sol! {