OSDN Git Service

aggregate coinbase rewards (#239)
[bytom/vapor.git] / proposal / proposal_test.go
1 package proposal
2
3 import (
4         "bytes"
5         "testing"
6
7         "github.com/vapor/protocol/bc"
8 )
9
10 func TestCreateCoinbaseTx(t *testing.T) {
11         cases := []struct {
12                 desc          string
13                 blockHeight   uint64
14                 wantArbitrary []byte
15                 wantAmount    uint64
16         }{
17                 {
18                         desc:          "the coinbase block height is reductionInterval",
19                         blockHeight:   1,
20                         wantArbitrary: []byte{0x00, 0x31},
21                         wantAmount:    0,
22                 },
23                 {
24                         desc:          "the coinbase block height is reductionInterval",
25                         blockHeight:   100,
26                         wantArbitrary: []byte{0x00, 0x31, 0x30, 0x30},
27                         wantAmount:    0,
28                 },
29         }
30
31         for i, c := range cases {
32                 coinbaseTx, err := createCoinbaseTx(nil, c.blockHeight)
33                 if err != nil {
34                         t.Fatal(err)
35                 }
36
37                 input, _ := coinbaseTx.Entries[coinbaseTx.Tx.InputIDs[0]].(*bc.Coinbase)
38                 gotArbitrary := input.Arbitrary
39                 if res := bytes.Compare(gotArbitrary, c.wantArbitrary); res != 0 {
40                         t.Fatalf("coinbase tx arbitrary dismatch, case: %d, got: %d, want: %d", i, gotArbitrary, c.wantArbitrary)
41                 }
42
43                 gotAmount := coinbaseTx.Outputs[0].AssetAmount().Amount
44                 if gotAmount != c.wantAmount {
45                         t.Fatalf("coinbase tx output amount dismatch, case: %d, got: %d, want: %d", i, gotAmount, c.wantAmount)
46                 }
47         }
48 }