mukan-sdk/x/gov/migrations/v4/json_test.go
Mukan Erkin Törük 20afb5db80
Some checks failed
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
Build & Push SDK Proto Builder / build (push) Has been cancelled
initial: sovereign Mukan Network fork
2026-05-11 03:18:24 +03:00

99 lines
2.7 KiB
Go

package v4_test
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/x/gov"
v4 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v4"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)
func TestMigrateJSON(t *testing.T) {
encodingConfig := moduletestutil.MakeTestEncodingConfig(gov.AppModuleBasic{})
clientCtx := client.Context{}.
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithCodec(encodingConfig.Codec)
govGenState := v1.DefaultGenesisState()
oldGovState := &v1.GenesisState{
StartingProposalId: govGenState.StartingProposalId,
Deposits: govGenState.Deposits,
Votes: govGenState.Votes,
Proposals: govGenState.Proposals,
DepositParams: &v1.DepositParams{
MinDeposit: govGenState.Params.MinDeposit,
MaxDepositPeriod: govGenState.Params.MaxDepositPeriod,
},
VotingParams: &v1.VotingParams{
VotingPeriod: govGenState.Params.VotingPeriod,
},
TallyParams: &v1.TallyParams{
Quorum: govGenState.Params.Quorum,
Threshold: govGenState.Params.Threshold,
VetoThreshold: govGenState.Params.VetoThreshold,
},
}
migrated, err := v4.MigrateJSON(oldGovState)
require.NoError(t, err)
require.Equal(t, migrated, govGenState)
bz, err := clientCtx.Codec.MarshalJSON(migrated)
require.NoError(t, err)
// Indent the JSON bz correctly.
var jsonObj map[string]any
err = json.Unmarshal(bz, &jsonObj)
require.NoError(t, err)
indentedBz, err := json.MarshalIndent(jsonObj, "", "\t")
require.NoError(t, err)
// Make sure about:
// - Proposals use MsgExecLegacyContent
expected := `{
"constitution": "",
"deposit_params": null,
"deposits": [],
"params": {
"burn_proposal_deposit_prevote": false,
"burn_vote_quorum": false,
"burn_vote_veto": true,
"expedited_min_deposit": [
{
"amount": "50000000",
"denom": "stake"
}
],
"expedited_threshold": "0.667000000000000000",
"expedited_voting_period": "86400s",
"max_deposit_period": "172800s",
"min_deposit": [
{
"amount": "10000000",
"denom": "stake"
}
],
"min_deposit_ratio": "0.010000000000000000",
"min_initial_deposit_ratio": "0.000000000000000000",
"proposal_cancel_dest": "",
"proposal_cancel_ratio": "0.500000000000000000",
"quorum": "0.334000000000000000",
"threshold": "0.500000000000000000",
"veto_threshold": "0.334000000000000000",
"voting_period": "172800s"
},
"proposals": [],
"starting_proposal_id": "1",
"tally_params": null,
"votes": [],
"voting_params": null
}`
require.Equal(t, expected, string(indentedBz))
}