laconicd/x/evm/types/genesis.go
Tomas Tauber e91ec58aa1
evm: fixed commented out simulations, pubsub, and handler tests (#655)
* evm: fixed commented out simulations, pubsub, and handler tests

fixes #640

simulations are very basic: they can be built and executed,
but they don't generate any EVM-related transactions yet.
(It should be a matter of adding simulation-related code to the
modules + potentially extra helpers to the simulation.)
handler tests miss some extra assertions due to changes
in the return values snapshotting logic (ADR-001 and ADR-002).

Besides the test suites identified in the audit,
there's also "importer_test.go" which wasn't yet fixed.
(it'd require major rewriting + extra test resources)

* gofumpt
2021-10-11 13:09:53 +02:00

50 lines
1.2 KiB
Go

package types
import (
"fmt"
ethermint "github.com/tharsis/ethermint/types"
)
// Validate performs a basic validation of a GenesisAccount fields.
func (ga GenesisAccount) Validate() error {
if err := ethermint.ValidateAddress(ga.Address); err != nil {
return err
}
return ga.Storage.Validate()
}
// DefaultGenesisState sets default evm genesis state with empty accounts and default params and
// chain config values.
func DefaultGenesisState() *GenesisState {
return &GenesisState{
Accounts: []GenesisAccount{},
Params: DefaultParams(),
}
}
// NewGenesisState creates a new genesis state.
func NewGenesisState(params Params, accounts []GenesisAccount) *GenesisState {
return &GenesisState{
Accounts: accounts,
Params: params,
}
}
// Validate performs basic genesis state validation returning an error upon any
// failure.
func (gs GenesisState) Validate() error {
seenAccounts := make(map[string]bool)
for _, acc := range gs.Accounts {
if seenAccounts[acc.Address] {
return fmt.Errorf("duplicated genesis account %s", acc.Address)
}
if err := acc.Validate(); err != nil {
return fmt.Errorf("invalid genesis account %s: %w", acc.Address, err)
}
seenAccounts[acc.Address] = true
}
return gs.Params.Validate()
}