diff --git a/.github/workflows/hypersdk-ci.yml b/.github/workflows/hypersdk-ci.yml index 9005f47243..77a9b61a2b 100644 --- a/.github/workflows/hypersdk-ci.yml +++ b/.github/workflows/hypersdk-ci.yml @@ -10,17 +10,6 @@ concurrency: cancel-in-progress: true jobs: - mock-gen: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Go - uses: ./.github/actions/install-go - - shell: bash - run: scripts/mock.gen.sh - - shell: bash - run: scripts/tests.clean.sh - go-mod-tidy: runs-on: ubuntu-latest steps: @@ -90,7 +79,7 @@ jobs: hypersdk-tests: runs-on: ubuntu-latest - needs: [mock-gen, go-mod-tidy, hypersdk-lint, hypersdk-unit-tests] + needs: [go-mod-tidy, hypersdk-lint, hypersdk-unit-tests] outputs: only_contracts_changed: ${{ steps.check_changes.outputs.only_contracts_changed }} steps: diff --git a/.golangci.yml b/.golangci.yml index efd683a013..f04adc3d70 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -89,8 +89,6 @@ linters-settings: deny: - pkg: "container/list" desc: github.com/ava-labs/avalanchego/utils/linked should be used instead. - - pkg: "github.com/golang/mock/gomock" - desc: go.uber.org/mock/gomock should be used instead. - pkg: "github.com/stretchr/testify/assert" desc: github.com/stretchr/testify/require should be used instead. - pkg: "io/ioutil" diff --git a/chain/mock_rules.go b/chain/mock_rules.go deleted file mode 100644 index a9abb857b6..0000000000 --- a/chain/mock_rules.go +++ /dev/null @@ -1,308 +0,0 @@ -// Code generated by MockGen. DO NOT EDIT. -// Source: github.com/ava-labs/hypersdk/chain (interfaces: Rules) -// -// Generated by this command: -// -// mockgen -package=chain -destination=chain/mock_rules.go github.com/ava-labs/hypersdk/chain Rules -// - -// Package chain is a generated GoMock package. -package chain - -import ( - reflect "reflect" - - ids "github.com/ava-labs/avalanchego/ids" - fees "github.com/ava-labs/hypersdk/fees" - gomock "go.uber.org/mock/gomock" -) - -// MockRules is a mock of Rules interface. -type MockRules struct { - ctrl *gomock.Controller - recorder *MockRulesMockRecorder -} - -// MockRulesMockRecorder is the mock recorder for MockRules. -type MockRulesMockRecorder struct { - mock *MockRules -} - -// NewMockRules creates a new mock instance. -func NewMockRules(ctrl *gomock.Controller) *MockRules { - mock := &MockRules{ctrl: ctrl} - mock.recorder = &MockRulesMockRecorder{mock} - return mock -} - -// EXPECT returns an object that allows the caller to indicate expected use. -func (m *MockRules) EXPECT() *MockRulesMockRecorder { - return m.recorder -} - -// FetchCustom mocks base method. -func (m *MockRules) FetchCustom(arg0 string) (any, bool) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "FetchCustom", arg0) - ret0, _ := ret[0].(any) - ret1, _ := ret[1].(bool) - return ret0, ret1 -} - -// FetchCustom indicates an expected call of FetchCustom. -func (mr *MockRulesMockRecorder) FetchCustom(arg0 any) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FetchCustom", reflect.TypeOf((*MockRules)(nil).FetchCustom), arg0) -} - -// GetBaseComputeUnits mocks base method. -func (m *MockRules) GetBaseComputeUnits() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetBaseComputeUnits") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetBaseComputeUnits indicates an expected call of GetBaseComputeUnits. -func (mr *MockRulesMockRecorder) GetBaseComputeUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetBaseComputeUnits", reflect.TypeOf((*MockRules)(nil).GetBaseComputeUnits)) -} - -// GetChainID mocks base method. -func (m *MockRules) GetChainID() ids.ID { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetChainID") - ret0, _ := ret[0].(ids.ID) - return ret0 -} - -// GetChainID indicates an expected call of GetChainID. -func (mr *MockRulesMockRecorder) GetChainID() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetChainID", reflect.TypeOf((*MockRules)(nil).GetChainID)) -} - -// GetMaxActionsPerTx mocks base method. -func (m *MockRules) GetMaxActionsPerTx() byte { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMaxActionsPerTx") - ret0, _ := ret[0].(byte) - return ret0 -} - -// GetMaxActionsPerTx indicates an expected call of GetMaxActionsPerTx. -func (mr *MockRulesMockRecorder) GetMaxActionsPerTx() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMaxActionsPerTx", reflect.TypeOf((*MockRules)(nil).GetMaxActionsPerTx)) -} - -// GetMaxBlockUnits mocks base method. -func (m *MockRules) GetMaxBlockUnits() fees.Dimensions { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMaxBlockUnits") - ret0, _ := ret[0].(fees.Dimensions) - return ret0 -} - -// GetMaxBlockUnits indicates an expected call of GetMaxBlockUnits. -func (mr *MockRulesMockRecorder) GetMaxBlockUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMaxBlockUnits", reflect.TypeOf((*MockRules)(nil).GetMaxBlockUnits)) -} - -// GetMinBlockGap mocks base method. -func (m *MockRules) GetMinBlockGap() int64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMinBlockGap") - ret0, _ := ret[0].(int64) - return ret0 -} - -// GetMinBlockGap indicates an expected call of GetMinBlockGap. -func (mr *MockRulesMockRecorder) GetMinBlockGap() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMinBlockGap", reflect.TypeOf((*MockRules)(nil).GetMinBlockGap)) -} - -// GetMinEmptyBlockGap mocks base method. -func (m *MockRules) GetMinEmptyBlockGap() int64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMinEmptyBlockGap") - ret0, _ := ret[0].(int64) - return ret0 -} - -// GetMinEmptyBlockGap indicates an expected call of GetMinEmptyBlockGap. -func (mr *MockRulesMockRecorder) GetMinEmptyBlockGap() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMinEmptyBlockGap", reflect.TypeOf((*MockRules)(nil).GetMinEmptyBlockGap)) -} - -// GetMinUnitPrice mocks base method. -func (m *MockRules) GetMinUnitPrice() fees.Dimensions { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetMinUnitPrice") - ret0, _ := ret[0].(fees.Dimensions) - return ret0 -} - -// GetMinUnitPrice indicates an expected call of GetMinUnitPrice. -func (mr *MockRulesMockRecorder) GetMinUnitPrice() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetMinUnitPrice", reflect.TypeOf((*MockRules)(nil).GetMinUnitPrice)) -} - -// GetNetworkID mocks base method. -func (m *MockRules) GetNetworkID() uint32 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetNetworkID") - ret0, _ := ret[0].(uint32) - return ret0 -} - -// GetNetworkID indicates an expected call of GetNetworkID. -func (mr *MockRulesMockRecorder) GetNetworkID() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetNetworkID", reflect.TypeOf((*MockRules)(nil).GetNetworkID)) -} - -// GetSponsorStateKeysMaxChunks mocks base method. -func (m *MockRules) GetSponsorStateKeysMaxChunks() []uint16 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetSponsorStateKeysMaxChunks") - ret0, _ := ret[0].([]uint16) - return ret0 -} - -// GetSponsorStateKeysMaxChunks indicates an expected call of GetSponsorStateKeysMaxChunks. -func (mr *MockRulesMockRecorder) GetSponsorStateKeysMaxChunks() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetSponsorStateKeysMaxChunks", reflect.TypeOf((*MockRules)(nil).GetSponsorStateKeysMaxChunks)) -} - -// GetStorageKeyAllocateUnits mocks base method. -func (m *MockRules) GetStorageKeyAllocateUnits() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetStorageKeyAllocateUnits") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetStorageKeyAllocateUnits indicates an expected call of GetStorageKeyAllocateUnits. -func (mr *MockRulesMockRecorder) GetStorageKeyAllocateUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageKeyAllocateUnits", reflect.TypeOf((*MockRules)(nil).GetStorageKeyAllocateUnits)) -} - -// GetStorageKeyReadUnits mocks base method. -func (m *MockRules) GetStorageKeyReadUnits() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetStorageKeyReadUnits") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetStorageKeyReadUnits indicates an expected call of GetStorageKeyReadUnits. -func (mr *MockRulesMockRecorder) GetStorageKeyReadUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageKeyReadUnits", reflect.TypeOf((*MockRules)(nil).GetStorageKeyReadUnits)) -} - -// GetStorageKeyWriteUnits mocks base method. -func (m *MockRules) GetStorageKeyWriteUnits() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetStorageKeyWriteUnits") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetStorageKeyWriteUnits indicates an expected call of GetStorageKeyWriteUnits. -func (mr *MockRulesMockRecorder) GetStorageKeyWriteUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageKeyWriteUnits", reflect.TypeOf((*MockRules)(nil).GetStorageKeyWriteUnits)) -} - -// GetStorageValueAllocateUnits mocks base method. -func (m *MockRules) GetStorageValueAllocateUnits() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetStorageValueAllocateUnits") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetStorageValueAllocateUnits indicates an expected call of GetStorageValueAllocateUnits. -func (mr *MockRulesMockRecorder) GetStorageValueAllocateUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageValueAllocateUnits", reflect.TypeOf((*MockRules)(nil).GetStorageValueAllocateUnits)) -} - -// GetStorageValueReadUnits mocks base method. -func (m *MockRules) GetStorageValueReadUnits() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetStorageValueReadUnits") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetStorageValueReadUnits indicates an expected call of GetStorageValueReadUnits. -func (mr *MockRulesMockRecorder) GetStorageValueReadUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageValueReadUnits", reflect.TypeOf((*MockRules)(nil).GetStorageValueReadUnits)) -} - -// GetStorageValueWriteUnits mocks base method. -func (m *MockRules) GetStorageValueWriteUnits() uint64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetStorageValueWriteUnits") - ret0, _ := ret[0].(uint64) - return ret0 -} - -// GetStorageValueWriteUnits indicates an expected call of GetStorageValueWriteUnits. -func (mr *MockRulesMockRecorder) GetStorageValueWriteUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetStorageValueWriteUnits", reflect.TypeOf((*MockRules)(nil).GetStorageValueWriteUnits)) -} - -// GetUnitPriceChangeDenominator mocks base method. -func (m *MockRules) GetUnitPriceChangeDenominator() fees.Dimensions { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetUnitPriceChangeDenominator") - ret0, _ := ret[0].(fees.Dimensions) - return ret0 -} - -// GetUnitPriceChangeDenominator indicates an expected call of GetUnitPriceChangeDenominator. -func (mr *MockRulesMockRecorder) GetUnitPriceChangeDenominator() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetUnitPriceChangeDenominator", reflect.TypeOf((*MockRules)(nil).GetUnitPriceChangeDenominator)) -} - -// GetValidityWindow mocks base method. -func (m *MockRules) GetValidityWindow() int64 { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetValidityWindow") - ret0, _ := ret[0].(int64) - return ret0 -} - -// GetValidityWindow indicates an expected call of GetValidityWindow. -func (mr *MockRulesMockRecorder) GetValidityWindow() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetValidityWindow", reflect.TypeOf((*MockRules)(nil).GetValidityWindow)) -} - -// GetWindowTargetUnits mocks base method. -func (m *MockRules) GetWindowTargetUnits() fees.Dimensions { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "GetWindowTargetUnits") - ret0, _ := ret[0].(fees.Dimensions) - return ret0 -} - -// GetWindowTargetUnits indicates an expected call of GetWindowTargetUnits. -func (mr *MockRulesMockRecorder) GetWindowTargetUnits() *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetWindowTargetUnits", reflect.TypeOf((*MockRules)(nil).GetWindowTargetUnits)) -} diff --git a/go.mod b/go.mod index aa7521f18c..b0f7e5ac8c 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,6 @@ require ( go.opentelemetry.io/otel/sdk v1.22.0 go.opentelemetry.io/otel/trace v1.22.0 go.uber.org/atomic v1.11.0 - go.uber.org/mock v0.4.0 go.uber.org/zap v1.26.0 golang.org/x/crypto v0.21.0 golang.org/x/exp v0.0.0-20231127185646-65229373498e @@ -140,6 +139,7 @@ require ( go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0 // indirect go.opentelemetry.io/otel/metric v1.22.0 // indirect go.opentelemetry.io/proto/otlp v1.0.0 // indirect + go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.23.0 // indirect golang.org/x/sys v0.18.0 // indirect diff --git a/internal/mempool/mempool_test.go b/internal/mempool/mempool_test.go index 23a3253484..5af01037c6 100644 --- a/internal/mempool/mempool_test.go +++ b/internal/mempool/mempool_test.go @@ -9,7 +9,6 @@ import ( "github.com/ava-labs/avalanchego/ids" "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" "github.com/ava-labs/hypersdk/codec" "github.com/ava-labs/hypersdk/internal/trace" @@ -50,8 +49,6 @@ func GenerateTestItem(sponsor codec.Address, t int64) *TestItem { func TestMempool(t *testing.T) { require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() ctx := context.TODO() tracer, _ := trace.New(&trace.Config{Enabled: false}) @@ -71,8 +68,6 @@ func TestMempool(t *testing.T) { func TestMempoolAddDuplicates(t *testing.T) { require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() ctx := context.TODO() tracer, _ := trace.New(&trace.Config{Enabled: false}) txm := New[*TestItem](tracer, 3, 16) @@ -93,8 +88,6 @@ func TestMempoolAddExceedMaxSponsorSize(t *testing.T) { // Sponsor1 has reached his max // Sponsor2 is exempt from max size require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() ctx := context.TODO() tracer, _ := trace.New(&trace.Config{Enabled: false}) sponsor := codec.CreateAddress(4, ids.GenerateTestID()) @@ -111,8 +104,6 @@ func TestMempoolAddExceedMaxSponsorSize(t *testing.T) { func TestMempoolAddExceedMaxSize(t *testing.T) { require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() ctx := context.TODO() tracer, _ := trace.New(&trace.Config{Enabled: false}) @@ -141,8 +132,6 @@ func TestMempoolAddExceedMaxSize(t *testing.T) { func TestMempoolRemoveTxs(t *testing.T) { require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() ctx := context.TODO() tracer, _ := trace.New(&trace.Config{Enabled: false}) @@ -161,8 +150,6 @@ func TestMempoolRemoveTxs(t *testing.T) { func TestMempoolSetMinTimestamp(t *testing.T) { require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() ctx := context.TODO() tracer, _ := trace.New(&trace.Config{Enabled: false}) diff --git a/scripts/mock.gen.sh b/scripts/mock.gen.sh deleted file mode 100755 index 483fc0524b..0000000000 --- a/scripts/mock.gen.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2023, Ava Labs, Inc. All rights reserved. -# See the file LICENSE for licensing terms. - -set -e - -if ! [[ "$0" =~ scripts/mock.gen.sh ]]; then - echo "must be run from repository root" - exit 255 -fi - -SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) -# shellcheck source=/scripts/common/utils.sh -source "$SCRIPT_DIR"/common/utils.sh -# shellcheck source=/scripts/constants.sh -source "$SCRIPT_DIR"/constants.sh - -install_if_not_exists mockgen go.uber.org/mock/mockgen@v0.4.0 - -# tuples of (source interface import path, comma-separated interface names, output file path) -input="scripts/mocks.mockgen.txt" -while IFS= read -r line -do - IFS='=' read -r src_import_path interface_name output_path <<< "${line}" - package_name=$(basename "$(dirname "$output_path")") - echo "Generating ${output_path}..." - mockgen -package="${package_name}" -destination="${output_path}" "${src_import_path}" "${interface_name}" -done < "$input" - -echo "SUCCESS" diff --git a/scripts/mocks.mockgen.txt b/scripts/mocks.mockgen.txt deleted file mode 100644 index fa18799c73..0000000000 --- a/scripts/mocks.mockgen.txt +++ /dev/null @@ -1 +0,0 @@ -github.com/ava-labs/hypersdk/chain=Rules=chain/mock_rules.go diff --git a/vm/vm_test.go b/vm/vm_test.go index 46714c431f..22aceebcf5 100644 --- a/vm/vm_test.go +++ b/vm/vm_test.go @@ -13,7 +13,6 @@ import ( "github.com/ava-labs/avalanchego/snow" "github.com/ava-labs/avalanchego/utils/logging" "github.com/stretchr/testify/require" - "go.uber.org/mock/gomock" "github.com/ava-labs/hypersdk/chain" "github.com/ava-labs/hypersdk/genesis" @@ -25,8 +24,6 @@ import ( func TestBlockCache(t *testing.T) { require := require.New(t) - ctrl := gomock.NewController(t) - defer ctrl.Finish() // create a block with "Unknown" status blk := &chain.StatefulBlock{ @@ -40,7 +37,7 @@ func TestBlockCache(t *testing.T) { tracer, _ := trace.New(&trace.Config{Enabled: false}) bByID, _ := cache.NewFIFO[ids.ID, *chain.StatefulBlock](3) bByHeight, _ := cache.NewFIFO[uint64, ids.ID](3) - rules := chain.NewMockRules(ctrl) + rules := genesis.NewDefaultRules() vm := VM{ snowCtx: &snow.Context{Log: logging.NoLog{}, Metrics: metrics.NewPrefixGatherer()}, config: NewConfig(), @@ -66,7 +63,7 @@ func TestBlockCache(t *testing.T) { // put the block into the cache "vm.blocks" // and delete from "vm.verifiedBlocks" ctx := context.TODO() - rules.EXPECT().GetValidityWindow().Return(int64(60)) + rules.ValidityWindow = int64(60) vm.Accepted(ctx, blk) // we have not set up any persistent db