OSDN Git Service

modify miner block to propose block (#92)
[bytom/vapor.git] / proposal / proposal_test.go
diff --git a/proposal/proposal_test.go b/proposal/proposal_test.go
new file mode 100644 (file)
index 0000000..fde4624
--- /dev/null
@@ -0,0 +1,46 @@
+package proposal
+
+import "testing"
+
+func TestCreateCoinbaseTx(t *testing.T) {
+       reductionInterval := uint64(840000)
+       baseSubsidy := uint64(41250000000)
+       cases := []struct {
+               height  uint64
+               txFee   uint64
+               subsidy uint64
+       }{
+               {
+                       height:  reductionInterval - 1,
+                       txFee:   100000000,
+                       subsidy: baseSubsidy + 100000000,
+               },
+               {
+                       height:  reductionInterval,
+                       txFee:   2000000000,
+                       subsidy: baseSubsidy/2 + 2000000000,
+               },
+               {
+                       height:  reductionInterval + 1,
+                       txFee:   0,
+                       subsidy: baseSubsidy / 2,
+               },
+               {
+                       height:  reductionInterval * 2,
+                       txFee:   100000000,
+                       subsidy: baseSubsidy/4 + 100000000,
+               },
+       }
+
+       for _, c := range cases {
+               coinbaseTx, err := createCoinbaseTx(nil, c.txFee, c.height)
+               if err != nil {
+                       t.Fatal(err)
+               }
+
+               outputAmount := coinbaseTx.Outputs[0].OutputCommitment().Amount
+               if outputAmount != c.subsidy {
+                       t.Fatalf("coinbase tx reward dismatch, expected: %d, have: %d", c.subsidy, outputAmount)
+               }
+       }
+}