forked from terra-money/classic-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_common.go
218 lines (186 loc) · 7.28 KB
/
test_common.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package budget
// import (
// "encoding/hex"
// "os"
// "testing"
// "github.com/stretchr/testify/require"
// "github.com/tendermint/tendermint/libs/db"
// "github.com/tendermint/tendermint/libs/log"
// "github.com/cosmos/cosmos-sdk/store"
// sdk "github.com/cosmos/cosmos-sdk/types"
// "github.com/cosmos/cosmos-sdk/x/auth"
// "github.com/cosmos/cosmos-sdk/x/bank"
// "github.com/cosmos/cosmos-sdk/x/staking"
// )
// // dummy addresses used for testing
// var (
// addrs = []sdk.Address{
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6160"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6161"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6162"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6163"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6164"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6165"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6166"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6167"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6168"),
// testAddr("A58856F0FD53BF058B4909A21AEC019107BA6169"),
// }
// // dummy pubkeys used for testing
// pks = []crypto.PubKey{
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB50"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB51"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB52"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB53"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB54"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB55"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB56"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB57"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB58"),
// newPubKey("0B485CFC0EECC619440448436F8FC9DF40566F2369E72400281454CB552AFB59"),
// }
// titles = []string{
// "Photons at launch",
// "IBC integration at launch",
// "Voting Period update",
// "Validator Set migration",
// "Upgrade Zone to a Hub",
// "Other Fees",
// "Change downtime parameter",
// "Change validator limit",
// }
// descriptions = []string{
// "Should we include Photons at launch?",
// "Should we include IBC integration at launch?",
// "Should we update the proposal voting period to 13000000 blocks?",
// "Should we change from the default Cosmos Hub validator set to our own zone validator set?",
// "Should we upgrade our zone to convert it to an independent Hub?",
// "Should we accept coins from other zones as fees?",
// "Should we change downtime to 50% of the last 50 blocks instead of last 100 blocks?",
// "Should we change the number of validators to 500?",
// }
// coinsHandlerTest = []sdk.Coins{
// sdk.Coins{{"Atom", 101}, {"eth", 20}}, // ok
// sdk.Coins{{"eth", 10}, {"Atom", 0}}, // empty coins
// sdk.Coins{{"BTC", 15}, {"Atom", 50}}, // balance below deposit
// }
// options = []string{
// "Yes",
// "No",
// "Abstain",
// "",
// " ",
// }
// emptyAddr sdk.Address
// emptyPubkey crypto.PubKey
// )
// //_______________________________________________________________________________________
// // // intended to be used with require/assert: require.True(ValEq(...))
// // func valEq(t *testing.T, exp, got Validator) (*testing.T, bool, string, Validator, Validator) {
// // return t, exp.equal(got), "expected:\t%v\ngot:\t\t%v", exp, got
// // }
// func loggerAndDB() (log.Logger, db.DB) {
// logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "sdk/app")
// dB := db.NewMemDB()
// return logger, dB
// }
// func newSimpleGovApp() *app.SimpleGovApp {
// logger, dB := loggerAndDB()
// return app.NewSimpleGovApp(logger, dB)
// }
// func keyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.Address) {
// key := crypto.GenPrivKeyEd25519()
// pub := key.PubKey()
// addr := sdk.Address(pub.Address())
// return key, pub, addr
// }
// func initialPool() stake.Pool {
// return stake.Pool{
// LooseUnbondedTokens: 0,
// BondedTokens: 0,
// UnbondingTokens: 0,
// UnbondedTokens: 0,
// BondedShares: sdk.ZeroRat(),
// UnbondingShares: sdk.ZeroRat(),
// UnbondedShares: sdk.ZeroRat(),
// InflationLastTime: 0,
// Inflation: sdk.NewRat(7, 100),
// DateLastCommissionReset: 0,
// PrevBondedShares: sdk.ZeroRat(),
// }
// }
// func defaultParams() stake.Params {
// return stake.Params{
// InflationRateChange: sdk.NewRat(13, 100),
// InflationMax: sdk.NewRat(20, 100),
// InflationMin: sdk.NewRat(7, 100),
// GoalBonded: sdk.NewRat(67, 100),
// MaxValidators: 100,
// BondDenom: "steak",
// }
// }
// //_______________________________________________________________________________________
// func makeTestCodec() *wire.Codec {
// var cdc = wire.NewCodec()
// // Register Msgs
// cdc.RegisterInterface((*sdk.Msg)(nil), nil)
// cdc.RegisterConcrete(bank.MsgSend{}, "test/stake/Send", nil)
// cdc.RegisterConcrete(bank.MsgIssue{}, "test/stake/Issue", nil)
// cdc.RegisterConcrete(SubmitProposalMsg{}, "simple_governance/SubmitProposalMsg", nil)
// cdc.RegisterConcrete(VoteMsg{}, "simple_governance/VoteMsg", nil)
// // Register AppAccount
// cdc.RegisterInterface((*auth.Account)(nil), nil)
// cdc.RegisterConcrete(&auth.BaseAccount{}, "test/stake/Account", nil)
// wire.RegisterCrypto(cdc)
// return cdc
// }
// // hogpodge of all sorts of input required for testing
// func createTestInput(t *testing.T, initCoins int64) (sdk.Context, auth.AccountMapper, Keeper) {
// app := newSimpleGovApp()
// keyStake := sdk.NewKVStoreKey("stake")
// keyAuth := sdk.NewKVStoreKey("auth")
// simpleGovKey := sdk.NewKVStoreKey("simpleGov")
// // db := dbm.NewMemDB()
// db := dbm.NewDB("filesystemDB", dbm.FSDBBackend, "dir")
// ms := store.NewCommitMultiStore(db)
// app.MountStoreWithDB(keyStake, sdk.StoreTypeIAVL, db)
// app.MountStoreWithDB(keyAuth, sdk.StoreTypeIAVL, db)
// app.MountStoreWithDB(simpleGovKey, sdk.StoreTypeIAVL, db)
// err := ms.LoadLatestVersion()
// require.Nil(t, err)
// ctx := app.NewContext(isCheckTx, abci.Header{ChainID: "foochainid"})
// app.Mo
// accountMapper := auth.NewAccountMapper(
// cdc, // amino codec
// keyAuth, // target store
// &auth.BaseAccount{}, // prototype
// )
// ck := bank.NewKeeper(accountMapper)
// stakeKeeper := stake.NewKeeper(cdc, keyStake, ck, DefaultCodespace)
// // fill all the addresses with some coins
// for _, addr := range addrs {
// ck.AddCoins(ctx, addr, sdk.Coins{
// {"Atom", initCoins},
// })
// }
// keeper := NewKeeper(simpleGovKey, ck, stakeKeeper, DefaultCodespace)
// return ctx, accountMapper, keeper
// }
// func newPubKey(pk string) (res crypto.PubKey) {
// pkBytes, err := hex.DecodeString(pk)
// if err != nil {
// panic(err)
// }
// //res, err = crypto.PubKeyFromBytes(pkBytes)
// var pkEd crypto.PubKeyEd25519
// copy(pkEd[:], pkBytes[:])
// return pkEd
// }
// // for incode address generation
// func testAddr(addr string) sdk.Address {
// res, err := sdk.GetAccAddressHex(addr)
// if err != nil {
// panic(err)
// }
// return res
// }