This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 564
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp, ci: address pending issues from EVM simulation (#1063)
* add note fix note * add TestAppStateFn TestRandomAccounts * marshal int slice to json * add paramschange for enableCreate and enableCall * AppStateFn -> StateFn * add TestDecodeStore * update github actions to run evm simulation * add TestParamChanges * add TestRandomizedGenState * use go install for runsim * resolve conflict * use random gasCap to estimate gas * use estimateGas to calculate max transferableAmount * update godoc * TestAppStateFn -> TestStateFn * Update x/evm/simulation/genesis.go * comment Co-authored-by: Federico Kunze Küllmer <[email protected]> Co-authored-by: Federico Kunze Küllmer <[email protected]>
- Loading branch information
1 parent
c25669c
commit 4ea9b6d
Showing
12 changed files
with
348 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,4 +117,84 @@ jobs: | |
- name: Test e2e | ||
run: | | ||
make test-integration | ||
if: env.GIT_DIFF | ||
|
||
test-sim-nondeterminism: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.17 | ||
check-latest: true | ||
- uses: actions/checkout@v3 | ||
- uses: technote-space/[email protected] | ||
with: | ||
PATTERNS: | | ||
**/**.go | ||
go.mod | ||
go.sum | ||
- name: Test x/evm simulation nondeterminism | ||
run: | | ||
make test-sim-nondeterminism | ||
if: env.GIT_DIFF | ||
|
||
test-sim-random-genesis-fast: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.17 | ||
check-latest: true | ||
- uses: actions/checkout@v3 | ||
- uses: technote-space/[email protected] | ||
with: | ||
PATTERNS: | | ||
**/**.go | ||
go.mod | ||
go.sum | ||
- name: Test x/evm simulation with random genesis | ||
run: | | ||
make test-sim-random-genesis-fast | ||
if: env.GIT_DIFF | ||
|
||
test-sim-import-export: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.17 | ||
check-latest: true | ||
- uses: actions/checkout@v3 | ||
- uses: technote-space/[email protected] | ||
with: | ||
PATTERNS: | | ||
**/**.go | ||
go.mod | ||
go.sum | ||
- name: Test x/evm simulation import and export | ||
run: | | ||
make test-sim-import-export | ||
if: env.GIT_DIFF | ||
|
||
test-sim-after-import: | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 15 | ||
steps: | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.17 | ||
check-latest: true | ||
- uses: actions/checkout@v3 | ||
- uses: technote-space/[email protected] | ||
with: | ||
PATTERNS: | | ||
**/**.go | ||
go.mod | ||
go.sum | ||
- name: Test x/evm simulation after import | ||
run: | | ||
make test-sim-after-import | ||
if: env.GIT_DIFF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package simulation | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/kv" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/tharsis/ethermint/x/evm/types" | ||
) | ||
|
||
// TestDecodeStore tests that evm simulation decoder decodes the key value pairs as expected. | ||
func TestDecodeStore(t *testing.T) { | ||
dec := NewDecodeStore() | ||
|
||
hash := common.BytesToHash([]byte("hash")) | ||
code := common.Bytes2Hex([]byte{1, 2, 3}) | ||
|
||
kvPairs := kv.Pairs{ | ||
Pairs: []kv.Pair{ | ||
{Key: types.KeyPrefixCode, Value: common.FromHex(code)}, | ||
{Key: types.KeyPrefixStorage, Value: hash.Bytes()}, | ||
}, | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
expectedLog string | ||
}{ | ||
{"Code", fmt.Sprintf("%v\n%v", code, code)}, | ||
{"Storage", fmt.Sprintf("%v\n%v", hash, hash)}, | ||
{"other", ""}, | ||
} | ||
for i, tt := range tests { | ||
i, tt := i, tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
switch i { | ||
case len(tests) - 1: | ||
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) | ||
default: | ||
require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package simulation_test | ||
|
||
import ( | ||
"encoding/json" | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
codectypes "github.com/cosmos/cosmos-sdk/codec/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/tharsis/ethermint/x/evm/simulation" | ||
"github.com/tharsis/ethermint/x/evm/types" | ||
) | ||
|
||
// TestRandomizedGenState tests the normal scenario of applying RandomizedGenState. | ||
// Abonormal scenarios are not tested here. | ||
func TestRandomizedGenState(t *testing.T) { | ||
registry := codectypes.NewInterfaceRegistry() | ||
types.RegisterInterfaces(registry) | ||
cdc := codec.NewProtoCodec(registry) | ||
|
||
s := rand.NewSource(1) | ||
r := rand.New(s) | ||
|
||
simState := module.SimulationState{ | ||
AppParams: make(simtypes.AppParams), | ||
Cdc: cdc, | ||
Rand: r, | ||
NumBonded: 3, | ||
Accounts: simtypes.RandomAccounts(r, 3), | ||
InitialStake: 1000, | ||
GenState: make(map[string]json.RawMessage), | ||
} | ||
|
||
simulation.RandomizedGenState(&simState) | ||
|
||
var evmGenesis types.GenesisState | ||
simState.Cdc.MustUnmarshalJSON(simState.GenState[types.ModuleName], &evmGenesis) | ||
|
||
require.Equal(t, true, evmGenesis.Params.GetEnableCreate()) | ||
require.Equal(t, true, evmGenesis.Params.GetEnableCall()) | ||
require.Equal(t, types.DefaultEVMDenom, evmGenesis.Params.GetEvmDenom()) | ||
require.Equal(t, simulation.GenExtraEIPs(r), evmGenesis.Params.GetExtraEIPs()) | ||
require.Equal(t, types.DefaultChainConfig(), evmGenesis.Params.GetChainConfig()) | ||
|
||
require.Equal(t, len(evmGenesis.Accounts), 0) | ||
} |
Oops, something went wrong.