@@ -7,14 +7,14 @@ package helloworld
77import (
88 "testing"
99
10- "github.com/ava-labs/subnet-evm/core/state"
11- "github.com/ava-labs/subnet-evm/precompile/allowlist"
10+ "github.com/ava-labs/libevm/common"
11+ "github.com/ava-labs/libevm/core/vm"
12+ "github.com/ava-labs/subnet-evm/core/extstate"
13+ "github.com/ava-labs/subnet-evm/precompile/allowlist/allowlisttest"
1214 "github.com/ava-labs/subnet-evm/precompile/contract"
1315 "github.com/ava-labs/subnet-evm/precompile/precompileconfig"
14- "github.com/ava-labs/subnet-evm/precompile/testutils "
16+ "github.com/ava-labs/subnet-evm/precompile/precompiletest "
1517 "github.com/ava-labs/subnet-evm/utils"
16- "github.com/ava-labs/subnet-evm/vmerrs"
17- "github.com/ethereum/go-ethereum/common"
1818 "github.com/stretchr/testify/require"
1919 "go.uber.org/mock/gomock"
2020)
@@ -28,10 +28,10 @@ const testGreeting = "test"
2828const longString = "a very long string that is longer than 32 bytes and will cause an error"
2929
3030var (
31- tests = map [string ]testutils .PrecompileTest {
31+ tests = map [string ]precompiletest .PrecompileTest {
3232 "calling sayHello from NoRole should succeed" : {
33- Caller : allowlist .TestNoRoleAddr ,
34- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
33+ Caller : allowlisttest .TestNoRoleAddr ,
34+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
3535 InputFn : func (t testing.TB ) []byte {
3636 input , err := PackSayHello ()
3737 require .NoError (t , err )
5454 ExpectedErr : "" ,
5555 },
5656 "calling sayHello from Enabled should succeed" : {
57- Caller : allowlist .TestEnabledAddr ,
58- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
57+ Caller : allowlisttest .TestEnabledAddr ,
58+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
5959 InputFn : func (t testing.TB ) []byte {
6060 input , err := PackSayHello ()
6161 require .NoError (t , err )
7878 ExpectedErr : "" ,
7979 },
8080 "calling sayHello from Manager should succeed" : {
81- Caller : allowlist .TestManagerAddr ,
82- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
81+ Caller : allowlisttest .TestManagerAddr ,
82+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
8383 InputFn : func (t testing.TB ) []byte {
8484 input , err := PackSayHello ()
8585 require .NoError (t , err )
@@ -102,8 +102,8 @@ var (
102102 ExpectedErr : "" ,
103103 },
104104 "calling sayHello from Admin should succeed" : {
105- Caller : allowlist .TestAdminAddr ,
106- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
105+ Caller : allowlisttest .TestAdminAddr ,
106+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
107107 InputFn : func (t testing.TB ) []byte {
108108 input , err := PackSayHello ()
109109 require .NoError (t , err )
@@ -126,8 +126,8 @@ var (
126126 ExpectedErr : "" ,
127127 },
128128 "calling sayHello from NoRole with a config should return default greeting" : {
129- Caller : allowlist .TestNoRoleAddr ,
130- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
129+ Caller : allowlisttest .TestNoRoleAddr ,
130+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
131131 Config : NewConfig (utils .NewUint64 (0 ), nil , nil , nil ),
132132 InputFn : func (t testing.TB ) []byte {
133133 input , err := PackSayHello ()
@@ -156,11 +156,11 @@ var (
156156 },
157157 SuppliedGas : SayHelloGasCost - 1 ,
158158 ReadOnly : false ,
159- ExpectedErr : vmerrs .ErrOutOfGas .Error (),
159+ ExpectedErr : vm .ErrOutOfGas .Error (),
160160 },
161161 "calling setGreeting from NoRole should fail" : {
162- Caller : allowlist .TestNoRoleAddr ,
163- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
162+ Caller : allowlisttest .TestNoRoleAddr ,
163+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
164164 InputFn : func (t testing.TB ) []byte {
165165 // CUSTOM CODE STARTS HERE
166166 // set test input to a value here
@@ -173,8 +173,8 @@ var (
173173 ExpectedErr : ErrCannotSetGreeting .Error (),
174174 },
175175 "calling setGreeting from Enabled should succeed" : {
176- Caller : allowlist .TestEnabledAddr ,
177- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
176+ Caller : allowlisttest .TestEnabledAddr ,
177+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
178178 InputFn : func (t testing.TB ) []byte {
179179 // CUSTOM CODE STARTS HERE
180180 // set test input to a value here
@@ -191,14 +191,14 @@ var (
191191 }),
192192 ReadOnly : false ,
193193 ExpectedErr : "" ,
194- AfterHook : func (t testing.TB , state contract .StateDB ) {
194+ AfterHook : func (t testing.TB , state * extstate .StateDB ) {
195195 greeting := GetGreeting (state )
196196 require .Equal (t , greeting , testGreeting )
197197 },
198198 },
199199 "calling setGreeting from Manager should succeed" : {
200- Caller : allowlist .TestManagerAddr ,
201- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
200+ Caller : allowlisttest .TestManagerAddr ,
201+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
202202 InputFn : func (t testing.TB ) []byte {
203203 // CUSTOM CODE STARTS HERE
204204 // set test input to a value here
@@ -215,14 +215,14 @@ var (
215215 }),
216216 ReadOnly : false ,
217217 ExpectedErr : "" ,
218- AfterHook : func (t testing.TB , state contract .StateDB ) {
218+ AfterHook : func (t testing.TB , state * extstate .StateDB ) {
219219 greeting := GetGreeting (state )
220220 require .Equal (t , greeting , testGreeting )
221221 },
222222 },
223223 "calling setGreeting from Admin should succeed" : {
224- Caller : allowlist .TestAdminAddr ,
225- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
224+ Caller : allowlisttest .TestAdminAddr ,
225+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
226226 InputFn : func (t testing.TB ) []byte {
227227 // CUSTOM CODE STARTS HERE
228228 // set test input to a value here
@@ -239,7 +239,7 @@ var (
239239 }),
240240 ReadOnly : false ,
241241 ExpectedErr : "" ,
242- AfterHook : func (t testing.TB , state contract .StateDB ) {
242+ AfterHook : func (t testing.TB , state * extstate .StateDB ) {
243243 greeting := GetGreeting (state )
244244 require .Equal (t , greeting , testGreeting )
245245 },
@@ -256,11 +256,11 @@ var (
256256 },
257257 SuppliedGas : SetGreetingGasCost ,
258258 ReadOnly : true ,
259- ExpectedErr : vmerrs .ErrWriteProtection .Error (),
259+ ExpectedErr : vm .ErrWriteProtection .Error (),
260260 },
261261 "insufficient gas for setGreeting should fail" : {
262- Caller : allowlist .TestEnabledAddr ,
263- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
262+ Caller : allowlisttest .TestEnabledAddr ,
263+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
264264 InputFn : func (t testing.TB ) []byte {
265265 // CUSTOM CODE STARTS HERE
266266 // set test input to a value here
@@ -273,13 +273,13 @@ var (
273273 NewGreeting : testGreeting ,
274274 }) - 1 ,
275275 ReadOnly : false ,
276- ExpectedErr : vmerrs .ErrOutOfGas .Error (),
276+ ExpectedErr : vm .ErrOutOfGas .Error (),
277277 },
278278 // more custom tests
279279 "store greeting then say hello from non-enabled address" : {
280- Caller : allowlist .TestNoRoleAddr ,
281- BeforeHook : func (t testing.TB , state contract .StateDB ) {
282- allowlist .SetDefaultRoles (Module .Address )(t , state )
280+ Caller : allowlisttest .TestNoRoleAddr ,
281+ BeforeHook : func (t testing.TB , state * extstate .StateDB ) {
282+ allowlisttest .SetDefaultRoles (Module .Address )(t , state )
283283 StoreGreeting (state , testGreeting )
284284 },
285285 InputFn : func (t testing.TB ) []byte {
@@ -298,8 +298,8 @@ var (
298298 }(),
299299 },
300300 "set a very long greeting from enabled address before Durango" : {
301- Caller : allowlist .TestEnabledAddr ,
302- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
301+ Caller : allowlisttest .TestEnabledAddr ,
302+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
303303 // By default Durango is enabled in the tests.
304304 ChainConfigFn : func (ctrl * gomock.Controller ) precompileconfig.ChainConfig {
305305 config := precompileconfig .NewMockChainConfig (ctrl )
@@ -318,8 +318,8 @@ var (
318318 ExpectedErr : ErrInputExceedsLimit .Error (),
319319 },
320320 "set a very long greeting from enabled address after Durango" : {
321- Caller : allowlist .TestEnabledAddr ,
322- BeforeHook : allowlist .SetDefaultRoles (Module .Address ),
321+ Caller : allowlisttest .TestEnabledAddr ,
322+ BeforeHook : allowlisttest .SetDefaultRoles (Module .Address ),
323323 InputFn : func (t testing.TB ) []byte {
324324 input , err := PackSetGreeting (longString )
325325 require .NoError (t , err )
@@ -344,7 +344,7 @@ func TestHelloWorldRun(t *testing.T) {
344344 // and runs them all together.
345345 // Even if you don't add any custom tests, keep this. This will still
346346 // run the default allowlist tests.
347- allowlist .RunPrecompileWithAllowListTests (t , Module , state . NewTestStateDB , tests )
347+ allowlisttest .RunPrecompileWithAllowListTests (t , Module , tests )
348348}
349349
350350// TestPackUnpackGreetingChangedEventData tests the Pack/UnpackGreetingChangedEventData.
@@ -368,12 +368,3 @@ func TestPackUnpackGreetingChangedEventData(t *testing.T) {
368368 require .NoError (t , err )
369369 require .Equal (t , dataInput , unpacked )
370370}
371-
372- func BenchmarkHelloWorld (b * testing.B ) {
373- // Benchmark tests with allowlist tests.
374- // This adds allowlist run tests to your custom tests
375- // and benchmarks them all together.
376- // Even if you don't add any custom tests, keep this. This will still
377- // run the default allowlist tests.
378- allowlist .BenchPrecompileWithAllowList (b , Module , state .NewTestStateDB , tests )
379- }
0 commit comments