Documentation ¶
Index ¶
- Variables
- func ChunkSize(minPieces uint64) uint64
- func Fuzz() int
- func Miner(dir string) node.NodeParams
- func Retry(tries int, durationBetweenAttempts time.Duration, fn func() error) (err error)
- func TestDir(dirs ...string) (string, error)
- type DependencyInterruptOnceOnKeyword
- type GroupParams
- type LocalFile
- type RemoteFile
- type TestGroup
- func (tg *TestGroup) AddNodeN(np node.NodeParams, n int) error
- func (tg *TestGroup) AddNodes(nps ...node.NodeParams) error
- func (tg *TestGroup) Close() error
- func (tg *TestGroup) Hosts() []*TestNode
- func (tg *TestGroup) Miners() []*TestNode
- func (tg *TestGroup) Nodes() []*TestNode
- func (tg *TestGroup) RemoveNode(tn *TestNode) error
- func (tg *TestGroup) Renters() []*TestNode
- func (tg *TestGroup) SetRenterAllowance(renter *TestNode, allowance modules.Allowance) error
- func (tg *TestGroup) StartNode(tn *TestNode) error
- func (tg *TestGroup) StopNode(tn *TestNode) error
- func (tg *TestGroup) Sync() error
- type TestNode
- func (tn *TestNode) DownloadByStream(rf *RemoteFile) (data []byte, err error)
- func (tn *TestNode) DownloadInfo(lf *LocalFile, rf *RemoteFile) (*api.DownloadInfo, error)
- func (tn *TestNode) DownloadToDisk(rf *RemoteFile, async bool) (*LocalFile, error)
- func (tn *TestNode) File(siaPath string) (modules.FileInfo, error)
- func (tn *TestNode) FileInfo(rf *RemoteFile) (modules.FileInfo, error)
- func (tn *TestNode) Files() ([]modules.FileInfo, error)
- func (tn *TestNode) KnowsHost(host *TestNode) error
- func (tn *TestNode) MineBlock() error
- func (tn *TestNode) RestartNode() error
- func (tn *TestNode) StartNode() error
- func (tn *TestNode) StopNode() error
- func (tn *TestNode) Stream(rf *RemoteFile) (data []byte, err error)
- func (tn *TestNode) StreamPartial(rf *RemoteFile, lf *LocalFile, from, to uint64) (data []byte, err error)
- func (tn *TestNode) Upload(lf *LocalFile, dataPieces, parityPieces uint64) (*RemoteFile, error)
- func (tn *TestNode) UploadNewFile(filesize int, dataPieces uint64, parityPieces uint64) (*LocalFile, *RemoteFile, error)
- func (tn *TestNode) UploadNewFileBlocking(filesize int, dataPieces uint64, parityPieces uint64) (*LocalFile, *RemoteFile, error)
- func (tn *TestNode) WaitForDecreasingRedundancy(rf *RemoteFile, redundancy float64) error
- func (tn *TestNode) WaitForDownload(lf *LocalFile, rf *RemoteFile) error
- func (tn *TestNode) WaitForUploadProgress(rf *RemoteFile, progress float64) error
- func (tn *TestNode) WaitForUploadRedundancy(rf *RemoteFile, redundancy float64) error
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultAllowance is the allowance used for the group's renters DefaultAllowance = modules.Allowance{ Funds: types.SiacoinPrecision.Mul64(1e3), Hosts: 5, Period: 50, RenewWindow: 24, } )
var ( // MinerTemplate is a template for a Sia node that has a functioning // miner. The node has a miner and all dependencies, but no other // modules. MinerTemplate = node.NodeParams{ CreateConsensusSet: true, CreateExplorer: false, CreateGateway: true, CreateHost: false, CreateMiner: true, CreateRenter: false, CreateTransactionPool: true, CreateWallet: true, } )
var ( // SiaTestingDir is the directory that contains all of the files and // folders created during testing. SiaTestingDir = filepath.Join(os.TempDir(), "SiaTesting") )
Functions ¶
func ChunkSize ¶ added in v1.3.3
ChunkSize is a helper method to calculate the size of a chunk depending on the minimum number of pieces required to restore the chunk.
func Fuzz ¶
func Fuzz() int
Fuzz returns 0, 1 or -1. This can be used to test for random off-by-one errors in the code. For example fuzz can be used to create a File that is either sector aligned or off-by-one.
func Miner ¶
func Miner(dir string) node.NodeParams
Miner returns an MinerTemplate filled out with the provided dir.
Types ¶
type DependencyInterruptOnceOnKeyword ¶ added in v1.3.3
type DependencyInterruptOnceOnKeyword struct { modules.ProductionDependencies // contains filtered or unexported fields }
DependencyInterruptOnceOnKeyword is a generic dependency that interrupts the flow of the program if the argument passed to Disrupt equals str and if f was set to true by calling Fail.
func NewDependencyInterruptOnceOnKeyword ¶ added in v1.3.3
func NewDependencyInterruptOnceOnKeyword(str string) *DependencyInterruptOnceOnKeyword
NewDependencyInterruptOnceOnKeyword creates a new DependencyInterruptOnceOnKeyword from a given disrupt key.
func (*DependencyInterruptOnceOnKeyword) Disable ¶ added in v1.3.3
func (d *DependencyInterruptOnceOnKeyword) Disable()
Disable sets the flag to false to make sure that the dependency won't fail.
func (*DependencyInterruptOnceOnKeyword) Disrupt ¶ added in v1.3.3
func (d *DependencyInterruptOnceOnKeyword) Disrupt(s string) bool
Disrupt returns true if the correct string is provided and if the flag was set to true by calling fail on the dependency beforehand. After simulating a crash the flag will be set to false and fail has to be called again for another disruption.
func (*DependencyInterruptOnceOnKeyword) Fail ¶ added in v1.3.3
func (d *DependencyInterruptOnceOnKeyword) Fail()
Fail causes the next call to Disrupt to return true if the correct string is provided.
type GroupParams ¶
type GroupParams struct { Hosts int // number of hosts to create Renters int // number of renters to create Miners int // number of miners to create }
GroupParams is a helper struct to make creating TestGroups easier.
type LocalFile ¶
type LocalFile struct {
// contains filtered or unexported fields
}
LocalFile is a helper struct that represents a file uploaded to the Sia network.
type RemoteFile ¶
type RemoteFile struct {
// contains filtered or unexported fields
}
RemoteFile is a helper struct that represents a file uploaded to the Sia network.
type TestGroup ¶
type TestGroup struct {
// contains filtered or unexported fields
}
TestGroup is a group of of TestNodes that are funded, synced and ready for upload, download and mining depending on their configuration
func NewGroup ¶
func NewGroup(nodeParams ...node.NodeParams) (*TestGroup, error)
NewGroup creates a group of TestNodes from node params. All the nodes will be connected, synced and funded. Hosts nodes are also announced.
func NewGroupFromTemplate ¶
func NewGroupFromTemplate(groupParams GroupParams) (*TestGroup, error)
NewGroupFromTemplate will create hosts, renters and miners according to the settings in groupParams.
func (*TestGroup) AddNodeN ¶ added in v1.3.3
func (tg *TestGroup) AddNodeN(np node.NodeParams, n int) error
AddNodeN adds n nodes of a given template to the group.
func (*TestGroup) AddNodes ¶ added in v1.3.3
func (tg *TestGroup) AddNodes(nps ...node.NodeParams) error
AddNodes creates a node and adds it to the group.
func (*TestGroup) Close ¶
Close closes the group and all its nodes. Closing a node is usually a slow process, but we can speed it up a lot by closing each node in a separate goroutine.
func (*TestGroup) RemoveNode ¶ added in v1.3.3
RemoveNode removes a node from the group and shuts it down.
func (*TestGroup) SetRenterAllowance ¶ added in v1.3.3
SetRenterAllowance finished the setup for the renter test node
func (*TestGroup) StartNode ¶ added in v1.3.3
StartNode starts a node from the group that has previously been stopped.
type TestNode ¶
TestNode is a helper struct for testing that contains a server and a client as embedded fields.
func NewCleanNode ¶
func NewCleanNode(nodeParams node.NodeParams) (*TestNode, error)
NewCleanNode creates a new TestNode that's not yet funded
func NewNode ¶
func NewNode(nodeParams node.NodeParams) (*TestNode, error)
NewNode creates a new funded TestNode
func (*TestNode) DownloadByStream ¶
func (tn *TestNode) DownloadByStream(rf *RemoteFile) (data []byte, err error)
DownloadByStream downloads a file and returns its contents as a slice of bytes.
func (*TestNode) DownloadInfo ¶
func (tn *TestNode) DownloadInfo(lf *LocalFile, rf *RemoteFile) (*api.DownloadInfo, error)
DownloadInfo returns the DownloadInfo struct of a file. If it returns nil, the download has either finished, or was never started in the first place. If the corresponding download info was found, DownloadInfo also performs a few sanity checks on its fields.
func (*TestNode) DownloadToDisk ¶
func (tn *TestNode) DownloadToDisk(rf *RemoteFile, async bool) (*LocalFile, error)
DownloadToDisk downloads a previously uploaded file. The file will be downloaded to a random location and returned as a TestFile object.
func (*TestNode) FileInfo ¶
func (tn *TestNode) FileInfo(rf *RemoteFile) (modules.FileInfo, error)
FileInfo retrieves the info of a certain file that is tracked by the renter
func (*TestNode) KnowsHost ¶ added in v1.3.3
KnowsHost checks if tn has a certain host in its hostdb. This check is performed using the host's public key.
func (*TestNode) MineBlock ¶
MineBlock makes the underlying node mine a single block and broadcast it.
func (*TestNode) RestartNode ¶ added in v1.3.3
RestartNode restarts a TestNode
func (*TestNode) Stream ¶ added in v1.3.3
func (tn *TestNode) Stream(rf *RemoteFile) (data []byte, err error)
Stream uses the streaming endpoint to download a file.
func (*TestNode) StreamPartial ¶ added in v1.3.3
func (tn *TestNode) StreamPartial(rf *RemoteFile, lf *LocalFile, from, to uint64) (data []byte, err error)
StreamPartial uses the streaming endpoint to download a partial file in range [from;to]. A local file can be provided optionally to implicitly check the checksum of the downloaded data.
func (*TestNode) Upload ¶
func (tn *TestNode) Upload(lf *LocalFile, dataPieces, parityPieces uint64) (*RemoteFile, error)
Upload uses the node to upload the file.
func (*TestNode) UploadNewFile ¶
func (tn *TestNode) UploadNewFile(filesize int, dataPieces uint64, parityPieces uint64) (*LocalFile, *RemoteFile, error)
UploadNewFile initiates the upload of a filesize bytes large file.
func (*TestNode) UploadNewFileBlocking ¶
func (tn *TestNode) UploadNewFileBlocking(filesize int, dataPieces uint64, parityPieces uint64) (*LocalFile, *RemoteFile, error)
UploadNewFileBlocking uploads a filesize bytes large file and waits for the upload to reach 100% progress and redundancy.
func (*TestNode) WaitForDecreasingRedundancy ¶ added in v1.3.3
func (tn *TestNode) WaitForDecreasingRedundancy(rf *RemoteFile, redundancy float64) error
WaitForDecreasingRedundancy waits until the redundancy decreases to a certain point.
func (*TestNode) WaitForDownload ¶
func (tn *TestNode) WaitForDownload(lf *LocalFile, rf *RemoteFile) error
WaitForDownload waits for the download of a file to finish. If a file wasn't scheduled for download it will return instantly without an error. If parent is provided, it will compare the contents of the downloaded file to the contents of tf2 after the download is finished. WaitForDownload also verifies the checksum of the downloaded file.
func (*TestNode) WaitForUploadProgress ¶
func (tn *TestNode) WaitForUploadProgress(rf *RemoteFile, progress float64) error
WaitForUploadProgress waits for a file to reach a certain upload progress.
func (*TestNode) WaitForUploadRedundancy ¶
func (tn *TestNode) WaitForUploadRedundancy(rf *RemoteFile, redundancy float64) error
WaitForUploadRedundancy waits for a file to reach a certain upload redundancy.