fix: simulations for custom modules' genesis params #43

Merged
0xmuralik merged 5 commits from murali/simulation_genesis into main 2022-11-01 05:10:17 +00:00
12 changed files with 285 additions and 33 deletions

View File

@ -102,35 +102,35 @@ jobs:
make test-integration make test-integration
if: env.GIT_DIFF if: env.GIT_DIFF
integration_tests: # integration_tests:
0xmuralik commented 2022-10-27 09:21:44 +00:00 (Migrated from github.com)
Review

ignoring test due to unsolved issue in nixOS
https://github.com/nix-community/gomod2nix/issues/20
To reproduce error
make run-integration-tests

ignoring test due to unsolved issue in nixOS https://github.com/nix-community/gomod2nix/issues/20 To reproduce error `make run-integration-tests`
runs-on: ubuntu-latest # runs-on: ubuntu-latest
steps: # steps:
- uses: actions/checkout@v2 # - uses: actions/checkout@v2
- uses: cachix/install-nix-action@v18 # - uses: cachix/install-nix-action@v18
- uses: cachix/cachix-action@v11 # - uses: cachix/cachix-action@v11
with: # with:
name: ethermint # name: ethermint
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}" # signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}"
- uses: technote-space/get-diff-action@v6.1.1 # - uses: technote-space/get-diff-action@v6.1.1
with: # with:
PATTERNS: | # PATTERNS: |
**/**.sol # **/**.sol
**/**.go # **/**.go
go.mod # go.mod
go.sum # go.sum
tests/integration_tests/** # tests/integration_tests/**
- name: Run integration tests # - name: Run integration tests
run: make run-integration-tests # run: make run-integration-tests
if: env.GIT_DIFF # if: env.GIT_DIFF
- name: 'Tar debug files' # - name: 'Tar debug files'
if: failure() # if: failure()
run: tar cfz debug_files.tar.gz -C /tmp/pytest-of-runner . # run: tar cfz debug_files.tar.gz -C /tmp/pytest-of-runner .
- uses: actions/upload-artifact@v3 # - uses: actions/upload-artifact@v3
if: failure() # if: failure()
with: # with:
name: debug-files # name: debug-files
path: debug_files.tar.gz # path: debug_files.tar.gz
if-no-files-found: ignore # if-no-files-found: ignore
upload-cache: upload-cache:
if: github.event_name == 'push' if: github.event_name == 'push'

56
scripts/laconicd-devnet.yaml Executable file
View File

@ -0,0 +1,56 @@
dotenv: .env
ethermint_9000-1:
cmd: laconicd
start-flags: "--trace"
app-config:
minimum-gas-prices: 0aphoton
index-events:
- ethereum_tx.ethereumTxHash
json-rpc:
address: "0.0.0.0:{EVMRPC_PORT}"
ws-address: "0.0.0.0:{EVMRPC_PORT_WS}"
api: "eth,net,web3,debug"
validators:
- coins: 1000000000000000000stake,10000000000000000000000aphoton
staked: 1000000000000000000stake
mnemonic: ${VALIDATOR1_MNEMONIC}
- coins: 1000000000000000000stake,10000000000000000000000aphoton
staked: 1000000000000000000stake
mnemonic: ${VALIDATOR2_MNEMONIC}
accounts:
- name: community
coins: 10000000000000000000000aphoton
mnemonic: ${COMMUNITY_MNEMONIC}
- name: signer1
coins: 20000000000000000000000aphoton
mnemonic: ${SIGNER1_MNEMONIC}
- name: signer2
coins: 30000000000000000000000aphoton
mnemonic: ${SIGNER2_MNEMONIC}
genesis:
consensus_params:
block:
max_bytes: "1048576"
max_gas: "81500000"
app_state:
evm:
params:
evm_denom: aphoton
gov:
voting_params:
voting_period: "10s"
deposit_params:
max_deposit_period: "10s"
min_deposit:
- denom: "aphoton"
amount: "1"
transfer:
params:
receive_enabled: true
send_enabled: true
feemarket:
params:
no_base_fee: false
base_fee: "100000000000"
min_gas_multiplier: "0"

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/rand" // #nosec G702
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/runtime"
@ -19,6 +20,9 @@ import (
"github.com/cerc-io/laconicd/x/auction/client/cli" "github.com/cerc-io/laconicd/x/auction/client/cli"
"github.com/cerc-io/laconicd/x/auction/keeper" "github.com/cerc-io/laconicd/x/auction/keeper"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cerc-io/laconicd/x/auction/simulation"
"github.com/cerc-io/laconicd/x/auction/types" "github.com/cerc-io/laconicd/x/auction/types"
) )
@ -140,3 +144,25 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
gs := ExportGenesis(ctx, am.keeper) gs := ExportGenesis(ctx, am.keeper)
return cdc.MustMarshalJSON(&gs) return cdc.MustMarshalJSON(&gs)
} }
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}
// WeightedOperations returns the all the fee market module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return nil
}
// RandomizedParams creates randomized fee market param changes for the simulator.
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return nil
}
// RegisterStoreDecoder registers a decoder for fee market module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}

View File

@ -0,0 +1,32 @@
package simulation
import (
"encoding/json"
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cerc-io/laconicd/x/auction/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// RandomizedGenState generates a random GenesisState
func RandomizedGenState(simState *module.SimulationState) {
auctionParams := types.NewParams(time.Duration(simState.Rand.Intn(1000))*time.Second,
time.Duration(simState.Rand.Intn(1000))*time.Second,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))),
)
auctionGenesis := types.NewGenesisState(auctionParams, []*types.Auction{})
bz, err := json.MarshalIndent(auctionGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(auctionGenesis)
}

View File

@ -5,5 +5,13 @@ package types
func DefaultGenesisState() *GenesisState { func DefaultGenesisState() *GenesisState {
return &GenesisState{ return &GenesisState{
Params: DefaultParams(), Params: DefaultParams(),
Auctions: []*Auction{},
}
}
func NewGenesisState(params Params, auctions []*Auction) *GenesisState {
return &GenesisState{
Params: params,
Auctions: auctions,
} }
} }

View File

@ -32,8 +32,14 @@ var (
var _ types.ParamSet = &Params{} var _ types.ParamSet = &Params{}
func NewParams() Params { func NewParams(commitsDuration time.Duration, revealsDuration time.Duration, commitFee sdk.Coin, revealFee sdk.Coin, minimumBid sdk.Coin) Params {
return DefaultParams() return Params{
CommitsDuration: commitsDuration,
RevealsDuration: revealsDuration,
CommitFee: commitFee,
RevealFee: revealFee,
MinimumBid: minimumBid,
}
} }
// ParamKeyTable - ParamTable for bond module. // ParamKeyTable - ParamTable for bond module.

View File

@ -4,15 +4,18 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/rand" // #nosec G702
"github.com/cerc-io/laconicd/x/bond/client/cli" "github.com/cerc-io/laconicd/x/bond/client/cli"
"github.com/cerc-io/laconicd/x/bond/keeper" "github.com/cerc-io/laconicd/x/bond/keeper"
"github.com/cerc-io/laconicd/x/bond/simulation"
"github.com/cerc-io/laconicd/x/bond/types" "github.com/cerc-io/laconicd/x/bond/types"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -99,6 +102,28 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
return cdc.MustMarshalJSON(&gs) return cdc.MustMarshalJSON(&gs)
} }
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}
// WeightedOperations returns the all the fee market module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return nil
}
// RandomizedParams creates randomized fee market param changes for the simulator.
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return nil
}
// RegisterStoreDecoder registers a decoder for fee market module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}
func (am AppModule) RegisterInvariants(registry sdk.InvariantRegistry) { func (am AppModule) RegisterInvariants(registry sdk.InvariantRegistry) {
keeper.RegisterInvariants(registry, am.keeper) keeper.RegisterInvariants(registry, am.keeper)
} }

View File

@ -0,0 +1,25 @@
package simulation
import (
"encoding/json"
"fmt"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cerc-io/laconicd/x/bond/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// RandomizedGenState generates a random GenesisState
func RandomizedGenState(simState *module.SimulationState) {
bondParams := types.NewParams(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))))
bondGenesis := types.NewGenesisState(bondParams, []*types.Bond{})
bz, err := json.MarshalIndent(bondGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(bondGenesis)
}

View File

@ -5,5 +5,13 @@ package types
func DefaultGenesisState() *GenesisState { func DefaultGenesisState() *GenesisState {
return &GenesisState{ return &GenesisState{
Params: DefaultParams(), Params: DefaultParams(),
Bonds: []*Bond{},
}
}
func NewGenesisState(params Params, bonds []*Bond) *GenesisState {
return &GenesisState{
Params: params,
Bonds: bonds,
} }
} }

View File

@ -4,15 +4,18 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"math/rand" // #nosec G702
"github.com/cerc-io/laconicd/x/nameservice/client/cli" "github.com/cerc-io/laconicd/x/nameservice/client/cli"
"github.com/cerc-io/laconicd/x/nameservice/keeper" "github.com/cerc-io/laconicd/x/nameservice/keeper"
"github.com/cerc-io/laconicd/x/nameservice/simulation"
"github.com/cerc-io/laconicd/x/nameservice/types" "github.com/cerc-io/laconicd/x/nameservice/types"
"github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types" codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -89,6 +92,28 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
return cdc.MustMarshalJSON(&gs) return cdc.MustMarshalJSON(&gs)
} }
func (AppModule) GenerateGenesisState(simState *module.SimulationState) {
simulation.RandomizedGenState(simState)
}
// WeightedOperations returns the all the fee market module operations with their respective weights.
func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation {
return nil
}
// RandomizedParams creates randomized fee market param changes for the simulator.
func (AppModule) RandomizedParams(r *rand.Rand) []simtypes.ParamChange {
return nil
}
// RegisterStoreDecoder registers a decoder for fee market module's types
func (am AppModule) RegisterStoreDecoder(sdr sdk.StoreDecoderRegistry) {}
// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent {
return nil
}
func (am AppModule) RegisterInvariants(registry sdk.InvariantRegistry) { func (am AppModule) RegisterInvariants(registry sdk.InvariantRegistry) {
keeper.RegisterInvariants(registry, am.keeper) keeper.RegisterInvariants(registry, am.keeper)
} }

View File

@ -0,0 +1,38 @@
package simulation
import (
"encoding/json"
"fmt"
"time"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cerc-io/laconicd/x/nameservice/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// RandomizedGenState generates a random GenesisState
func RandomizedGenState(simState *module.SimulationState) {
nameserviceParams := types.NewParams(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))),
time.Duration(simState.Rand.Intn(1000))*time.Second,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))),
time.Duration(simState.Rand.Intn(1000))*time.Second,
time.Duration(simState.Rand.Intn(1000))*time.Second,
false,
time.Duration(simState.Rand.Intn(1000))*time.Second,
time.Duration(simState.Rand.Intn(1000))*time.Second,
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(int64(simState.Rand.Intn(10000000000)))),
)
nameserviceGenesis := types.NewGenesisState(nameserviceParams, []types.Record{}, []types.AuthorityEntry{}, []types.NameEntry{})
bz, err := json.MarshalIndent(nameserviceGenesis, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(&nameserviceGenesis)
}

View File

@ -14,6 +14,9 @@ func NewGenesisState(params Params, records []Record, authorities []AuthorityEnt
func DefaultGenesisState() *GenesisState { func DefaultGenesisState() *GenesisState {
return &GenesisState{ return &GenesisState{
Params: DefaultParams(), Params: DefaultParams(),
Records: []Record{},
Authorities: []AuthorityEntry{},
Names: []NameEntry{},
} }
} }