mirror of
https://github.com/luxfi/proto.git
synced 2026-10-30 15:21:09 +00:00
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.
97 lines
2.2 KiB
Go
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
|
|
}
|