Skip to content

Commit

Permalink
Fix bytes in encode method args not properly handled (#138)
Browse files Browse the repository at this point in the history
* Update contract_call_data_test.go

* Update contract_call_data.go
  • Loading branch information
sidt-cb authored Nov 20, 2024
1 parent bd67e53 commit dc39758
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

0 comments on commit dc39758

Please sign in to comment.