OSDN Git Service

Hulk did something
[bytom/vapor.git] / mining / mining_test.go
1 package mining
2
3 import "testing"
4
5 func TestCreateCoinbaseTx(t *testing.T) {
6         reductionInterval := uint64(840000)
7         baseSubsidy := uint64(41250000000)
8         cases := []struct {
9                 height  uint64
10                 txFee   uint64
11                 subsidy uint64
12         }{
13                 {
14                         height:  reductionInterval - 1,
15                         txFee:   100000000,
16                         subsidy: baseSubsidy + 100000000,
17                 },
18                 {
19                         height:  reductionInterval,
20                         txFee:   2000000000,
21                         subsidy: baseSubsidy/2 + 2000000000,
22                 },
23                 {
24                         height:  reductionInterval + 1,
25                         txFee:   0,
26                         subsidy: baseSubsidy / 2,
27                 },
28                 {
29                         height:  reductionInterval * 2,
30                         txFee:   100000000,
31                         subsidy: baseSubsidy/4 + 100000000,
32                 },
33         }
34
35         for _, c := range cases {
36                 coinbaseTx, err := createCoinbaseTx(nil, c.txFee, c.height)
37                 if err != nil {
38                         t.Fatal(err)
39                 }
40
41                 outputAmount := coinbaseTx.Outputs[0].OutputCommitment.Amount
42                 if outputAmount != c.subsidy {
43                         t.Fatalf("coinbase tx reward dismatch, expected: %d, have: %d", c.subsidy, outputAmount)
44                 }
45         }
46 }