Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sol-macro): correct SolCall::abi_decode_returns #367

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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