Code review for Mainnet (#706)

* Add debug log to test package t

* Add comments for test restrictions

* Add explicit errors for mainnet

* Panic instead of error in case of mainnet during tests

* Now panic with illegal network

* Validate the compiler flag for mainnet

* Made test for unset mainnet explicit

* Forgot to use my flag

* Linter has troubles with unused field

* Add default network id

In e2e tests there's no default anymore in go code. So ensure in Makefile.

* Fix dumb syntax error

* CI needs build with Mainnet

* Explicit rebuild only for tests

* No more separation of mainnet and testnet builds

* Build flags now set in Makefile
This commit is contained in:
Frank Mueller 2018-03-15 12:36:28 +01:00 committed by GitHub
parent fe1a99772b
commit 81c8669518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 65 deletions

View File

@ -10,14 +10,18 @@ ifndef GOPATH
endif
CGO_CFLAGS=-I/$(JAVA_HOME)/include -I/$(JAVA_HOME)/include/darwin
BUILD_TAGS =
GOBIN=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))build/bin
BUILD_TAGS =
BUILD_FLAGS := $(shell echo "-ldflags '-X main.buildStamp=`date -u '+%Y-%m-%d.%H:%M:%S'` -X main.gitCommit=$(git rev-parse HEAD)'")
GO ?= latest
XGOVERSION ?= 1.9.2
XGOIMAGE = statusteam/xgo:$(XGOVERSION)
XGOIMAGEIOSSIM = statusteam/xgo-ios-simulator:$(XGOVERSION)
networkid ?= StatusChain
DOCKER_IMAGE_NAME ?= statusteam/status-go
DOCKER_TEST_WORKDIR = /go/src/github.com/status-im/status-go/
@ -47,7 +51,7 @@ HELP_FUN = \
}
statusgo: ##@build Build status-go as statusd server
go build -i -o $(GOBIN)/statusd -v -tags '$(BUILD_TAGS)' $(shell _assets/build/testnet-flags.sh) ./cmd/statusd
go build -i -o $(GOBIN)/statusd -v -tags '$(BUILD_TAGS)' $(BUILD_FLAGS) ./cmd/statusd
@echo "Compilation done."
@echo "Run \"build/bin/statusd -h\" to view available commands."
@ -57,20 +61,20 @@ statusgo-cross: statusgo-android statusgo-ios
statusgo-android: xgo ##@cross-compile Build status-go for Android
./_assets/patches/patcher -b . -p geth-xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=android-16/aar -v -tags '$(BUILD_TAGS)' $(shell _assets/build/testnet-flags.sh) ./lib
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=android-16/aar -v -tags '$(BUILD_TAGS)' $(BUILD_FLAGS) ./lib
./_assets/patches/patcher -b . -p geth-xgo -r
@echo "Android cross compilation done."
statusgo-ios: xgo ##@cross-compile Build status-go for iOS
./_assets/patches/patcher -b . -p geth-xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v -tags '$(BUILD_TAGS)' $(shell _assets/build/testnet-flags.sh) ./lib
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v -tags '$(BUILD_TAGS)' $(BUILD_FLAGS) ./lib
./_assets/patches/patcher -b . -p geth-xgo -r
@echo "iOS framework cross compilation done."
statusgo-ios-simulator: xgo ##@cross-compile Build status-go for iOS Simulator
@docker pull $(XGOIMAGEIOSSIM)
./_assets/patches/patcher -b . -p geth-xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGEIOSSIM) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v -tags '$(BUILD_TAGS)' $(shell _assets/build/testnet-flags.sh) ./lib
$(GOPATH)/bin/xgo --image $(XGOIMAGEIOSSIM) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v -tags '$(BUILD_TAGS)' $(BUILD_FLAGS) ./lib
./_assets/patches/patcher -b . -p geth-xgo -r
@echo "iOS framework cross compilation done."
@ -97,23 +101,6 @@ xgo:
docker pull $(XGOIMAGE)
go get github.com/karalabe/xgo
statusgo-mainnet:
go build -i -o $(GOBIN)/statusgo -v $(shell _assets/build/mainnet-flags.sh) ./cmd/statusd
@echo "status go compilation done (mainnet)."
@echo "Run \"build/bin/statusgo\" to view available commands"
statusgo-android-mainnet: xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=android-16/aar -v $(shell _assets/build/mainnet-flags.sh) ./lib
@echo "Android cross compilation done (mainnet)."
statusgo-ios-mainnet: xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGE) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v $(shell _assets/build/mainnet-flags.sh) ./lib
@echo "iOS framework cross compilation done (mainnet)."
statusgo-ios-simulator-mainnet: xgo
$(GOPATH)/bin/xgo --image $(XGOIMAGEIOSSIM) --go=$(GO) -out statusgo --dest=$(GOBIN) --targets=ios-9.3/framework -v $(shell _assets/build/mainnet-flags.sh) ./lib
@echo "iOS framework cross compilation done (mainnet)."
generate: ##@other Regenerate assets and other auto-generated stuff
cp ./_assets/node_modules/web3/dist/web3.min.js ./static/scripts/web3.js
go generate ./static

View File

@ -1,13 +0,0 @@
#!/bin/sh
set -e
if [ ! -f "_assets/build/mainnet-flags.sh" ]; then
echo "$0 must be run from the root of the repository."
exit 2
fi
# set gitCommit when running from a Git checkout.
if [ -f ".git/HEAD" ]; then
echo "-ldflags '-X github.com/status-im/status-go/geth/params.UseMainnetFlag=true -X main.buildStamp=`date -u '+%Y-%m-%d.%H:%M:%S'` -X main.gitCommit=$(git rev-parse HEAD)'";
fi

View File

@ -1,13 +0,0 @@
#!/bin/sh
set -e
if [ ! -f "_assets/build/testnet-flags.sh" ]; then
echo "$0 must be run from the root of the repository."
exit 2
fi
# set gitCommit when running from a Git checkout.
if [ -f ".git/HEAD" ]; then
echo "-ldflags '-X github.com/status-im/status-go/geth/params.UseMainnetFlag=false -X main.buildStamp=`date -u '+%Y-%m-%d.%H:%M:%S'` -X main.gitCommit=$(git rev-parse HEAD)'";
fi

View File

@ -15,18 +15,6 @@ import (
"github.com/status-im/status-go/static"
)
// default node configuration options
var (
UseMainnetFlag = "false" // to be overridden via -ldflags '-X geth/params.UseMainnetFlag'
UseMainnet = false
)
func init() {
if UseMainnetFlag == "true" { // set at compile time, here we make sure to set corresponding boolean flag
UseMainnet = true
}
}
// errors
var (
ErrMissingDataDir = errors.New("missing required 'DataDir' parameter")
@ -436,6 +424,7 @@ func (c *NodeConfig) Save() error {
// updateConfig traverses configuration and adjusts dependent fields
// (we have a development/production and mobile/full node dependent configurations)
func (c *NodeConfig) updateConfig() error {
// Update separate configurations.
if err := c.updateGenesisConfig(); err != nil {
return err
}

4
t/doc.go Normal file
View File

@ -0,0 +1,4 @@
// Package t and its sub-packages are intended to support the testing
// of status-go. So the code here is not intended to run on Mainnet.
// It only supports Ropsten, Rinkeby, and StatusChain for tests.
package t

View File

@ -164,6 +164,7 @@ func GetRemoteURLFromNetworkID(id int) (url string, err error) {
}
// GetHeadHashFromNetworkID returns the hash associated with a given network id.
// Mainnet is not supported for tests.
func GetHeadHashFromNetworkID(id int) string {
switch id {
case params.RinkebyNetworkID:
@ -173,8 +174,8 @@ func GetHeadHashFromNetworkID(id int) string {
case params.StatusChainNetworkID:
return "0xe9d8920a99dc66a9557a87d51f9d14a34ec50aae04298e0f142187427d3c832e"
}
return ""
// Every other ID must break the test.
panic(fmt.Sprintf("invalid network id: %d", id))
}
// GetRemoteURL returns the url associated with a given network id.
@ -188,7 +189,8 @@ func GetHeadHash() string {
}
// GetNetworkID returns appropriate network id for test based on
// default or provided -network flag.
// default or provided -network flag. Mainnet is not supported for
// tests.
func GetNetworkID() int {
switch strings.ToLower(*networkSelected) {
case fmt.Sprintf("%d", params.RinkebyNetworkID), "rinkeby":
@ -198,8 +200,8 @@ func GetNetworkID() int {
case fmt.Sprintf("%d", params.StatusChainNetworkID), "statuschain":
return params.StatusChainNetworkID
}
return params.StatusChainNetworkID
// Every other selected network must break the test.
panic(fmt.Sprintf("invalid selected network: %q", *networkSelected))
}
// GetAccount1PKFile returns the filename for Account1 keystore based