forked from Finschia/finschia-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabci_test.go
113 lines (100 loc) · 2.84 KB
/
abci_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
package internal_test
import (
sdk "github.com/line/lbm-sdk/types"
"github.com/line/lbm-sdk/x/foundation"
"github.com/line/lbm-sdk/x/foundation/keeper/internal"
)
func (s *KeeperTestSuite) TestBeginBlocker() {
ctx, _ := s.ctx.CacheContext()
taxRatio := sdk.MustNewDecFromStr("0.123456789")
s.impl.SetParams(ctx, foundation.Params{
FoundationTax: taxRatio,
})
before := s.impl.GetTreasury(ctx)
s.Require().Equal(1, len(before))
s.Require().Equal(sdk.NewDecFromInt(s.balance), before[0].Amount)
// collect
internal.BeginBlocker(ctx, s.impl)
tax := sdk.NewDecFromInt(s.balance).MulTruncate(taxRatio).TruncateInt()
// ensure the behavior does not change
s.Require().Equal(sdk.NewInt(121932631), tax)
expectedAfter := s.balance.Add(tax)
after := s.impl.GetTreasury(ctx)
s.Require().Equal(1, len(after))
s.Require().Equal(sdk.NewDecFromInt(expectedAfter), after[0].Amount)
}
func (s *KeeperTestSuite) TestEndBlocker() {
ctx, _ := s.ctx.CacheContext()
// check preconditions
for name, tc := range map[string]struct {
id uint64
status foundation.ProposalStatus
}{
"active proposal": {
s.activeProposal,
foundation.PROPOSAL_STATUS_SUBMITTED,
},
"voted proposal": {
s.votedProposal,
foundation.PROPOSAL_STATUS_SUBMITTED,
},
"withdrawn proposal": {
s.withdrawnProposal,
foundation.PROPOSAL_STATUS_WITHDRAWN,
},
"invalid proposal": {
s.invalidProposal,
foundation.PROPOSAL_STATUS_SUBMITTED,
},
} {
s.Run(name, func() {
proposal, err := s.impl.GetProposal(ctx, tc.id)
s.Require().NoError(err)
s.Require().NotNil(proposal)
s.Require().Equal(tc.status, proposal.Status)
})
}
// voting periods end
votingPeriod := s.impl.GetFoundationInfo(ctx).GetDecisionPolicy().GetVotingPeriod()
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(votingPeriod))
internal.EndBlocker(ctx, s.impl)
for name, tc := range map[string]struct {
id uint64
removed bool
status foundation.ProposalStatus
}{
"active proposal": {
id: s.activeProposal,
status: foundation.PROPOSAL_STATUS_ACCEPTED,
},
"voted proposal": {
id: s.votedProposal,
status: foundation.PROPOSAL_STATUS_REJECTED,
},
"withdrawn proposal": {
id: s.withdrawnProposal,
removed: true,
},
"invalid proposal": {
id: s.invalidProposal,
status: foundation.PROPOSAL_STATUS_ACCEPTED,
},
} {
s.Run(name, func() {
proposal, err := s.impl.GetProposal(ctx, tc.id)
if tc.removed {
s.Require().Error(err)
return
}
s.Require().NoError(err)
s.Require().NotNil(proposal)
s.Require().Equal(tc.status, proposal.Status)
})
}
// proposals expire
maxExecutionPeriod := foundation.DefaultConfig().MaxExecutionPeriod
ctx = ctx.WithBlockTime(ctx.BlockTime().Add(maxExecutionPeriod))
internal.EndBlocker(ctx, s.impl)
// all proposals must be pruned
s.Require().Empty(s.impl.GetProposals(ctx))
}