laconicd-deprecated/app/utils_test.go

114 lines
3.6 KiB
Go
Raw Normal View History

fix: simulations don't generate EVM transactions (#996) * use SimAppChainId instead of the default cosmos-sdk simulation chainid * implement custom RandomGenesisAccounts for auth module simulation * use customized RandomGenesisAccounts * generate random ethereum txs operations * use sdk.DefaultBondDenom * implement WeightedOperations * fix self assignment * use customized RandomAccounts to generate accounts with ethsecp256k1 private key * RandomAccounts generate random accounts with ethsecp256k1 private key * implement SimulateEthSimpleTransfer * implement SimulateEthCreateContract * refactor and implement operationSimulateEthCallContract as future operations of SimulateEthCreateContract * Update app/app.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix r.Read return only 1 result * fix linter errors * change SimulateContext to private * return transferable amount immediately * fix linter errors * fix linter errors: append assign to different slice * fix linter error: remove else block * use gofumpt * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix recipient typo * add nosec comment to escape Potential hardcoded credentials check * add comments * use SimAppChainID as valid chainID * do not specify genesis.json to create random genesis state for simulation * sub estimateGas to avoid overflow * correct RandomGenesisAccounts comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * correct app/test_helpers.go comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove NewTxConfig * implement RegisterStoreDecoder * remove WeightMsgEthCallContract and adjust weights * use gofmt * update godoc * use types.DefaultEVMDenom in evm genesis params Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * use types.DefaultEVMDenom Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update godoc * Update x/evm/simulation/genesis.go * replace evmdenom with bonddenom in AppStateFn * fix AppStateFn * fix lint error * add ParamChanges for RandomizedParams * rename app/test_helpers.go -> app/utils.go * testing for RandomGenesisAccounts * use cdc for marshaling * lint * changelog * changelog 2 Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com> Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-04-19 09:50:00 +00:00
package app
import (
"encoding/json"
fix: simulations don't generate EVM transactions (#996) * use SimAppChainId instead of the default cosmos-sdk simulation chainid * implement custom RandomGenesisAccounts for auth module simulation * use customized RandomGenesisAccounts * generate random ethereum txs operations * use sdk.DefaultBondDenom * implement WeightedOperations * fix self assignment * use customized RandomAccounts to generate accounts with ethsecp256k1 private key * RandomAccounts generate random accounts with ethsecp256k1 private key * implement SimulateEthSimpleTransfer * implement SimulateEthCreateContract * refactor and implement operationSimulateEthCallContract as future operations of SimulateEthCreateContract * Update app/app.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix r.Read return only 1 result * fix linter errors * change SimulateContext to private * return transferable amount immediately * fix linter errors * fix linter errors: append assign to different slice * fix linter error: remove else block * use gofumpt * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix recipient typo * add nosec comment to escape Potential hardcoded credentials check * add comments * use SimAppChainID as valid chainID * do not specify genesis.json to create random genesis state for simulation * sub estimateGas to avoid overflow * correct RandomGenesisAccounts comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * correct app/test_helpers.go comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove NewTxConfig * implement RegisterStoreDecoder * remove WeightMsgEthCallContract and adjust weights * use gofmt * update godoc * use types.DefaultEVMDenom in evm genesis params Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * use types.DefaultEVMDenom Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update godoc * Update x/evm/simulation/genesis.go * replace evmdenom with bonddenom in AppStateFn * fix AppStateFn * fix lint error * add ParamChanges for RandomizedParams * rename app/test_helpers.go -> app/utils.go * testing for RandomGenesisAccounts * use cdc for marshaling * lint * changelog * changelog 2 Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com> Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-04-19 09:50:00 +00:00
"math/rand"
"os"
fix: simulations don't generate EVM transactions (#996) * use SimAppChainId instead of the default cosmos-sdk simulation chainid * implement custom RandomGenesisAccounts for auth module simulation * use customized RandomGenesisAccounts * generate random ethereum txs operations * use sdk.DefaultBondDenom * implement WeightedOperations * fix self assignment * use customized RandomAccounts to generate accounts with ethsecp256k1 private key * RandomAccounts generate random accounts with ethsecp256k1 private key * implement SimulateEthSimpleTransfer * implement SimulateEthCreateContract * refactor and implement operationSimulateEthCallContract as future operations of SimulateEthCreateContract * Update app/app.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix r.Read return only 1 result * fix linter errors * change SimulateContext to private * return transferable amount immediately * fix linter errors * fix linter errors: append assign to different slice * fix linter error: remove else block * use gofumpt * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix recipient typo * add nosec comment to escape Potential hardcoded credentials check * add comments * use SimAppChainID as valid chainID * do not specify genesis.json to create random genesis state for simulation * sub estimateGas to avoid overflow * correct RandomGenesisAccounts comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * correct app/test_helpers.go comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove NewTxConfig * implement RegisterStoreDecoder * remove WeightMsgEthCallContract and adjust weights * use gofmt * update godoc * use types.DefaultEVMDenom in evm genesis params Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * use types.DefaultEVMDenom Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update godoc * Update x/evm/simulation/genesis.go * replace evmdenom with bonddenom in AppStateFn * fix AppStateFn * fix lint error * add ParamChanges for RandomizedParams * rename app/test_helpers.go -> app/utils.go * testing for RandomGenesisAccounts * use cdc for marshaling * lint * changelog * changelog 2 Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com> Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-04-19 09:50:00 +00:00
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
evmtypes "github.com/evmos/ethermint/x/evm/types"
fix: simulations don't generate EVM transactions (#996) * use SimAppChainId instead of the default cosmos-sdk simulation chainid * implement custom RandomGenesisAccounts for auth module simulation * use customized RandomGenesisAccounts * generate random ethereum txs operations * use sdk.DefaultBondDenom * implement WeightedOperations * fix self assignment * use customized RandomAccounts to generate accounts with ethsecp256k1 private key * RandomAccounts generate random accounts with ethsecp256k1 private key * implement SimulateEthSimpleTransfer * implement SimulateEthCreateContract * refactor and implement operationSimulateEthCallContract as future operations of SimulateEthCreateContract * Update app/app.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix r.Read return only 1 result * fix linter errors * change SimulateContext to private * return transferable amount immediately * fix linter errors * fix linter errors: append assign to different slice * fix linter error: remove else block * use gofumpt * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix recipient typo * add nosec comment to escape Potential hardcoded credentials check * add comments * use SimAppChainID as valid chainID * do not specify genesis.json to create random genesis state for simulation * sub estimateGas to avoid overflow * correct RandomGenesisAccounts comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * correct app/test_helpers.go comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove NewTxConfig * implement RegisterStoreDecoder * remove WeightMsgEthCallContract and adjust weights * use gofmt * update godoc * use types.DefaultEVMDenom in evm genesis params Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * use types.DefaultEVMDenom Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update godoc * Update x/evm/simulation/genesis.go * replace evmdenom with bonddenom in AppStateFn * fix AppStateFn * fix lint error * add ParamChanges for RandomizedParams * rename app/test_helpers.go -> app/utils.go * testing for RandomGenesisAccounts * use cdc for marshaling * lint * changelog * changelog 2 Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com> Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-04-19 09:50:00 +00:00
"github.com/evmos/ethermint/crypto/ethsecp256k1"
ethermint "github.com/evmos/ethermint/types"
fix: simulations don't generate EVM transactions (#996) * use SimAppChainId instead of the default cosmos-sdk simulation chainid * implement custom RandomGenesisAccounts for auth module simulation * use customized RandomGenesisAccounts * generate random ethereum txs operations * use sdk.DefaultBondDenom * implement WeightedOperations * fix self assignment * use customized RandomAccounts to generate accounts with ethsecp256k1 private key * RandomAccounts generate random accounts with ethsecp256k1 private key * implement SimulateEthSimpleTransfer * implement SimulateEthCreateContract * refactor and implement operationSimulateEthCallContract as future operations of SimulateEthCreateContract * Update app/app.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix r.Read return only 1 result * fix linter errors * change SimulateContext to private * return transferable amount immediately * fix linter errors * fix linter errors: append assign to different slice * fix linter error: remove else block * use gofumpt * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix recipient typo * add nosec comment to escape Potential hardcoded credentials check * add comments * use SimAppChainID as valid chainID * do not specify genesis.json to create random genesis state for simulation * sub estimateGas to avoid overflow * correct RandomGenesisAccounts comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * correct app/test_helpers.go comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove NewTxConfig * implement RegisterStoreDecoder * remove WeightMsgEthCallContract and adjust weights * use gofmt * update godoc * use types.DefaultEVMDenom in evm genesis params Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * use types.DefaultEVMDenom Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update godoc * Update x/evm/simulation/genesis.go * replace evmdenom with bonddenom in AppStateFn * fix AppStateFn * fix lint error * add ParamChanges for RandomizedParams * rename app/test_helpers.go -> app/utils.go * testing for RandomGenesisAccounts * use cdc for marshaling * lint * changelog * changelog 2 Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com> Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-04-19 09:50:00 +00:00
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
maxTestingAccounts = 100
seed = int64(233)
)
fix: simulations don't generate EVM transactions (#996) * use SimAppChainId instead of the default cosmos-sdk simulation chainid * implement custom RandomGenesisAccounts for auth module simulation * use customized RandomGenesisAccounts * generate random ethereum txs operations * use sdk.DefaultBondDenom * implement WeightedOperations * fix self assignment * use customized RandomAccounts to generate accounts with ethsecp256k1 private key * RandomAccounts generate random accounts with ethsecp256k1 private key * implement SimulateEthSimpleTransfer * implement SimulateEthCreateContract * refactor and implement operationSimulateEthCallContract as future operations of SimulateEthCreateContract * Update app/app.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix r.Read return only 1 result * fix linter errors * change SimulateContext to private * return transferable amount immediately * fix linter errors * fix linter errors: append assign to different slice * fix linter error: remove else block * use gofumpt * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix recipient typo * add nosec comment to escape Potential hardcoded credentials check * add comments * use SimAppChainID as valid chainID * do not specify genesis.json to create random genesis state for simulation * sub estimateGas to avoid overflow * correct RandomGenesisAccounts comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * correct app/test_helpers.go comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove NewTxConfig * implement RegisterStoreDecoder * remove WeightMsgEthCallContract and adjust weights * use gofmt * update godoc * use types.DefaultEVMDenom in evm genesis params Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * use types.DefaultEVMDenom Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update godoc * Update x/evm/simulation/genesis.go * replace evmdenom with bonddenom in AppStateFn * fix AppStateFn * fix lint error * add ParamChanges for RandomizedParams * rename app/test_helpers.go -> app/utils.go * testing for RandomGenesisAccounts * use cdc for marshaling * lint * changelog * changelog 2 Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com> Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-04-19 09:50:00 +00:00
func TestRandomGenesisAccounts(t *testing.T) {
r := rand.New(rand.NewSource(seed))
accs := RandomAccounts(r, rand.Intn(maxTestingAccounts))
encodingConfig := MakeEncodingConfig()
appCodec := encodingConfig.Codec
fix: simulations don't generate EVM transactions (#996) * use SimAppChainId instead of the default cosmos-sdk simulation chainid * implement custom RandomGenesisAccounts for auth module simulation * use customized RandomGenesisAccounts * generate random ethereum txs operations * use sdk.DefaultBondDenom * implement WeightedOperations * fix self assignment * use customized RandomAccounts to generate accounts with ethsecp256k1 private key * RandomAccounts generate random accounts with ethsecp256k1 private key * implement SimulateEthSimpleTransfer * implement SimulateEthCreateContract * refactor and implement operationSimulateEthCallContract as future operations of SimulateEthCreateContract * Update app/app.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix r.Read return only 1 result * fix linter errors * change SimulateContext to private * return transferable amount immediately * fix linter errors * fix linter errors: append assign to different slice * fix linter error: remove else block * use gofumpt * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix recipient typo * add nosec comment to escape Potential hardcoded credentials check * add comments * use SimAppChainID as valid chainID * do not specify genesis.json to create random genesis state for simulation * sub estimateGas to avoid overflow * correct RandomGenesisAccounts comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * correct app/test_helpers.go comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove NewTxConfig * implement RegisterStoreDecoder * remove WeightMsgEthCallContract and adjust weights * use gofmt * update godoc * use types.DefaultEVMDenom in evm genesis params Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * use types.DefaultEVMDenom Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update godoc * Update x/evm/simulation/genesis.go * replace evmdenom with bonddenom in AppStateFn * fix AppStateFn * fix lint error * add ParamChanges for RandomizedParams * rename app/test_helpers.go -> app/utils.go * testing for RandomGenesisAccounts * use cdc for marshaling * lint * changelog * changelog 2 Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com> Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-04-19 09:50:00 +00:00
cdc := encodingConfig.Amino
paramsKeeper := initParamsKeeper(appCodec, cdc, sdk.NewKVStoreKey(paramstypes.StoreKey), sdk.NewTransientStoreKey(paramstypes.StoreKey))
subSpace, find := paramsKeeper.GetSubspace(authtypes.ModuleName)
require.True(t, find)
accountKeeper := authkeeper.NewAccountKeeper(
appCodec, sdk.NewKVStoreKey(authtypes.StoreKey), subSpace, ethermint.ProtoAccount, maccPerms, sdk.GetConfig().GetBech32AccountAddrPrefix(),
fix: simulations don't generate EVM transactions (#996) * use SimAppChainId instead of the default cosmos-sdk simulation chainid * implement custom RandomGenesisAccounts for auth module simulation * use customized RandomGenesisAccounts * generate random ethereum txs operations * use sdk.DefaultBondDenom * implement WeightedOperations * fix self assignment * use customized RandomAccounts to generate accounts with ethsecp256k1 private key * RandomAccounts generate random accounts with ethsecp256k1 private key * implement SimulateEthSimpleTransfer * implement SimulateEthCreateContract * refactor and implement operationSimulateEthCallContract as future operations of SimulateEthCreateContract * Update app/app.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update app/test_helpers.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix r.Read return only 1 result * fix linter errors * change SimulateContext to private * return transferable amount immediately * fix linter errors * fix linter errors: append assign to different slice * fix linter error: remove else block * use gofumpt * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * Update x/evm/simulation/operations.go Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * fix recipient typo * add nosec comment to escape Potential hardcoded credentials check * add comments * use SimAppChainID as valid chainID * do not specify genesis.json to create random genesis state for simulation * sub estimateGas to avoid overflow * correct RandomGenesisAccounts comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * correct app/test_helpers.go comments Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * remove NewTxConfig * implement RegisterStoreDecoder * remove WeightMsgEthCallContract and adjust weights * use gofmt * update godoc * use types.DefaultEVMDenom in evm genesis params Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * use types.DefaultEVMDenom Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> * update godoc * Update x/evm/simulation/genesis.go * replace evmdenom with bonddenom in AppStateFn * fix AppStateFn * fix lint error * add ParamChanges for RandomizedParams * rename app/test_helpers.go -> app/utils.go * testing for RandomGenesisAccounts * use cdc for marshaling * lint * changelog * changelog 2 Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com> Co-authored-by: crypto-facs <84574577+crypto-facs@users.noreply.github.com> Co-authored-by: Freddy Caceres <freddy.caceres@crypto.com> Co-authored-by: Federico Kunze Küllmer <federico.kunze94@gmail.com>
2022-04-19 09:50:00 +00:00
)
authModule := auth.NewAppModule(appCodec, accountKeeper, RandomGenesisAccounts)
genesisState := simapp.NewDefaultGenesisState(appCodec)
simState := &module.SimulationState{Accounts: accs, Cdc: appCodec, Rand: r, GenState: genesisState}
authModule.GenerateGenesisState(simState)
authStateBz, find := genesisState[authtypes.ModuleName]
require.True(t, find)
authState := new(authtypes.GenesisState)
appCodec.MustUnmarshalJSON(authStateBz, authState)
accounts, err := authtypes.UnpackAccounts(authState.Accounts)
require.NoError(t, err)
for _, acc := range accounts {
_, ok := acc.(ethermint.EthAccountI)
require.True(t, ok)
}
}
func TestStateFn(t *testing.T) {
config, db, dir, logger, skip, err := simapp.SetupSimulation("leveldb-app-sim", "Simulation")
if skip {
t.Skip("skipping AppStateFn testing")
}
require.NoError(t, err, "simulation setup failed")
config.ChainID = SimAppChainID
config.Commit = true
defer func() {
db.Close()
require.NoError(t, os.RemoveAll(dir))
}()
app := NewEthermintApp(logger, db, nil, true, map[int64]bool{}, DefaultNodeHome, simapp.FlagPeriodValue, MakeEncodingConfig(), simapp.EmptyAppOptions{}, fauxMerkleModeOpt)
require.Equal(t, appName, app.Name())
appStateFn := StateFn(app.AppCodec(), app.SimulationManager())
r := rand.New(rand.NewSource(seed))
accounts := RandomAccounts(r, rand.Intn(maxTestingAccounts))
appState, _, _, _ := appStateFn(r, accounts, config)
rawState := make(map[string]json.RawMessage)
err = json.Unmarshal(appState, &rawState)
require.NoError(t, err)
stakingStateBz, ok := rawState[stakingtypes.ModuleName]
require.True(t, ok)
stakingState := new(stakingtypes.GenesisState)
app.AppCodec().MustUnmarshalJSON(stakingStateBz, stakingState)
bondDenom := stakingState.Params.BondDenom
evmStateBz, ok := rawState[evmtypes.ModuleName]
require.True(t, ok)
evmState := new(evmtypes.GenesisState)
app.AppCodec().MustUnmarshalJSON(evmStateBz, evmState)
require.Equal(t, bondDenom, evmState.Params.EvmDenom)
}
func TestRandomAccounts(t *testing.T) {
r := rand.New(rand.NewSource(seed))
accounts := RandomAccounts(r, rand.Intn(maxTestingAccounts))
for _, acc := range accounts {
_, ok := acc.PrivKey.(*ethsecp256k1.PrivKey)
require.True(t, ok)
}
}