Skip to content

Commit

Permalink
Cherry pick latest changes (evmos#1265)
Browse files Browse the repository at this point in the history
* changelog

* Add support for miner_setGasPrice API (evmos#1237)

* fix kv indexer unit test

* fix(rpc): get_proof test fail because block numbers are not high enough (evmos#1239)

* Problem: get_proof test fail because block numbers are not high enough

Solution:
- wait for app block height rather than tendermint block height

* Update tests/integration_tests/test_types.py

* keep get_proof response the same as geth

Co-authored-by: Daniel Burckhardt <[email protected]>

* tests(rpc): add filter tests (evmos#1233)

* tests(rpc): add pending transaction filter test

* tests(rpc): add block filter and event log  test

* tests(rpc): simplify to cluster instead of comparing types

* tests(rpc): wip filter by address

* tests(rpc): add get_logs test

* fix flake8 linter

* fix flake8 linter

* add caching to readme

* add caching to readme

Co-authored-by: Federico Kunze Küllmer <[email protected]>

* changelog

* update gomod2nix

* fix python linter

* Apply suggestions from code review

* Update CHANGELOG.md

Co-authored-by: yihuang <[email protected]>
Co-authored-by: Daniel Burckhardt <[email protected]>
Co-authored-by: Federico Kunze Küllmer <[email protected]>
  • Loading branch information
4 people authored and hoanguyenkh committed Aug 17, 2022
1 parent 34d9fd4 commit b7acaa6
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 21 deletions.
12 changes: 6 additions & 6 deletions gomod2nix.toml
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,8 @@ schema = 3
version = "v1.3.6"
hash = "sha256-DenVAmyN22xUiivk6fdJp4C9ZnUJXCMDUf8E0goRRV4="
[mod."golang.org/x/crypto"]
version = "v0.0.0-20220622213112-05595931fe9d"
hash = "sha256-2c4wvwiQ0DJSJsApfmNoxCxx1siRCiJvW9hhrGlcvds="
version = "v0.0.0-20220722155217-630584e8d5aa"
hash = "sha256-gLzdWnyJtT1z2lw/GGmJEFBZ7AS1qVAo8M9Fqi0xFuE="
[mod."golang.org/x/net"]
version = "v0.0.0-20220520000938-2e3eb7b945c2"
hash = "sha256-uCMgd3uUlLREUdD9CYRbYlbJgRQyOts0jC1Okjk8Al8="
Expand All @@ -424,15 +424,15 @@ schema = 3
version = "v0.3.7"
hash = "sha256-XH2pUzzQx95O0rak00grQvfACfL+EmZiV7ZzJBkX+XY="
[mod."google.golang.org/genproto"]
version = "v0.0.0-20220628213854-d9e0b6570c03"
hash = "sha256-sM4ik5KAdxxNYqhinnE/baQzjKgzrZ8fJURhZarcDO8="
version = "v0.0.0-20220810155839-1856144b1d9c"
hash = "sha256-veGcsuGWHmWHLnnq+z1SJrY+//j2kxzVwVpdXeFpSZ0="
[mod."google.golang.org/grpc"]
version = "v1.33.2"
hash = "sha256-0vOeuHDvRviofJmr4dOzUh4Y1y2X6ujGCcLcICVnQ0Q="
replaced = "google.golang.org/grpc"
[mod."google.golang.org/protobuf"]
version = "v1.28.0"
hash = "sha256-p1cVM3OeEErh1WeNRAg4n3zYm/0qPTPmIiWNjRmJiMQ="
version = "v1.28.1"
hash = "sha256-sTJYgvlv5is7vHNxcuigF2lNASp0QonhUgnrguhfHSU="
[mod."gopkg.in/ini.v1"]
version = "v1.66.4"
hash = "sha256-PZ5vwf47Pjv7lzaUlm/mIdkIfnwEpmSNYG1UIfGh3M4="
Expand Down
14 changes: 7 additions & 7 deletions indexer/kv_indexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestKVIndexer(t *testing.T) {
txHash := tx.AsTransaction().Hash()

encodingConfig := MakeEncodingConfig()
clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig).WithCodec(encodingConfig.Codec)
clientCtx := client.Context{}.WithTxConfig(encodingConfig.TxConfig).WithCodec(encodingConfig.Marshaler)

// build cosmos-sdk wrapper tx
tmTx, err := tx.BuildTx(clientCtx.TxConfig.NewTxBuilder(), "aphoton")
Expand All @@ -62,7 +62,7 @@ func TestKVIndexer(t *testing.T) {
"success, format 1",
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz}}},
[]*abci.ResponseDeliverTx{
&abci.ResponseDeliverTx{
{
Code: 0,
Events: []abci.Event{
{Type: types.EventTypeEthereumTx, Attributes: []abci.EventAttribute{
Expand All @@ -82,7 +82,7 @@ func TestKVIndexer(t *testing.T) {
"success, format 2",
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz}}},
[]*abci.ResponseDeliverTx{
&abci.ResponseDeliverTx{
{
Code: 0,
Events: []abci.Event{
{Type: types.EventTypeEthereumTx, Attributes: []abci.EventAttribute{
Expand All @@ -104,7 +104,7 @@ func TestKVIndexer(t *testing.T) {
"success, exceed block gas limit",
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz}}},
[]*abci.ResponseDeliverTx{
&abci.ResponseDeliverTx{
{
Code: 11,
Log: "out of gas in location: block gas meter; gasWanted: 21000",
Events: []abci.Event{},
Expand All @@ -116,7 +116,7 @@ func TestKVIndexer(t *testing.T) {
"fail, failed eth tx",
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz}}},
[]*abci.ResponseDeliverTx{
&abci.ResponseDeliverTx{
{
Code: 15,
Log: "nonce mismatch",
Events: []abci.Event{},
Expand All @@ -128,7 +128,7 @@ func TestKVIndexer(t *testing.T) {
"fail, invalid events",
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz}}},
[]*abci.ResponseDeliverTx{
&abci.ResponseDeliverTx{
{
Code: 0,
Events: []abci.Event{},
},
Expand All @@ -139,7 +139,7 @@ func TestKVIndexer(t *testing.T) {
"fail, not eth tx",
&tmtypes.Block{Header: tmtypes.Header{Height: 1}, Data: tmtypes.Data{Txs: []tmtypes.Tx{txBz2}}},
[]*abci.ResponseDeliverTx{
&abci.ResponseDeliverTx{
{
Code: 0,
Events: []abci.Event{},
},
Expand Down
5 changes: 2 additions & 3 deletions rpc/backend/account_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ func (b *Backend) GetProof(address common.Address, storageKeys []string, blockNr
height := blockNum.Int64()
_, err = b.GetTendermintBlockByNumber(blockNum)
if err != nil {
// Get 'latest' proof if query is in the future
// this imitates geth behavior
height = 0
// the error message imitates geth behavior
return nil, errors.New("header not found")
}
ctx := rpctypes.ContextWithHeight(height)

Expand Down
1 change: 1 addition & 0 deletions rpc/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type EVMBackend interface {
Accounts() ([]common.Address, error)
Syncing() (interface{}, error)
SetEtherbase(etherbase common.Address) bool
SetGasPrice(gasPrice hexutil.Big) bool
ImportRawKey(privkey, password string) (common.Address, error)
ListAccounts() ([]common.Address, error)
NewMnemonic(uid string, language keyring.Language, hdPath, bip39Passphrase string, algo keyring.SignatureAlgo) (keyring.Info, error)
Expand Down
31 changes: 31 additions & 0 deletions rpc/backend/node_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/tx"
sdkcrypto "github.com/cosmos/cosmos-sdk/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
sdkconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
Expand All @@ -18,6 +19,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/evmos/ethermint/crypto/ethsecp256k1"
rpctypes "github.com/evmos/ethermint/rpc/types"
"github.com/evmos/ethermint/server/config"
ethermint "github.com/evmos/ethermint/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
tmtypes "github.com/tendermint/tendermint/types"
Expand Down Expand Up @@ -230,6 +232,35 @@ func (b *Backend) NewMnemonic(uid string, language keyring.Language, hdPath, bip
return info, err
}

// SetGasPrice sets the minimum accepted gas price for the miner.
// NOTE: this function accepts only integers to have the same interface than go-eth
// to use float values, the gas prices must be configured using the configuration file
func (b *Backend) SetGasPrice(gasPrice hexutil.Big) bool {
appConf := config.GetConfig(b.clientCtx.Viper)

var unit string
minGasPrices := appConf.GetMinGasPrices()

// fetch the base denom from the sdk Config in case it's not currently defined on the node config
if len(minGasPrices) == 0 || minGasPrices.Empty() {
var err error
unit, err = sdk.GetBaseDenom()
if err != nil {
b.logger.Debug("could not get the denom of smallest unit registered", "error", err.Error())
return false
}
} else {
unit = minGasPrices[0].Denom
}

c := sdk.NewDecCoin(unit, sdk.NewIntFromBigInt(gasPrice.ToInt()))

appConf.SetMinGasPrices(sdk.DecCoins{c})
sdkconfig.WriteConfigFile(b.clientCtx.Viper.ConfigFileUsed(), appConf)
b.logger.Info("Your configuration file was modified. Please RESTART your node.", "gas-price", c.String())
return true
}

// UnprotectedAllowed returns the node configuration value for allowing
// unprotected transactions (i.e not replay-protected)
func (b Backend) UnprotectedAllowed() bool {
Expand Down
8 changes: 4 additions & 4 deletions rpc/namespaces/ethereum/eth/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (

// FilterAPI gathers
type FilterAPI interface {
GetLogs(ctx context.Context, crit filters.FilterCriteria) ([]*ethtypes.Log, error)
GetFilterChanges(id rpc.ID) (interface{}, error)
GetFilterLogs(ctx context.Context, id rpc.ID) ([]*ethtypes.Log, error)
NewPendingTransactionFilter() rpc.ID
NewBlockFilter() rpc.ID
NewFilter(criteria filters.FilterCriteria) (rpc.ID, error)
NewPendingTransactionFilter() rpc.ID
GetFilterChanges(id rpc.ID) (interface{}, error)
GetFilterLogs(ctx context.Context, id rpc.ID) ([]*ethtypes.Log, error)
UninstallFilter(id rpc.ID) bool
GetLogs(ctx context.Context, crit filters.FilterCriteria) ([]*ethtypes.Log, error)
}

// Backend defines the methods requided by the PublicFilterAPI backend
Expand Down
7 changes: 7 additions & 0 deletions rpc/namespaces/ethereum/miner/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/server"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/tendermint/tendermint/libs/log"

Expand Down Expand Up @@ -34,3 +35,9 @@ func (api *API) SetEtherbase(etherbase common.Address) bool {
api.logger.Debug("miner_setEtherbase")
return api.backend.SetEtherbase(etherbase)
}

// SetGasPrice sets the minimum accepted gas price for the miner.
func (api *API) SetGasPrice(gasPrice hexutil.Big) bool {
api.logger.Info(api.ctx.Viper.ConfigFileUsed())
return api.backend.SetGasPrice(gasPrice)
}
55 changes: 55 additions & 0 deletions tests/integration_tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# RPC Integration tests

The RPC integration test suite uses nix for reproducible and configurable
builds allowing to run integration tests using python web3 library against
different Ethermint and [Geth](https:/ethereum/go-ethereum) clients with multiple configurations.

## Installation

Nix Multi-user installation:

```
sh <(curl -L https://nixos.org/nix/install) --daemon
```

Make sure the following line has been added to your shell profile (e.g. ~/.profile):

```
source ~/.nix-profile/etc/profile.d/nix.sh
```

Then re-login shell, the nix installation is completed.

For linux:

```
sh <(curl -L https://nixos.org/nix/install) --no-daemon
```

## Run Local

First time run (can take a while):

```
make run-integration-tests
```

Once you've run them once and, you can run:

```
nix-shell tests/integration_tests/shell.nix
cd tests/integration_tests
pytest -s -vv
```

If you're changing anything on the ethermint rpc, rerun the first command.


## Caching

You can enable Binary Cache to speed up the tests:

```
$ nix-env -iA cachix -f https://cachix.org/api/v1/install
$ cachix use ethermint
```
20 changes: 20 additions & 0 deletions tests/integration_tests/contracts/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma solidity >0.5.0;

contract Greeter {
string public greeting;

event ChangeGreeting(address from, string value);

constructor() public {
greeting = "Hello";
}

function setGreeting(string memory _greeting) public {
greeting = _greeting;
emit ChangeGreeting(msg.sender, _greeting);
}

function greet() public view returns (string memory) {
return greeting;
}
}
1 change: 1 addition & 0 deletions tests/integration_tests/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def setup_ethermint(path, base_port):
cfg = Path(__file__).parent / "configs/default.jsonnet"
yield from setup_custom_ethermint(path, base_port, cfg)


def setup_geth(path, base_port):
with (path / "geth.log").open("w") as logfile:
cmd = [
Expand Down
Loading

0 comments on commit b7acaa6

Please sign in to comment.