forked from Finschia/finschia-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate_test.go
126 lines (112 loc) · 3.29 KB
/
migrate_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
package v0_36
import (
"testing"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/types"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_34"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_34"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
"github.com/stretchr/testify/require"
)
var (
priv = secp256k1.GenPrivKey()
addr = types.AccAddress(priv.PubKey().Address())
depositedCoinsAccAddr = types.AccAddress(crypto.AddressHash([]byte("govDepositedCoins")))
burnedDepositCoinsAccAddr = types.AccAddress(crypto.AddressHash([]byte("govBurnedDepositCoins")))
coins = types.Coins{types.NewInt64Coin(types.DefaultBondDenom, 10)}
halfCoins = types.Coins{types.NewInt64Coin(types.DefaultBondDenom, 5)}
accountDeposited = v034accounts.GenesisAccount{
Address: depositedCoinsAccAddr,
Coins: coins,
Sequence: 1,
AccountNumber: 1,
OriginalVesting: coins,
DelegatedFree: coins,
DelegatedVesting: coins,
StartTime: 0,
EndTime: 0,
}
accountBurned = v034accounts.GenesisAccount{
Address: burnedDepositCoinsAccAddr,
Coins: coins,
Sequence: 2,
AccountNumber: 2,
OriginalVesting: coins,
DelegatedFree: coins,
DelegatedVesting: coins,
StartTime: 0,
EndTime: 0,
}
deposit = v034gov.DepositWithMetadata{
ProposalID: 1,
Deposit: v034gov.Deposit{
ProposalID: 1,
Depositor: addr,
Amount: coins,
},
}
)
func TestMigrateEmptyRecord(t *testing.T) {
type args struct {
accounts v034accounts.GenesisState
deposits []v034gov.DepositWithMetadata
}
tests := []struct {
name string
args args
}{
{"No Accounts", args{v034accounts.GenesisState{}, []v034gov.DepositWithMetadata{}}},
{"Deposited account", args{v034accounts.GenesisState{accountDeposited}, []v034gov.DepositWithMetadata{deposit}}},
{"Burned account", args{v034accounts.GenesisState{accountBurned}, []v034gov.DepositWithMetadata{}}},
{"Burned and deposited accounts", args{v034accounts.GenesisState{accountDeposited, accountBurned}, []v034gov.DepositWithMetadata{deposit}}},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
require.NotPanics(t, func() {
Migrate(
tt.args.accounts,
types.Coins{},
types.DecCoins{},
tt.args.deposits,
v034staking.Validators{},
[]v034staking.UnbondingDelegation{},
[]v034distr.ValidatorOutstandingRewardsRecord{},
types.DefaultBondDenom,
v034distr.ModuleName,
v034gov.ModuleName,
)
})
})
}
}
func TestMigrateWrongDeposit(t *testing.T) {
require.Panics(t, func() {
Migrate(
v034accounts.GenesisState{
accountDeposited,
accountBurned,
},
types.Coins{},
types.DecCoins{},
[]v034gov.DepositWithMetadata{
{
ProposalID: 1,
Deposit: v034gov.Deposit{
ProposalID: 1,
Depositor: addr,
Amount: halfCoins,
},
},
},
v034staking.Validators{},
[]v034staking.UnbondingDelegation{},
[]v034distr.ValidatorOutstandingRewardsRecord{},
types.DefaultBondDenom,
v034distr.ModuleName,
v034gov.ModuleName,
)
})
}