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)
}
}
-}*/
+}
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,
},
}
}
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)
}
}
}