Skip to content

Commit a95417f

Browse files
accounts/abi/bind: added test cases for negative ints in topics
1 parent f070287 commit a95417f

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

accounts/abi/bind/topics_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/ethereum/go-ethereum/accounts/abi"
2525
"github.com/ethereum/go-ethereum/common"
26+
"github.com/ethereum/go-ethereum/crypto"
2627
)
2728

2829
func TestMakeTopics(t *testing.T) {
@@ -41,6 +42,80 @@ func TestMakeTopics(t *testing.T) {
4142
[][]common.Hash{{common.Hash{1, 2, 3, 4, 5}}},
4243
false,
4344
},
45+
{
46+
"support common hash types in topics",
47+
args{[][]interface{}{{common.Hash{1, 2, 3, 4, 5}}}},
48+
[][]common.Hash{{common.Hash{1, 2, 3, 4, 5}}},
49+
false,
50+
},
51+
{
52+
"support address types in topics",
53+
args{[][]interface{}{{common.Address{1, 2, 3, 4, 5}}}},
54+
[][]common.Hash{{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5}}},
55+
false,
56+
},
57+
{
58+
"support *big.Int types in topics",
59+
args{[][]interface{}{{big.NewInt(1).Lsh(big.NewInt(2), 254)}}},
60+
[][]common.Hash{{common.Hash{128}}},
61+
false,
62+
},
63+
{
64+
"support boolean types in topics",
65+
args{[][]interface{}{
66+
{true},
67+
{false},
68+
}},
69+
[][]common.Hash{
70+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}},
71+
{common.Hash{0}},
72+
},
73+
false,
74+
},
75+
{
76+
"support int/uint(8/16/32/64) types in topics",
77+
args{[][]interface{}{
78+
{int8(-2)},
79+
{int16(-3)},
80+
{int32(-4)},
81+
{int64(-5)},
82+
{int8(1)},
83+
{int16(256)},
84+
{int32(65536)},
85+
{int64(4294967296)},
86+
{uint8(1)},
87+
{uint16(256)},
88+
{uint32(65536)},
89+
{uint64(4294967296)},
90+
}},
91+
[][]common.Hash{
92+
{common.Hash{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254}},
93+
{common.Hash{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253}},
94+
{common.Hash{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 252}},
95+
{common.Hash{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 251}},
96+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}},
97+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}},
98+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}},
99+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}},
100+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}},
101+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}},
102+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0}},
103+
{common.Hash{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0}},
104+
},
105+
false,
106+
},
107+
{
108+
"support string types in topics",
109+
args{[][]interface{}{{"hello world"}}},
110+
[][]common.Hash{{crypto.Keccak256Hash([]byte("hello world"))}},
111+
false,
112+
},
113+
{
114+
"support byte slice types in topics",
115+
args{[][]interface{}{{[]byte{1, 2, 3}}}},
116+
[][]common.Hash{{crypto.Keccak256Hash([]byte{1, 2, 3})}},
117+
false,
118+
},
44119
}
45120
for _, tt := range tests {
46121
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)