OSDN Git Service

move subsidy tests to consensus
authorlbqds <lbqds@outlook.com>
Mon, 16 Apr 2018 12:23:32 +0000 (20:23 +0800)
committerlbqds <lbqds@outlook.com>
Mon, 16 Apr 2018 12:23:32 +0000 (20:23 +0800)
consensus/general_test.go
mining/mining_test.go
test/tx_test.go

index dc861c8..a8c8f36 100644 (file)
@@ -1,29 +1,38 @@
 package consensus
 
-/*func TestSubsidy(t *testing.T) {
+import "testing"
+
+func TestSubsidy(t *testing.T) {
        cases := []struct {
-               bh      *BlockHeader
                subsidy uint64
+               height  uint64
        }{
                {
-                       bh: &BlockHeader{
-                               Height: 1,
-                       },
-                       subsidy: 624000000000,
+                       subsidy: baseSubsidy,
+                       height:  1,
+               },
+               {
+                       subsidy: baseSubsidy,
+                       height:  subsidyReductionInterval - 1,
+               },
+               {
+                       subsidy: baseSubsidy / 2,
+                       height:  subsidyReductionInterval,
+               },
+               {
+                       subsidy: baseSubsidy / 2,
+                       height:  subsidyReductionInterval + 1,
                },
                {
-                       bh: &BlockHeader{
-                               Height: 560640,
-                       },
-                       subsidy: 312000000000,
+                       subsidy: baseSubsidy / 1024,
+                       height:  subsidyReductionInterval * 10,
                },
        }
 
        for _, c := range cases {
-               subsidy := c.bh.BlockSubsidy()
-
+               subsidy := BlockSubsidy(c.height)
                if subsidy != c.subsidy {
                        t.Errorf("got subsidy %s, want %s", subsidy, c.subsidy)
                }
        }
-}*/
+}
index 205fb96..039e38e 100644 (file)
@@ -1,42 +1,34 @@
 package mining
 
-import (
-       "fmt"
-       "testing"
-)
+import "testing"
 
 func TestCreateCoinbaseTx(t *testing.T) {
        reductionInterval := uint64(560640)
-       baseReward := uint64(41250000000)
+       baseSubsidy := uint64(41250000000)
        cases := []struct {
-               height uint64
-               txFee  uint64
-               reward uint64
+               height  uint64
+               txFee   uint64
+               subsidy uint64
        }{
                {
-                       height: reductionInterval - 1,
-                       txFee:  0,
-                       reward: baseReward,
+                       height:  reductionInterval - 1,
+                       txFee:   100000000,
+                       subsidy: baseSubsidy + 100000000,
                },
                {
-                       height: reductionInterval,
-                       txFee:  0,
-                       reward: baseReward / 2,
+                       height:  reductionInterval,
+                       txFee:   2000000000,
+                       subsidy: baseSubsidy/2 + 2000000000,
                },
                {
-                       height: reductionInterval + 1,
-                       txFee:  0,
-                       reward: baseReward / 2,
+                       height:  reductionInterval + 1,
+                       txFee:   0,
+                       subsidy: baseSubsidy / 2,
                },
                {
-                       height: reductionInterval * 2,
-                       txFee:  100000000,
-                       reward: baseReward/4 + 100000000,
-               },
-               {
-                       height: reductionInterval * 10,
-                       txFee:  0,
-                       reward: baseReward / 1024,
+                       height:  reductionInterval * 2,
+                       txFee:   100000000,
+                       subsidy: baseSubsidy/4 + 100000000,
                },
        }
 
@@ -47,9 +39,8 @@ func TestCreateCoinbaseTx(t *testing.T) {
                }
 
                outputAmount := coinbaseTx.Outputs[0].OutputCommitment.Amount
-               fmt.Println(outputAmount)
-               if outputAmount != c.reward {
-                       t.Fatalf("coinbase tx reward dismatch, expected: %d, have: %d", c.reward, outputAmount)
+               if outputAmount != c.subsidy {
+                       t.Fatalf("coinbase tx reward dismatch, expected: %d, have: %d", c.subsidy, outputAmount)
                }
        }
 }
index cf8f04d..9c3fec4 100644 (file)
@@ -248,8 +248,7 @@ func TestCoinbaseTx(t *testing.T) {
                        t.Fatal(err)
                }
 
-               err = SolveAndUpdate(chain, block)
-               if err == nil {
+               if err := SolveAndUpdate(chain, block); err == nil {
                        t.Fatalf("invalid coinbase tx validate success")
                }
        }