Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

fix: simulations don't generate EVM transactions #996

Merged
merged 65 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
de71644
use SimAppChainId instead of the default cosmos-sdk simulation chainid
adu-web3 Mar 16, 2022
9bccb19
implement custom RandomGenesisAccounts for auth module simulation
adu-web3 Mar 16, 2022
2cee1bc
use customized RandomGenesisAccounts
adu-web3 Mar 20, 2022
5e5201a
generate random ethereum txs operations
adu-web3 Mar 20, 2022
2af14bf
use sdk.DefaultBondDenom
adu-web3 Mar 20, 2022
0d2afd0
implement WeightedOperations
adu-web3 Mar 20, 2022
7d366c3
fix self assignment
adu-web3 Mar 21, 2022
4ab9534
use customized RandomAccounts to generate accounts with ethsecp256k1 …
adu-web3 Mar 24, 2022
3ca68cc
RandomAccounts generate random accounts with ethsecp256k1 private key
adu-web3 Mar 24, 2022
582558a
implement SimulateEthSimpleTransfer
adu-web3 Mar 24, 2022
5d6bf3d
implement SimulateEthCreateContract
adu-web3 Mar 28, 2022
b2e991a
refactor and implement operationSimulateEthCallContract as future ope…
adu-web3 Mar 30, 2022
fa4c327
Update app/app.go
adu-web3 Mar 30, 2022
161eea5
Update app/test_helpers.go
adu-web3 Mar 30, 2022
2ddd4b3
Update x/evm/simulation/operations.go
adu-web3 Mar 30, 2022
6a06c83
Update x/evm/simulation/operations.go
adu-web3 Mar 30, 2022
4720c35
Update app/test_helpers.go
adu-web3 Mar 30, 2022
6b027bf
fix r.Read return only 1 result
adu-web3 Mar 31, 2022
c9dddff
fix linter errors
adu-web3 Mar 31, 2022
b53c633
change SimulateContext to private
adu-web3 Mar 31, 2022
8a556d7
return transferable amount immediately
adu-web3 Mar 31, 2022
bbff196
fix linter errors
adu-web3 Mar 31, 2022
cc9463f
fix linter errors: append assign to different slice
adu-web3 Mar 31, 2022
594acd0
fix linter error: remove else block
adu-web3 Mar 31, 2022
205dd54
use gofumpt
adu-web3 Mar 31, 2022
0902155
Merge branch 'main' into evm-simulation
fedekunze Apr 5, 2022
2ac8af8
Merge branch 'main' into evm-simulation
fedekunze Apr 5, 2022
c1f584f
Update x/evm/simulation/operations.go
crypto-facs Apr 5, 2022
7c94884
Update x/evm/simulation/operations.go
crypto-facs Apr 5, 2022
760dbc3
Update x/evm/simulation/operations.go
crypto-facs Apr 5, 2022
538acdc
Update x/evm/simulation/operations.go
crypto-facs Apr 5, 2022
8a5f6f0
Merge branch 'main' into evm-simulation
crypto-facs Apr 6, 2022
9318807
fix recipient typo
crypto-facs Apr 6, 2022
61cf53d
add nosec comment to escape Potential hardcoded credentials check
adu-web3 Apr 7, 2022
1ae5730
add comments
adu-web3 Apr 7, 2022
d5631a9
use SimAppChainID as valid chainID
adu-web3 Apr 7, 2022
cd4f8ab
do not specify genesis.json to create random genesis state for simula…
adu-web3 Apr 7, 2022
dae71a5
sub estimateGas to avoid overflow
adu-web3 Apr 7, 2022
c8c1800
correct RandomGenesisAccounts comments
adu-web3 Apr 8, 2022
b53e690
correct app/test_helpers.go comments
adu-web3 Apr 8, 2022
4f5bd58
Merge branch 'main' into evm-simulation
fedekunze Apr 12, 2022
54501d1
Merge branch 'main' into evm-simulation
fedekunze Apr 12, 2022
53689aa
remove NewTxConfig
adu-web3 Apr 11, 2022
90af055
implement RegisterStoreDecoder
adu-web3 Apr 13, 2022
ec377e7
remove WeightMsgEthCallContract and adjust weights
adu-web3 Apr 13, 2022
ff49ca9
use gofmt
adu-web3 Apr 13, 2022
744e9f6
Merge branch 'main' into evm-simulation
fedekunze Apr 13, 2022
6865918
update godoc
adu-web3 Apr 14, 2022
b251a2f
use types.DefaultEVMDenom in evm genesis params
adu-web3 Apr 14, 2022
f7de910
use types.DefaultEVMDenom
adu-web3 Apr 14, 2022
0e7fc56
update godoc
adu-web3 Apr 14, 2022
ac5500a
Update x/evm/simulation/genesis.go
fedekunze Apr 14, 2022
521cb9c
replace evmdenom with bonddenom in AppStateFn
adu-web3 Apr 14, 2022
c587e23
fix AppStateFn
adu-web3 Apr 15, 2022
52e4331
fix lint error
adu-web3 Apr 15, 2022
7694a7c
Merge branch 'main' into evm-simulation
fedekunze Apr 15, 2022
7abc387
add ParamChanges for RandomizedParams
adu-web3 Apr 18, 2022
1d565ae
rename app/test_helpers.go -> app/utils.go
adu-web3 Apr 18, 2022
1b17bee
testing for RandomGenesisAccounts
adu-web3 Apr 18, 2022
bb31e56
Merge branch 'main' into evm-simulation
fedekunze Apr 19, 2022
300d671
Merge branch 'main' into evm-simulation
fedekunze Apr 19, 2022
90aaede
use cdc for marshaling
fedekunze Apr 19, 2022
27879c4
lint
fedekunze Apr 19, 2022
85a29c4
changelog
fedekunze Apr 19, 2022
29cc44b
changelog 2
fedekunze Apr 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ func NewEthermintApp(
// NOTE: this is not required apps that don't use the simulator for fuzz testing
// transactions
app.sm = module.NewSimulationManager(
auth.NewAppModule(appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts),
auth.NewAppModule(appCodec, app.AccountKeeper, RandomGenesisAccounts),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
Expand Down
17 changes: 11 additions & 6 deletions app/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/cosmos/cosmos-sdk/simapp/params"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -72,6 +71,8 @@ func TestFullAppSimulation(t *testing.T) {
}
require.NoError(t, err, "simulation setup failed")

config.ChainID = SimAppChainID

defer func() {
db.Close()
require.NoError(t, os.RemoveAll(dir))
Expand All @@ -86,7 +87,7 @@ func TestFullAppSimulation(t *testing.T) {
os.Stdout,
app.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simapp.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand All @@ -110,6 +111,8 @@ func TestAppImportExport(t *testing.T) {
}
require.NoError(t, err, "simulation setup failed")

config.ChainID = SimAppChainID

defer func() {
db.Close()
require.NoError(t, os.RemoveAll(dir))
Expand All @@ -124,7 +127,7 @@ func TestAppImportExport(t *testing.T) {
os.Stdout,
app.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simapp.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down Expand Up @@ -210,6 +213,8 @@ func TestAppSimulationAfterImport(t *testing.T) {
}
require.NoError(t, err, "simulation setup failed")

config.ChainID = SimAppChainID

defer func() {
db.Close()
require.NoError(t, os.RemoveAll(dir))
Expand All @@ -224,7 +229,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
os.Stdout,
app.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simapp.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down Expand Up @@ -272,7 +277,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
os.Stdout,
newApp.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simapp.SimulationOperations(newApp, newApp.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down Expand Up @@ -323,7 +328,7 @@ func TestAppStateDeterminism(t *testing.T) {
os.Stdout,
app.BaseApp,
simapp.AppStateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simapp.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down
49 changes: 49 additions & 0 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ package app

import (
"encoding/json"
"math/rand"
"time"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/tharsis/ethermint/encoding"
ethermint "github.com/tharsis/ethermint/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
"github.com/tharsis/ethermint/crypto/ethsecp256k1"
)

// DefaultConsensusParams defines the default Tendermint consensus params used in
Expand Down Expand Up @@ -62,3 +74,40 @@ func Setup(isCheckTx bool, patchGenesis func(*EthermintApp, simapp.GenesisState)

return app
}

func RandomGenesisAccounts(simState *module.SimulationState) authtypes.GenesisAccounts {
adu-web3 marked this conversation as resolved.
Show resolved Hide resolved
emptyCodeHash := crypto.Keccak256(nil)
genesisAccs := make(authtypes.GenesisAccounts, len(simState.Accounts))
for i, acc := range simState.Accounts {
bacc := authtypes.NewBaseAccountWithAddress(acc.Address)

ethacc := &ethermint.EthAccount{
BaseAccount: bacc,
CodeHash: common.BytesToHash(emptyCodeHash).String(),
}
genesisAccs[i] = ethacc
}

return genesisAccs
}

func RandomAccounts(r *rand.Rand, n int) []simtypes.Account {
adu-web3 marked this conversation as resolved.
Show resolved Hide resolved
accs := make([]simtypes.Account, n)

for i := 0; i < n; i++ {
// don't need that much entropy for simulation
privkeySeed := make([]byte, 15)
_ = r.Read(privkeySeed)

prv := secp256k1.GenPrivKeyFromSecret(privkeySeed)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
ethPrv := &ethsecp256k1.PrivKey{}
ethPrv.UnmarshalAmino(prv.Bytes())
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
accs[i].PrivKey = ethPrv
accs[i].PubKey = accs[i].PrivKey.PubKey()
accs[i].Address = sdk.AccAddress(accs[i].PubKey.Address())

accs[i].ConsKey = ed25519.GenPrivKeyFromSecret(privkeySeed)
}

return accs
}
4 changes: 3 additions & 1 deletion x/evm/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) {

// WeightedOperations returns the all the evm module operations with their respective weights.
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return nil
return simulation.WeightedOperations(
simState.AppParams, simState.Cdc, am.ak, am.keeper,
)
}
5 changes: 3 additions & 2 deletions x/evm/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"encoding/json"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/tharsis/ethermint/x/evm/types"
)

// RandomizedGenState generates a random GenesisState for nft
func RandomizedGenState(simState *module.SimulationState) {
params := types.NewParams(types.DefaultEVMDenom, true, true, types.DefaultChainConfig())
params := types.NewParams(sdk.DefaultBondDenom, true, true, types.DefaultChainConfig())
adu-web3 marked this conversation as resolved.
Show resolved Hide resolved
if simState.Rand.Uint32()%2 == 0 {
params = types.NewParams(types.DefaultEVMDenom, true, true, types.DefaultChainConfig(), 1344, 1884, 2200, 2929, 3198, 3529)
params = types.NewParams(sdk.DefaultBondDenom, true, true, types.DefaultChainConfig(), 1344, 1884, 2200, 2929, 3198, 3529)
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
adu-web3 marked this conversation as resolved.
Show resolved Hide resolved
}
evmGenesis := types.NewGenesisState(params, []types.GenesisAccount{})

Expand Down
Loading