forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
json_test.go
129 lines (118 loc) · 3.15 KB
/
json_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package v043_test
import (
"encoding/json"
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
v043gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v043"
"github.com/cosmos/cosmos-sdk/x/gov/types"
)
func TestMigrateJSON(t *testing.T) {
encodingConfig := simapp.MakeTestEncodingConfig()
clientCtx := client.Context{}.
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithCodec(encodingConfig.Marshaler)
voter, err := sdk.AccAddressFromBech32("cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh")
require.NoError(t, err)
govGenState := &types.GenesisState{
Votes: types.Votes{
types.Vote{ProposalId: 1, Voter: voter.String(), Option: types.OptionAbstain},
types.Vote{ProposalId: 2, Voter: voter.String(), Option: types.OptionEmpty},
types.Vote{ProposalId: 3, Voter: voter.String(), Option: types.OptionNo},
types.Vote{ProposalId: 4, Voter: voter.String(), Option: types.OptionNoWithVeto},
types.Vote{ProposalId: 5, Voter: voter.String(), Option: types.OptionYes},
},
}
migrated := v043gov.MigrateJSON(govGenState)
bz, err := clientCtx.Codec.MarshalJSON(migrated)
require.NoError(t, err)
// Indent the JSON bz correctly.
var jsonObj map[string]interface{}
err = json.Unmarshal(bz, &jsonObj)
require.NoError(t, err)
indentedBz, err := json.MarshalIndent(jsonObj, "", "\t")
require.NoError(t, err)
// Make sure about:
// - Votes are all ADR-037 weighted votes with weight 1.
expected := `{
"deposit_params": {
"max_deposit_period": "0s",
"min_deposit": [],
"min_initial_deposit_ratio": "0"
},
"deposits": [],
"proposals": [],
"starting_proposal_id": "0",
"tally_params": {
"quorum": "0",
"threshold": "0",
"veto_threshold": "0"
},
"votes": [
{
"option": "VOTE_OPTION_UNSPECIFIED",
"options": [
{
"option": "VOTE_OPTION_ABSTAIN",
"weight": "1.000000000000000000"
}
],
"proposal_id": "1",
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
},
{
"option": "VOTE_OPTION_UNSPECIFIED",
"options": [
{
"option": "VOTE_OPTION_UNSPECIFIED",
"weight": "1.000000000000000000"
}
],
"proposal_id": "2",
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
},
{
"option": "VOTE_OPTION_UNSPECIFIED",
"options": [
{
"option": "VOTE_OPTION_NO",
"weight": "1.000000000000000000"
}
],
"proposal_id": "3",
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
},
{
"option": "VOTE_OPTION_UNSPECIFIED",
"options": [
{
"option": "VOTE_OPTION_NO_WITH_VETO",
"weight": "1.000000000000000000"
}
],
"proposal_id": "4",
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
},
{
"option": "VOTE_OPTION_UNSPECIFIED",
"options": [
{
"option": "VOTE_OPTION_YES",
"weight": "1.000000000000000000"
}
],
"proposal_id": "5",
"voter": "cosmos1fl48vsnmsdzcv85q5d2q4z5ajdha8yu34mf0eh"
}
],
"voting_params": {
"voting_period": "0s"
}
}`
fmt.Println(string(indentedBz))
require.Equal(t, expected, string(indentedBz))
}