testnodes

package
v0.0.0-...-75360cb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Overview

Package testnodes contains stubbed implementations of the StorageProviderNode and StorageClientNode interface to simulate communications with a filecoin node

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DelayFakeCommonNode

type DelayFakeCommonNode struct {
	OnDealSectorPreCommitted     bool
	OnDealSectorPreCommittedChan chan struct{}

	OnDealSectorCommitted     bool
	OnDealSectorCommittedChan chan struct{}

	OnDealExpiredOrSlashed     bool
	OnDealExpiredOrSlashedChan chan struct{}

	ValidatePublishedDeal     bool
	ValidatePublishedDealChan chan struct{}
}

DelayFakeCommonNode allows configuring delay in the FakeCommonNode functions

type FakeClientNode

type FakeClientNode struct {
	FakeCommonNode
	ClientAddr              address.Address
	MinerAddr               address.Address
	WorkerAddr              address.Address
	ValidationError         error
	ValidatePublishedDealID abi.DealID
	ValidatePublishedError  error
	ExpectedMinerInfos      []address.Address
	// contains filtered or unexported fields
}

FakeClientNode is a node adapter for a storage client whose responses are stubbed

func (*FakeClientNode) GetDefaultWalletAddress

func (n *FakeClientNode) GetDefaultWalletAddress(ctx context.Context) (address.Address, error)

GetDefaultWalletAddress returns a stubbed ClientAddr

func (*FakeClientNode) GetMinerInfo

func (n *FakeClientNode) GetMinerInfo(ctx context.Context, maddr address.Address, tok shared.TipSetToken) (*storagemarket.StorageProviderInfo, error)

GetMinerInfo returns stubbed information for the first miner in storage market state

func (*FakeClientNode) ListStorageProviders

func (n *FakeClientNode) ListStorageProviders(ctx context.Context, tok shared.TipSetToken) ([]*storagemarket.StorageProviderInfo, error)

ListStorageProviders lists the providers in the storage market state

func (*FakeClientNode) SignProposal

func (n *FakeClientNode) SignProposal(ctx context.Context, signer address.Address, proposal market.DealProposal) (*market.ClientDealProposal, error)

SignProposal signs a deal with a dummy signature

func (*FakeClientNode) ValidatePublishedDeal

func (n *FakeClientNode) ValidatePublishedDeal(ctx context.Context, deal storagemarket.ClientDeal) (abi.DealID, error)

ValidatePublishedDeal always succeeds

func (*FakeClientNode) VerifyExpectations

func (n *FakeClientNode) VerifyExpectations(t *testing.T)

type FakeCommonNode

type FakeCommonNode struct {
	SMState                    *StorageMarketState
	DealFunds                  *shared_testutil.TestDealFunds
	AddFundsCid                cid.Cid
	ReserveFundsError          error
	VerifySignatureFails       bool
	GetBalanceError            error
	GetChainHeadError          error
	SignBytesError             error
	PreCommittedSectorNumber   abi.SectorNumber
	PreCommittedIsActive       bool
	DealPreCommittedSyncError  error
	DealPreCommittedAsyncError error
	DealCommittedSyncError     error
	DealCommittedAsyncError    error
	WaitForDealCompletionError error
	OnDealExpiredError         error
	OnDealSlashedError         error
	OnDealSlashedEpoch         abi.ChainEpoch

	WaitForMessageBlocks    bool
	WaitForMessageError     error
	WaitForMessageExitCode  exitcode.ExitCode
	WaitForMessageRetBytes  []byte
	WaitForMessageFinalCid  cid.Cid
	WaitForMessageNodeError error
	WaitForMessageCalls     []cid.Cid

	DelayFakeCommonNode DelayFakeCommonNode
}

FakeCommonNode implements common methods for the storage & client node adapters where responses are stubbed

func (*FakeCommonNode) AddFunds

func (n *FakeCommonNode) AddFunds(ctx context.Context, addr address.Address, amount abi.TokenAmount) (cid.Cid, error)

AddFunds adds funds to the given actor in the storage market state

func (*FakeCommonNode) DealProviderCollateralBounds

func (n *FakeCommonNode) DealProviderCollateralBounds(ctx context.Context, size abi.PaddedPieceSize, isVerified bool) (abi.TokenAmount, abi.TokenAmount, error)

func (*FakeCommonNode) GetBalance

func (n *FakeCommonNode) GetBalance(ctx context.Context, addr address.Address, tok shared.TipSetToken) (storagemarket.Balance, error)

GetBalance returns the funds in the storage market state

func (*FakeCommonNode) GetChainHead

GetChainHead returns the state id in the storage market state

func (*FakeCommonNode) OnDealExpiredOrSlashed

func (n *FakeCommonNode) OnDealExpiredOrSlashed(ctx context.Context, dealID abi.DealID, onDealExpired storagemarket.DealExpiredCallback, onDealSlashed storagemarket.DealSlashedCallback) error

OnDealExpiredOrSlashed simulates waiting for a deal to be expired or slashed, but provides stubbed behavior

func (*FakeCommonNode) OnDealSectorCommitted

func (n *FakeCommonNode) OnDealSectorCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, sectorNumber abi.SectorNumber, proposal market.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorCommittedCallback) error

OnDealSectorCommitted returns immediately, and returns stubbed errors

func (*FakeCommonNode) OnDealSectorPreCommitted

func (n *FakeCommonNode) OnDealSectorPreCommitted(ctx context.Context, provider address.Address, dealID abi.DealID, proposal market.DealProposal, publishCid *cid.Cid, cb storagemarket.DealSectorPreCommittedCallback) error

OnDealSectorPreCommitted returns immediately, and returns stubbed errors

func (*FakeCommonNode) ReleaseFunds

func (n *FakeCommonNode) ReleaseFunds(ctx context.Context, addr address.Address, amt abi.TokenAmount) error

ReleaseFunds releases funds reserved with ReserveFunds

func (*FakeCommonNode) ReserveFunds

func (n *FakeCommonNode) ReserveFunds(ctx context.Context, wallet, addr address.Address, amt abi.TokenAmount) (cid.Cid, error)

ReserveFunds reserves funds required for a deal with the storage market actor

func (*FakeCommonNode) SignBytes

func (n *FakeCommonNode) SignBytes(ctx context.Context, signer address.Address, b []byte) (*crypto.Signature, error)

SignBytes simulates signing data by returning a test signature

func (*FakeCommonNode) VerifySignature

func (n *FakeCommonNode) VerifySignature(ctx context.Context, signature crypto.Signature, addr address.Address, data []byte, tok shared.TipSetToken) (bool, error)

VerifySignature just always returns true, for now

func (*FakeCommonNode) WaitForMessage

func (n *FakeCommonNode) WaitForMessage(ctx context.Context, mcid cid.Cid, onCompletion func(exitcode.ExitCode, []byte, cid.Cid, error) error) error

WaitForMessage simulates waiting for a message to appear on chain

type FakeProviderNode

type FakeProviderNode struct {
	FakeCommonNode
	MinerAddr                           address.Address
	MinerWorkerError                    error
	PieceLength                         uint64
	PieceSectorID                       uint64
	PublishDealID                       abi.DealID
	PublishDealsError                   error
	WaitForPublishDealsError            error
	OnDealCompleteError                 error
	OnDealCompleteSkipCommP             bool
	LastOnDealCompleteBytes             []byte
	OnDealCompleteCalls                 []storagemarket.MinerDeal
	LocatePieceForDealWithinSectorError error
	DataCap                             *verifreg.DataCap
	GetDataCapErr                       error

	Sealed map[abi.SectorNumber]bool
	// contains filtered or unexported fields
}

FakeProviderNode implements functions specific to the StorageProviderNode

func (*FakeProviderNode) GetDataCap

func (n *FakeProviderNode) GetDataCap(ctx context.Context, addr address.Address, tok shared.TipSetToken) (*verifreg.DataCap, error)

GetDataCap gets the current data cap for addr

func (*FakeProviderNode) GetMinerWorkerAddress

func (n *FakeProviderNode) GetMinerWorkerAddress(ctx context.Context, miner address.Address, tok shared.TipSetToken) (address.Address, error)

GetMinerWorkerAddress returns the address specified by MinerAddr

func (*FakeProviderNode) GetProofType

func (n *FakeProviderNode) GetProofType(ctx context.Context, addr address.Address, tok shared.TipSetToken) (abi.RegisteredSealProof, error)

GetProofType returns the miner's proof type.

func (*FakeProviderNode) OnDealComplete

OnDealComplete simulates passing of the deal to the storage miner, and does nothing

func (*FakeProviderNode) PublishDeals

func (n *FakeProviderNode) PublishDeals(ctx context.Context, deal storagemarket.MinerDeal) (cid.Cid, error)

PublishDeals simulates publishing a deal by adding it to the storage market state

func (*FakeProviderNode) WaitForPublishDeals

func (n *FakeProviderNode) WaitForPublishDeals(ctx context.Context, mcid cid.Cid, proposal market.DealProposal) (*storagemarket.PublishDealsWaitResult, error)

WaitForPublishDeals simulates waiting for the deal to be published and calling the callback with the results

type StorageMarketState

type StorageMarketState struct {
	TipSetToken shared.TipSetToken
	Epoch       abi.ChainEpoch
	DealID      abi.DealID
	Balances    map[address.Address]abi.TokenAmount
	Providers   map[address.Address]*storagemarket.StorageProviderInfo
}

StorageMarketState represents a state for the storage market that can be inspected - methods on the provider nodes will affect this state

func NewStorageMarketState

func NewStorageMarketState() *StorageMarketState

NewStorageMarketState returns a new empty state for the storage market

func (*StorageMarketState) AddFunds

func (sma *StorageMarketState) AddFunds(addr address.Address, amount abi.TokenAmount)

AddFunds adds funds for a given address in the storage market

func (*StorageMarketState) Balance

func (sma *StorageMarketState) Balance(addr address.Address) storagemarket.Balance

Balance returns the balance of a given address in the market

func (*StorageMarketState) StateKey

func (sma *StorageMarketState) StateKey() (shared.TipSetToken, abi.ChainEpoch)

StateKey returns a state key with the storage market states set Epoch

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL