Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
local testnet command (#378)
Browse files Browse the repository at this point in the history
* evm: fix non-determinism

* fixes

* typo

* fix tests

* local testnet command

* fix testnet cmd (#383)

fix export-eth-key

generate eth type account in genesis.json file

* fixes

* update docker

* minor changes

* fix build-docker-local-ethermint

* fix dockerfile

* update Makefile

* update denoms

* update genesis file

* update makefile

* fix docker-compose.yml images

* fix localnet execution (#398)

* finish documentation

* changelog and comment rpc tests workflow

* update codecov

* update testnet docs

* fix docker-compose execution

* update docs

* fix errors and make testnet work (#403)

* fix errors and make testnet work

* Update Dockerfile

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* wip - fix db

* fixes emintd nodes and syncs nodes

* starts daemon and rpc server in bg

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Federico Kunze <federico.kunze94@gmail.com>

* update entrypoint and docs

* update logs

* try fix rpc

* build docker image

* Update Dockerfile

Co-authored-by: Holechain <nrgh@foxmail.com>
Co-authored-by: Alessio Treglia <quadrispro@ubuntu.com>
Co-authored-by: Daniel Choi <choidanielw@gmail.com>
  • Loading branch information
4 people committed Jul 31, 2020
1 parent 0dc45bc commit 375a7a0
Show file tree
Hide file tree
Showing 19 changed files with 936 additions and 198 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
.glide/
vendor
build
bin
tools/bin/*
docs/_build
docs/tutorial
Expand All @@ -28,6 +29,7 @@ dist
tools-stamp
proto-tools-stamp
golangci-lint
keyring_test_cosmos

# Testing
coverage.txt
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

* (build) [\#378](https://github.com/ChainSafe/ethermint/pull/378) Create multi-node, local, automated testnet setup with `make localnet-start`.
* (rpc) [\#330](https://github.com/ChainSafe/ethermint/issues/330) Implement `PublicFilterAPI`'s `EventSystem` which subscribes to Tendermint events upon `Filter` creation.
* (rpc) [\#231](https://github.com/ChainSafe/ethermint/issues/231) Implement `NewBlockFilter` in rpc/filters.go which instantiates a polling block filter
* Polls for new blocks via `BlockNumber` rpc call; if block number changes, it requests the new block via `GetBlockByNumber` rpc call and adds it to its internal list of blocks
Expand Down
236 changes: 101 additions & 135 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,32 @@ ETHERMINT_DAEMON_BINARY = emintd
ETHERMINT_CLI_BINARY = emintcli
GO_MOD=GO111MODULE=on
BINDIR ?= $(GOPATH)/bin
BUILDDIR ?= $(CURDIR)/build
SIMAPP = github.com/cosmos/ethermint/app
RUNSIM = $(BINDIR)/runsim

all: tools verify install

#######################
### Build / Install ###
#######################
###############################################################################
### Build ###
###############################################################################

build: go.sum
go build -mod=readonly ./...

build-ethermint: go.sum
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./cmd/$(ETHERMINT_DAEMON_BINARY)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./cmd/$(ETHERMINT_CLI_BINARY)

build:
ifeq ($(OS),Windows_NT)
${GO_MOD} go build $(BUILD_FLAGS) -o build/$(ETHERMINT_DAEMON_BINARY).exe ./cmd/emintd
${GO_MOD} go build $(BUILD_FLAGS) -o build/$(ETHERMINT_CLI_BINARY).exe ./cmd/emintcli
else
${GO_MOD} go build $(BUILD_FLAGS) -o build/$(ETHERMINT_DAEMON_BINARY) ./cmd/emintd/
${GO_MOD} go build $(BUILD_FLAGS) -o build/$(ETHERMINT_CLI_BINARY) ./cmd/emintcli/
endif
build-ethermint-linux: go.sum
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 $(MAKE) build-ethermint

.PHONY: build build-ethermint build-ethermint-linux

install:
${GO_MOD} go install $(BUILD_FLAGS) ./cmd/emintd
${GO_MOD} go install $(BUILD_FLAGS) ./cmd/emintcli
${GO_MOD} go install $(BUILD_FLAGS) ./cmd/$(ETHERMINT_DAEMON_BINARY)
${GO_MOD} go install $(BUILD_FLAGS) ./cmd/$(ETHERMINT_CLI_BINARY)

clean:
@rm -rf ./build ./vendor
Expand All @@ -55,31 +60,26 @@ verify:
@echo "--> Verifying dependencies have not been modified"
${GO_MOD} go mod verify

docker:
docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} .
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:${COMMIT_HASH}
# update old container
docker rm ethermint
# create a new container from the latest image
docker create --name ethermint -t -i cosmos/ethermint:latest ethermint
# move the binaries to the ./build directory
mkdir -p ./build/
docker cp ethermint:/usr/bin/emintd ./build/ ; \
docker cp ethermint:/usr/bin/emintcli ./build/

docker-localnet:
# build the image
docker build -f ./networks/local/ethermintnode/Dockerfile . -t emintd/node

############################
### Tools / Dependencies ###
############################

##########################################################
### TODO: Move tool depedencies to a separate makefile ###
##########################################################

GOLINT = github.com/tendermint/lint/golint
GOCILINT = github.com/golangci/golangci-lint/cmd/golangci-lint
UNCONVERT = github.com/mdempsky/unconvert
INEFFASSIGN = github.com/gordonklaus/ineffassign
MISSPELL = github.com/client9/misspell/cmd/misspell
ERRCHECK = github.com/kisielk/errcheck
UNPARAM = mvdan.cc/unparam

GOLINT_CHECK := $(shell command -v golint 2> /dev/null)
GOCILINT_CHECK := $(shell command -v golangci-lint 2> /dev/null)
UNCONVERT_CHECK := $(shell command -v unconvert 2> /dev/null)
INEFFASSIGN_CHECK := $(shell command -v ineffassign 2> /dev/null)
MISSPELL_CHECK := $(shell command -v misspell 2> /dev/null)
ERRCHECK_CHECK := $(shell command -v errcheck 2> /dev/null)
UNPARAM_CHECK := $(shell command -v unparam 2> /dev/null)

###############################################################################
### Tools & Dependencies ###
###############################################################################

# Install the runsim binary with a temporary workaround of entering an outside
# directory as the "go get" command ignores the -mod option and will polute the
Expand All @@ -91,53 +91,10 @@ $(RUNSIM):
@(cd /tmp && go get github.com/cosmos/tools/cmd/runsim@v1.0.0)

tools: $(RUNSIM)
ifdef GOLINT_CHECK
@echo "Golint is already installed. Run 'make update-tools' to update."
else
@echo "--> Installing golint"
${GO_MOD} go get -v $(GOLINT)
endif
ifdef GOCILINT_CHECK
@echo "golangci-lint is already installed. Run 'make update-tools' to update."
else
@echo "--> Installing golangci-lint"
${GO_MOD} go get -v $(GOCILINT)
endif
ifdef UNCONVERT_CHECK
@echo "Unconvert is already installed. Run 'make update-tools' to update."
else
@echo "--> Installing unconvert"
${GO_MOD} go get -v $(UNCONVERT)
endif
ifdef INEFFASSIGN_CHECK
@echo "Ineffassign is already installed. Run 'make update-tools' to update."
else
@echo "--> Installing ineffassign"
${GO_MOD} go get -v $(INEFFASSIGN)
endif
ifdef MISSPELL_CHECK
@echo "misspell is already installed. Run 'make update-tools' to update."
else
@echo "--> Installing misspell"
${GO_MOD} go get -v $(MISSPELL)
endif
ifdef ERRCHECK_CHECK
@echo "errcheck is already installed. Run 'make update-tools' to update."
else
@echo "--> Installing errcheck"
${GO_MOD} go get -v $(ERRCHECK)
endif
ifdef UNPARAM_CHECK
@echo "unparam is already installed. Run 'make update-tools' to update."
else
@echo "--> Installing unparam"
${GO_MOD} go get -v $(UNPARAM)
endif


#######################
### Testing / Misc. ###
#######################

###############################################################################
### Tests & Simulation ###
###############################################################################

test: test-unit

Expand All @@ -155,15 +112,40 @@ test-import:
test-rpc:
./scripts/integration-test-all.sh -q 1 -z 1 -s 2

godocs:
@echo "--> Wait a few seconds and visit http://localhost:6060/pkg/github.com/cosmos/ethermint"
godoc -http=:6060
test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

docker:
docker build -t ${DOCKER_IMAGE}:${DOCKER_TAG} .
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:${COMMIT_HASH}
test-sim-custom-genesis-fast:
@echo "Running custom genesis simulation..."
@echo "By default, ${HOME}/.$(ETHERMINT_DAEMON_BINARY)/config/genesis.json will be used."
@go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=${HOME}/.$(ETHERMINT_DAEMON_BINARY)/config/genesis.json \
-Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h

test-sim-import-export: runsim
@echo "Running Ethermint import/export simulation. This may take several minutes..."
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 25 5 TestAppImportExport

test-sim-after-import: runsim
@echo "Running Ethermint simulation-after-import. This may take several minutes..."
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 25 5 TestAppSimulationAfterImport

test-sim-custom-genesis-multi-seed: runsim
@echo "Running multi-seed custom genesis simulation..."
@echo "By default, ${HOME}/.$(ETHERMINT_DAEMON_BINARY)/config/genesis.json will be used."
@$(BINDIR)/runsim -Jobs=4 -Genesis=${HOME}/.$(ETHERMINT_DAEMON_BINARY)/config/genesis.json 400 5 TestFullAppSimulation

test-sim-multi-seed-long: runsim
@echo "Running multi-seed application simulation. This may take awhile!"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 500 50 TestFullAppSimulation

test-sim-multi-seed-short: runsim
@echo "Running multi-seed application simulation. This may take awhile!"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 50 10 TestFullAppSimulation

.PHONY: runsim test-sim-nondeterminism test-sim-custom-genesis-fast test-sim-fast sim-import-export \
test-sim-simulation-after-import test-sim-custom-genesis-multi-seed test-sim-multi-seed

.PHONY: build install update-tools tools godocs clean format lint \
test-cli test-race test-unit test test-import
Expand Down Expand Up @@ -256,50 +238,10 @@ proto-update-deps:

.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-update-deps

#######################
### Simulations ###
#######################

test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

test-sim-custom-genesis-fast:
@echo "Running custom genesis simulation..."
@echo "By default, ${HOME}/.emintd/config/genesis.json will be used."
@go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=${HOME}/.emintd/config/genesis.json \
-Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h

test-sim-import-export: runsim
@echo "Running Ethermint import/export simulation. This may take several minutes..."
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 25 5 TestAppImportExport

test-sim-after-import: runsim
@echo "Running Ethermint simulation-after-import. This may take several minutes..."
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 25 5 TestAppSimulationAfterImport

test-sim-custom-genesis-multi-seed: runsim
@echo "Running multi-seed custom genesis simulation..."
@echo "By default, ${HOME}/.emintd/config/genesis.json will be used."
@$(BINDIR)/runsim -Jobs=4 -Genesis=${HOME}/.emintd/config/genesis.json 400 5 TestFullAppSimulation

test-sim-multi-seed-long: runsim
@echo "Running multi-seed application simulation. This may take awhile!"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 500 50 TestFullAppSimulation

test-sim-multi-seed-short: runsim
@echo "Running multi-seed application simulation. This may take awhile!"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) 50 10 TestFullAppSimulation

.PHONY: runsim test-sim-nondeterminism test-sim-custom-genesis-fast test-sim-fast sim-import-export \
test-sim-simulation-after-import test-sim-custom-genesis-multi-seed test-sim-multi-seed \



#######################
### Documentation ###
#######################
###############################################################################
### Documentation ###
###############################################################################

# Start docs site at localhost:8080
docs-serve:
Expand All @@ -311,4 +253,28 @@ docs-serve:
docs-build:
@cd docs && \
npm install && \
npm run build
npm run build

godocs:
@echo "--> Wait a few seconds and visit http://localhost:6060/pkg/github.com/cosmos/ethermint"
godoc -http=:6060

###############################################################################
### Localnet ###
###############################################################################

build-docker-local-ethermint:
@$(MAKE) -C networks/local

# Run a 4-node testnet locally
localnet-start: localnet-stop
mkdir -p ./build/
@$(MAKE) docker-localnet

if ! [ -f build/node0/$(ETHERMINT_DAEMON_BINARY)/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/ethermint:Z emintd/node "emintd testnet --v 4 -o /ethermint --starting-ip-address 192.168.10.2 --keyring-backend=test"; fi
docker-compose up -d

localnet-stop:
docker-compose down

.PHONY: build-docker-local-ethermint localnet-start localnet-stop
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ parent:
<a href="https://goreportcard.com/report/github.com/ChainSafe/ethermint">
<img alt="Go report card" src="https://goreportcard.com/badge/github.com/ChainSafe/ethermint"/>
</a>
<a href="https://codecov.io/gh/cosmos/ethermint">
<img alt="Code Coverage" src="https://codecov.io/gh/ChainSafe/ethermint/branch/development/graph/badge.svg"/>
<a href="https://codecov.io/gh/ChainSafe/ethermint">
<img alt="Code Coverage" src="https://codecov.io/gh/ChainSafe/ethermint/branch/development/graph/badge.svg" />
</a>
</div>
<div align="center">
Expand Down
12 changes: 3 additions & 9 deletions cmd/emintcli/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"bufio"
"io"

"github.com/tendermint/tendermint/crypto"

"github.com/cosmos/cosmos-sdk/client/flags"
clientkeys "github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdk "github.com/cosmos/cosmos-sdk/types"

emintCrypto "github.com/cosmos/ethermint/crypto"
"github.com/cosmos/ethermint/crypto"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -54,15 +52,15 @@ func keyCommands() *cobra.Command {

func getKeybase(transient bool, buf io.Reader) (keyring.Keybase, error) {
if transient {
return keyring.NewInMemory(keyring.WithKeygenFunc(ethermintKeygenFunc)), nil
return keyring.NewInMemory(keyring.WithKeygenFunc(crypto.EthermintKeygenFunc)), nil
}

return keyring.NewKeyring(
sdk.KeyringServiceName(),
viper.GetString(flags.FlagKeyringBackend),
viper.GetString(flags.FlagHome),
buf,
keyring.WithKeygenFunc(ethermintKeygenFunc))
keyring.WithKeygenFunc(crypto.EthermintKeygenFunc))
}

func runAddCmd(cmd *cobra.Command, args []string) error {
Expand All @@ -74,7 +72,3 @@ func runAddCmd(cmd *cobra.Command, args []string) error {

return clientkeys.RunAddCmd(cmd, args, kb, inBuf)
}

func ethermintKeygenFunc(bz []byte, algo keyring.SigningAlgo) (crypto.PrivKey, error) {
return emintCrypto.PrivKeySecp256k1(bz), nil
}
2 changes: 1 addition & 1 deletion cmd/emintd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {
app.DefaultNodeHome, app.DefaultCLIHome,
),
genutilcli.ValidateGenesisCmd(ctx, cdc, app.ModuleBasics),

testnetCmd(ctx, cdc, app.ModuleBasics, bank.GenesisBalancesIterator{}),
// AddGenesisAccountCmd allows users to add accounts to the genesis file
AddGenesisAccountCmd(ctx, cdc, appCodec, app.DefaultNodeHome, app.DefaultCLIHome),
flags.NewCompletionCmd(rootCmd, true),
Expand Down
Loading

0 comments on commit 375a7a0

Please sign in to comment.