Documentation ¶
Index ¶
- Constants
- Variables
- func AssertFilesEqual(t *testing.T, left, right string)
- func CreateImportFile(ctx context.Context, client api.FullNode, rseed int, size int) (res *api.ImportRes, path string, data []byte, err error)
- func CreateRPCServer(t *testing.T, handler http.Handler) (*httptest.Server, multiaddr.Multiaddr)
- func CreateRandomFile(t *testing.T, rseed, size int) (path string)
- func EnsembleMinimal(t *testing.T, opts ...interface{}) (*TestFullNode, *TestMiner, *Ensemble)
- func EnsembleOneTwo(t *testing.T, opts ...interface{}) (*TestFullNode, *TestMiner, *TestMiner, *Ensemble)
- func EnsembleTwoOne(t *testing.T, opts ...interface{}) (*TestFullNode, *TestFullNode, *TestMiner, *Ensemble)
- func Expensive(t *testing.T)
- func InstantaneousNetworkVersion(version network.Version) node.Option
- func LatestActorsAt(upgradeHeight abi.ChainEpoch) node.Option
- func NetworkUpgradeAt(version network.Version, upgradeHeight abi.ChainEpoch) node.Option
- func QuietMiningLogs()
- func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode *TestFullNode)
- func SDRUpgradeAt(calico, persian abi.ChainEpoch) node.Option
- func SendFunds(ctx context.Context, t *testing.T, sender *TestFullNode, ...)
- type BlockMiner
- type ChainPredicate
- type DealHarness
- func (dh *DealHarness) ExtractFileFromCAR(ctx context.Context, file *os.File) (out *os.File)
- func (dh *DealHarness) MakeOnlineDeal(ctx context.Context, params MakeFullDealParams) (deal *cid.Cid, res *api.ImportRes, path string)
- func (dh *DealHarness) PerformRetrieval(ctx context.Context, deal *cid.Cid, root cid.Cid, carExport bool) (path string)
- func (dh *DealHarness) RunConcurrentDeals(opts RunConcurrentDealsOpts)
- func (dh *DealHarness) StartDeal(ctx context.Context, fcid cid.Cid, fastRet bool, startEpoch abi.ChainEpoch) *cid.Cid
- func (dh *DealHarness) StartSealingWaiting(ctx context.Context)
- func (dh *DealHarness) WaitDealPublished(ctx context.Context, deal *cid.Cid)
- func (dh *DealHarness) WaitDealSealed(ctx context.Context, deal *cid.Cid, noseal, noSealStart bool, cb func())
- type Ensemble
- func (n *Ensemble) BeginMining(blocktime time.Duration, miners ...*TestMiner) []*BlockMiner
- func (n *Ensemble) Connect(from api.Common, to ...api.Common) *Ensemble
- func (n *Ensemble) FullNode(full *TestFullNode, opts ...NodeOpt) *Ensemble
- func (n *Ensemble) InterconnectAll() *Ensemble
- func (n *Ensemble) Miner(miner *TestMiner, full *TestFullNode, opts ...NodeOpt) *Ensemble
- func (n *Ensemble) Start() *Ensemble
- type EnsembleOpt
- type MakeFullDealParams
- type MockCLI
- type MockCLIClient
- type NodeOpt
- type OptBuilder
- type RunConcurrentDealsOpts
- type TestDealState
- type TestFullNode
- type TestMiner
Constants ¶
const ( TestDealStateFailed = TestDealState(-1) TestDealStateInProgress = TestDealState(0) TestDealStateComplete = TestDealState(1) )
const DefaultPresealsPerBootstrapMiner = 2
DefaultPresealsPerBootstrapMiner is the number of preseals that every bootstrap miner has by default. It can be overridden through the PresealSectors option.
const EnvRunExpensiveTests = "LOTUS_RUN_EXPENSIVE_TESTS"
EnvRunExpensiveTests is the environment variable that needs to be present and set to value "1" to enable running expensive tests outside of CI.
const TestSpt = abi.RegisteredSealProof_StackedDrg2KiBV1_1
Variables ¶
var DefaultEnsembleOpts = ensembleOpts{ // contains filtered or unexported fields }
var DefaultNodeOpts = nodeOpts{ // contains filtered or unexported fields }
DefaultNodeOpts are the default options that will be applied to test nodes.
var DefaultTestUpgradeSchedule = stmgr.UpgradeSchedule{{ Network: network.Version9, Height: 1, Migration: stmgr.UpgradeActorsV2, }, { Network: network.Version10, Height: 2, Migration: stmgr.UpgradeActorsV3, }, { Network: network.Version12, Height: 3, Migration: stmgr.UpgradeActorsV4, }, { Network: network.Version13, Height: 4, Migration: stmgr.UpgradeActorsV5, }}
DefaultTestUpgradeSchedule
Functions ¶
func AssertFilesEqual ¶
AssertFilesEqual compares two files by blake2b hash equality and fails the test if unequal.
func CreateImportFile ¶
func CreateRPCServer ¶
func CreateRandomFile ¶
CreateRandomFile creates a random file with the provided seed and the provided size.
func EnsembleMinimal ¶
func EnsembleMinimal(t *testing.T, opts ...interface{}) (*TestFullNode, *TestMiner, *Ensemble)
EnsembleMinimal creates and starts an Ensemble with a single full node and a single miner. It does not interconnect nodes nor does it begin mining.
This function supports passing both ensemble and node functional options. Functional options are applied to all nodes.
func EnsembleOneTwo ¶
func EnsembleOneTwo(t *testing.T, opts ...interface{}) (*TestFullNode, *TestMiner, *TestMiner, *Ensemble)
EnsembleOneTwo creates and starts an Ensemble with one full node and two miners. It does not interconnect nodes nor does it begin mining.
This function supports passing both ensemble and node functional options. Functional options are applied to all nodes.
func EnsembleTwoOne ¶
func EnsembleTwoOne(t *testing.T, opts ...interface{}) (*TestFullNode, *TestFullNode, *TestMiner, *Ensemble)
EnsembleTwoOne creates and starts an Ensemble with two full nodes and one miner. It does not interconnect nodes nor does it begin mining.
This function supports passing both ensemble and node functional options. Functional options are applied to all nodes.
func InstantaneousNetworkVersion ¶
InstantaneousNetworkVersion starts the network instantaneously at the specified version in height 1.
func LatestActorsAt ¶
func LatestActorsAt(upgradeHeight abi.ChainEpoch) node.Option
func NetworkUpgradeAt ¶
func QuietMiningLogs ¶
func QuietMiningLogs()
func RunClientTest ¶
func RunClientTest(t *testing.T, cmds []*lcli.Command, clientNode *TestFullNode)
RunClientTest exercises some of the Client CLI commands
func SDRUpgradeAt ¶
func SDRUpgradeAt(calico, persian abi.ChainEpoch) node.Option
func SendFunds ¶
func SendFunds(ctx context.Context, t *testing.T, sender *TestFullNode, recipient address.Address, amount abi.TokenAmount)
SendFunds sends funds from the default wallet of the specified sender node to the recipient address.
Types ¶
type BlockMiner ¶
type BlockMiner struct {
// contains filtered or unexported fields
}
BlockMiner is a utility that makes a test miner Mine blocks on a timer.
func NewBlockMiner ¶
func NewBlockMiner(t *testing.T, miner *TestMiner) *BlockMiner
func (*BlockMiner) InjectNulls ¶
func (bm *BlockMiner) InjectNulls(rounds abi.ChainEpoch)
InjectNulls injects the specified amount of null rounds in the next mining rounds.
func (*BlockMiner) MineBlocks ¶
func (bm *BlockMiner) MineBlocks(ctx context.Context, blocktime time.Duration)
func (*BlockMiner) MineUntilBlock ¶
func (bm *BlockMiner) MineUntilBlock(ctx context.Context, fn *TestFullNode, cb func(abi.ChainEpoch))
type ChainPredicate ¶
ChainPredicate encapsulates a chain condition.
func BlockMinedBy ¶
func BlockMinedBy(miner address.Address) ChainPredicate
BlockMinedBy returns a ChainPredicate that is satisfied when we observe the first block mined by the specified miner.
func HeightAtLeast ¶
func HeightAtLeast(target abi.ChainEpoch) ChainPredicate
HeightAtLeast returns a ChainPredicate that is satisfied when the chain height is equal or higher to the target.
type DealHarness ¶
type DealHarness struct {
// contains filtered or unexported fields
}
func NewDealHarness ¶
func NewDealHarness(t *testing.T, client *TestFullNode, miner *TestMiner) *DealHarness
NewDealHarness creates a test harness that contains testing utilities for deals.
func (*DealHarness) ExtractFileFromCAR ¶
func (*DealHarness) MakeOnlineDeal ¶
func (dh *DealHarness) MakeOnlineDeal(ctx context.Context, params MakeFullDealParams) (deal *cid.Cid, res *api.ImportRes, path string)
MakeOnlineDeal makes an online deal, generating a random file with the supplied seed, and setting the specified fast retrieval flag and start epoch on the storage deal. It returns when the deal is sealed.
TODO: convert input parameters to struct, and add size as an input param.
func (*DealHarness) PerformRetrieval ¶
func (dh *DealHarness) PerformRetrieval(ctx context.Context, deal *cid.Cid, root cid.Cid, carExport bool) (path string)
func (*DealHarness) RunConcurrentDeals ¶
func (dh *DealHarness) RunConcurrentDeals(opts RunConcurrentDealsOpts)
func (*DealHarness) StartDeal ¶
func (dh *DealHarness) StartDeal(ctx context.Context, fcid cid.Cid, fastRet bool, startEpoch abi.ChainEpoch) *cid.Cid
StartDeal starts a storage deal between the client and the miner.
func (*DealHarness) StartSealingWaiting ¶
func (dh *DealHarness) StartSealingWaiting(ctx context.Context)
func (*DealHarness) WaitDealPublished ¶
func (dh *DealHarness) WaitDealPublished(ctx context.Context, deal *cid.Cid)
WaitDealPublished waits until the deal is published.
func (*DealHarness) WaitDealSealed ¶
func (dh *DealHarness) WaitDealSealed(ctx context.Context, deal *cid.Cid, noseal, noSealStart bool, cb func())
WaitDealSealed waits until the deal is sealed.
type Ensemble ¶
type Ensemble struct {
// contains filtered or unexported fields
}
Ensemble is a collection of nodes instantiated within a test.
Create a new ensemble with:
ens := kit.NewEnsemble()
Create full nodes and miners:
var full TestFullNode var miner TestMiner ens.FullNode(&full, opts...) // populates a full node ens.Miner(&miner, &full, opts...) // populates a miner, using the full node as its chain daemon
It is possible to pass functional options to set initial balances, presealed sectors, owner keys, etc.
After the initial nodes are added, call `ens.Start()` to forge genesis and start the network. Mining will NOT be started automatically. It needs to be started explicitly by calling `BeginMining`.
Nodes also need to be connected with one another, either via `ens.Connect()` or `ens.InterconnectAll()`. A common inchantation for simple tests is to do:
ens.InterconnectAll().BeginMining(blocktime)
You can continue to add more nodes, but you must always follow with `ens.Start()` to activate the new nodes.
The API is chainable, so it's possible to do a lot in a very succinct way:
kit.NewEnsemble().FullNode(&full).Miner(&miner, &full).Start().InterconnectAll().BeginMining()
You can also find convenient fullnode:miner presets, such as 1:1, 1:2, and 2:1, e.g.:
kit.EnsembleMinimal() kit.EnsembleOneTwo() kit.EnsembleTwoOne()
func NewEnsemble ¶
func NewEnsemble(t *testing.T, opts ...EnsembleOpt) *Ensemble
NewEnsemble instantiates a new blank Ensemble.
func (*Ensemble) BeginMining ¶
func (n *Ensemble) BeginMining(blocktime time.Duration, miners ...*TestMiner) []*BlockMiner
BeginMining kicks off mining for the specified miners. If nil or 0-length, it will kick off mining for all enrolled and active miners. It also adds a cleanup function to stop all mining operations on test teardown.
func (*Ensemble) FullNode ¶
func (n *Ensemble) FullNode(full *TestFullNode, opts ...NodeOpt) *Ensemble
FullNode enrolls a new full node.
func (*Ensemble) InterconnectAll ¶
InterconnectAll connects all miners and full nodes to one another.
type EnsembleOpt ¶
type EnsembleOpt func(opts *ensembleOpts) error
func Account ¶
func Account(key *wallet.Key, balance abi.TokenAmount) EnsembleOpt
Account sets up an account at genesis with the specified key and balance.
func MockProofs ¶
func MockProofs() EnsembleOpt
MockProofs activates mock proofs for the entire ensemble.
func RootVerifier ¶
func RootVerifier(key *wallet.Key, balance abi.TokenAmount) EnsembleOpt
RootVerifier specifies the key to be enlisted as the verified registry root, as well as the initial balance to be attributed during genesis.
type MakeFullDealParams ¶
type MakeFullDealParams struct { Rseed int FastRet bool StartEpoch abi.ChainEpoch // SuspendUntilCryptoeconStable suspends deal-making, until cryptoecon // parameters are stabilised. This affects projected collateral, and tests // will fail in network version 13 and higher if deals are started too soon // after network birth. // // The reason is that the formula for collateral calculation takes // circulating supply into account: // // [portion of power this deal will be] * [~1% of tokens]. // // In the first epochs after genesis, the total circulating supply is // changing dramatically in percentual terms. Therefore, if the deal is // proposed too soon, by the time it gets published on chain, the quoted // provider collateral will no longer be valid. // // The observation is that deals fail with: // // GasEstimateMessageGas error: estimating gas used: message execution // failed: exit 16, reason: Provider collateral out of bounds. (RetCode=16) // // Enabling this will suspend deal-making until the network has reached a // height of 300. SuspendUntilCryptoeconStable bool }
type MockCLI ¶
type MockCLI struct {
// contains filtered or unexported fields
}
func (*MockCLI) Client ¶
func (c *MockCLI) Client(addr multiaddr.Multiaddr) *MockCLIClient
type MockCLIClient ¶
type MockCLIClient struct {
// contains filtered or unexported fields
}
MockCLIClient runs commands against a particular node
func (*MockCLIClient) RunCmd ¶
func (c *MockCLIClient) RunCmd(input ...string) string
func (*MockCLIClient) RunCmdRaw ¶
func (c *MockCLIClient) RunCmdRaw(input ...string) (string, error)
func (*MockCLIClient) RunInteractiveCmd ¶
func (c *MockCLIClient) RunInteractiveCmd(cmd []string, interactive []string) string
type NodeOpt ¶
type NodeOpt func(opts *nodeOpts) error
NodeOpt is a functional option for test nodes.
func ConstructorOpts ¶
ConstructorOpts are Lotus node constructor options that are passed as-is to the node.
func LiteNode ¶
func LiteNode() NodeOpt
LiteNode specifies that this node will be a lite node. Only relevant when creating a fullnode.
func OwnerBalance ¶
func OwnerBalance(balance abi.TokenAmount) NodeOpt
OwnerBalance specifies the balance to be attributed to a miner's owner account. Only relevant when creating a miner.
func PresealSectors ¶
PresealSectors specifies the amount of preseal sectors to give to a miner at genesis. Only relevant when creating a miner.
func ProofType ¶
func ProofType(proofType abi.RegisteredSealProof) NodeOpt
ProofType sets the proof type for this node. If you're using new actor versions, this should be a _1 proof type.
func ThroughRPC ¶
func ThroughRPC() NodeOpt
ThroughRPC makes interactions with this node throughout the test flow through the JSON-RPC API.
type OptBuilder ¶
type OptBuilder func(activeNodes []*TestFullNode) node.Option
OptBuilder is used to create an option after some other node is already active. Takes all active nodes as a parameter.
type RunConcurrentDealsOpts ¶
type RunConcurrentDealsOpts struct { N int FastRetrieval bool CarExport bool StartEpoch abi.ChainEpoch }
type TestDealState ¶
type TestDealState int
func CategorizeDealState ¶
func CategorizeDealState(dealStatus string) TestDealState
CategorizeDealState categorizes deal states into one of three states: Complete, InProgress, Failed.
type TestFullNode ¶
type TestFullNode struct { v1api.FullNode // ListenAddr is the address on which an API server is listening, if an // API server is created for this Node. ListenAddr multiaddr.Multiaddr DefaultKey *wallet.Key // contains filtered or unexported fields }
TestFullNode represents a full node enrolled in an Ensemble.
func (*TestFullNode) CreateImportFile ¶
func (f *TestFullNode) CreateImportFile(ctx context.Context, rseed int, size int) (res *api.ImportRes, path string)
CreateImportFile creates a random file with the specified seed and size, and imports it into the full node.
func (*TestFullNode) WaitTillChain ¶
func (f *TestFullNode) WaitTillChain(ctx context.Context, pred ChainPredicate) *types.TipSet
WaitTillChain waits until a specified chain condition is met. It returns the first tipset where the condition is met.
type TestMiner ¶
type TestMiner struct { api.StorageMiner // ListenAddr is the address on which an API server is listening, if an // API server is created for this Node ListenAddr multiaddr.Multiaddr ActorAddr address.Address OwnerKey *wallet.Key MineOne func(context.Context, miner.MineReq) error Stop func(context.Context) error FullNode *TestFullNode PresealDir string Libp2p struct { PeerID peer.ID PrivKey libp2pcrypto.PrivKey } // contains filtered or unexported fields }
TestMiner represents a miner enrolled in an Ensemble.