-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
178 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ SWAGGER = $(GOBIN)/swagger | |
PROTOC_GEN_GO = $(GOBIN)/protoc-gen-go | ||
PROTOC_GEN_GO_GRPC = $(GOBIN)/protoc-gen-go-grpc | ||
GOMERGETYPES = $(GOBIN)/gomergetypes | ||
MOCKGEN = $(GOBIN)/mockgen | ||
|
||
PROTOC = ./toolbin/protoc --plugin=protoc-gen-go=$(PROTOC_GEN_GO) --plugin=protoc-gen-go-grpc=$(PROTOC_GEN_GO_GRPC) | ||
|
||
|
@@ -32,6 +33,8 @@ tools: | |
@go install github.com/golangci/golangci-lint/cmd/[email protected] | ||
@go install golang.org/x/tools/cmd/[email protected] | ||
|
||
@go install github.com/golang/mock/mockgen@5b455625bd2c8ffbcc0de6a0873f864ba3820904 | ||
|
||
@go install github.com/go-swagger/go-swagger/cmd/[email protected] | ||
|
||
@go install google.golang.org/protobuf/cmd/[email protected] | ||
|
@@ -67,18 +70,19 @@ protogen: require-tools | |
|
||
.PHONY: mocks | ||
mocks: | ||
mockgen -source ethereum/client.go -destination ethereum/mocks/mock_client.go | ||
mockgen -source feeds/interfaces.go -destination feeds/mocks/mock_feeds.go | ||
mockgen -source ethereum/contract_backend.go -destination ethereum/mocks/mock_ethclient.go | ||
mockgen -source registry/client.go -destination registry/mocks/mock_client.go | ||
mockgen -source registry/version.go -destination registry/mocks/mock_version.go | ||
mockgen -source domain/registry/regmsg/regmsg.go -destination domain/registry/regmsg/mocks/mock_regmsg.go | ||
mockgen -source ipfs/client.go -destination ipfs/mocks/mock_client.go | ||
mockgen -source release/client.go -destination release/mocks/mock_client.go | ||
mockgen -source domain/ethereum.go -destination domain/mocks/mock_ethereum.go | ||
mockgen -source manifest/client.go -destination manifest/mocks/mock_client.go | ||
mockgen -source clients/graphql/client.go -destination clients/mocks/mock_graphql_client.go | ||
mockgen -source utils/ethutils/iterator.go -destination utils/ethutils/mocks/mock_iterator.go | ||
$(MOCKGEN) -source ethereum/client.go -destination ethereum/mocks/mock_client.go | ||
$(MOCKGEN) -source feeds/interfaces.go -destination feeds/mocks/mock_feeds.go | ||
$(MOCKGEN) -source ethereum/contract_backend.go -destination ethereum/mocks/mock_ethclient.go | ||
$(MOCKGEN) -source registry/client.go -destination registry/mocks/mock_client.go | ||
$(MOCKGEN) -source registry/version.go -destination registry/mocks/mock_version.go | ||
$(MOCKGEN) -source domain/registry/regmsg/regmsg.go -destination domain/registry/regmsg/mocks/mock_regmsg.go | ||
$(MOCKGEN) -source ipfs/client.go -destination ipfs/mocks/mock_client.go | ||
$(MOCKGEN) -source release/client.go -destination release/mocks/mock_client.go | ||
$(MOCKGEN) -source domain/ethereum.go -destination domain/mocks/mock_ethereum.go | ||
$(MOCKGEN) -source manifest/client.go -destination manifest/mocks/mock_client.go | ||
$(MOCKGEN) -source clients/graphql/client.go -destination clients/mocks/mock_graphql_client.go | ||
$(MOCKGEN) -source utils/ethutils/iterator.go -destination utils/ethutils/mocks/mock_iterator.go | ||
$(MOCKGEN) -source inspect/proxy_api.go -destination inspect/mocks/mock_proxy_api.go | ||
|
||
.PHONY: test | ||
test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package inspect | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
mock_inspect "github.com/forta-network/forta-core-go/inspect/mocks" | ||
"github.com/golang/mock/gomock" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCalculateOffsetStats(t *testing.T) { | ||
// Create a test context with a timeout | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
||
ctrl := gomock.NewController(t) | ||
primaryClient := mock_inspect.NewMockProxyAPIClient(ctrl) | ||
secondaryClient := mock_inspect.NewMockProxyAPIClient(ctrl) | ||
|
||
// Test when everything is successful | ||
primaryClient.EXPECT().BlockNumber(gomock.Any()).Return(uint64(5), nil) | ||
primaryClient.EXPECT().BlockByNumber(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() | ||
secondaryClient.EXPECT().BlockByNumber(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes() | ||
stats, err := calculateOffsetStats(ctx, primaryClient, secondaryClient) | ||
assert.NoError(t, err) | ||
assert.Equal(t, stats, offsetStats{0, 0, 0, 10}) | ||
|
||
// Test when collectOffsetData returns an error | ||
primaryClient.EXPECT().BlockNumber(gomock.Any()).Return(uint64(0), fmt.Errorf("error")) | ||
|
||
stats, err = calculateOffsetStats(ctx, primaryClient, secondaryClient) | ||
assert.Error(t, err) | ||
assert.Equal(t, stats, offsetStats{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.