Commit 13b243a8 authored by David Vorick's avatar David Vorick

refactor hostdb tests to use a default hostdb entry

parent 0d58e861
Pipeline #57330608 passed with stages
in 25 minutes and 28 seconds
......@@ -10,6 +10,7 @@ import (
)
var (
// An allowance to give to every hostdb for testing.
DefaultTestAllowance = modules.Allowance{
Funds: types.SiacoinPrecision.Mul64(500),
Hosts: uint64(50),
......@@ -20,6 +21,24 @@ var (
ExpectedDownload: modules.DefaultAllowance.ExpectedDownload,
ExpectedRedundancy: modules.DefaultAllowance.ExpectedRedundancy,
}
// The default entry to use when performing scoring.
DefaultHostDBEntry = modules.HostDBEntry{
HostExternalSettings: modules.HostExternalSettings{
AcceptingContracts: true,
MaxDuration: 26e3,
RemainingStorage: 250e9,
WindowSize: 144,
Collateral: types.NewCurrency64(250).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte),
MaxCollateral: types.NewCurrency64(750).Mul(types.SiacoinPrecision),
ContractPrice: types.NewCurrency64(5).Mul(types.SiacoinPrecision),
StoragePrice: types.NewCurrency64(100).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte),
Version: build.Version,
},
}
)
// calculateWeightFromUInt64Price will fill out a host entry with a bunch of
......@@ -28,14 +47,11 @@ func calculateWeightFromUInt64Price(price, collateral uint64) (weight types.Curr
hdb := bareHostDB()
hdb.SetAllowance(DefaultTestAllowance)
hdb.blockHeight = 0
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(1e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(5).Mul(types.SiacoinPrecision)
entry := DefaultHostDBEntry
entry.StoragePrice = types.NewCurrency64(price).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(collateral).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
return hdb.weightFunc(entry).Score()
}
......@@ -158,6 +174,26 @@ func TestHostWeightWithNoCollateral(t *testing.T) {
}
}
// TestHostWeightMaxDuration checks that the host with more collateral has more
// weight.
func TestHostWeightMaxDuration(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
hdb := bareHostDB()
hdb.SetAllowance(DefaultTestAllowance)
entry := DefaultHostDBEntry
entry2 := DefaultHostDBEntry
entry2.MaxDuration = 100 // Shorter than the allowance period.
w1 := hdb.weightFunc(entry).Score()
w2 := hdb.weightFunc(entry2).Score()
if w1.Cmp(w2) <= 0 {
t.Error("Acceptable duration should have more weight", w1, w2)
}
}
// TestHostWeightStorageRemainingDifferences checks that the host with more
// collateral has more weight.
func TestHostWeightCollateralDifferences(t *testing.T) {
......@@ -165,12 +201,9 @@ func TestHostWeightCollateralDifferences(t *testing.T) {
t.SkipNow()
}
hdb := bareHostDB()
var entry modules.HostDBEntry
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.StoragePrice = types.NewCurrency64(1000).Mul(types.SiacoinPrecision)
entry.Collateral = types.NewCurrency64(1000).Mul(types.SiacoinPrecision)
entry2 := entry
entry := DefaultHostDBEntry
entry2 := DefaultHostDBEntry
entry2.Collateral = types.NewCurrency64(500).Mul(types.SiacoinPrecision)
w1 := hdb.weightFunc(entry).Score()
......@@ -187,16 +220,9 @@ func TestHostWeightStorageRemainingDifferences(t *testing.T) {
t.SkipNow()
}
hdb := bareHostDB()
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(1e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(5).Mul(types.SiacoinPrecision)
entry.StoragePrice = types.NewCurrency64(100).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(300).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry2 := entry
entry := DefaultHostDBEntry
entry2 := DefaultHostDBEntry
entry2.RemainingStorage = 50e3
w1 := hdb.weightFunc(entry).Score()
w2 := hdb.weightFunc(entry2).Score()
......@@ -215,16 +241,9 @@ func TestHostWeightVersionDifferences(t *testing.T) {
t.SkipNow()
}
hdb := bareHostDB()
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(1e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(5).Mul(types.SiacoinPrecision)
entry.StoragePrice = types.NewCurrency64(100).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(300).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry2 := entry
entry := DefaultHostDBEntry
entry2 := DefaultHostDBEntry
entry2.Version = "v1.3.2"
w1 := hdb.weightFunc(entry)
w2 := hdb.weightFunc(entry2)
......@@ -244,16 +263,9 @@ func TestHostWeightLifetimeDifferences(t *testing.T) {
}
hdb := bareHostDB()
hdb.blockHeight = 10000
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(1e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(5).Mul(types.SiacoinPrecision)
entry.StoragePrice = types.NewCurrency64(100).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(300).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry2 := entry
entry := DefaultHostDBEntry
entry2 := DefaultHostDBEntry
entry2.FirstSeen = 8100
w1 := hdb.weightFunc(entry).Score()
w2 := hdb.weightFunc(entry2).Score()
......@@ -273,14 +285,8 @@ func TestHostWeightUptimeDifferences(t *testing.T) {
}
hdb := bareHostDB()
hdb.blockHeight = 10000
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(1e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(5).Mul(types.SiacoinPrecision)
entry.StoragePrice = types.NewCurrency64(100).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(300).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry := DefaultHostDBEntry
entry.ScanHistory = modules.HostDBScans{
{Timestamp: time.Now().Add(time.Hour * -100), Success: true},
{Timestamp: time.Now().Add(time.Hour * -80), Success: true},
......@@ -315,14 +321,8 @@ func TestHostWeightUptimeDifferences2(t *testing.T) {
}
hdb := bareHostDB()
hdb.blockHeight = 10000
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(1e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(5).Mul(types.SiacoinPrecision)
entry.StoragePrice = types.NewCurrency64(100).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(300).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry := DefaultHostDBEntry
entry.ScanHistory = modules.HostDBScans{
{Timestamp: time.Now().Add(time.Hour * -100), Success: true},
{Timestamp: time.Now().Add(time.Hour * -80), Success: false},
......@@ -355,14 +355,8 @@ func TestHostWeightUptimeDifferences3(t *testing.T) {
}
hdb := bareHostDB()
hdb.blockHeight = 10000
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(1e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(5).Mul(types.SiacoinPrecision)
entry.StoragePrice = types.NewCurrency64(100).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(300).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry := DefaultHostDBEntry
entry.ScanHistory = modules.HostDBScans{
{Timestamp: time.Now().Add(time.Hour * -100), Success: true},
{Timestamp: time.Now().Add(time.Hour * -80), Success: false},
......@@ -395,14 +389,8 @@ func TestHostWeightUptimeDifferences4(t *testing.T) {
}
hdb := bareHostDB()
hdb.blockHeight = 10000
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(1e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(5).Mul(types.SiacoinPrecision)
entry.StoragePrice = types.NewCurrency64(100).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(300).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry := DefaultHostDBEntry
entry.ScanHistory = modules.HostDBScans{
{Timestamp: time.Now().Add(time.Hour * -100), Success: true},
{Timestamp: time.Now().Add(time.Hour * -80), Success: true},
......@@ -456,14 +444,8 @@ func TestHostWeightConstants(t *testing.T) {
hdb := bareHostDB()
hdb.SetAllowance(DefaultTestAllowance)
hdb.blockHeight = 0
var entry modules.HostDBEntry
entry.Version = build.Version
entry.RemainingStorage = 250e3
entry.MaxDuration = 100e3
entry.MaxCollateral = types.NewCurrency64(100e3).Mul(types.SiacoinPrecision)
entry.ContractPrice = types.NewCurrency64(50e3)
entry.StoragePrice = types.NewCurrency64(100e3).Mul(types.SiacoinPrecision).Div(modules.BlockBytesPerMonthTerabyte)
entry.Collateral = types.NewCurrency64(50e3)
entry := DefaultHostDBEntry
weight = hdb.weightFunc(entry).Score()
if weight.Cmp(types.NewCurrency64(1e9)) < 0 {
t.Error("weight is not sufficiently high for hosts")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment