build: github actions (#346)

* add workflows

* fix

* fix lint

* rpc tests

* build and format

* fix build errors

* remove dontcover

* update importer test

* more fixes

* lint

* split importer test

* fix

* remove tmp dir

* revert

* comment test import
This commit is contained in:
Federico Kunze 2020-06-27 00:26:55 +02:00 committed by GitHub
parent e9c494cf71
commit edf4357176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 353 additions and 194 deletions

2
.github/CODEOWNERS vendored
View File

@ -1,4 +1,4 @@
# CODEOWNERS: https://help.github.com/articles/about-codeowners/
# Primary repo maintainers
* @alexanderbez @AlexeyAkhunov @jackzampolin
* @fedekunze @noot

21
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,21 @@
name: Build
on:
pull_request:
branches:
- "development"
jobs:
cleanup-runs:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/development'"
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
make build

12
.github/workflows/linkchecker.yml vendored Normal file
View File

@ -0,0 +1,12 @@
name: Check Markdown links
on:
schedule:
- cron: "* */24 * * *"
jobs:
markdown-link-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@development
- uses: gaurav-nelson/github-action-markdown-link-check@0.6.0
with:
folder-path: "docs"

29
.github/workflows/lint.yml vendored Normal file
View File

@ -0,0 +1,29 @@
name: Lint
# Lint runs golangci-lint over the entire cosmos-sdk repository
# This workflow is run on every pull request and push to development
# The `golangci` will pass without running if no *.{go, mod, sum} files have been changed.
on:
pull_request:
push:
branches:
- development
jobs:
golangci:
name: golangci-lint
runs-on: ubuntu-latest
timeout-minutes: 6
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- uses: golangci/golangci-lint-action@master
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.27
args: --timeout 10m
github-token: ${{ secrets.github_token }}
if: "env.GIT_DIFF != ''"

212
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,212 @@
name: Tests / Code Coverage
# Tests / Code Coverage workflow runs unit tests and uploads a code coverage report
# This workflow is run on pushes to development & every Pull Requests where a .go, .mod, .sum have been changed
on:
pull_request:
push:
branches:
- development
jobs:
split-test-files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create a file with all the pkgs
run: go list ./... | grep -Ev 'vendor|importer|rpc/tester' > pkgs.txt
- name: Split pkgs into 4 files
run: split -n l/4 --additional-suffix=.txt ./pkgs.txt
# cache multiple
- uses: actions/upload-artifact@v2
with:
name: "${{ github.sha }}-aa"
path: ./xaa.txt
- uses: actions/upload-artifact@v2
with:
name: "${{ github.sha }}-ab"
path: ./xab.txt
- uses: actions/upload-artifact@v2
with:
name: "${{ github.sha }}-ac"
path: ./xac.txt
- uses: actions/upload-artifact@v2
with:
name: "${{ github.sha }}-ad"
path: ./xad.txt
test-coverage-run-1:
runs-on: ubuntu-latest
needs: split-test-files
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-aa"
if: "env.GIT_DIFF != ''"
- name: test & coverage report creation
run: |
cat xaa.txt | xargs go test -mod=readonly -timeout 8m -coverprofile=coverage.txt -covermode=atomic
if: "env.GIT_DIFF != ''"
- name: filter out proto files
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/ethermint/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
if: "env.GIT_DIFF != ''"
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
test-coverage-run-2:
runs-on: ubuntu-latest
needs: split-test-files
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-ab"
if: "env.GIT_DIFF != ''"
- name: test & coverage report creation
run: |
cat xab.txt | xargs go test -mod=readonly -timeout 6m -coverprofile=coverage.txt -covermode=atomic
if: "env.GIT_DIFF != ''"
- name: filter out proto files
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/ethermint/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
if: "env.GIT_DIFF != ''"
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
test-coverage-run-3:
runs-on: ubuntu-latest
needs: split-test-files
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-ac"
if: "env.GIT_DIFF != ''"
- name: test & coverage report creation
run: |
cat xac.txt | xargs go test -mod=readonly -timeout 6m -coverprofile=coverage.txt -covermode=atomic
if: "env.GIT_DIFF != ''"
- name: filter out proto files
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/ethermint/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
if: "env.GIT_DIFF != ''"
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
test-coverage-run-4:
runs-on: ubuntu-latest
needs: split-test-files
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- uses: actions/download-artifact@v2
with:
name: "${{ github.sha }}-ad"
if: "env.GIT_DIFF != ''"
- name: test & coverage report creation
run: |
cat xad.txt | xargs go test -mod=readonly -timeout 6m -coverprofile=coverage.txt -covermode=atomic
if: "env.GIT_DIFF != ''"
- name: filter out proto files
run: |
excludelist+=" $(find ./ -type f -name '*.pb.go')"
for filename in ${excludelist}; do
filename=$(echo $filename | sed 's/^./github.com\/cosmos\/ethermint/g')
echo "Excluding ${filename} from coverage report..."
sed -i.bak "/$(echo $filename | sed 's/\//\\\//g')/d" coverage.txt
done
if: "env.GIT_DIFF != ''"
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
rpc-tests:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- name: rpc-test
run: |
make test-rpc
if: "env.GIT_DIFF != ''"
# TODO: remove tmp dir to fix this
# test-importer:
# runs-on: ubuntu-latest
# timeout-minutes: 10
# steps:
# - uses: actions/checkout@v2
# - uses: technote-space/get-diff-action@v1
# id: git_diff
# with:
# SUFFIX_FILTER: |
# .go
# .mod
# .sum
# - name: importer-test
# run: |
# make test-import
# if: "env.GIT_DIFF != ''"

View File

@ -1,4 +1,5 @@
# run:
run:
tests: false
# # timeout for analysis, e.g. 30s, 5m, default is 1m
# timeout: 5m
@ -31,8 +32,8 @@ linters:
- typecheck
- unconvert
- unused
- unparam
- misspell
- varcheck
issues:
exclude-rules:
@ -53,9 +54,9 @@ issues:
- text: "ST1016:"
linters:
- stylecheck
- linters:
- golint
text: "don't use ALL_CAPS in Go names;"
max-issues-per-linter: 10000
max-same-issues: 10000
linters-settings:
dogsled:
max-blank-identifiers: 3

View File

@ -1,27 +0,0 @@
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

View File

@ -142,27 +142,16 @@ endif
test: test-unit
test-unit:
@${GO_MOD} go test -v --vet=off $(PACKAGES)
@go test -v ./... $(PACKAGES)
test-race:
@${GO_MOD} go test -v --vet=off -race $(PACKAGES)
test-cli:
@echo "NO CLI TESTS"
lint:
@echo "--> Running ci lint..."
GOBIN=$(PWD)/bin go run scripts/ci.go lint
@go test -v --vet=off -race ./... $(PACKAGES)
test-import:
@${GO_MOD} go test ./importer -v --vet=off --run=TestImportBlocks --datadir tmp \
@go test ./importer -v --vet=off --run=TestImportBlocks --datadir tmp \
--blockchain blockchain --timeout=10m
# TODO: remove tmp directory after test run to avoid subsequent errors
test-rpc:
@${GO_MOD} go test -v --vet=off ./tests/rpc_test
it-tests:
./scripts/integration-test-all.sh -q 1 -z 1 -s 2
godocs:
@ -174,15 +163,28 @@ docker:
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:latest
docker tag ${DOCKER_IMAGE}:${DOCKER_TAG} ${DOCKER_IMAGE}:${COMMIT_HASH}
format:
@echo "--> Formatting go files"
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -w -s
@find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs misspell -w
.PHONY: build install update-tools tools godocs clean format lint \
test-cli test-race test-unit test test-import
###############################################################################
### Linting ###
###############################################################################
lint:
golangci-lint run --out-format=tab --issues-exit-code=0
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s
format:
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs gofmt -w -s
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs misspell -w
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/tendermint
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/ethereum/go-ethereum
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/cosmos-sdk
find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" -not -name '*.pb.go' | xargs goimports -w -local github.com/cosmos/ethermint
.PHONY: lint format
###############################################################################
### Protobuf ###
###############################################################################

View File

@ -131,7 +131,7 @@ func createAndTestGenesis(t *testing.T, cms sdk.CommitMultiStore, ak auth.Accoun
}
}
// get balance of one of the genesis account having 200 ETH
// get balance of one of the genesis account having 400 ETH
b := stateDB.GetBalance(genInvestor)
require.Equal(t, "200000000000000000000", b.String())
@ -206,8 +206,7 @@ func TestImportBlocks(t *testing.T) {
blockchainInput, err := os.Open(flagBlockchain)
require.Nil(t, err)
// nolint: gosec
defer blockchainInput.Close()
defer require.NoError(t, blockchainInput.Close())
// ethereum mainnet config
chainContext := core.NewChainContext()

View File

@ -6,8 +6,7 @@ import (
"strconv"
"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/ethermint/x/evm"
"github.com/cosmos/ethermint/x/evm/types"
evmtypes "github.com/cosmos/ethermint/x/evm/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
@ -32,12 +31,13 @@ type Backend interface {
// TODO: Bloom methods
}
// EmintBackend implements Backend
// EthermintBackend implements Backend
type EthermintBackend struct {
cliCtx context.CLIContext
gasLimit int64
}
// NewEthermintBackend creates a new EthermintBackend instance
func NewEthermintBackend(cliCtx context.CLIContext) *EthermintBackend {
return &EthermintBackend{
cliCtx: cliCtx,
@ -47,12 +47,12 @@ func NewEthermintBackend(cliCtx context.CLIContext) *EthermintBackend {
// BlockNumber returns the current block number.
func (e *EthermintBackend) BlockNumber() (hexutil.Uint64, error) {
res, height, err := e.cliCtx.QueryWithData(fmt.Sprintf("custom/%s/blockNumber", types.ModuleName), nil)
res, height, err := e.cliCtx.QueryWithData(fmt.Sprintf("custom/%s/blockNumber", evmtypes.ModuleName), nil)
if err != nil {
return hexutil.Uint64(0), err
}
var out types.QueryResBlockNumber
var out evmtypes.QueryResBlockNumber
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
e.cliCtx.WithHeight(height)
@ -67,12 +67,12 @@ func (e *EthermintBackend) GetBlockByNumber(blockNum BlockNumber, fullTx bool) (
// GetBlockByHash returns the block identified by hash.
func (e *EthermintBackend) GetBlockByHash(hash common.Hash, fullTx bool) (map[string]interface{}, error) {
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryHashToHeight, hash.Hex()))
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryHashToHeight, hash.Hex()))
if err != nil {
return nil, err
}
var out types.QueryResBlockNumber
var out evmtypes.QueryResBlockNumber
if err := e.cliCtx.Codec.UnmarshalJSON(res, &out); err != nil {
return nil, err
}
@ -120,12 +120,12 @@ func (e *EthermintBackend) getEthBlockByNumber(height int64, fullTx bool) (map[s
}
}
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryBloom, strconv.FormatInt(block.Block.Height, 10)))
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryBloom, strconv.FormatInt(block.Block.Height, 10)))
if err != nil {
return nil, err
}
var out types.QueryBloomFilter
var out evmtypes.QueryBloomFilter
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
return formatBlock(header, block.Block.Size(), gasLimit, gasUsed, transactions, out.Bloom), nil
@ -161,12 +161,12 @@ func (e *EthermintBackend) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.L
// do we need to use the block height somewhere?
ctx := e.cliCtx
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryTransactionLogs, txHash.Hex()), nil)
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryTransactionLogs, txHash.Hex()), nil)
if err != nil {
return nil, err
}
out := new(types.QueryETHLogs)
out := new(evmtypes.QueryETHLogs)
if err := e.cliCtx.Codec.UnmarshalJSON(res, &out); err != nil {
return nil, err
}

View File

@ -18,8 +18,7 @@ import (
emint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/utils"
"github.com/cosmos/ethermint/version"
"github.com/cosmos/ethermint/x/evm"
"github.com/cosmos/ethermint/x/evm/types"
evmtypes "github.com/cosmos/ethermint/x/evm/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
@ -160,12 +159,12 @@ func (e *PublicEthAPI) BlockNumber() (hexutil.Uint64, error) {
// GetBalance returns the provided account's balance up to the provided block number.
func (e *PublicEthAPI) GetBalance(address common.Address, blockNum BlockNumber) (*hexutil.Big, error) {
ctx := e.cliCtx.WithHeight(blockNum.Int64())
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/balance/%s", types.ModuleName, address.Hex()), nil)
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/balance/%s", evmtypes.ModuleName, address.Hex()), nil)
if err != nil {
return nil, err
}
var out types.QueryResBalance
var out evmtypes.QueryResBalance
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
val, err := utils.UnmarshalBigInt(out.Balance)
if err != nil {
@ -178,12 +177,12 @@ func (e *PublicEthAPI) GetBalance(address common.Address, blockNum BlockNumber)
// GetStorageAt returns the contract storage at the given address, block number, and key.
func (e *PublicEthAPI) GetStorageAt(address common.Address, key string, blockNum BlockNumber) (hexutil.Bytes, error) {
ctx := e.cliCtx.WithHeight(blockNum.Int64())
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/storage/%s/%s", types.ModuleName, address.Hex(), key), nil)
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/storage/%s/%s", evmtypes.ModuleName, address.Hex(), key), nil)
if err != nil {
return nil, err
}
var out types.QueryResStorage
var out evmtypes.QueryResStorage
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
return out.Value, nil
}
@ -215,13 +214,13 @@ func (e *PublicEthAPI) GetTransactionCount(address common.Address, blockNum Bloc
// GetBlockTransactionCountByHash returns the number of transactions in the block identified by hash.
func (e *PublicEthAPI) GetBlockTransactionCountByHash(hash common.Hash) *hexutil.Uint {
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryHashToHeight, hash.Hex()))
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryHashToHeight, hash.Hex()))
if err != nil {
// Return nil if block does not exist
return nil
}
var out types.QueryResBlockNumber
var out evmtypes.QueryResBlockNumber
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
return e.getBlockTransactionCountByNumber(out.Number)
}
@ -256,12 +255,12 @@ func (e *PublicEthAPI) GetUncleCountByBlockNumber(blockNum BlockNumber) hexutil.
// GetCode returns the contract code at the given address and block number.
func (e *PublicEthAPI) GetCode(address common.Address, blockNumber BlockNumber) (hexutil.Bytes, error) {
ctx := e.cliCtx.WithHeight(blockNumber.Int64())
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryCode, address.Hex()), nil)
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryCode, address.Hex()), nil)
if err != nil {
return nil, err
}
var out types.QueryResCode
var out evmtypes.QueryResCode
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
return out.Code, nil
}
@ -276,7 +275,7 @@ func (e *PublicEthAPI) GetTransactionLogs(txHash common.Hash) ([]*ethtypes.Log,
func (e *PublicEthAPI) ExportAccount(address common.Address, blockNumber BlockNumber) (string, error) {
ctx := e.cliCtx.WithHeight(blockNumber.Int64())
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryExportAccount, address.Hex()), nil)
res, _, err := ctx.QueryWithData(fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryExportAccount, address.Hex()), nil)
if err != nil {
return "", err
}
@ -352,7 +351,7 @@ func (e *PublicEthAPI) SendTransaction(args params.SendTxArgs) (common.Hash, err
// SendRawTransaction send a raw Ethereum transaction.
func (e *PublicEthAPI) SendRawTransaction(data hexutil.Bytes) (common.Hash, error) {
tx := new(types.MsgEthereumTx)
tx := new(evmtypes.MsgEthereumTx)
// RLP decode raw transaction bytes
if err := rlp.DecodeBytes(data, tx); err != nil {
@ -395,7 +394,7 @@ func (e *PublicEthAPI) Call(args CallArgs, blockNr rpc.BlockNumber, overrides *m
return []byte{}, err
}
data, err := types.DecodeResultData(simRes.Result.Data)
data, err := evmtypes.DecodeResultData(simRes.Result.Data)
if err != nil {
return []byte{}, err
}
@ -417,7 +416,7 @@ type account struct {
StateDiff *map[common.Hash]common.Hash `json:"stateDiff"`
}
// DoCall performs a simulated call operation through the evm. It returns the
// DoCall performs a simulated call operation through the evmtypes. It returns the
// estimated gas used on the operation or an error if fails.
func (e *PublicEthAPI) doCall(
args CallArgs, blockNr rpc.BlockNumber, globalGasCap *big.Int,
@ -476,7 +475,7 @@ func (e *PublicEthAPI) doCall(
}
// Create new call message
msg := types.NewMsgEthermint(0, &toAddr, sdk.NewIntFromBigInt(value), gas,
msg := evmtypes.NewMsgEthermint(0, &toAddr, sdk.NewIntFromBigInt(value), gas,
sdk.NewIntFromBigInt(gasPrice), data, sdk.AccAddress(addr.Bytes()))
// Generate tx to be used to simulate (signature isn't needed)
@ -594,14 +593,14 @@ type Transaction struct {
S *hexutil.Big `json:"s"`
}
func bytesToEthTx(cliCtx context.CLIContext, bz []byte) (*types.MsgEthereumTx, error) {
func bytesToEthTx(cliCtx context.CLIContext, bz []byte) (*evmtypes.MsgEthereumTx, error) {
var stdTx sdk.Tx
err := cliCtx.Codec.UnmarshalBinaryBare(bz, &stdTx)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
ethTx, ok := stdTx.(types.MsgEthereumTx)
ethTx, ok := stdTx.(evmtypes.MsgEthereumTx)
if !ok {
return nil, fmt.Errorf("invalid transaction type, must be an amino encoded Ethereum transaction")
}
@ -610,7 +609,7 @@ func bytesToEthTx(cliCtx context.CLIContext, bz []byte) (*types.MsgEthereumTx, e
// newRPCTransaction returns a transaction that will serialize to the RPC
// representation, with the given location metadata set (if available).
func newRPCTransaction(tx types.MsgEthereumTx, txHash, blockHash common.Hash, blockNumber *uint64, index uint64) (*Transaction, error) {
func newRPCTransaction(tx evmtypes.MsgEthereumTx, txHash, blockHash common.Hash, blockNumber *uint64, index uint64) (*Transaction, error) {
// Verify signature and retrieve sender address
from, err := tx.VerifySig(tx.ChainID())
if err != nil {
@ -666,12 +665,12 @@ func (e *PublicEthAPI) GetTransactionByHash(hash common.Hash) (*Transaction, err
// GetTransactionByBlockHashAndIndex returns the transaction identified by hash and index.
func (e *PublicEthAPI) GetTransactionByBlockHashAndIndex(hash common.Hash, idx hexutil.Uint) (*Transaction, error) {
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryHashToHeight, hash.Hex()))
res, _, err := e.cliCtx.Query(fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryHashToHeight, hash.Hex()))
if err != nil {
return nil, err
}
var out types.QueryResBlockNumber
var out evmtypes.QueryResBlockNumber
e.cliCtx.Codec.MustUnmarshalJSON(res, &out)
return e.getTransactionByBlockNumberAndIndex(out.Number, idx)
}
@ -738,7 +737,7 @@ func (e *PublicEthAPI) GetTransactionReceipt(hash common.Hash) (map[string]inter
txData := tx.TxResult.GetData()
data, err := types.DecodeResultData(txData)
data, err := evmtypes.DecodeResultData(txData)
if err != nil {
status = 0 // transaction failed
}
@ -814,7 +813,7 @@ type StorageResult struct {
// GetProof returns an account object with proof and any storage proofs
func (e *PublicEthAPI) GetProof(address common.Address, storageKeys []string, block BlockNumber) (*AccountResult, error) {
e.cliCtx = e.cliCtx.WithHeight(int64(block))
path := fmt.Sprintf("custom/%s/%s/%s", types.ModuleName, evm.QueryAccount, address.Hex())
path := fmt.Sprintf("custom/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryAccount, address.Hex())
// query eth account at block height
resBz, _, err := e.cliCtx.Query(path)
@ -822,20 +821,20 @@ func (e *PublicEthAPI) GetProof(address common.Address, storageKeys []string, bl
return nil, err
}
var account types.QueryResAccount
var account evmtypes.QueryResAccount
e.cliCtx.Codec.MustUnmarshalJSON(resBz, &account)
storageProofs := make([]StorageResult, len(storageKeys))
opts := client.ABCIQueryOptions{Height: int64(block), Prove: true}
for i, k := range storageKeys {
// Get value for key
vPath := fmt.Sprintf("custom/%s/%s/%s/%s", types.ModuleName, evm.QueryStorage, address, k)
vPath := fmt.Sprintf("custom/%s/%s/%s/%s", evmtypes.ModuleName, evmtypes.QueryStorage, address, k)
vRes, err := e.cliCtx.Client.ABCIQueryWithOptions(vPath, nil, opts)
if err != nil {
return nil, err
}
var value types.QueryResStorage
var value evmtypes.QueryResStorage
e.cliCtx.Codec.MustUnmarshalJSON(vRes.Response.GetValue(), &value)
// check for proof
@ -883,7 +882,7 @@ func (e *PublicEthAPI) GetProof(address common.Address, storageKeys []string, bl
}
// generateFromArgs populates tx message with args (used in RPC API)
func (e *PublicEthAPI) generateFromArgs(args params.SendTxArgs) (*types.MsgEthereumTx, error) {
func (e *PublicEthAPI) generateFromArgs(args params.SendTxArgs) (*evmtypes.MsgEthereumTx, error) {
var (
nonce uint64
gasLimit uint64
@ -954,7 +953,7 @@ func (e *PublicEthAPI) generateFromArgs(args params.SendTxArgs) (*types.MsgEther
} else {
gasLimit = (uint64)(*args.Gas)
}
msg := types.NewMsgEthereumTx(nonce, args.To, amount, gasLimit, gasPrice, input)
msg := evmtypes.NewMsgEthereumTx(nonce, args.To, amount, gasLimit, gasPrice, input)
return &msg, nil
}

View File

@ -1,73 +0,0 @@
// +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")
}

View File

@ -7,35 +7,19 @@ import (
// nolint
const (
ModuleName = types.ModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
QueryProtocolVersion = types.QueryProtocolVersion
QueryBalance = types.QueryBalance
QueryBlockNumber = types.QueryBlockNumber
QueryStorage = types.QueryStorage
QueryCode = types.QueryCode
QueryNonce = types.QueryNonce
QueryHashToHeight = types.QueryHashToHeight
QueryTransactionLogs = types.QueryTransactionLogs
QueryBloom = types.QueryBloom
QueryLogs = types.QueryLogs
QueryAccount = types.QueryAccount
QueryExportAccount = types.QueryExportAccount
ModuleName = types.ModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
)
// nolint
var (
NewKeeper = keeper.NewKeeper
TxDecoder = types.TxDecoder
NewGenesisStorage = types.NewGenesisStorage
NewKeeper = keeper.NewKeeper
TxDecoder = types.TxDecoder
)
//nolint
type (
Keeper = keeper.Keeper
QueryResAccount = types.QueryResAccount
GenesisState = types.GenesisState
GenesisAccount = types.GenesisAccount
GenesisStorage = types.GenesisStorage
Keeper = keeper.Keeper
GenesisState = types.GenesisState
)

View File

@ -46,7 +46,7 @@ func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) []abci.ValidatorU
// ExportGenesis exports genesis state
func ExportGenesis(ctx sdk.Context, k Keeper, ak types.AccountKeeper) GenesisState {
// nolint: prealloc
var ethGenAccounts []GenesisAccount
var ethGenAccounts []types.GenesisAccount
accounts := ak.GetAllAccounts(ctx)
var err error
@ -58,16 +58,16 @@ func ExportGenesis(ctx sdk.Context, k Keeper, ak types.AccountKeeper) GenesisSta
addr := common.BytesToAddress(ethAccount.GetAddress().Bytes())
var storage []GenesisStorage
var storage []types.GenesisStorage
err = k.CommitStateDB.ForEachStorage(addr, func(key, value common.Hash) bool {
storage = append(storage, NewGenesisStorage(key, value))
storage = append(storage, types.NewGenesisStorage(key, value))
return false
})
if err != nil {
panic(err)
}
genAccount := GenesisAccount{
genAccount := types.GenesisAccount{
Address: addr,
Balance: k.GetBalance(ctx, addr),
Code: k.GetCode(ctx, addr),

View File

@ -21,7 +21,7 @@ func NewQuerier(k Keeper) sdk.Querier {
}
}
func queryFunded(ctx sdk.Context, req abci.RequestQuery, k Keeper) ([]byte, error) {
func queryFunded(ctx sdk.Context, _ abci.RequestQuery, k Keeper) ([]byte, error) {
funded := k.GetFunded(ctx)
bz, err := codec.MarshalJSONIndent(k.cdc, funded)