Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
182 changes: 182 additions & 0 deletions .github/workflows/sims.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
name: Sims
# Sims workflow runs multiple types of simulations (nondeterminism, import-export, after-import, multi-seed-short)
# This workflow will run on main and release branches, if a .go, .mod or .sum file have been changed
on:
push:
paths-ignore:
- 'docs/**'
branches:
- main
- release/**
tags:
- "*"
pull_request:
types: auto_merge_enabled
issue_comment:
types: [created, edited]

jobs:
build:
runs-on: ubuntu-latest
if: >-
(github.event_name == 'issue_comment' && github.event.comment.body == '/runsim') ||
github.event_name == 'push' || github.event_name == 'pull_request'
steps:
- name: Check if organization member
uses: JamesSingleton/is-organization-member@main
id: checkMember
with:
username: ${{ github.actor }}
organization: crypto-org-chain
token: ${{ secrets.GITHUB_TOKEN }}
- name: Comment PR for authentication failure
uses: allthatjazzleo/actions-pull-request-add-comment@master
if: steps.checkMember.outputs.result == 'false'
with:
message: |
Sorry only crypto-org-chain member could run simulations by '/runsim'.
If you are a crypto-org-chain member, please set your membership visibility to `public` in this [page](https://github.com/orgs/crypto-org-chain/people).
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail and exit the job if authentication failed
if: steps.checkMember.outputs.result == 'false'
run: exit 1
- name: Comment PR for Sim test started
uses: allthatjazzleo/actions-pull-request-add-comment@master
with:
message: |
Simulation tests started and triggered by `/runsim`.
Can further check progress [here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions/setup-go@v2.1.3
with:
go-version: 1.17
- name: Display go version
run: go version
- run: make build

install-runsim:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/setup-go@v2.1.3
with:
go-version: 1.17
- name: Display go version
run: go version
- name: Install runsim
run: export GO111MODULE="on" && go get github.com/cosmos/tools/cmd/runsim@v1.0.0
- uses: actions/cache@v2.1.6
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary

test-sim-nondeterminism:
runs-on: ubuntu-latest
needs: [build, install-runsim]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2.1.3
with:
go-version: 1.17
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- uses: actions/cache@v2.1.6
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
if: env.GIT_DIFF
- name: test-sim-nondeterminism
run: |
make test-sim-nondeterminism
if: env.GIT_DIFF

test-sim-import-export:
runs-on: ubuntu-latest
needs: [build, install-runsim]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2.1.3
with:
go-version: 1.17
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
with:
SUFFIX_FILTER: |
**/**.go
go.mod
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/cache@v2.1.6
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
if: env.GIT_DIFF
- name: test-sim-import-export
run: |
make test-sim-import-export
if: env.GIT_DIFF

test-sim-after-import:
runs-on: ubuntu-latest
needs: [build, install-runsim]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2.1.3
with:
go-version: 1.17
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
with:
SUFFIX_FILTER: |
**/**.go
go.mod
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/cache@v2.1.6
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
if: env.GIT_DIFF
- name: test-sim-after-import
run: |
make test-sim-after-import
if: env.GIT_DIFF

test-sim-multi-seed-short:
runs-on: ubuntu-latest
needs: [build, install-runsim]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2.1.3
with:
go-version: 1.17
- name: Display go version
run: go version
- uses: technote-space/get-diff-action@v4
with:
SUFFIX_FILTER: |
**/**.go
go.mod
go.sum
SET_ENV_NAME_INSERTIONS: 1
SET_ENV_NAME_LINES: 1
- uses: actions/cache@v2.1.6
with:
path: ~/go/bin
key: ${{ runner.os }}-go-runsim-binary
if: env.GIT_DIFF
- name: test-sim-multi-seed-short
run: |
make test-sim-multi-seed-short
if: env.GIT_DIFF
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,16 @@ SIMAPP = github.com/crypto-org-chain/cronos/app
runsim: $(BINDIR)/runsim
$(BINDIR)/runsim:
@echo "Installing runsim..."
@(cd /tmp && go get github.com/cosmos/tools/cmd/runsim@v1.0.0)
@(cd /tmp && go install github.com/cosmos/tools/cmd/runsim@v1.0.0)

test-sim-nondeterminism:
@echo "Running non-determinism test..."
@go test -mod=readonly $(SIMAPP) -run TestAppStateDeterminism -Enabled=true \
-NumBlocks=100 -BlockSize=200 -Commit=true -Period=0 -v -timeout 24h

test-sim-custom-genesis-fast:
@echo "Running custom genesis simulation..."
@echo "By default, ${HOME}/.cronosd/config/genesis.json will be used."
@go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation -Genesis=${HOME}/.cronosd/config/genesis.json \
test-sim-random-genesis-fast:
@echo "Running random genesis simulation..."
@go test -mod=readonly $(SIMAPP) -run TestFullAppSimulation \
-Enabled=true -NumBlocks=100 -BlockSize=200 -Commit=true -Seed=99 -Period=5 -v -timeout 24h

test-sim-import-export: runsim
Expand Down
6 changes: 4 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
Expand Down Expand Up @@ -97,6 +96,7 @@ import (
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
tmjson "github.com/tendermint/tendermint/libs/json"

ethermintapp "github.com/tharsis/ethermint/app"
evmante "github.com/tharsis/ethermint/app/ante"
srvflags "github.com/tharsis/ethermint/server/flags"
ethermint "github.com/tharsis/ethermint/types"
Expand Down Expand Up @@ -655,7 +655,8 @@ func New(
// 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),
// Use custom RandomGenesisAccounts so that auth module could create random EthAccounts in genesis state when genesis.json not specified
auth.NewAppModule(appCodec, app.AccountKeeper, ethermintapp.RandomGenesisAccounts),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper),
Expand All @@ -671,6 +672,7 @@ func New(
transferModule,
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper),
feemarket.NewAppModule(app.FeeMarketKeeper),
cronos.NewAppModule(appCodec, app.CronosKeeper),
)

app.sm.RegisterStoreDecoders()
Expand Down
12 changes: 6 additions & 6 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
dbm "github.com/tendermint/tm-db"
ethermintapp "github.com/tharsis/ethermint/app"
evmtypes "github.com/tharsis/ethermint/x/evm/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"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"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestFullAppSimulation(t *testing.T) {
os.Stdout,
app.BaseApp,
StateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
ethermintapp.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestAppImportExport(t *testing.T) {
os.Stdout,
app.BaseApp,
StateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
ethermintapp.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
os.Stdout,
app.BaseApp,
StateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
ethermintapp.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
os.Stdout,
newApp.BaseApp,
StateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
ethermintapp.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
SimulationOperations(newApp, newApp.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down Expand Up @@ -320,7 +320,7 @@ func TestAppStateDeterminism(t *testing.T) {
os.Stdout,
app.BaseApp,
StateFn(app.AppCodec(), app.SimulationManager()),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
ethermintapp.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
config,
Expand Down
18 changes: 18 additions & 0 deletions app/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

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

// StateFn returns the initial application state using a genesis or the simulation parameters.
Expand Down Expand Up @@ -123,9 +125,25 @@ func StateFn(cdc codec.JSONCodec, simManager *module.SimulationManager) simtypes
})
}

// we should get the BondDenom and make it the evmdenom.
// thus simulation accounts could have positive amount of gas token.
bondDenom := stakingState.Params.BondDenom

evmStateBz, ok := rawState[evmtypes.ModuleName]
if !ok {
panic("staking genesis state is missing")
}

evmState := new(evmtypes.GenesisState)
cdc.MustUnmarshalJSON(evmStateBz, evmState)

// we should replace the EvmDenom with BondDenom
evmState.Params.EvmDenom = bondDenom

// change appState back
rawState[stakingtypes.ModuleName] = cdc.MustMarshalJSON(stakingState)
rawState[banktypes.ModuleName] = cdc.MustMarshalJSON(bankState)
rawState[evmtypes.ModuleName] = cdc.MustMarshalJSON(evmState)

// replace appstate
appState, err = json.Marshal(rawState)
Expand Down
Empty file added test.json
Empty file.
9 changes: 9 additions & 0 deletions x/cronos/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package keeper
import (
"fmt"

authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -198,3 +199,11 @@ func (k Keeper) OnRecvVouchers(
receiver, tokens.String(), err))
}
}

func (k Keeper) GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin {
return k.bankKeeper.GetBalance(ctx, addr, denom)
}

func (k Keeper) GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI {
return k.accountKeeper.GetAccount(ctx, addr)
}
Loading