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 (
24
24
"reflect"
25
25
26
26
"github.com/ethereum/go-ethereum/common"
27
+ "github.com/ethereum/go-ethereum/common/math"
27
28
"github.com/ethereum/go-ethereum/crypto"
28
29
)
29
30
@@ -41,8 +42,7 @@ func MakeTopics(query ...[]interface{}) ([][]common.Hash, error) {
41
42
case common.Address :
42
43
copy (topic [common .HashLength - common .AddressLength :], rule [:])
43
44
case * big.Int :
44
- blob := rule .Bytes ()
45
- copy (topic [common .HashLength - len (blob ):], blob )
45
+ copy (topic [:], math .U256Bytes (rule ))
46
46
case bool :
47
47
if rule {
48
48
topic [common .HashLength - 1 ] = 1
Original file line number Diff line number Diff line change 17
17
package abi
18
18
19
19
import (
20
+ "math"
20
21
"math/big"
21
22
"reflect"
22
23
"testing"
@@ -55,9 +56,27 @@ func TestMakeTopics(t *testing.T) {
55
56
false ,
56
57
},
57
58
{
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
+ },
61
80
false ,
62
81
},
63
82
{
You can’t perform that action at this time.
0 commit comments