Files
zeekay f480e48e39 run on the native fleet
Adds .hanzo/workflows/cicd.yml calling the canonical pipeline and drops the
GitHub-hosted workflows it replaces. Lands here because this is where the repo
is written — git.hanzo.ai is upstream and github.com is its push mirror, so the
same change made on github.com never reaches the runner fleet.
2026-08-20 20:20:25 -07:00

97 lines
2.2 KiB
Go

// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package statetest
import (
"testing"
"time"
"github.com/luxfi/metric"
"github.com/stretchr/testify/require"
"github.com/luxfi/constants"
"github.com/luxfi/database"
"github.com/luxfi/database/memdb"
"github.com/luxfi/ids"
log "github.com/luxfi/log"
"github.com/luxfi/proto/p/config"
"github.com/luxfi/proto/p/genesis/genesistest"
"github.com/luxfi/proto/p/metrics"
"github.com/luxfi/proto/p/reward"
"github.com/luxfi/proto/p/state"
"github.com/luxfi/runtime"
"github.com/luxfi/upgrade"
"github.com/luxfi/upgrade/upgradetest"
validators "github.com/luxfi/validators"
)
var DefaultNodeID = ids.GenerateTestNodeID()
type Config struct {
DB database.Database
Genesis []byte
Registerer metric.Registerer
Validators validators.Manager
Upgrades upgrade.Config
Config config.Config
Context *runtime.Runtime
Metrics metrics.Metrics
Rewards reward.Calculator
}
func New(t testing.TB, c Config) state.State {
if c.DB == nil {
c.DB = memdb.New()
}
if c.Context == nil {
c.Context = &runtime.Runtime{
NetworkID: constants.UnitTestID,
NodeID: DefaultNodeID,
Log: log.NoLog{},
}
}
if len(c.Genesis) == 0 {
c.Genesis = genesistest.NewBytes(t, genesistest.Config{
NetworkID: c.Context.NetworkID,
})
}
if c.Registerer == nil {
c.Registerer = metric.NewRegistry()
}
if c.Validators == nil {
c.Validators = validators.NewManager()
}
if c.Upgrades == (upgrade.Config{}) {
c.Upgrades = upgradetest.GetConfig(upgradetest.Latest)
}
if c.Config.BlockCacheSize == 0 {
c.Config = config.Default
}
if c.Metrics == nil {
c.Metrics = metrics.Noop
}
if c.Rewards == nil {
c.Rewards = reward.NewCalculator(reward.Config{
MaxConsumptionRate: .12 * reward.PercentDenominator,
MinConsumptionRate: .1 * reward.PercentDenominator,
MintingPeriod: 365 * 24 * time.Hour,
SupplyCap: 720 * constants.MegaLux,
})
}
s, err := state.New(
c.DB,
c.Genesis,
c.Registerer,
c.Validators,
c.Upgrades,
&c.Config,
c.Context,
c.Metrics,
c.Rewards,
)
require.NoError(t, err)
return s
}