Skip to content

Commit 3d537bd

Browse files
committed
wip
1 parent da88ddf commit 3d537bd

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

ethcoder/abi_helpers.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,14 @@ func ABIUnmarshalStringValues(argTypes []string, stringValues []string) ([]any,
414414
return nil, fmt.Errorf("ethcoder: value at position %d is invalid. invalid number type '%s'", i, typ)
415415
}
416416

417+
base := 10
418+
if strings.HasPrefix(s, "0x") {
419+
base = 16
420+
s = s[2:]
421+
}
422+
417423
num := big.NewInt(0)
418-
num, ok := num.SetString(s, 10)
424+
num, ok := num.SetString(s, base)
419425
if !ok {
420426
return nil, fmt.Errorf("ethcoder: value at position %d is invalid. expecting number. unable to set value of '%s'", i, s)
421427
}

ethcoder/abi_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ func TestABIUnmarshalStringValuesAny(t *testing.T) {
226226
assert.Equal(t, int64(2), v2.Int64())
227227
}
228228

229+
{
230+
values, err := ABIUnmarshalStringValuesAny([]string{"address", "uint256"}, []any{"0x6615e4e985bf0d137196897dfa182dbd7127f54f", "0x123456"})
231+
assert.NoError(t, err)
232+
assert.Len(t, values, 2)
233+
234+
v1, ok := values[0].(common.Address)
235+
assert.True(t, ok)
236+
assert.Equal(t, "0x6615e4e985BF0D137196897Dfa182dBD7127f54f", v1.String())
237+
238+
v2, ok := values[1].(*big.Int)
239+
assert.True(t, ok)
240+
assert.Equal(t, int64(1193046), v2.Int64())
241+
}
242+
229243
{
230244
values, err := ABIUnmarshalStringValuesAny([]string{"address", "bytes8"}, []any{"0x6615e4e985bf0d137196897dfa182dbd7127f54f", "0xaabbccddaabbccdd"})
231245
assert.NoError(t, err)
@@ -360,6 +374,20 @@ func TestABIUnmarshalStringValues(t *testing.T) {
360374
assert.Equal(t, int64(2), v2.Int64())
361375
}
362376

377+
{
378+
values, err := ABIUnmarshalStringValues([]string{"address", "uint256"}, []string{"0x6615e4e985bf0d137196897dfa182dbd7127f54f", "0x123456"})
379+
assert.NoError(t, err)
380+
assert.Len(t, values, 2)
381+
382+
v1, ok := values[0].(common.Address)
383+
assert.True(t, ok)
384+
assert.Equal(t, "0x6615e4e985BF0D137196897Dfa182dBD7127f54f", v1.String())
385+
386+
v2, ok := values[1].(*big.Int)
387+
assert.True(t, ok)
388+
assert.Equal(t, int64(1193046), v2.Int64())
389+
}
390+
363391
{
364392
values, err := ABIUnmarshalStringValues([]string{"address", "bytes8"}, []string{"0x6615e4e985bf0d137196897dfa182dbd7127f54f", "0xaabbccddaabbccdd"})
365393
assert.NoError(t, err)

ethcoder/typed_data_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func TestTypedDataFromJSONPart5(t *testing.T) {
443443
},
444444
"message": {
445445
"message": "Test message",
446-
"value": "0x634abebe1d4da48b00000000000000000cde63753dad4f0f42f79ebef71ee924,
446+
"value": "0x634abebe1d4da48b00000000000000000cde63753dad4f0f42f79ebef71ee924",
447447
"from": "0xc0ffee254729296a45a3885639AC7E10F9d54979",
448448
"to": "0xc0ffee254729296a45a3885639AC7E10F9d54979"
449449
}

0 commit comments

Comments
 (0)