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-26 18:26:55 -04:00
committed by GitHub
parent e9c494cf71
commit edf4357176
15 changed files with 353 additions and 194 deletions
+11 -11
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
}
+26 -27
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
}