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 bytes in encode method args not properly handled #138

Merged
merged 2 commits into from
Nov 20, 2024
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 services/construction/contract_call_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ func encodeMethodArgsStrings(methodID []byte, methodSig string, methodArgs []str
{
// No fixed size set as it would make it an "array" instead
// of a "slice" when encoding. We want it to be a slice.
value := []byte{}
bytes, err := hexutil.Decode(methodArgs[i])
if err != nil {
log.Fatal(err)
}
value := make([]byte, len(bytes))
copy(value[:], bytes) // nolint:gocritic
argData = value
}
Expand Down
6 changes: 6 additions & 0 deletions services/construction/contract_call_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func TestConstruction_ContractCallData(t *testing.T) {
methodArgs: []interface{}{"[\"0x000000000000000000000000911a81c0a2cd632fd4c45461541bf8973d11870a\",\"0x0000000000000000000000006ecb18183838265968039955f1e8829480db5329\",\"0x0000000000000000000000000bfc799df7e440b7c88cc2454f12c58f8a29d986\"]", "0"},
expectedResponse: "0x3ffba36f000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000911a81c0a2cd632fd4c45461541bf8973d11870a00000000000000000000000000000000000000000000000000000000000000200000000000000000000000006ecb18183838265968039955f1e8829480db532900000000000000000000000000000000000000000000000000000000000000200000000000000000000000000bfc799df7e440b7c88cc2454f12c58f8a29d986",
},
// https://sepolia.basescan.org/tx/0x9c6854169cccd609225bec508ca11ec0fe84620493488b54d638e54350422b79
"happy path: address and bytes": {
methodSig: "createRecoverySigner(address,address,bytes)",
methodArgs: []string{"0x4e7E5249d2Cb9255367C716e1452752A1390e44A", "0x2149ada7A6B036c0C5215A88921856D9974D810C", "0x9ba55864842d7142d780c93c0112994ba08ce5fed82d574ec864eb0f16fb6b767b69030cec56ec2662e483ae6fbddf1f4d233b9dad4bb4190d9178fc1cdfaa951c"},
expectedResponse: "0x25cb56700000000000000000000000004e7e5249d2cb9255367c716e1452752a1390e44a0000000000000000000000002149ada7a6b036c0c5215a88921856d9974d810c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000419ba55864842d7142d780c93c0112994ba08ce5fed82d574ec864eb0f16fb6b767b69030cec56ec2662e483ae6fbddf1f4d233b9dad4bb4190d9178fc1cdfaa951c00000000000000000000000000000000000000000000000000000000000000",
},
"happy path: method sig is NO-METHOD-SIG and args is a list of interface": {
methodSig: NoMethodSig,
methodArgs: []interface{}{"0xaabbcc112233"},
Expand Down
Loading