Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
migrate build to Travis #258 (#259)
Browse files Browse the repository at this point in the history
* add travis file
* update lint so it reports properly
* disable circleci
* separate test structure into Verify deps & Lint, Unit Tests, Race Tests, Integration Tests
* fix path issue now evident on ci build err
* fixed golangci version to latest stable
* Upgrade ci lint to go script and avoid cache issues #268
* fix lint issues #268
* bump go version for travis build to match go.mod version recently updated with Cosmos SDK upgrade
* add panic for err edge cases on os.Stat
* increase timeout to 10m since its failing on jenkins
* bump GOLANGCI_VERSION to 1.23.8 in order to try avoiding some weird errors on CI
  • Loading branch information
thomasmodeneis authored Apr 29, 2020
1 parent 7c5e0af commit 5417b4b
Show file tree
Hide file tree
Showing 14 changed files with 275 additions and 104 deletions.
90 changes: 0 additions & 90 deletions .circleci/config.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ build/

# Goland
.idea/
start.sh
start.sh

bin/
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ issues:
- text: "ST1016:"
linters:
- stylecheck

- linters:
- golint
text: "don't use ALL_CAPS in Go names;"
linters-settings:
dogsled:
max-blank-identifiers: 3
Expand Down
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: go

go:
- 1.14.x

cache:
directories:
- "$HOME/.cache/go-build"
- "$GOPATH/pkg/mod"

matrix:
include:
- name: Verify deps & Lint
script:
- rm -rf $HOME/.cache/golangci-lint || true
- make verify build
- make lint
- name: Unit Tests
script:
- make test-import
- make test-unit
- name: Race Tests
script:
- make test-race
- name: Integration Tests
script:
- make it-tests || true
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ test-cli:
@echo "NO CLI TESTS"

lint:
@echo "--> Running golangci-lint..."
@${GO_MOD} golangci-lint run ./... -c .golangci.yml --deadline=5m
@echo "--> Running ci lint..."
GOBIN=$(PWD)/bin go run scripts/ci.go lint

test-import:
@${GO_MOD} go test ./importer -v --vet=off --run=TestImportBlocks --datadir tmp \
--blockchain blockchain --timeout=5m
--blockchain blockchain --timeout=10m
# TODO: remove tmp directory after test run to avoid subsequent errors

test-rpc:
Expand Down
3 changes: 1 addition & 2 deletions cmd/emintcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import (
)

var (
cdc = codec.MakeCodec(app.ModuleBasics)
appCodec = codec.NewAppCodec(cdc)
cdc = codec.MakeCodec(app.ModuleBasics)
)

func main() {
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ require (
github.com/ethereum/go-ethereum v1.9.13
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
github.com/gogo/protobuf v1.3.1
github.com/golangci/golangci-lint v1.23.8 // indirect
github.com/gorilla/mux v1.7.4
github.com/huin/goupnp v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/onsi/ginkgo v1.10.3 // indirect
github.com/onsi/gomega v1.7.1 // indirect
github.com/pkg/errors v0.9.1
github.com/prometheus/tsdb v0.9.1 // indirect
github.com/regen-network/cosmos-proto v0.1.1-0.20200213154359-02baa11ea7c2
Expand Down
150 changes: 150 additions & 0 deletions go.sum

Large diffs are not rendered by default.

73 changes: 73 additions & 0 deletions scripts/ci.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// +build none

package main

import (
"flag"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)

const (
GOLANGCI_VERSION = "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.23.8"
)

func main() {

log.SetFlags(log.Lshortfile)

if _, err := os.Stat(filepath.Join("scripts", "ci.go")); os.IsNotExist(err) {
log.Fatal("should run build from root dir")
} else if err != nil {
panic(err)
}
if len(os.Args) < 2 {
log.Fatal("cmd required, eg: install")
}
switch os.Args[1] {
case "lint":
lint()
default:
log.Fatal("cmd not found", os.Args[1])
}
}

func lint() {

verbose := flag.Bool("v", false, "Whether to log verbosely")

// Make sure golangci-lint is available
argsGet := append([]string{"get", GOLANGCI_VERSION})
cmd := exec.Command(filepath.Join(runtime.GOROOT(), "bin", "go"), argsGet...)
out, err := cmd.CombinedOutput()
if err != nil {
log.Fatalf("could not list packages: %v\n%s", err, string(out))
}

cmd = exec.Command(filepath.Join(GOBIN(), "golangci-lint"))
cmd.Args = append(cmd.Args, "run", "--config", ".golangci.yml")

if *verbose {
cmd.Args = append(cmd.Args, "-v")
}

fmt.Println("Lint Ethermint", strings.Join(cmd.Args, " \\\n"))
cmd.Stderr, cmd.Stdout = os.Stderr, os.Stdout

if err := cmd.Run(); err != nil {
log.Fatal("Error: Could not Lint Ethermint. ", "error: ", err, ", cmd: ", cmd)
}
}

// GOBIN returns the GOBIN environment variable
func GOBIN() string {
if os.Getenv("GOBIN") == "" {
log.Fatal("GOBIN is not set")
}
return os.Getenv("GOBIN")
}
2 changes: 1 addition & 1 deletion scripts/integration-test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ init_func() {
"$PWD"/build/emintcli config trust-node true --home "$DATA_CLI_DIR$i"
echo "prepare genesis: Allocate genesis accounts"
"$PWD"/build/emintd add-genesis-account \
"$(emintcli keys show "$KEY$i" -a --home "$DATA_CLI_DIR$i" )" 1000000000000000000photon,1000000000000000000stake \
"$("$PWD"/build/emintcli keys show "$KEY$i" -a --home "$DATA_CLI_DIR$i" )" 1000000000000000000photon,1000000000000000000stake \
--home "$DATA_DIR$i" --home-client "$DATA_CLI_DIR$i"
echo "prepare genesis: Sign genesis transaction"
"$PWD"/build/emintd gentx --name $KEY"$i" --keyring-backend test --home "$DATA_DIR$i" --home-client "$DATA_CLI_DIR$i"
Expand Down
4 changes: 4 additions & 0 deletions x/evm/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ func (suite *EvmTestSuite) TestHandleMsgEthereumTx() {
for _, tc := range testCases {
suite.Run("", func() {
suite.SetupTest() // reset
//nolint
tc.malleate()

res, err := suite.handler(suite.ctx, tx)

//nolint
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
Expand Down Expand Up @@ -176,10 +178,12 @@ func (suite *EvmTestSuite) TestMsgEthermint() {
for _, tc := range testCases {
suite.Run("", func() {
suite.SetupTest() // reset
//nolint
tc.malleate()

res, err := suite.handler(suite.ctx, tx)

//nolint
if tc.expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
Expand Down
5 changes: 5 additions & 0 deletions x/evm/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ func (suite *KeeperTestSuite) TestQuerier() {

for i, tc := range testCases {
suite.Run("", func() {
//nolint
tc := tc
suite.SetupTest() // reset
//nolint
tc.malleate()

bz, err := suite.querier(suite.ctx, tc.path, abci.RequestQuery{})

//nolint
if tc.expPass {
//nolint
suite.Require().NoError(err, "valid test %d failed: %s", i, tc.msg)
suite.Require().NotZero(len(bz))
} else {
//nolint
suite.Require().Error(err, "invalid test %d passed: %s", i, tc.msg)
}
})
Expand Down
1 change: 0 additions & 1 deletion x/evm/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ type MsgEthereumTx struct {
Data TxData

// caches
hash atomic.Value
size atomic.Value
from atomic.Value
}
Expand Down
6 changes: 4 additions & 2 deletions x/evm/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ func TestMsgEthereumTxSig(t *testing.T) {

// require valid signature passes validation
msg := NewMsgEthereumTx(0, &addr1, nil, 100000, nil, []byte("test"))
msg.Sign(chainID, priv1.ToECDSA())
err := msg.Sign(chainID, priv1.ToECDSA())
require.Nil(t, err)

signer, err := msg.VerifySig(chainID)
require.NoError(t, err)
Expand All @@ -178,7 +179,8 @@ func TestMsgEthereumTxSig(t *testing.T) {

// require invalid chain ID fail validation
msg = NewMsgEthereumTx(0, &addr1, nil, 100000, nil, []byte("test"))
msg.Sign(chainID, priv1.ToECDSA())
err = msg.Sign(chainID, priv1.ToECDSA())
require.Nil(t, err)

signer, err = msg.VerifySig(big.NewInt(4))
require.Error(t, err)
Expand Down

0 comments on commit 5417b4b

Please sign in to comment.