@@ -27,46 +27,66 @@ func TestDecodeStore(t *testing.T) {
27
27
28
28
endTime := time .Now ().UTC ()
29
29
content := types .ContentFromProposalType ("test" , "test" , types .ProposalTypeText )
30
- proposal , err := types .NewProposal (content , 1 , endTime , endTime .Add (24 * time .Hour ))
30
+ proposalA , err := types .NewProposal (content , 1 , endTime , endTime .Add (24 * time .Hour ))
31
+ require .NoError (t , err )
32
+ proposalB , err := types .NewProposal (content , 2 , endTime , endTime .Add (24 * time .Hour ))
31
33
require .NoError (t , err )
32
34
33
35
proposalIDBz := make ([]byte , 8 )
34
36
binary .LittleEndian .PutUint64 (proposalIDBz , 1 )
35
37
deposit := types .NewDeposit (1 , delAddr1 , sdk .NewCoins (sdk .NewCoin (sdk .DefaultBondDenom , sdk .OneInt ())))
36
38
vote := types .NewVote (1 , delAddr1 , types .NewNonSplitVoteOption (types .OptionYes ))
37
39
38
- proposalBz , err := cdc .MarshalBinaryBare (& proposal )
40
+ proposalBzA , err := cdc .MarshalBinaryBare (& proposalA )
41
+ require .NoError (t , err )
42
+ proposalBzB , err := cdc .MarshalBinaryBare (& proposalB )
39
43
require .NoError (t , err )
40
-
41
- kvPairs := kv.Pairs {
42
- Pairs : []kv.Pair {
43
- {Key : types .ProposalKey (1 ), Value : proposalBz },
44
- {Key : types .InactiveProposalQueueKey (1 , endTime ), Value : proposalIDBz },
45
- {Key : types .DepositKey (1 , delAddr1 ), Value : cdc .MustMarshalBinaryBare (& deposit )},
46
- {Key : types .VoteKey (1 , delAddr1 ), Value : cdc .MustMarshalBinaryBare (& vote )},
47
- {Key : []byte {0x99 }, Value : []byte {0x99 }},
48
- },
49
- }
50
44
51
45
tests := []struct {
52
46
name string
47
+ kvA , kvB kv.Pair
53
48
expectedLog string
49
+ wantPanic bool
54
50
}{
55
- {"proposals" , fmt .Sprintf ("%v\n %v" , proposal , proposal )},
56
- {"proposal IDs" , "proposalIDA: 1\n ProposalIDB: 1" },
57
- {"deposits" , fmt .Sprintf ("%v\n %v" , deposit , deposit )},
58
- {"votes" , fmt .Sprintf ("%v\n %v" , vote , vote )},
59
- {"other" , "" },
51
+ {
52
+ "proposals" ,
53
+ kv.Pair {Key : types .ProposalKey (1 ), Value : proposalBzA },
54
+ kv.Pair {Key : types .ProposalKey (2 ), Value : proposalBzB },
55
+ fmt .Sprintf ("%v\n %v" , proposalA , proposalB ), false ,
56
+ },
57
+ {
58
+ "proposal IDs" ,
59
+ kv.Pair {Key : types .InactiveProposalQueueKey (1 , endTime ), Value : proposalIDBz },
60
+ kv.Pair {Key : types .InactiveProposalQueueKey (1 , endTime ), Value : proposalIDBz },
61
+ "proposalIDA: 1\n ProposalIDB: 1" , false ,
62
+ },
63
+ {
64
+ "deposits" ,
65
+ kv.Pair {Key : types .DepositKey (1 , delAddr1 ), Value : cdc .MustMarshalBinaryBare (& deposit )},
66
+ kv.Pair {Key : types .DepositKey (1 , delAddr1 ), Value : cdc .MustMarshalBinaryBare (& deposit )},
67
+ fmt .Sprintf ("%v\n %v" , deposit , deposit ), false ,
68
+ },
69
+ {
70
+ "votes" ,
71
+ kv.Pair {Key : types .VoteKey (1 , delAddr1 ), Value : cdc .MustMarshalBinaryBare (& vote )},
72
+ kv.Pair {Key : types .VoteKey (1 , delAddr1 ), Value : cdc .MustMarshalBinaryBare (& vote )},
73
+ fmt .Sprintf ("%v\n %v" , vote , vote ), false ,
74
+ },
75
+ {
76
+ "other" ,
77
+ kv.Pair {Key : []byte {0x99 }, Value : []byte {0x99 }},
78
+ kv.Pair {Key : []byte {0x99 }, Value : []byte {0x99 }},
79
+ "" , true ,
80
+ },
60
81
}
61
82
62
- for i , tt := range tests {
63
- i , tt := i , tt
83
+ for _ , tt := range tests {
84
+ tt := tt
64
85
t .Run (tt .name , func (t * testing.T ) {
65
- switch i {
66
- case len (tests ) - 1 :
67
- require .Panics (t , func () { dec (kvPairs .Pairs [i ], kvPairs .Pairs [i ]) }, tt .name )
68
- default :
69
- require .Equal (t , tt .expectedLog , dec (kvPairs .Pairs [i ], kvPairs .Pairs [i ]), tt .name )
86
+ if tt .wantPanic {
87
+ require .Panics (t , func () { dec (tt .kvA , tt .kvB ) }, tt .name )
88
+ } else {
89
+ require .Equal (t , tt .expectedLog , dec (tt .kvA , tt .kvB ), tt .name )
70
90
}
71
91
})
72
92
}
0 commit comments