add mocks for precompile tests (#812)

* add mocks for precompile tests

* Update compatibility

* Bump AvalancheGo dep to v1.10.9

* Bump ANR dep to be compatible with ago v1.10.9

* revert ConfigurationBlockContext changes
This commit is contained in:
aaronbuchwald
2023-08-25 12:58:05 -04:00
committed by GitHub
parent e99ce82534
commit ce59e115b5
25 changed files with 411 additions and 205 deletions
+1
View File
@@ -49,6 +49,7 @@ The Subnet EVM runs in a separate process from the main AvalancheGo process and
[v0.5.2] [email protected] (Protocol Version: 26)
[v0.5.3] [email protected] (Protocol Version: 27)
[v0.5.4] [email protected] (Protocol Version: 27)
[v0.5.5] [email protected] (Protocol Version: 28)
```
## API
@@ -68,7 +68,7 @@ func TestEqual(t *testing.T) {
},
"different type": {
Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds{{- end}}),
Other: precompileconfig.NewNoopStatefulPrecompileConfig(),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
"different timestamp": {
+1
View File
@@ -1,5 +1,6 @@
{
"rpcChainVMProtocolVersion": {
"v0.5.5": 28,
"v0.5.4": 27,
"v0.5.3": 27,
"v0.5.2": 26,
+4 -4
View File
@@ -4,8 +4,8 @@ go 1.19
require (
github.com/VictoriaMetrics/fastcache v1.10.0
github.com/ava-labs/avalanche-network-runner v1.7.1
github.com/ava-labs/avalanchego v1.10.8
github.com/ava-labs/avalanche-network-runner v1.7.2-0.20230825150237-723bc7b31724
github.com/ava-labs/avalanchego v1.10.9
github.com/cespare/cp v0.1.0
github.com/cockroachdb/pebble v0.0.0-20230209160836-829675f94811
github.com/davecgh/go-spew v1.1.1
@@ -16,7 +16,6 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
github.com/go-cmd/cmd v1.4.1
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
github.com/gorilla/rpc v1.2.0
github.com/gorilla/websocket v1.4.2
@@ -42,6 +41,7 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a
github.com/tyler-smith/go-bip39 v1.1.0
github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa
go.uber.org/mock v0.2.0
golang.org/x/crypto v0.1.0
golang.org/x/sync v0.2.0
golang.org/x/sys v0.8.0
@@ -53,7 +53,7 @@ require (
github.com/DataDog/zstd v1.5.2 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/ava-labs/coreth v0.12.5-rc.1 // indirect
github.com/ava-labs/coreth v0.12.5-rc.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
+8 -9
View File
@@ -59,12 +59,12 @@ github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/ava-labs/avalanche-network-runner v1.7.1 h1:XRC2NcchESSxSlJEgb47lAkTG5eF1t2sMs8CoJKeAuE=
github.com/ava-labs/avalanche-network-runner v1.7.1/go.mod h1:q/2ws64daRXXsiq08bVA1iESRY1CNOQQQDKPeMauZrc=
github.com/ava-labs/avalanchego v1.10.8 h1:fUudA4J37y8wyNG3iiX0kpoZXunsWpCgvsGDgIsi0NY=
github.com/ava-labs/avalanchego v1.10.8/go.mod h1:2zuce+beHe25wQ5RlrEeDpa+SqY/sjEOjDky+Q1NxfU=
github.com/ava-labs/coreth v0.12.5-rc.1 h1:rLJ6mT/44jgc+vPpKaspGpxDIdQGLkSK6wDSmKgYPxY=
github.com/ava-labs/coreth v0.12.5-rc.1/go.mod h1:K7Xm2jqx90wxKZXfLvkLEL+zlM5843gGq9XkqVDwKds=
github.com/ava-labs/avalanche-network-runner v1.7.2-0.20230825150237-723bc7b31724 h1:ptqFgQtJ5DyLb2lvuvawLJNlvo1A1qv+JXYTneNeg14=
github.com/ava-labs/avalanche-network-runner v1.7.2-0.20230825150237-723bc7b31724/go.mod h1:euKHwZ77sGvGfhVj4v9WPM4jD2b5N80ldE2XHqO7lwA=
github.com/ava-labs/avalanchego v1.10.9 h1:qxhp3YoD2Wm/iIKP6Wb1isbkUPWmIrJxWgivDoL0obM=
github.com/ava-labs/avalanchego v1.10.9/go.mod h1:C8R5uiltpc8MQ62ixxgODR+15mesWF0aAw3H+Qrl9Iw=
github.com/ava-labs/coreth v0.12.5-rc.3 h1:cpmC+fSZMsO4gaFWqXHzAHrJACf05u5HPAYmwh7nmkU=
github.com/ava-labs/coreth v0.12.5-rc.3/go.mod h1:HI+jTIflnDFBd0bledgkgid1Uurwr8q1h7zb3LsFsSo=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -262,8 +262,6 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -657,6 +655,8 @@ go.opentelemetry.io/proto/otlp v0.19.0/go.mod h1:H7XAot3MsfNsj7EXtrA2q5xSNQ10UqI
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A=
go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU=
go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
@@ -935,7 +935,6 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+1 -1
View File
@@ -14,8 +14,8 @@ import (
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
"github.com/ava-labs/subnet-evm/trie"
"github.com/ethereum/go-ethereum/common"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
func TestHandlePrecompileAccept(t *testing.T) {
+1 -1
View File
@@ -11,7 +11,7 @@ var (
// GitCommit is set by the build script
GitCommit string
// Version is the version of Subnet EVM
Version string = "v0.5.4"
Version string = "v0.5.5"
)
func init() {
+1 -3
View File
@@ -83,7 +83,6 @@ import (
var (
_ block.ChainVM = &VM{}
_ block.HeightIndexedChainVM = &VM{}
_ block.BuildBlockWithContextChainVM = &VM{}
)
@@ -762,8 +761,7 @@ func (vm *VM) VerifyHeightIndex(context.Context) error {
return nil
}
// GetBlockAtHeight implements the HeightIndexedChainVM interface and returns the
// canonical block at [blkHeight].
// GetBlockAtHeight returns the canonical block at [blkHeight].
// If [blkHeight] is less than the height of the last accepted block, this will return
// the block accepted at that height. Otherwise, it may return a blkID that has not yet
// been accepted.
-57
View File
@@ -1,57 +0,0 @@
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package contract
import (
"math/big"
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
)
// TODO: replace with gomock library
var (
_ BlockContext = &mockBlockContext{}
_ AccessibleState = &mockAccessibleState{}
)
type mockBlockContext struct {
blockNumber *big.Int
timestamp uint64
}
func NewMockBlockContext(blockNumber *big.Int, timestamp uint64) *mockBlockContext {
return &mockBlockContext{
blockNumber: blockNumber,
timestamp: timestamp,
}
}
func (mb *mockBlockContext) Number() *big.Int { return mb.blockNumber }
func (mb *mockBlockContext) Timestamp() uint64 { return mb.timestamp }
type mockAccessibleState struct {
state StateDB
blockContext *mockBlockContext
snowContext *snow.Context
chainConfig precompileconfig.ChainConfig
}
func NewMockAccessibleState(state StateDB, blockContext *mockBlockContext, snowContext *snow.Context, chainConfig precompileconfig.ChainConfig) *mockAccessibleState {
return &mockAccessibleState{
state: state,
blockContext: blockContext,
snowContext: snowContext,
chainConfig: chainConfig,
}
}
func (m *mockAccessibleState) GetStateDB() StateDB { return m.state }
func (m *mockAccessibleState) GetBlockContext() BlockContext { return m.blockContext }
func (m *mockAccessibleState) GetSnowContext() *snow.Context { return m.snowContext }
func (m *mockAccessibleState) GetChainConfig() precompileconfig.ChainConfig { return m.chainConfig }
+144
View File
@@ -0,0 +1,144 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/ava-labs/subnet-evm/precompile/contract (interfaces: BlockContext,AccessibleState)
// Package contract is a generated GoMock package.
package contract
import (
big "math/big"
reflect "reflect"
snow "github.com/ava-labs/avalanchego/snow"
common "github.com/ethereum/go-ethereum/common"
gomock "go.uber.org/mock/gomock"
)
// MockBlockContext is a mock of BlockContext interface.
type MockBlockContext struct {
ctrl *gomock.Controller
recorder *MockBlockContextMockRecorder
}
// MockBlockContextMockRecorder is the mock recorder for MockBlockContext.
type MockBlockContextMockRecorder struct {
mock *MockBlockContext
}
// NewMockBlockContext creates a new mock instance.
func NewMockBlockContext(ctrl *gomock.Controller) *MockBlockContext {
mock := &MockBlockContext{ctrl: ctrl}
mock.recorder = &MockBlockContextMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockBlockContext) EXPECT() *MockBlockContextMockRecorder {
return m.recorder
}
// GetPredicateResults mocks base method.
func (m *MockBlockContext) GetPredicateResults(arg0 common.Hash, arg1 common.Address) []byte {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetPredicateResults", arg0, arg1)
ret0, _ := ret[0].([]byte)
return ret0
}
// GetPredicateResults indicates an expected call of GetPredicateResults.
func (mr *MockBlockContextMockRecorder) GetPredicateResults(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetPredicateResults", reflect.TypeOf((*MockBlockContext)(nil).GetPredicateResults), arg0, arg1)
}
// Number mocks base method.
func (m *MockBlockContext) Number() *big.Int {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Number")
ret0, _ := ret[0].(*big.Int)
return ret0
}
// Number indicates an expected call of Number.
func (mr *MockBlockContextMockRecorder) Number() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Number", reflect.TypeOf((*MockBlockContext)(nil).Number))
}
// Timestamp mocks base method.
func (m *MockBlockContext) Timestamp() uint64 {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Timestamp")
ret0, _ := ret[0].(uint64)
return ret0
}
// Timestamp indicates an expected call of Timestamp.
func (mr *MockBlockContextMockRecorder) Timestamp() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Timestamp", reflect.TypeOf((*MockBlockContext)(nil).Timestamp))
}
// MockAccessibleState is a mock of AccessibleState interface.
type MockAccessibleState struct {
ctrl *gomock.Controller
recorder *MockAccessibleStateMockRecorder
}
// MockAccessibleStateMockRecorder is the mock recorder for MockAccessibleState.
type MockAccessibleStateMockRecorder struct {
mock *MockAccessibleState
}
// NewMockAccessibleState creates a new mock instance.
func NewMockAccessibleState(ctrl *gomock.Controller) *MockAccessibleState {
mock := &MockAccessibleState{ctrl: ctrl}
mock.recorder = &MockAccessibleStateMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockAccessibleState) EXPECT() *MockAccessibleStateMockRecorder {
return m.recorder
}
// GetBlockContext mocks base method.
func (m *MockAccessibleState) GetBlockContext() BlockContext {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetBlockContext")
ret0, _ := ret[0].(BlockContext)
return ret0
}
// GetBlockContext indicates an expected call of GetBlockContext.
func (mr *MockAccessibleStateMockRecorder) GetBlockContext() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBlockContext", reflect.TypeOf((*MockAccessibleState)(nil).GetBlockContext))
}
// GetSnowContext mocks base method.
func (m *MockAccessibleState) GetSnowContext() *snow.Context {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetSnowContext")
ret0, _ := ret[0].(*snow.Context)
return ret0
}
// GetSnowContext indicates an expected call of GetSnowContext.
func (mr *MockAccessibleStateMockRecorder) GetSnowContext() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSnowContext", reflect.TypeOf((*MockAccessibleState)(nil).GetSnowContext))
}
// GetStateDB mocks base method.
func (m *MockAccessibleState) GetStateDB() StateDB {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetStateDB")
ret0, _ := ret[0].(StateDB)
return ret0
}
// GetStateDB indicates an expected call of GetStateDB.
func (mr *MockAccessibleStateMockRecorder) GetStateDB() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStateDB", reflect.TypeOf((*MockAccessibleState)(nil).GetStateDB))
}
@@ -11,6 +11,7 @@ import (
"github.com/ava-labs/subnet-evm/precompile/testutils"
"github.com/ava-labs/subnet-evm/utils"
"github.com/ethereum/go-ethereum/common"
"go.uber.org/mock/gomock"
)
func TestVerify(t *testing.T) {
@@ -28,7 +29,7 @@ func TestEqual(t *testing.T) {
},
"different type": {
Config: NewConfig(nil, nil, nil),
Other: precompileconfig.NewNoopStatefulPrecompileConfig(),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
"different timestamp": {
@@ -13,6 +13,7 @@ import (
"github.com/ava-labs/subnet-evm/precompile/testutils"
"github.com/ava-labs/subnet-evm/utils"
"github.com/ethereum/go-ethereum/common"
"go.uber.org/mock/gomock"
)
var validFeeConfig = commontype.FeeConfig{
@@ -56,7 +57,7 @@ func TestEqual(t *testing.T) {
},
"different type": {
Config: NewConfig(utils.NewUint64(3), admins, enableds, nil),
Other: precompileconfig.NewNoopStatefulPrecompileConfig(),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
"different timestamp": {
@@ -15,6 +15,7 @@ import (
"github.com/ava-labs/subnet-evm/vmerrs"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
var (
@@ -96,7 +97,9 @@ var (
SuppliedGas: SetFeeConfigGasCost,
ReadOnly: false,
ExpectedRes: []byte{},
BlockNumber: testBlockNumber.Int64(),
SetupBlockContext: func(mbc *contract.MockBlockContext) {
mbc.EXPECT().Number().Return(testBlockNumber).AnyTimes()
},
AfterHook: func(t testing.TB, state contract.StateDB) {
feeConfig := GetStoredFeeConfig(state)
require.Equal(t, testFeeConfig, feeConfig)
@@ -107,8 +110,10 @@ var (
"get fee config from non-enabled address": {
Caller: allowlist.TestNoRoleAddr,
BeforeHook: func(t testing.TB, state contract.StateDB) {
blockContext := contract.NewMockBlockContext(gomock.NewController(t))
blockContext.EXPECT().Number().Return(big.NewInt(6)).Times(1)
allowlist.SetDefaultRoles(Module.Address)(t, state)
err := StoreFeeConfig(state, testFeeConfig, contract.NewMockBlockContext(big.NewInt(6), 0))
err := StoreFeeConfig(state, testFeeConfig, blockContext)
require.NoError(t, err)
},
Input: PackGetFeeConfigInput(),
@@ -144,7 +149,9 @@ var (
}
return res
}(),
BlockNumber: testBlockNumber.Int64(),
SetupBlockContext: func(mbc *contract.MockBlockContext) {
mbc.EXPECT().Number().Return(testBlockNumber)
},
AfterHook: func(t testing.TB, state contract.StateDB) {
feeConfig := GetStoredFeeConfig(state)
lastChangedAt := GetFeeConfigLastChangedAt(state)
@@ -155,8 +162,10 @@ var (
"get last changed at from non-enabled address": {
Caller: allowlist.TestNoRoleAddr,
BeforeHook: func(t testing.TB, state contract.StateDB) {
blockContext := contract.NewMockBlockContext(gomock.NewController(t))
blockContext.EXPECT().Number().Return(testBlockNumber).Times(1)
allowlist.SetDefaultRoles(Module.Address)(t, state)
err := StoreFeeConfig(state, testFeeConfig, contract.NewMockBlockContext(testBlockNumber, 0))
err := StoreFeeConfig(state, testFeeConfig, blockContext)
require.NoError(t, err)
},
Input: PackGetLastChangedAtInput(),
@@ -12,6 +12,7 @@ import (
"github.com/ava-labs/subnet-evm/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"go.uber.org/mock/gomock"
)
func TestVerify(t *testing.T) {
@@ -61,7 +62,7 @@ func TestEqual(t *testing.T) {
},
"different type": {
Config: NewConfig(utils.NewUint64(3), admins, enableds, nil),
Other: precompileconfig.NewNoopStatefulPrecompileConfig(),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
"different timestamps": {
@@ -11,6 +11,7 @@ import (
"github.com/ava-labs/subnet-evm/precompile/testutils"
"github.com/ava-labs/subnet-evm/utils"
"github.com/ethereum/go-ethereum/common"
"go.uber.org/mock/gomock"
)
func TestVerify(t *testing.T) {
@@ -39,7 +40,7 @@ func TestEqual(t *testing.T) {
},
"different type": {
Config: NewConfig(utils.NewUint64(3), admins, enableds, nil),
Other: precompileconfig.NewNoopStatefulPrecompileConfig(),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
"different timestamp": {
@@ -11,6 +11,7 @@ import (
"github.com/ava-labs/subnet-evm/precompile/testutils"
"github.com/ava-labs/subnet-evm/utils"
"github.com/ethereum/go-ethereum/common"
"go.uber.org/mock/gomock"
)
func TestVerify(t *testing.T) {
@@ -28,7 +29,7 @@ func TestEqual(t *testing.T) {
},
"different type": {
Config: NewConfig(nil, nil, nil),
Other: precompileconfig.NewNoopStatefulPrecompileConfig(),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
"different timestamp": {
@@ -1,60 +0,0 @@
// (c) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
// TODO: replace with gomock
package precompileconfig
import (
"github.com/ava-labs/subnet-evm/commontype"
"github.com/ethereum/go-ethereum/common"
)
var (
_ Config = &noopStatefulPrecompileConfig{}
_ ChainConfig = &mockChainConfig{}
)
type noopStatefulPrecompileConfig struct{}
func NewNoopStatefulPrecompileConfig() *noopStatefulPrecompileConfig {
return &noopStatefulPrecompileConfig{}
}
func (n *noopStatefulPrecompileConfig) Key() string {
return ""
}
func (n *noopStatefulPrecompileConfig) Address() common.Address {
return common.Address{}
}
func (n *noopStatefulPrecompileConfig) Timestamp() *uint64 {
return nil
}
func (n *noopStatefulPrecompileConfig) IsDisabled() bool {
return false
}
func (n *noopStatefulPrecompileConfig) Equal(Config) bool {
return false
}
func (n *noopStatefulPrecompileConfig) Verify(ChainConfig) error {
return nil
}
type mockChainConfig struct {
feeConfig commontype.FeeConfig
allowedFeeRecipients bool
}
func (m *mockChainConfig) GetFeeConfig() commontype.FeeConfig { return m.feeConfig }
func (m *mockChainConfig) AllowedFeeRecipients() bool { return m.allowedFeeRecipients }
func NewMockChainConfig(feeConfig commontype.FeeConfig, allowedFeeRecipients bool) *mockChainConfig {
return &mockChainConfig{
feeConfig: feeConfig,
allowedFeeRecipients: allowedFeeRecipients,
}
}
+194
View File
@@ -0,0 +1,194 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/ava-labs/subnet-evm/precompile/precompileconfig (interfaces: Config,ChainConfig,Accepter)
// Package precompileconfig is a generated GoMock package.
package precompileconfig
import (
reflect "reflect"
commontype "github.com/ava-labs/subnet-evm/commontype"
common "github.com/ethereum/go-ethereum/common"
"go.uber.org/mock/gomock"
)
// MockConfig is a mock of Config interface.
type MockConfig struct {
ctrl *gomock.Controller
recorder *MockConfigMockRecorder
}
// MockConfigMockRecorder is the mock recorder for MockConfig.
type MockConfigMockRecorder struct {
mock *MockConfig
}
// NewMockConfig creates a new mock instance.
func NewMockConfig(ctrl *gomock.Controller) *MockConfig {
mock := &MockConfig{ctrl: ctrl}
mock.recorder = &MockConfigMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockConfig) EXPECT() *MockConfigMockRecorder {
return m.recorder
}
// Equal mocks base method.
func (m *MockConfig) Equal(arg0 Config) bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Equal", arg0)
ret0, _ := ret[0].(bool)
return ret0
}
// Equal indicates an expected call of Equal.
func (mr *MockConfigMockRecorder) Equal(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Equal", reflect.TypeOf((*MockConfig)(nil).Equal), arg0)
}
// IsDisabled mocks base method.
func (m *MockConfig) IsDisabled() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "IsDisabled")
ret0, _ := ret[0].(bool)
return ret0
}
// IsDisabled indicates an expected call of IsDisabled.
func (mr *MockConfigMockRecorder) IsDisabled() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsDisabled", reflect.TypeOf((*MockConfig)(nil).IsDisabled))
}
// Key mocks base method.
func (m *MockConfig) Key() string {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Key")
ret0, _ := ret[0].(string)
return ret0
}
// Key indicates an expected call of Key.
func (mr *MockConfigMockRecorder) Key() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Key", reflect.TypeOf((*MockConfig)(nil).Key))
}
// Timestamp mocks base method.
func (m *MockConfig) Timestamp() *uint64 {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Timestamp")
ret0, _ := ret[0].(*uint64)
return ret0
}
// Timestamp indicates an expected call of Timestamp.
func (mr *MockConfigMockRecorder) Timestamp() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Timestamp", reflect.TypeOf((*MockConfig)(nil).Timestamp))
}
// Verify mocks base method.
func (m *MockConfig) Verify(arg0 ChainConfig) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Verify", arg0)
ret0, _ := ret[0].(error)
return ret0
}
// Verify indicates an expected call of Verify.
func (mr *MockConfigMockRecorder) Verify(arg0 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Verify", reflect.TypeOf((*MockConfig)(nil).Verify), arg0)
}
// MockChainConfig is a mock of ChainConfig interface.
type MockChainConfig struct {
ctrl *gomock.Controller
recorder *MockChainConfigMockRecorder
}
// MockChainConfigMockRecorder is the mock recorder for MockChainConfig.
type MockChainConfigMockRecorder struct {
mock *MockChainConfig
}
// NewMockChainConfig creates a new mock instance.
func NewMockChainConfig(ctrl *gomock.Controller) *MockChainConfig {
mock := &MockChainConfig{ctrl: ctrl}
mock.recorder = &MockChainConfigMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockChainConfig) EXPECT() *MockChainConfigMockRecorder {
return m.recorder
}
// AllowedFeeRecipients mocks base method.
func (m *MockChainConfig) AllowedFeeRecipients() bool {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "AllowedFeeRecipients")
ret0, _ := ret[0].(bool)
return ret0
}
// AllowedFeeRecipients indicates an expected call of AllowedFeeRecipients.
func (mr *MockChainConfigMockRecorder) AllowedFeeRecipients() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AllowedFeeRecipients", reflect.TypeOf((*MockChainConfig)(nil).AllowedFeeRecipients))
}
// GetFeeConfig mocks base method.
func (m *MockChainConfig) GetFeeConfig() commontype.FeeConfig {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "GetFeeConfig")
ret0, _ := ret[0].(commontype.FeeConfig)
return ret0
}
// GetFeeConfig indicates an expected call of GetFeeConfig.
func (mr *MockChainConfigMockRecorder) GetFeeConfig() *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetFeeConfig", reflect.TypeOf((*MockChainConfig)(nil).GetFeeConfig))
}
// MockAccepter is a mock of Accepter interface.
type MockAccepter struct {
ctrl *gomock.Controller
recorder *MockAccepterMockRecorder
}
// MockAccepterMockRecorder is the mock recorder for MockAccepter.
type MockAccepterMockRecorder struct {
mock *MockAccepter
}
// NewMockAccepter creates a new mock instance.
func NewMockAccepter(ctrl *gomock.Controller) *MockAccepter {
mock := &MockAccepter{ctrl: ctrl}
mock.recorder = &MockAccepterMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockAccepter) EXPECT() *MockAccepterMockRecorder {
return m.recorder
}
// Accept mocks base method.
func (m *MockAccepter) Accept(arg0 *AcceptContext, arg1 common.Hash, arg2 int, arg3 []common.Hash, arg4 []byte) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Accept", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(error)
return ret0
}
// Accept indicates an expected call of Accept.
func (mr *MockAccepterMockRecorder) Accept(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Accept", reflect.TypeOf((*MockAccepter)(nil).Accept), arg0, arg1, arg2, arg3, arg4)
}
@@ -1,49 +0,0 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/ava-labs/subnet-evm/precompile/precompileconfig (interfaces: Accepter)
// Package precompileconfig is a generated GoMock package.
package precompileconfig
import (
reflect "reflect"
common "github.com/ethereum/go-ethereum/common"
gomock "github.com/golang/mock/gomock"
)
// MockAccepter is a mock of Accepter interface.
type MockAccepter struct {
ctrl *gomock.Controller
recorder *MockAccepterMockRecorder
}
// MockAccepterMockRecorder is the mock recorder for MockAccepter.
type MockAccepterMockRecorder struct {
mock *MockAccepter
}
// NewMockAccepter creates a new mock instance.
func NewMockAccepter(ctrl *gomock.Controller) *MockAccepter {
mock := &MockAccepter{ctrl: ctrl}
mock.recorder = &MockAccepterMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use.
func (m *MockAccepter) EXPECT() *MockAccepterMockRecorder {
return m.recorder
}
// Accept mocks base method.
func (m *MockAccepter) Accept(arg0 *AcceptContext, arg1 common.Hash, arg2 int, arg3 []common.Hash, arg4 []byte) error {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Accept", arg0, arg1, arg2, arg3, arg4)
ret0, _ := ret[0].(error)
return ret0
}
// Accept indicates an expected call of Accept.
func (mr *MockAccepterMockRecorder) Accept(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Accept", reflect.TypeOf((*MockAccepter)(nil).Accept), arg0, arg1, arg2, arg3, arg4)
}
+21 -5
View File
@@ -15,10 +15,9 @@ import (
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
var DefaultChainConfig = precompileconfig.NewMockChainConfig(commontype.ValidTestFeeConfig, false)
// PrecompileTest is a test case for a precompile
type PrecompileTest struct {
// Caller is the address of the precompile caller
@@ -40,6 +39,8 @@ type PrecompileTest struct {
Config precompileconfig.Config
// BeforeHook is called before the precompile is called.
BeforeHook func(t testing.TB, state contract.StateDB)
// SetupBlockContext sets the expected calls on MockBlockContext for the test execution.
SetupBlockContext func(*contract.MockBlockContext)
// AfterHook is called after the precompile is called.
AfterHook func(t testing.TB, state contract.StateDB)
// ExpectedRes is the expected raw byte result returned by the precompile
@@ -85,17 +86,32 @@ func (test PrecompileTest) setup(t testing.TB, module modules.Module, state cont
t.Helper()
contractAddress := module.Address
ctrl := gomock.NewController(t)
if test.BeforeHook != nil {
test.BeforeHook(t, state)
}
blockContext := contract.NewMockBlockContext(big.NewInt(test.BlockNumber), 0)
chainConfig := test.ChainConfig
if chainConfig == nil {
chainConfig = DefaultChainConfig
mockChainConfig := precompileconfig.NewMockChainConfig(ctrl)
mockChainConfig.EXPECT().GetFeeConfig().AnyTimes().Return(commontype.ValidTestFeeConfig)
mockChainConfig.EXPECT().AllowedFeeRecipients().AnyTimes().Return(false)
chainConfig = mockChainConfig
}
accessibleState := contract.NewMockAccessibleState(state, blockContext, snow.DefaultContextTest(), chainConfig)
blockContext := contract.NewMockBlockContext(ctrl)
if test.SetupBlockContext != nil {
test.SetupBlockContext(blockContext)
} else {
blockContext.EXPECT().Number().Return(big.NewInt(0)).AnyTimes()
}
snowContext := snow.DefaultContextTest()
accessibleState := contract.NewMockAccessibleState(ctrl)
accessibleState.EXPECT().GetStateDB().Return(state).AnyTimes()
accessibleState.EXPECT().GetBlockContext().Return(blockContext).AnyTimes()
accessibleState.EXPECT().GetSnowContext().Return(snowContext).AnyTimes()
if test.Config != nil {
err := module.Configure(chainConfig, test.Config, state, blockContext)
+1 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Don't export them as they're used in the context of other calls
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.10.8'}
AVALANCHE_VERSION=${AVALANCHE_VERSION:-'v1.10.9'}
AVALANCHEGO_VERSION=${AVALANCHEGO_VERSION:-$AVALANCHE_VERSION}
GINKGO_VERSION=${GINKGO_VERSION:-'v2.2.0'}
+6 -2
View File
@@ -113,9 +113,13 @@ func CreateSubnetsSuite(genesisFiles map[string]string) *SubnetSuite {
func CreateNewSubnet(ctx context.Context, genesisFilePath string) string {
kc := secp256k1fx.NewKeychain(genesis.EWOQKey)
// NewWalletFromURI fetches the available UTXOs owned by [kc] on the network
// MakeWallet fetches the available UTXOs owned by [kc] on the network
// that [LocalAPIURI] is hosting.
wallet, err := wallet.NewWalletFromURI(ctx, DefaultLocalNodeURI, kc)
wallet, err := wallet.MakeWallet(ctx, &wallet.WalletConfig{
URI: DefaultLocalNodeURI,
AVAXKeychain: kc,
EthKeychain: kc,
})
gomega.Expect(err).Should(gomega.BeNil())
pWallet := wallet.P()
+2 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
"github.com/ava-labs/subnet-evm/precompile/testutils"
"github.com/ava-labs/subnet-evm/utils"
"go.uber.org/mock/gomock"
)
func TestVerify(t *testing.T) {
@@ -46,7 +47,7 @@ func TestEqualWarpConfig(t *testing.T) {
"different type": {
Config: NewDefaultConfig(utils.NewUint64(3)),
Other: precompileconfig.NewNoopStatefulPrecompileConfig(),
Other: precompileconfig.NewMockConfig(gomock.NewController(t)),
Expected: false,
},
+1 -1
View File
@@ -24,8 +24,8 @@ import (
predicateutils "github.com/ava-labs/subnet-evm/utils/predicate"
warpPayload "github.com/ava-labs/subnet-evm/warp/payload"
"github.com/ethereum/go-ethereum/common"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
const pChainHeight uint64 = 1337
+1 -1
View File
@@ -13,8 +13,8 @@ import (
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/set"
avalancheWarp "github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
)
// This test copies the test coverage from https://github.com/ava-labs/avalanchego/blob/v1.10.0/vms/platformvm/warp/signature_test.go#L137.