File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed
Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import (
2424 "reflect"
2525
2626 "github.com/ethereum/go-ethereum/common"
27+ "github.com/ethereum/go-ethereum/common/math"
2728 "github.com/ethereum/go-ethereum/crypto"
2829)
2930
@@ -41,8 +42,7 @@ func MakeTopics(query ...[]interface{}) ([][]common.Hash, error) {
4142 case common.Address :
4243 copy (topic [common .HashLength - common .AddressLength :], rule [:])
4344 case * big.Int :
44- blob := rule .Bytes ()
45- copy (topic [common .HashLength - len (blob ):], blob )
45+ copy (topic [:], math .U256Bytes (rule ))
4646 case bool :
4747 if rule {
4848 topic [common .HashLength - 1 ] = 1
Original file line number Diff line number Diff line change 1717package abi
1818
1919import (
20+ "math"
2021 "math/big"
2122 "reflect"
2223 "testing"
@@ -55,9 +56,27 @@ func TestMakeTopics(t *testing.T) {
5556 false ,
5657 },
5758 {
58- "support *big.Int types in topics" ,
59- args {[][]interface {}{{big .NewInt (1 ).Lsh (big .NewInt (2 ), 254 )}}},
60- [][]common.Hash {{common.Hash {128 }}},
59+ "support positive *big.Int types in topics" ,
60+ args {[][]interface {}{
61+ {big .NewInt (1 )},
62+ {big .NewInt (1 ).Lsh (big .NewInt (2 ), 254 )},
63+ }},
64+ [][]common.Hash {
65+ {common .HexToHash ("0000000000000000000000000000000000000000000000000000000000000001" )},
66+ {common.Hash {128 }},
67+ },
68+ false ,
69+ },
70+ {
71+ "support negative *big.Int types in topics" ,
72+ args {[][]interface {}{
73+ {big .NewInt (- 1 )},
74+ {big .NewInt (math .MinInt64 )},
75+ }},
76+ [][]common.Hash {
77+ {common .MaxHash },
78+ {common .HexToHash ("ffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000" )},
79+ },
6180 false ,
6281 },
6382 {
You can’t perform that action at this time.
0 commit comments