go-blockchain/consensus/reward_test.go
Snider 34128d8e98
Some checks failed
Security Scan / security (pull_request) Successful in 11s
Test / Test (pull_request) Failing after 19s
refactor: migrate module path to dappco.re/go/core/blockchain
Update go.mod module line, all require/replace directives, and every
.go import path from forge.lthn.ai/core/go-blockchain to
dappco.re/go/core/blockchain. Add replace directives to bridge
dappco.re paths to existing forge.lthn.ai registry during migration.
Update CLAUDE.md, README, and docs to reflect the new module path.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 01:49:26 +00:00

65 lines
1.9 KiB
Go

//go:build !integration
package consensus
import (
"testing"
"dappco.re/go/core/blockchain/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBaseReward_Good(t *testing.T) {
assert.Equal(t, config.Premine, BaseReward(0), "genesis returns premine")
assert.Equal(t, config.BlockReward, BaseReward(1), "block 1 returns standard reward")
assert.Equal(t, config.BlockReward, BaseReward(10000), "arbitrary height")
}
func TestBlockReward_Good(t *testing.T) {
base := config.BlockReward
// Small block: full reward.
reward, err := BlockReward(base, 1000, config.BlockGrantedFullRewardZone)
require.NoError(t, err)
assert.Equal(t, base, reward)
// Block at exactly the zone boundary: full reward.
reward, err = BlockReward(base, config.BlockGrantedFullRewardZone, config.BlockGrantedFullRewardZone)
require.NoError(t, err)
assert.Equal(t, base, reward)
}
func TestBlockReward_Bad(t *testing.T) {
base := config.BlockReward
median := config.BlockGrantedFullRewardZone
// Block larger than 2*median: rejected.
_, err := BlockReward(base, 2*median+1, median)
assert.Error(t, err)
assert.Contains(t, err.Error(), "too large")
}
func TestBlockReward_Ugly(t *testing.T) {
base := config.BlockReward
median := config.BlockGrantedFullRewardZone
// Block slightly over zone: penalty applied, reward < base.
reward, err := BlockReward(base, median+10_000, median)
require.NoError(t, err)
assert.Less(t, reward, base, "penalty should reduce reward")
assert.Greater(t, reward, uint64(0), "reward should be positive")
}
func TestMinerReward_Good(t *testing.T) {
base := config.BlockReward
fees := uint64(50_000_000_000) // 0.05 LTHN
// Pre-HF4: fees added.
total := MinerReward(base, fees, false)
assert.Equal(t, base+fees, total)
// Post-HF4: fees burned.
total = MinerReward(base, fees, true)
assert.Equal(t, base, total)
}