OSDN Git Service

fix the bug (#372)
[bytom/vapor.git] / consensus / general_test.go
1 package consensus
2
3 import "testing"
4
5 func TestSubsidy(t *testing.T) {
6         ActiveNetParams = Params{
7                 ProducerSubsidys: []ProducerSubsidy{
8                         {BeginBlock: 0, EndBlock: 0, Subsidy: 24},
9                         {BeginBlock: 1, EndBlock: 840000, Subsidy: 24},
10                         {BeginBlock: 840001, EndBlock: 1680000, Subsidy: 12},
11                         {BeginBlock: 1680001, EndBlock: 3360000, Subsidy: 6},
12                 },
13         }
14         subsidyReductionInterval := uint64(840000)
15         cases := []struct {
16                 subsidy uint64
17                 height  uint64
18         }{
19                 {
20                         subsidy: 24,
21                         height:  1,
22                 },
23                 {
24                         subsidy: 24,
25                         height:  subsidyReductionInterval - 1,
26                 },
27                 {
28                         subsidy: 24,
29                         height:  subsidyReductionInterval,
30                 },
31                 {
32                         subsidy: 12,
33                         height:  subsidyReductionInterval + 1,
34                 },
35                 {
36                         subsidy: 0,
37                         height:  subsidyReductionInterval * 10,
38                 },
39         }
40
41         for _, c := range cases {
42                 subsidy := BlockSubsidy(c.height)
43                 if subsidy != c.subsidy {
44                         t.Errorf("got subsidy %d, want %d", subsidy, c.subsidy)
45                 }
46         }
47 }