Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt Mockery configuration #52

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
45 changes: 45 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
with-expecter: true
dir: "mocks"
filename: "{{.InterfaceName | lower }}.generated.go"
mockname: "{{.InterfaceName}}"
outpkg: "mocks"
packages:
github.com/ethereum/go-ethereum/event:
config:
interfaces:
Subscription:
config:
github.com/0xPolygon/cdk-data-availability/db:
config:
interfaces:
DB:
config:
Tx:
config:
github.com/0xPolygon/cdk-data-availability/client:
config:
interfaces:
ClientFactory:
config:
Client:
config:
github.com/0xPolygon/cdk-data-availability/etherman:
config:
interfaces:
Etherman:
config:
github.com/0xPolygon/cdk-data-availability/sequencer:
config:
interfaces:
ISequencerTracker:
config:
filename: sequencer_tracker.generated.go
github.com/0xPolygon/cdk-data-availability/types:
config:
interfaces:
IEthClient:
config:
filename: eth_client.generated.go
IEthClientFactory:
config:
filename: eth_client_factory.generated.go
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ LDFLAGS += -X 'github.com/0xPolygon/cdk-data-availability.BuildDate=$(DATE)'

.PHONY: generate
generate: ## Generates mocks and other autogenerated types
$(GOENVVARS) go generate ./...
mockery

.PHONY: build
build: ## Builds the binary locally into ./dist
Expand Down
26 changes: 11 additions & 15 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ import (
"github.com/ethereum/go-ethereum/common"
)

// IClientFactory interface for the client factory
//
//go:generate mockery --name IClientFactory --output ../mocks --case=underscore --filename client_factory.generated.go
type IClientFactory interface {
New(url string) IClient
// ClientFactory interface for the client factory
type ClientFactory interface {
New(url string) Client
}

// IClient is the interface that defines the implementation of all the endpoints
//
//go:generate mockery --name IClient --output ../mocks --case=underscore --filename client.generated.go
type IClient interface {
// Client is the interface that defines the implementation of all the endpoints
type Client interface {
GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error)
SignSequence(signedSequence types.SignedSequence) ([]byte, error)
}
Expand All @@ -29,25 +25,25 @@ type IClient interface {
type Factory struct{}

// New returns an implementation of the data committee node client
func (f *Factory) New(url string) IClient {
func (f *Factory) New(url string) Client {
return New(url)
}

// Client wraps all the available endpoints of the data abailability committee node server
type Client struct {
type client struct {
url string
}

// New returns a client ready to be used
func New(url string) *Client {
return &Client{
func New(url string) *client {
return &client{
url: url,
}
}

// SignSequence sends a request to sign the given sequence by the data committee member
// if successful returns the signature. The signature should be validated after using this method!
func (c *Client) SignSequence(signedSequence types.SignedSequence) ([]byte, error) {
func (c *client) SignSequence(signedSequence types.SignedSequence) ([]byte, error) {
response, err := rpc.JSONRPCCall(c.url, "datacom_signSequence", signedSequence)
if err != nil {
return nil, err
Expand All @@ -66,7 +62,7 @@ func (c *Client) SignSequence(signedSequence types.SignedSequence) ([]byte, erro
}

// GetOffChainData returns data based on it's hash
func (c *Client) GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error) {
func (c *client) GetOffChainData(ctx context.Context, hash common.Hash) ([]byte, error) {
response, err := rpc.JSONRPCCallWithContext(ctx, c.url, "sync_getOffChainData", hash)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestClient_GetOffChainData(t *testing.T) {
}))
defer svr.Close()

c := &Client{url: svr.URL}
c := &client{url: svr.URL}

got, err := c.GetOffChainData(context.Background(), tt.hash)
if tt.err != nil {
Expand Down
4 changes: 0 additions & 4 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ var (
)

// DB defines functions that a DB instance should implement
//
//go:generate mockery --name DB --output ../mocks --case=underscore --filename db.generated.go
type DB interface {
BeginStateTransaction(ctx context.Context) (Tx, error)
Exists(ctx context.Context, key common.Hash) bool
Expand All @@ -29,8 +27,6 @@ type DB interface {
}

// Tx is the interface that defines functions a db tx has to implement
//
//go:generate mockery --name Tx --output ../mocks --case=underscore --filename tx.generated.go
type Tx interface {
sqlx.ExecerContext
sqlx.QueryerContext
Expand Down
2 changes: 0 additions & 2 deletions etherman/etherman.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
)

// Etherman defines functions that should be implemented by Etherman
//
//go:generate mockery --name Etherman --output ../mocks --case=underscore --filename etherman.generated.go
type Etherman interface {
GetCurrentDataCommittee() (*DataCommittee, error)
GetCurrentDataCommitteeMembers() ([]DataCommitteeMember, error)
Expand Down
81 changes: 73 additions & 8 deletions mocks/client.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 0 additions & 47 deletions mocks/client_factory.generated.go

This file was deleted.

83 changes: 83 additions & 0 deletions mocks/clientfactory.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading