Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Oct 7, 2024
1 parent e3b00c3 commit 25e4313
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 52 deletions.
2 changes: 1 addition & 1 deletion x/evm/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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)
return fmt.Errorf("duplicate genesis account %s", acc.Address)
}
if err := acc.Validate(); err != nil {
return fmt.Errorf("invalid genesis account %s: %w", acc.Address, err)
Expand Down
69 changes: 18 additions & 51 deletions x/evm/genesis_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package evm_test

import (
"encoding/json"
"testing"

gethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -87,12 +88,11 @@ func (s *GenesisSuite) TestValidateGenesis() {
testCases := []struct {
name string
genState *evm.GenesisState
expPass bool
wantErr string
}{
{
name: "default",
genState: evm.DefaultGenesisState(),
expPass: true,
},
{
name: "valid genesis",
Expand All @@ -109,38 +109,34 @@ func (s *GenesisSuite) TestValidateGenesis() {
},
Params: evm.DefaultParams(),
},
expPass: true,
},
{
name: "empty genesis",
genState: &evm.GenesisState{},
expPass: false,
},
{
name: "copied genesis",
genState: &evm.GenesisState{
Accounts: evm.DefaultGenesisState().Accounts,
Params: evm.DefaultGenesisState().Params,
},
expPass: true,
},
{
name: "invalid genesis",
name: "happy genesis with account",
genState: &evm.GenesisState{
Accounts: []evm.GenesisAccount{
{
Address: gethcommon.Address{}.String(),
Address: gethcommon.Address{}.String(), // zero address
},
},
},
expPass: false,
},
{
name: "invalid genesis account",
genState: &evm.GenesisState{
Accounts: []evm.GenesisAccount{
{
Address: "123456",
Address: "123456", // not a valid ethereum hex address

Code: s.code,
Storage: evm.Storage{
Expand All @@ -150,34 +146,11 @@ func (s *GenesisSuite) TestValidateGenesis() {
},
Params: evm.DefaultParams(),
},
expPass: false,
wantErr: "not a valid ethereum hex address",
},
{
name: "duplicated genesis account",
genState: &evm.GenesisState{
Accounts: []evm.GenesisAccount{
{
Address: s.address,

Code: s.code,
Storage: evm.Storage{
evm.NewStateFromEthHashes(s.hash, s.hash),
},
},
{
Address: s.address,

Code: s.code,
Storage: evm.Storage{
evm.NewStateFromEthHashes(s.hash, s.hash),
},
},
},
},
expPass: false,
},
{
name: "duplicated tx log",
name: "duplicate account",
wantErr: "duplicate genesis account",
genState: &evm.GenesisState{
Accounts: []evm.GenesisAccount{
{
Expand All @@ -188,14 +161,6 @@ func (s *GenesisSuite) TestValidateGenesis() {
{Key: s.hash.String()},
},
},
},
},
expPass: false,
},
{
name: "invalid tx log",
genState: &evm.GenesisState{
Accounts: []evm.GenesisAccount{
{
Address: s.address,

Expand All @@ -206,23 +171,25 @@ func (s *GenesisSuite) TestValidateGenesis() {
},
},
},
expPass: false,
},
{
name: "happy: empty params",
genState: &evm.GenesisState{
Params: evm.Params{},
},
expPass: true,
},
}

for _, tc := range testCases {
err := tc.genState.Validate()
if tc.expPass {
s.Require().NoError(err, tc.name)
continue
}
s.Require().Error(err, tc.name)
s.Run(tc.name, func() {
err := tc.genState.Validate()
jsonBz, _ := json.Marshal(tc.genState)
jsonStr := string(jsonBz)
if tc.wantErr != "" {
s.Require().ErrorContains(err, tc.wantErr, jsonStr)
return
}
s.Require().NoError(err, jsonStr)
})
}
}

0 comments on commit 25e4313

Please sign in to comment.