mukan-sdk/x/genutil/client/cli/validate_genesis_test.go
Mukan Erkin Törük abb1ff956e
Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
refactor: complete sovereign stack cleanup — all github.com upstream refs purged
2026-05-11 03:46:06 +03:00

111 lines
2.6 KiB
Go

package cli_test
import (
"encoding/json"
"fmt"
"io"
"os"
"testing"
"github.com/stretchr/testify/require"
"git.cw.tr/mukan-network/mukan-sdk/client"
"git.cw.tr/mukan-network/mukan-sdk/codec"
"git.cw.tr/mukan-network/mukan-sdk/testutil"
clitestutil "git.cw.tr/mukan-network/mukan-sdk/testutil/cli"
"git.cw.tr/mukan-network/mukan-sdk/types/module"
"git.cw.tr/mukan-network/mukan-sdk/x/genutil/client/cli"
)
// An example exported genesis file from a 0.37 chain. Note that evidence
// parameters only contains `max_age`.
var v037Exported = `{
"app_hash": "",
"app_state": {},
"chain_id": "test",
"consensus_params": {
"block": {
"max_bytes": "22020096",
"max_gas": "-1",
"time_iota_ms": "1000"
},
"evidence": { "max_age": "100000" },
"validator": { "pub_key_types": ["ed25519"] }
},
"genesis_time": "2020-09-29T20:16:29.172362037Z",
"validators": []
}`
func TestValidateGenesis(t *testing.T) {
testCases := []struct {
name string
genesis string
expErrStr string
basicManager module.BasicManager
}{
{
"invalid json",
`{"app_state": {x,}}`,
"error at offset 16: invalid character",
module.NewBasicManager(),
},
{
"invalid: missing module config in app_state",
func() string {
bz, err := os.ReadFile("../../types/testdata/app_genesis.json")
require.NoError(t, err)
return string(bz)
}(),
"section is missing in the app_state",
module.NewBasicManager(mockModule{}),
},
{
"exported 0.37 genesis file",
v037Exported,
"make sure that you have correctly migrated all CometBFT consensus params",
module.NewBasicManager(),
},
{
"valid 0.50 genesis file",
func() string {
bz, err := os.ReadFile("../../types/testdata/app_genesis.json")
require.NoError(t, err)
return string(bz)
}(),
"",
module.NewBasicManager(),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
genesisFile := testutil.WriteToNewTempFile(t, tc.genesis)
_, err := clitestutil.ExecTestCLICmd(client.Context{}, cli.ValidateGenesisCmd(tc.basicManager), []string{genesisFile.Name()})
if tc.expErrStr != "" {
require.Contains(t, err.Error(), tc.expErrStr)
} else {
require.NoError(t, err)
}
})
}
}
var _ module.HasGenesisBasics = mockModule{}
type mockModule struct {
module.AppModuleBasic
}
func (m mockModule) Name() string {
return "mock"
}
func (m mockModule) DefaultGenesis(codec.JSONCodec) json.RawMessage {
return json.RawMessage(`{"foo": "bar"}`)
}
func (m mockModule) ValidateGenesis(codec.JSONCodec, client.TxEncodingConfig, json.RawMessage) error {
return fmt.Errorf("mock section is missing: %w", io.EOF)
}