Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pkieltyka committed Dec 19, 2024
1 parent da88ddf commit 3d537bd
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
8 changes: 7 additions & 1 deletion ethcoder/abi_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,14 @@ func ABIUnmarshalStringValues(argTypes []string, stringValues []string) ([]any,
return nil, fmt.Errorf("ethcoder: value at position %d is invalid. invalid number type '%s'", i, typ)
}

base := 10
if strings.HasPrefix(s, "0x") {
base = 16
s = s[2:]
}

num := big.NewInt(0)
num, ok := num.SetString(s, 10)
num, ok := num.SetString(s, base)
if !ok {
return nil, fmt.Errorf("ethcoder: value at position %d is invalid. expecting number. unable to set value of '%s'", i, s)
}
Expand Down
28 changes: 28 additions & 0 deletions ethcoder/abi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ func TestABIUnmarshalStringValuesAny(t *testing.T) {
assert.Equal(t, int64(2), v2.Int64())
}

{
values, err := ABIUnmarshalStringValuesAny([]string{"address", "uint256"}, []any{"0x6615e4e985bf0d137196897dfa182dbd7127f54f", "0x123456"})
assert.NoError(t, err)
assert.Len(t, values, 2)

v1, ok := values[0].(common.Address)
assert.True(t, ok)
assert.Equal(t, "0x6615e4e985BF0D137196897Dfa182dBD7127f54f", v1.String())

v2, ok := values[1].(*big.Int)
assert.True(t, ok)
assert.Equal(t, int64(1193046), v2.Int64())
}

{
values, err := ABIUnmarshalStringValuesAny([]string{"address", "bytes8"}, []any{"0x6615e4e985bf0d137196897dfa182dbd7127f54f", "0xaabbccddaabbccdd"})
assert.NoError(t, err)
Expand Down Expand Up @@ -360,6 +374,20 @@ func TestABIUnmarshalStringValues(t *testing.T) {
assert.Equal(t, int64(2), v2.Int64())
}

{
values, err := ABIUnmarshalStringValues([]string{"address", "uint256"}, []string{"0x6615e4e985bf0d137196897dfa182dbd7127f54f", "0x123456"})
assert.NoError(t, err)
assert.Len(t, values, 2)

v1, ok := values[0].(common.Address)
assert.True(t, ok)
assert.Equal(t, "0x6615e4e985BF0D137196897Dfa182dBD7127f54f", v1.String())

v2, ok := values[1].(*big.Int)
assert.True(t, ok)
assert.Equal(t, int64(1193046), v2.Int64())
}

{
values, err := ABIUnmarshalStringValues([]string{"address", "bytes8"}, []string{"0x6615e4e985bf0d137196897dfa182dbd7127f54f", "0xaabbccddaabbccdd"})
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion ethcoder/typed_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func TestTypedDataFromJSONPart5(t *testing.T) {
},
"message": {
"message": "Test message",
"value": "0x634abebe1d4da48b00000000000000000cde63753dad4f0f42f79ebef71ee924,
"value": "0x634abebe1d4da48b00000000000000000cde63753dad4f0f42f79ebef71ee924",
"from": "0xc0ffee254729296a45a3885639AC7E10F9d54979",
"to": "0xc0ffee254729296a45a3885639AC7E10F9d54979"
}
Expand Down

0 comments on commit 3d537bd

Please sign in to comment.