Merge branch 'develop' into feature/linter-in-travis
# Conflicts: # .travis.yml # Makefile
This commit is contained in:
commit
d1c47c5358
|
@ -12,11 +12,12 @@ dist: trusty
|
|||
|
||||
install:
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
- make mock-install
|
||||
- make mock
|
||||
- make lint-deps
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- stage: lint
|
||||
script: make lint
|
||||
- stage: Lint
|
||||
script: make lint
|
||||
- stage: Test unit and integration
|
||||
|
|
59
Makefile
59
Makefile
|
@ -1,6 +1,8 @@
|
|||
.PHONY: statusgo all test xgo clean help
|
||||
.PHONY: statusgo-android statusgo-ios
|
||||
|
||||
include ./static/tools/mk/lint.mk
|
||||
|
||||
GOBIN = build/bin
|
||||
GO ?= latest
|
||||
|
||||
|
@ -79,56 +81,6 @@ generate: ##@other Regenerate assets and other auto-generated stuff
|
|||
build/env.sh go generate ./static
|
||||
rm ./static/scripts/web3.js
|
||||
|
||||
lint-deps:
|
||||
go get -u github.com/alecthomas/gometalinter
|
||||
gometalinter --install
|
||||
|
||||
lint-cur:
|
||||
gometalinter --disable-all --enable=deadcode $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
|
||||
lint: ##@tests Run meta linter on code
|
||||
@echo "Linter: go vet\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=vet $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: go vet --shadow\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=vetshadow $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: gofmt\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=gofmt $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: goimports\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=goimports $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: golint\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=golint $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: deadcode\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=deadcode $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: misspell\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=misspell $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: unparam\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --deadline 45s --enable=unparam $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: unused\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --deadline 45s --enable=unused $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: gocyclo\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=gocyclo --cyclo-over=20 $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: errcheck\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=errcheck $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: dupl\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --exclude='.*_test.go' --disable-all --enable=dupl --dupl-threshold=100 extkeys cmd/... geth/... | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: ineffassign\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=ineffassign $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: interfacer\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=interfacer $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: unconvert\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=unconvert $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: goconst\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=goconst $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: staticcheck\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --deadline 45s --enable=staticcheck $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: gas\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=gas $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: varcheck\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --deadline 60s --enable=varcheck $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: structcheck\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=structcheck $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
@echo "Linter: gosimple\n--------------------"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --deadline 45s --enable=gosimple $(LINT_FOLDERS) | grep -v -f ./static/config/linter_exclude_list.txt || echo "OK!"
|
||||
|
||||
mock-install: ##@other Install mocking tools
|
||||
go get -u github.com/golang/mock/mockgen
|
||||
|
@ -146,6 +98,7 @@ test-unit-coverage: ##@tests Run unit and integration tests with coverage
|
|||
|
||||
test-e2e: ##@tests Run e2e tests
|
||||
# order: reliability then alphabetical
|
||||
# TODO(tiabc): make a single command out of them adding `-p 1` flag.
|
||||
build/env.sh go test -timeout 5m ./e2e/accounts/...
|
||||
build/env.sh go test -timeout 5m ./e2e/api/...
|
||||
build/env.sh go test -timeout 5m ./e2e/node/...
|
||||
|
@ -159,8 +112,4 @@ ci: lint mock-install mock test-unit test-e2e ##@tests Run all linters and tests
|
|||
|
||||
clean: ##@other Cleanup
|
||||
rm -fr build/bin/*
|
||||
rm coverage.out coverage-all.out coverage.html
|
||||
|
||||
|
||||
LINT_EXCLUDE := --exclude='.*_mock.go' --exclude='geth/jail/doc.go'
|
||||
LINT_FOLDERS := extkeys cmd/... geth/... e2e/...
|
||||
rm coverage.out coverage-all.out coverage.html
|
|
@ -2,8 +2,8 @@ package main
|
|||
|
||||
import "C"
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/big"
|
||||
"os"
|
||||
|
@ -18,10 +18,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/core"
|
||||
gethparams "github.com/ethereum/go-ethereum/params"
|
||||
|
||||
"fmt"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/status-im/status-go/geth/account"
|
||||
"github.com/status-im/status-go/geth/common"
|
||||
"github.com/status-im/status-go/geth/params"
|
||||
|
@ -35,7 +31,7 @@ import (
|
|||
const zeroHash = "0x0000000000000000000000000000000000000000000000000000000000000000"
|
||||
|
||||
var nodeConfigJSON = `{
|
||||
"NetworkId": ` + strconv.Itoa(params.RopstenNetworkID) + `,
|
||||
"NetworkId": ` + strconv.Itoa(params.StatusChainNetworkID) + `,
|
||||
"DataDir": "` + TestDataDir + `",
|
||||
"HTTPPort": ` + strconv.Itoa(TestConfig.Node.HTTPPort) + `,
|
||||
"WSPort": ` + strconv.Itoa(TestConfig.Node.WSPort) + `,
|
||||
|
@ -176,6 +172,7 @@ func testGetDefaultConfig(t *testing.T) bool {
|
|||
{params.MainNetworkID, gethparams.MainnetChainConfig},
|
||||
{params.RopstenNetworkID, gethparams.TestnetChainConfig},
|
||||
{params.RinkebyNetworkID, gethparams.RinkebyChainConfig},
|
||||
// TODO(tiabc): The same for params.StatusChainNetworkID
|
||||
}
|
||||
for i := range networks {
|
||||
network := networks[i]
|
||||
|
@ -217,18 +214,14 @@ func testResetChainData(t *testing.T) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
if err := EnsureNodeSync(statusAPI.NodeManager()); err != nil {
|
||||
t.Errorf("cannot ensure node synchronization: %v", err)
|
||||
return false
|
||||
}
|
||||
|
||||
EnsureNodeSync(statusAPI.NodeManager())
|
||||
testCompleteTransaction(t)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func testStopResumeNode(t *testing.T) bool { //nolint: gocyclo
|
||||
// to make sure that we start with empty account (which might get populated during previous tests)
|
||||
// to make sure that we start with empty account (which might have gotten populated during previous tests)
|
||||
if err := statusAPI.Logout(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -272,6 +265,8 @@ func testStopResumeNode(t *testing.T) bool { //nolint: gocyclo
|
|||
// nolint: dupl
|
||||
stopNodeFn := func() bool {
|
||||
response := common.APIResponse{}
|
||||
// FIXME(tiabc): Implement https://github.com/status-im/status-go/issues/254 to avoid
|
||||
// 9-sec timeout below after stopping the node.
|
||||
rawResponse = StopNode()
|
||||
|
||||
if err = json.Unmarshal([]byte(C.GoString(rawResponse)), &response); err != nil {
|
||||
|
@ -289,6 +284,8 @@ func testStopResumeNode(t *testing.T) bool { //nolint: gocyclo
|
|||
// nolint: dupl
|
||||
resumeNodeFn := func() bool {
|
||||
response := common.APIResponse{}
|
||||
// FIXME(tiabc): Implement https://github.com/status-im/status-go/issues/254 to avoid
|
||||
// 10-sec timeout below after resuming the node.
|
||||
rawResponse = StartNode(C.CString(nodeConfigJSON))
|
||||
|
||||
if err = json.Unmarshal([]byte(C.GoString(rawResponse)), &response); err != nil {
|
||||
|
@ -306,11 +303,14 @@ func testStopResumeNode(t *testing.T) bool { //nolint: gocyclo
|
|||
if !stopNodeFn() {
|
||||
return false
|
||||
}
|
||||
|
||||
time.Sleep(9 * time.Second) // allow to stop
|
||||
|
||||
if !resumeNodeFn() {
|
||||
return false
|
||||
}
|
||||
|
||||
time.Sleep(5 * time.Second) // allow to start (instead of using blocking version of start, of filter event)
|
||||
time.Sleep(10 * time.Second) // allow to start (instead of using blocking version of start, of filter event)
|
||||
|
||||
// now, verify that we still have account logged in
|
||||
whisperService, err = statusAPI.NodeManager().WhisperService()
|
||||
|
@ -730,11 +730,7 @@ func testCompleteTransaction(t *testing.T) bool {
|
|||
txQueue := txQueueManager.TransactionQueue()
|
||||
|
||||
txQueue.Reset()
|
||||
|
||||
if err := EnsureNodeSync(statusAPI.NodeManager()); err != nil {
|
||||
t.Errorf("cannot ensure node synchronization: %v", err)
|
||||
return false
|
||||
}
|
||||
EnsureNodeSync(statusAPI.NodeManager())
|
||||
|
||||
// log into account from which transactions will be sent
|
||||
if err := statusAPI.SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password); err != nil {
|
||||
|
@ -1368,10 +1364,7 @@ func startTestNode(t *testing.T) <-chan struct{} {
|
|||
// sync
|
||||
if syncRequired {
|
||||
t.Logf("Sync is required")
|
||||
if err := EnsureNodeSync(statusAPI.NodeManager()); err != nil {
|
||||
t.Errorf("cannot ensure node synchronization: %v", err)
|
||||
return
|
||||
}
|
||||
EnsureNodeSync(statusAPI.NodeManager())
|
||||
} else {
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ type AccountsRPCTestSuite struct {
|
|||
}
|
||||
|
||||
func (s *AccountsTestSuite) TestRPCEthAccounts() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
// log into test account
|
||||
|
@ -40,6 +40,9 @@ func (s *AccountsTestSuite) TestRPCEthAccounts() {
|
|||
}
|
||||
|
||||
func (s *AccountsTestSuite) TestRPCEthAccountsWithUpstream() {
|
||||
// FIXME(tiabc): Stop skipping after https://github.com/status-im/status-go/issues/424
|
||||
s.T().Skip()
|
||||
|
||||
s.StartTestBackend(
|
||||
params.RopstenNetworkID,
|
||||
e2e.WithUpstream("https://ropsten.infura.io/z6GCTmjdP3FETEJmMBI4"),
|
||||
|
|
|
@ -56,7 +56,7 @@ func (s *APITestSuite) TestRaceConditions() {
|
|||
progress := make(chan struct{}, cnt)
|
||||
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
nodeConfig1, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
||||
nodeConfig1, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
s.NoError(err)
|
||||
|
||||
nodeConfig2, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
|
||||
|
@ -129,7 +129,7 @@ func (s *APITestSuite) TestCellsRemovedAfterSwitchAccount() {
|
|||
}
|
||||
)
|
||||
|
||||
config, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
||||
config, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(err)
|
||||
err = s.api.StartNode(config)
|
||||
require.NoError(err)
|
||||
|
@ -166,7 +166,7 @@ func (s *APITestSuite) TestLogoutRemovesCells() {
|
|||
require = s.Require()
|
||||
)
|
||||
|
||||
config, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
||||
config, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(err)
|
||||
err = s.api.StartNode(config)
|
||||
require.NoError(err)
|
||||
|
|
|
@ -34,7 +34,7 @@ func (s *APIBackendTestSuite) TestRaceConditions() {
|
|||
progress := make(chan struct{}, cnt)
|
||||
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
nodeConfig1, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
||||
nodeConfig1, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
require.NoError(err)
|
||||
|
||||
nodeConfig2, err := e2e.MakeTestNodeConfig(params.RinkebyNetworkID)
|
||||
|
@ -242,7 +242,7 @@ func (s *APIBackendTestSuite) TestResetChainData() {
|
|||
s.StartTestBackend(params.RinkebyNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
s.True(s.Backend.IsNodeRunning())
|
||||
nodeReady, err := s.Backend.ResetChainData()
|
||||
|
|
|
@ -36,10 +36,10 @@ func (s *JailRPCTestSuite) SetupTest() {
|
|||
}
|
||||
|
||||
func (s *JailRPCTestSuite) TestJailRPCSend() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
// load Status JS and add test command to it
|
||||
s.jail.BaseJS(baseStatusJSCode)
|
||||
|
@ -69,7 +69,7 @@ func (s *JailRPCTestSuite) TestJailRPCSend() {
|
|||
}
|
||||
|
||||
func (s *JailRPCTestSuite) TestIsConnected() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.jail.Parse(testChatID, "")
|
||||
|
@ -96,7 +96,7 @@ func (s *JailRPCTestSuite) TestIsConnected() {
|
|||
|
||||
// regression test: eth_getTransactionReceipt with invalid transaction hash should return null
|
||||
func (s *JailRPCTestSuite) TestRegressionGetTransactionReceipt() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
rpcClient := s.Backend.NodeManager().RPCClient()
|
||||
|
@ -109,10 +109,10 @@ func (s *JailRPCTestSuite) TestRegressionGetTransactionReceipt() {
|
|||
}
|
||||
|
||||
func (s *JailRPCTestSuite) TestContractDeployment() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
// obtain VM for a given chat (to send custom JS to jailed version of Send())
|
||||
s.jail.Parse(testChatID, "")
|
||||
|
@ -195,10 +195,10 @@ func (s *JailRPCTestSuite) TestContractDeployment() {
|
|||
}
|
||||
|
||||
func (s *JailRPCTestSuite) TestJailVMPersistence() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
// log into account from which transactions will be sent
|
||||
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
|
||||
|
|
|
@ -194,7 +194,7 @@ func (s *ManagerTestSuite) TestReferencesWithStartedNode() {
|
|||
}
|
||||
|
||||
func (s *ManagerTestSuite) TestNodeStartStop() {
|
||||
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
||||
nodeConfig, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
s.NoError(err)
|
||||
|
||||
// try stopping non-started node
|
||||
|
@ -296,7 +296,7 @@ func (s *ManagerTestSuite) TestResetChainData() {
|
|||
s.StartTestNode(params.RinkebyNetworkID)
|
||||
defer s.StopTestNode()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.NodeManager), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.NodeManager)
|
||||
|
||||
// reset chain data
|
||||
nodeReady, err := s.NodeManager.ResetChainData()
|
||||
|
@ -446,8 +446,7 @@ func (s *ManagerTestSuite) TestRaceConditions() {
|
|||
}
|
||||
|
||||
time.Sleep(2 * time.Second) // so that we see some logs
|
||||
nodeStopped, e := s.NodeManager.StopNode() // just in case we have a node running
|
||||
s.NoError(e)
|
||||
nodeStopped, _ := s.NodeManager.StopNode() // just in case we have a node running
|
||||
|
||||
if nodeStopped != nil {
|
||||
<-nodeStopped
|
||||
|
|
|
@ -6,10 +6,13 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/status-im/status-go/e2e"
|
||||
"github.com/status-im/status-go/geth/node"
|
||||
"github.com/status-im/status-go/geth/params"
|
||||
. "github.com/status-im/status-go/testing"
|
||||
"github.com/stretchr/testify/suite"
|
||||
)
|
||||
|
||||
|
@ -119,7 +122,7 @@ func (s *RPCTestSuite) TestCallRPC() {
|
|||
|
||||
// TestCallRawResult checks if returned response is a valid JSON-RPC response.
|
||||
func (s *RPCTestSuite) TestCallRawResult() {
|
||||
nodeConfig, err := e2e.MakeTestNodeConfig(params.RopstenNetworkID)
|
||||
nodeConfig, err := e2e.MakeTestNodeConfig(params.StatusChainNetworkID)
|
||||
s.NoError(err)
|
||||
|
||||
nodeStarted, err := s.NodeManager.StartNode(nodeConfig)
|
||||
|
@ -138,20 +141,19 @@ func (s *RPCTestSuite) TestCallRawResult() {
|
|||
// TestCallContextResult checks if result passed to CallContext
|
||||
// is set accordingly to its underlying memory layout.
|
||||
func (s *RPCTestSuite) TestCallContextResult() {
|
||||
s.StartTestNode(
|
||||
params.RopstenNetworkID,
|
||||
e2e.WithUpstream("https://ropsten.infura.io/nKmXgiFgc2KqtoQ8BCGJ"),
|
||||
)
|
||||
s.StartTestNode(params.StatusChainNetworkID)
|
||||
defer s.StopTestNode()
|
||||
|
||||
EnsureNodeSync(s.NodeManager)
|
||||
|
||||
client := s.NodeManager.RPCClient()
|
||||
s.NotNil(client)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
var blockNumber hexutil.Uint
|
||||
err := client.CallContext(ctx, &blockNumber, "eth_blockNumber")
|
||||
var balance hexutil.Big
|
||||
err := client.CallContext(ctx, &balance, "eth_getBalance", "0xAdAf150b905Cf5E6A778E553E15A139B6618BbB7", "latest")
|
||||
s.NoError(err)
|
||||
s.True(blockNumber > 0, "blockNumber should be higher than 0")
|
||||
s.True(balance.ToInt().Cmp(big.NewInt(0)) > 0, "balance should be higher than 0")
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@ import (
|
|||
// NodeManagerTestSuite defines a test suit with NodeManager.
|
||||
type NodeManagerTestSuite struct {
|
||||
suite.Suite
|
||||
NodeManager common.NodeManager
|
||||
nodeSyncCompleted bool
|
||||
NodeManager common.NodeManager
|
||||
}
|
||||
|
||||
// StartTestNode initiazes a NodeManager instances with configuration retrieved
|
||||
|
@ -52,8 +51,7 @@ func (s *NodeManagerTestSuite) StopTestNode() {
|
|||
// and a few utility methods to start and stop node or get various services.
|
||||
type BackendTestSuite struct {
|
||||
suite.Suite
|
||||
Backend *api.StatusBackend
|
||||
nodeSyncCompleted bool
|
||||
Backend *api.StatusBackend
|
||||
}
|
||||
|
||||
// SetupTest initializes Backend.
|
||||
|
|
|
@ -9,8 +9,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
gethcommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
@ -34,10 +32,10 @@ type TransactionsTestSuite struct {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestCallRPCSendTransaction() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
err := s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)
|
||||
s.NoError(err)
|
||||
|
@ -82,6 +80,9 @@ func (s *TransactionsTestSuite) TestCallRPCSendTransaction() {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestCallRPCSendTransactionUpstream() {
|
||||
// FIXME(tiabc): Stop skipping after https://github.com/status-im/status-go/issues/424
|
||||
s.T().Skip()
|
||||
|
||||
s.StartTestBackend(
|
||||
params.RopstenNetworkID,
|
||||
e2e.WithUpstream("https://ropsten.infura.io/nKmXgiFgc2KqtoQ8BCGJ"),
|
||||
|
@ -138,10 +139,10 @@ func (s *TransactionsTestSuite) TestCallRPCSendTransactionUpstream() {
|
|||
|
||||
// FIXME(tiabc): Sometimes it fails due to "no suitable peers found".
|
||||
func (s *TransactionsTestSuite) TestSendContractTx() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
sampleAddress, _, _, err := s.Backend.AccountManager().CreateAccount(TestConfig.Account1.Password)
|
||||
s.NoError(err)
|
||||
|
@ -224,94 +225,12 @@ func (s *TransactionsTestSuite) TestSendContractTx() {
|
|||
s.Zero(s.TxQueueManager().TransactionQueue().Count(), "tx queue must be empty at this point")
|
||||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestSendEtherTx() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
|
||||
backend := s.LightEthereumService().StatusBackend
|
||||
s.NotNil(backend)
|
||||
|
||||
// create an account
|
||||
sampleAddress, _, _, err := s.Backend.AccountManager().CreateAccount(TestConfig.Account1.Password)
|
||||
s.NoError(err)
|
||||
|
||||
completeQueuedTransaction := make(chan struct{})
|
||||
|
||||
// replace transaction notification handler
|
||||
var txHash = gethcommon.Hash{}
|
||||
signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { // nolint: dupl
|
||||
var envelope signal.Envelope
|
||||
err := json.Unmarshal([]byte(jsonEvent), &envelope)
|
||||
s.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent))
|
||||
|
||||
if envelope.Type == txqueue.EventTransactionQueued {
|
||||
event := envelope.Event.(map[string]interface{})
|
||||
log.Info("transaction queued (will be completed shortly)", "id", event["id"].(string))
|
||||
|
||||
// the first call will fail (we are not logged in, but trying to complete tx)
|
||||
log.Info("trying to complete with no user logged in")
|
||||
txHash, err = s.Backend.CompleteTransaction(
|
||||
common.QueuedTxID(event["id"].(string)),
|
||||
TestConfig.Account1.Password,
|
||||
)
|
||||
s.EqualError(
|
||||
err,
|
||||
account.ErrNoAccountSelected.Error(),
|
||||
fmt.Sprintf("expected error on queued transaction[%v] not thrown", event["id"]),
|
||||
)
|
||||
|
||||
// the second call will also fail (we are logged in as different user)
|
||||
log.Info("trying to complete with invalid user")
|
||||
err = s.Backend.AccountManager().SelectAccount(sampleAddress, TestConfig.Account1.Password)
|
||||
s.NoError(err)
|
||||
txHash, err = s.Backend.CompleteTransaction(
|
||||
common.QueuedTxID(event["id"].(string)), TestConfig.Account1.Password)
|
||||
s.EqualError(
|
||||
err,
|
||||
txqueue.ErrInvalidCompleteTxSender.Error(),
|
||||
fmt.Sprintf("expected error on queued transaction[%v] not thrown", event["id"]),
|
||||
)
|
||||
|
||||
// the third call will work as expected (as we are logged in with correct credentials)
|
||||
log.Info("trying to complete with correct user, this should succeed")
|
||||
s.NoError(s.Backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password))
|
||||
txHash, err = s.Backend.CompleteTransaction(
|
||||
common.QueuedTxID(event["id"].(string)),
|
||||
TestConfig.Account1.Password,
|
||||
)
|
||||
s.NoError(err, fmt.Sprintf("cannot complete queued transaction[%v]", event["id"]))
|
||||
|
||||
log.Info("contract transaction complete", "URL", "https://ropsten.etherscan.io/tx/"+txHash.Hex())
|
||||
close(completeQueuedTransaction)
|
||||
return
|
||||
}
|
||||
})
|
||||
|
||||
// this call blocks, up until Complete Transaction is called
|
||||
txHashCheck, err := s.Backend.SendTransaction(context.TODO(), common.SendTxArgs{
|
||||
From: common.FromAddress(TestConfig.Account1.Address),
|
||||
To: common.ToAddress(TestConfig.Account2.Address),
|
||||
Value: (*hexutil.Big)(big.NewInt(1000000000000)),
|
||||
})
|
||||
s.NoError(err, "cannot send transaction")
|
||||
|
||||
select {
|
||||
case <-completeQueuedTransaction:
|
||||
case <-time.After(2 * time.Minute):
|
||||
s.FailNow("completing transaction timed out")
|
||||
}
|
||||
|
||||
s.Equal(txHashCheck.Hex(), txHash.Hex(), "transaction hash returned from SendTransaction is invalid")
|
||||
s.False(reflect.DeepEqual(txHashCheck, gethcommon.Hash{}), "transaction was never queued or completed")
|
||||
s.Zero(s.Backend.TxQueueManager().TransactionQueue().Count(), "tx queue must be empty at this point")
|
||||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestSendEtherOnStatusChainTx() {
|
||||
func (s *TransactionsTestSuite) TestSendEther() {
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
backend := s.LightEthereumService().StatusBackend
|
||||
s.NotNil(backend)
|
||||
|
||||
|
@ -390,6 +309,9 @@ func (s *TransactionsTestSuite) TestSendEtherOnStatusChainTx() {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestSendEtherTxUpstream() {
|
||||
// FIXME(tiabc): Stop skipping after https://github.com/status-im/status-go/issues/424
|
||||
s.T().Skip()
|
||||
|
||||
s.StartTestBackend(
|
||||
params.RopstenNetworkID,
|
||||
e2e.WithUpstream("https://ropsten.infura.io/z6GCTmjdP3FETEJmMBI4"),
|
||||
|
@ -444,10 +366,10 @@ func (s *TransactionsTestSuite) TestSendEtherTxUpstream() {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestDoubleCompleteQueuedTransactions() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
backend := s.LightEthereumService().StatusBackend
|
||||
s.NotNil(backend)
|
||||
|
@ -521,10 +443,10 @@ func (s *TransactionsTestSuite) TestDoubleCompleteQueuedTransactions() {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestDiscardQueuedTransaction() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
backend := s.LightEthereumService().StatusBackend
|
||||
s.NotNil(backend)
|
||||
|
@ -601,11 +523,10 @@ func (s *TransactionsTestSuite) TestDiscardQueuedTransaction() {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestCompleteMultipleQueuedTransactions() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
s.TxQueueManager().TransactionQueue().Reset()
|
||||
|
||||
// log into account from which transactions will be sent
|
||||
|
@ -695,10 +616,10 @@ func (s *TransactionsTestSuite) TestCompleteMultipleQueuedTransactions() {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestDiscardMultipleQueuedTransactions() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
s.NoError(EnsureNodeSync(s.Backend.NodeManager()), "cannot ensure node synchronization")
|
||||
EnsureNodeSync(s.Backend.NodeManager())
|
||||
|
||||
backend := s.LightEthereumService().StatusBackend
|
||||
s.NotNil(backend)
|
||||
|
@ -811,7 +732,7 @@ func (s *TransactionsTestSuite) TestDiscardMultipleQueuedTransactions() {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestNonExistentQueuedTransactions() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
backend := s.LightEthereumService().StatusBackend
|
||||
|
@ -830,7 +751,7 @@ func (s *TransactionsTestSuite) TestNonExistentQueuedTransactions() {
|
|||
}
|
||||
|
||||
func (s *TransactionsTestSuite) TestEvictionOfQueuedTransactions() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
backend := s.LightEthereumService().StatusBackend
|
||||
|
|
|
@ -20,6 +20,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
//nolint: unused, varcheck
|
||||
whisperMessage1 = `test message 1 (K1 -> K2, signed+encrypted, from us)`
|
||||
whisperMessage2 = `test message 3 (K1 -> "", signed broadcast)`
|
||||
whisperMessage3 = `test message 4 ("" -> "", anon broadcast)`
|
||||
|
@ -81,7 +82,7 @@ func (s *WhisperJailTestSuite) GetAccountKey(account struct {
|
|||
// TODO(adamb) Uncomment when issue #336 is fixed.
|
||||
/*
|
||||
func (s *WhisperJailTestSuite) DontTestJailWhisper() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
_, accountKey1Hex, err := s.GetAccountKey(TestConfig.Account1)
|
||||
|
@ -375,7 +376,7 @@ func (s *WhisperJailTestSuite) DontTestJailWhisper() {
|
|||
*/
|
||||
|
||||
func (s *WhisperJailTestSuite) TestEncryptedAnonymousMessage() {
|
||||
s.StartTestBackend(params.RopstenNetworkID)
|
||||
s.StartTestBackend(params.StatusChainNetworkID)
|
||||
defer s.StopTestBackend()
|
||||
|
||||
accountKey2, accountKey2Hex, err := s.GetAccountKey(TestConfig.Account2)
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
LINT_EXCLUDE := --exclude='.*_mock.go' --exclude='geth/jail/doc.go'
|
||||
LINT_FOLDERS := extkeys cmd/... geth/... e2e/...
|
||||
LINT_FOLDERS_WITHOUT_TESTS := extkeys cmd/... geth/...
|
||||
|
||||
lint-deps:
|
||||
go get -u github.com/alecthomas/gometalinter
|
||||
gometalinter --install
|
||||
|
||||
lint: lint-vet lint-vetshadow lint-goimports lint-gofmt lint-deadcode lint-misspell lint-unparam lint-unused lint-gocyclo lint-errcheck lint-ineffassign lint-interfacer lint-unconvert lint-staticcheck lint-goconst lint-gas lint-varcheck lint-structcheck lint-gosimple
|
||||
|
||||
lint-vet:
|
||||
@echo "lint-vet"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=vet --deadline=45s $(LINT_FOLDERS)
|
||||
lint-vetshadow:
|
||||
@echo "lint-vetshadow"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=vetshadow --deadline=45s $(LINT_FOLDERS)
|
||||
lint-goimports:
|
||||
@echo "lint-goimports"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=goimports --deadline=45s $(LINT_FOLDERS)
|
||||
lint-golint:
|
||||
@echo "lint-golint"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=golint --deadline=45s $(LINT_FOLDERS)
|
||||
lint-gofmt:
|
||||
@echo "lint-gofmt"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=gofmt --deadline=45s $(LINT_FOLDERS)
|
||||
lint-deadcode:
|
||||
@echo "lint-deadcode"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=deadcode --deadline=45s $(LINT_FOLDERS)
|
||||
lint-misspell:
|
||||
@echo "lint-misspell"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=misspell --deadline=45s $(LINT_FOLDERS)
|
||||
lint-unparam:
|
||||
@echo "lint-unparam"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=unparam --deadline=45s $(LINT_FOLDERS)
|
||||
lint-unused:
|
||||
@echo "lint-unused"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=unused --deadline=45s $(LINT_FOLDERS)
|
||||
lint-gocyclo:
|
||||
@echo "lint-gocyclo"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=gocyclo --cyclo-over=20 --deadline=45s $(LINT_FOLDERS)
|
||||
lint-errcheck:
|
||||
@echo "lint-errcheck"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=errcheck --deadline=45s $(LINT_FOLDERS)
|
||||
lint-ineffassign:
|
||||
@echo "lint-ineffassign"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=ineffassign --deadline=45s $(LINT_FOLDERS)
|
||||
lint-interfacer:
|
||||
@echo "lint-interfacer"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=interfacer --deadline=45s $(LINT_FOLDERS)
|
||||
lint-unconvert:
|
||||
@echo "lint-unconvert"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=unconvert --deadline=45s $(LINT_FOLDERS)
|
||||
lint-staticcheck:
|
||||
@echo "lint-staticcheck"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=staticcheck --deadline=45s $(LINT_FOLDERS)
|
||||
lint-goconst:
|
||||
@echo "lint-goconst"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=goconst --deadline=45s $(LINT_FOLDERS)
|
||||
lint-gas:
|
||||
@echo "lint-gas"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=gas --deadline=45s $(LINT_FOLDERS)
|
||||
lint-varcheck:
|
||||
@echo "lint-varcheck"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=varcheck --deadline=45s $(LINT_FOLDERS)
|
||||
lint-structcheck:
|
||||
@echo "lint-structcheck"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=structcheck --deadline=45s $(LINT_FOLDERS)
|
||||
lint-gosimple:
|
||||
@echo "lint-gosimple"
|
||||
@gometalinter $(LINT_EXCLUDE) --disable-all --enable=gosimple --deadline=45s $(LINT_FOLDERS)
|
|
@ -2,7 +2,6 @@ package integration
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -69,25 +68,34 @@ func LoadFromFile(filename string) string {
|
|||
}
|
||||
|
||||
// EnsureNodeSync waits until node synchronzation is done to continue
|
||||
// with tests afterwards. Returns an error in case of a timeout.
|
||||
func EnsureNodeSync(nodeManager common.NodeManager) error {
|
||||
// with tests afterwards. Panics in case of an error or a timeout.
|
||||
func EnsureNodeSync(nodeManager common.NodeManager) {
|
||||
nc, err := nodeManager.NodeConfig()
|
||||
if err != nil {
|
||||
panic("can't retrieve NodeConfig")
|
||||
}
|
||||
// Don't wait for any blockchain sync for the local private chain as blocks are never mined.
|
||||
if nc.NetworkID == params.StatusChainNetworkID {
|
||||
return
|
||||
}
|
||||
|
||||
les, err := nodeManager.LightEthereumService()
|
||||
if err != nil {
|
||||
return err
|
||||
panic(err)
|
||||
}
|
||||
if les == nil {
|
||||
return errors.New("LightEthereumService is nil")
|
||||
panic("LightEthereumService is nil")
|
||||
}
|
||||
|
||||
timeouter := time.NewTimer(20 * time.Minute)
|
||||
defer timeouter.Stop()
|
||||
ticker := time.NewTicker(time.Second)
|
||||
ticker := time.NewTicker(1 * time.Second)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-timeouter.C:
|
||||
return errors.New("timout during node synchronization")
|
||||
panic("timout during node synchronization")
|
||||
case <-ticker.C:
|
||||
downloader := les.Downloader()
|
||||
|
||||
|
@ -96,10 +104,9 @@ func EnsureNodeSync(nodeManager common.NodeManager) error {
|
|||
progress := downloader.Progress()
|
||||
|
||||
if !isSyncing && progress.HighestBlock > 0 && progress.CurrentBlock >= progress.HighestBlock {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue