siatest

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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,
	}
)
View Source
var (
	// SiaTestingDir is the directory that contains all of the files and
	// folders created during testing.
	SiaTestingDir = filepath.Join(os.TempDir(), "SiaTesting")
)

Functions

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.

func Retry

func Retry(tries int, durationBetweenAttempts time.Duration, fn func() error) (err error)

Retry will call 'fn' 'tries' times, waiting 'durationBetweenAttempts' between each attempt, returning 'nil' the first time that 'fn' returns nil. If 'nil' is never returned, then the final error returned by 'fn' is returned.

func TestDir

func TestDir(dirs ...string) (string, error)

TestDir joins the provided directories and prefixes them with the Sia testing directory, removing any files or directories that previously existed at that location.

Types

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.

func NewFile

func NewFile(size int) (*LocalFile, error)

NewFile creates and returns a new LocalFile. It will write size random bytes to the file and give the file a random name.

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) Close

func (tg *TestGroup) Close() error

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) Hosts

func (tg *TestGroup) Hosts() []*TestNode

Hosts returns all the hosts of the group

func (*TestGroup) Miners

func (tg *TestGroup) Miners() []*TestNode

Miners returns all the miners of the group

func (*TestGroup) Nodes

func (tg *TestGroup) Nodes() []*TestNode

Nodes returns all the nodes of the group

func (*TestGroup) Renters

func (tg *TestGroup) Renters() []*TestNode

Renters returns all the renters of the group

type TestNode

type TestNode struct {
	server.Server
	client.Client
	// contains filtered or unexported fields
}

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) Files

func (tn *TestNode) Files() ([]modules.FileInfo, error)

Files lists the files tracked by the renter

func (*TestNode) MineBlock

func (tn *TestNode) MineBlock() error

MineBlock makes the underlying node mine a single block and broadcast it.

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) (rf *RemoteFile, err error)

UploadNewFile initiates the upload of a filesize bytes large file.

func (*TestNode) UploadNewFileBlocking

func (tn *TestNode) UploadNewFileBlocking(filesize int, dataPieces uint64, parityPieces uint64) (rf *RemoteFile, err error)

UploadNewFileBlocking uploads a filesize bytes large file and waits for the upload to reach 100% progress and redundancy.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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