OSDN Git Service

doc: add cross-chain tx api doc (#154)
[bytom/vapor.git] / proposal / proposal_test.go
1 package proposal
2
3 import (
4         "testing"
5
6         "github.com/vapor/consensus"
7 )
8
9 func TestCreateCoinbaseTx(t *testing.T) {
10         consensus.ActiveNetParams = consensus.Params{
11                 ProducerSubsidys: []consensus.ProducerSubsidy{
12                         {BeginBlock: 0, EndBlock: 0, Subsidy: 24},
13                         {BeginBlock: 1, EndBlock: 840000, Subsidy: 24},
14                         {BeginBlock: 840001, EndBlock: 1680000, Subsidy: 12},
15                         {BeginBlock: 1680001, EndBlock: 3360000, Subsidy: 6},
16                 },
17         }
18         reductionInterval := uint64(840000)
19         cases := []struct {
20                 height  uint64
21                 txFee   uint64
22                 subsidy uint64
23         }{
24                 {
25                         height:  reductionInterval - 1,
26                         txFee:   100000000,
27                         subsidy: 24 + 100000000,
28                 },
29                 {
30                         height:  reductionInterval,
31                         txFee:   2000000000,
32                         subsidy: 24 + 2000000000,
33                 },
34                 {
35                         height:  reductionInterval + 1,
36                         txFee:   0,
37                         subsidy: 12,
38                 },
39                 {
40                         height:  reductionInterval * 2,
41                         txFee:   100000000,
42                         subsidy: 12 + 100000000,
43                 },
44         }
45
46         for index, c := range cases {
47                 coinbaseTx, err := createCoinbaseTx(nil, c.txFee, c.height)
48                 if err != nil {
49                         t.Fatal(err)
50                 }
51
52                 outputAmount := coinbaseTx.Outputs[0].OutputCommitment().Amount
53                 if outputAmount != c.subsidy {
54                         t.Fatalf("index:%d,coinbase tx reward dismatch, expected: %d, have: %d", index, c.subsidy, outputAmount)
55                 }
56         }
57 }