Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,8 @@ openrpc.json
.pnpm/
.pnpm-store/
.qodo
nil/**/mock_*.go

# mockery output (excluding helper-tests)
nil/**/mock_*.go
!nil/**/mock_*_test.go
13 changes: 13 additions & 0 deletions .mockery.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I see, mockery has a completely different API for assertions in comparison to moq
So, all existing tests should also be adjusted

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
all: true
mock-build-tags: "test"
with-expecter: true
inpackage: true
recursive: true

packages:
nil/nil/client: {}
nil/internal/db: {}
nil/internal/vm: {}
nil/services/rollup: {}

include-regex: '^(Client|DB|RwTx|StateDBReadOnly|L1BlockFetcher)$'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still plenty of types used for mock generation which are not covered here
For instance, check this Makefile.inc

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,7 @@ clean:
go clean -cache
rm -fr build/*
rm -fr contracts/compiled/*

.PHONY: mocks
mocks: ssz_types
mockery --config=.mockery.yaml
23 changes: 2 additions & 21 deletions nil/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,5 @@ gen_rollup_contracts_bindings: \
$(root_relayer)/gen_l2_mocks

.PHONY: generate_mocks
generate_mocks: \
$(root_client)/client_generated_mock.go \
$(root_vm)/state_generated_mock.go \
$(root_db)/rwtx_generated_mock.go \
$(root_db)/db_generated_mock.go \
$(root_rollup)/l1_fetcher_generated_mock.go \

$(root_client)/client_generated_mock.go: $(root_client)/client.go ssz_types
cd $(root_client) && go generate

$(root_vm)/state_generated_mock.go: $(root_vm)/interface.go ssz_types
cd $(root_vm) && go generate

$(root_db)/rwtx_generated_mock.go: $(root_db)/kv.go ssz_types
cd $(root_db) && go generate -run="rwtx_" kv.go

$(root_db)/db_generated_mock.go: $(root_db)/kv.go ssz_types
cd $(root_db) && go generate -run="db_" kv.go

$(root_rollup)/l1_fetcher_generated_mock.go: $(root_rollup)/l1_fetcher.go
cd $(root_rollup) && go generate l1_fetcher.go
generate_mocks: ssz_types
mockery --config=.mockery.yaml
1 change: 0 additions & 1 deletion nil/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/NilFoundation/nil/nil/services/txnpool"
)

//go:generate go run github.com/matryer/moq -out client_generated_mock.go -rm -stub -with-resets . Client

type BatchRequest interface {
GetBlock(shardId types.ShardId, blockId any, fullTx bool) (uint64, error)
Expand Down
2 changes: 0 additions & 2 deletions nil/internal/db/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/NilFoundation/nil/nil/internal/types"
)

//go:generate go run github.com/matryer/moq -out rwtx_generated_mock.go -rm . RwTx
//go:generate go run github.com/matryer/moq -out db_generated_mock.go -rm . DB

type Timestamp uint64

Expand Down
1 change: 0 additions & 1 deletion nil/internal/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/NilFoundation/nil/nil/internal/types"
)

//go:generate go run github.com/matryer/moq -out state_generated_mock.go -rm -stub -with-resets . StateDBReadOnly

type StateDBReadOnly interface {
// IsInternalTransaction returns true if the transaction that initiated execution is internal.
Expand Down
6 changes: 3 additions & 3 deletions nil/services/relayer/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ $(root_relayer)/generate_l1_abi: $(root_relayer)/embed_l1_abi

.PHONY: $(root_relayer)/gen_l1_mocks
$(root_relayer)/gen_l1_mocks: $(root_relayer)/generate_l1_abi
cd $(root_relayer)/internal/l1 && go run github.com/matryer/moq -out eth_client_generated_mock.go -rm -stub -with-resets . EthClient
cd $(root_relayer)/internal/l1 && go run github.com/matryer/moq -out l1_contract_generated_mock.go -rm -stub -with-resets . L1Contract
cd $(root_relayer)/internal/l1 && mockery --name=EthClient
cd $(root_relayer)/internal/l1 && mockery --name=L1Contract

.PHONY: $(root_relayer)/gen_l2_mocks
$(root_relayer)/gen_l2_mocks: $(root_relayer)/embed_l2_abi
cd $(root_relayer)/internal/l2 && go run github.com/matryer/moq -out l2_contract_generated_mock.go -rm -stub -with-resets . L2Contract
cd $(root_relayer)/internal/l2 && mockery --name=L2Contract
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try to build a project?

1 change: 0 additions & 1 deletion nil/services/rollup/l1_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

//go:generate go run github.com/matryer/moq -out l1_fetcher_generated_mock.go -rm -stub -with-resets . L1BlockFetcher

const pollInterval = 5 * time.Second

Expand Down