Skip to content

Commit

Permalink
fix(sol-macro): correct SolCall::abi_decode_returns (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes authored Oct 12, 2023
1 parent 8b33e7f commit bc34424
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/sol-macro/src/expand/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub(super) fn expand(cx: &ExpCtxt<'_>, function: &ItemFunction) -> Result<TokenS
}

fn abi_decode_returns(data: &[u8], validate: bool) -> ::alloy_sol_types::Result<Self::Return> {
<Self::ReturnTuple<'_> as ::alloy_sol_types::SolType>::abi_decode(data, validate).map(Into::into)
<Self::ReturnTuple<'_> as ::alloy_sol_types::SolType>::abi_decode_sequence(data, validate).map(Into::into)
}
}
};
Expand Down
47 changes: 46 additions & 1 deletion crates/sol-types/tests/sol.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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! {
Expand Down

0 comments on commit bc34424

Please sign in to comment.