Documentation
¶
Index ¶
- Constants
- Variables
- func NewWallet(t testing.TB, c *ConsensusNode, walletKey types.PrivateKey) *wallet.SingleAddressWallet
- type Cluster
- func (c *Cluster) AddAccount(t testing.TB) types.PrivateKey
- func (c *Cluster) AddHosts(ctx context.Context, t testing.TB, hosts ...*Host)
- func (c *Cluster) AnnounceHosts(ctx context.Context, t testing.TB, hosts ...*Host)
- func (c *Cluster) FundHosts(ctx context.Context, t testing.TB, hosts ...*Host)
- func (c *Cluster) NewHosts(t testing.TB, n int) []*Host
- func (c *Cluster) WaitForAccountFunding(t *testing.T, pk proto.Account)
- func (c *Cluster) WaitForContracts(t *testing.T)
- type ClusterOpt
- type ConsensusNode
- type Explorer
- type Host
- type Indexer
- func (i *Indexer) Accounts() *accounts.AccountManager
- func (idx *Indexer) AddTestAccount(t *testing.T, pk types.PublicKey)
- func (idx *Indexer) Alerter() *alerts.Manager
- func (idx *Indexer) ChainManager() *chain.Manager
- func (idx *Indexer) Client() *client.Client
- func (i *Indexer) Contracts() *contracts.ContractManager
- func (i *Indexer) Hosts() *hosts.HostManager
- func (idx *Indexer) Signer() rhp.FormContractSigner
- func (idx *Indexer) Store() TestStore
- func (idx *Indexer) Tip() (types.ChainIndex, error)
- func (idx *Indexer) WalletAddr() types.Address
- type IndexerOpt
- type Syncer
- type TestStore
- func (ts TestStore) AddTestAccount(t testing.TB, ak types.PublicKey)
- func (ts TestStore) AddTestHost(t testing.TB, host hosts.Host)
- func (ts TestStore) Exec(ctx context.Context, query string, args ...any) (pgconn.CommandTag, error)
- func (ts TestStore) Query(ctx context.Context, query string, args ...any) (pgx.Rows, error)
- func (ts TestStore) QueryRow(ctx context.Context, query string, args ...any) pgx.Row
Constants ¶
const (
// DefaultHostname is the default hostname used for the application API.
DefaultHostname = "indexer.sia.tech"
)
const (
// TestQuotaName is the name of the quota used in tests.
TestQuotaName = "testing"
)
Variables ¶
var ( // MaintenanceSettings are the default maintenance settings used in testing. MaintenanceSettings = contracts.MaintenanceSettings{ Enabled: true, Period: 144, RenewWindow: 72, WantedContracts: 30, } )
var TestQuotaFundTargetBytes uint64 = 1 << 30 // 1 GiB
TestQuotaFundTargetBytes is the fund target for the testing quota.
Functions ¶
func NewWallet ¶
func NewWallet(t testing.TB, c *ConsensusNode, walletKey types.PrivateKey) *wallet.SingleAddressWallet
NewWallet creates a new SingleAddressWallet for testing which is connected to all the other components created via the ConsensusNode.
Types ¶
type Cluster ¶
type Cluster struct {
ConsensusNode *ConsensusNode
Hosts []*Host
Indexer *Indexer
// contains filtered or unexported fields
}
Cluster is a test cluster that contains an indexer, hosts and other helper types as needed for integration testing.
func NewCluster ¶
func NewCluster(t testing.TB, opts ...ClusterOpt) *Cluster
NewCluster creates a cluster for testing. A cluster contains an indexer and multiple hosts.
func (*Cluster) AddAccount ¶
func (c *Cluster) AddAccount(t testing.TB) types.PrivateKey
AddAccount adds a new account to the indexer and returns the private key.
func (*Cluster) AnnounceHosts ¶
AnnounceHosts announces the hosts and blocks until they are indexed.
func (*Cluster) FundHosts ¶
FundHosts funds the hosts with multiple blocks, then waits for the funds to mature.
func (*Cluster) NewHosts ¶
NewHosts creates n new hosts using the cluster's network and genesis block.
func (*Cluster) WaitForAccountFunding ¶
WaitForAccountFunding waits until the given account is funded on every host in the cluster.
func (*Cluster) WaitForContracts ¶
WaitForContracts waits until all contracts are formed
type ClusterOpt ¶
type ClusterOpt func(*clusterCfg)
ClusterOpt is a functional option for configuring a cluster for testing
func WithHosts ¶
func WithHosts(n int) ClusterOpt
WithHosts allows for overriding the default number of hosts in the cluster
func WithIndexer ¶
func WithIndexer(opts ...IndexerOpt) ClusterOpt
WithIndexer allows for passing options to the indexer when creating the cluster. This is useful for configuring slab options, logger, etc.
func WithLogger ¶
func WithLogger(logger *zap.Logger) ClusterOpt
WithLogger allows for attaching a custom logger to the cluster for debugging if necessary
type ConsensusNode ¶
type ConsensusNode struct {
// contains filtered or unexported fields
}
ConsensusNode is a helper type that serves as the source of truth for anything consensus-related during testing. It can be used to create test types such as the Indexer or Wallet and will guarantee that a call to `MineBlock` won't return before all created components are done subscribing to the newly mined blocks.
func NewConsensusNode ¶
func NewConsensusNode(t testing.TB, log *zap.Logger) *ConsensusNode
NewConsensusNode creates a new node ready for testing. It will mine enough blocks to reach the V2 require height before returning.
func (*ConsensusNode) MineBlocks ¶
MineBlocks is a helper to mine blocks and broadcast the headers
func (*ConsensusNode) Network ¶
func (c *ConsensusNode) Network() *consensus.Network
Network returns the used network configuration of the ConsensusNode
func (*ConsensusNode) NewHost ¶
func (c *ConsensusNode) NewHost(t testing.TB, pk types.PrivateKey, log *zap.Logger) *Host
NewHost creates a new host.
type Explorer ¶
type Explorer struct {
// contains filtered or unexported fields
}
Explorer is a mock implementation of an explorer.
func NewExplorer ¶
func NewExplorer() *Explorer
NewExplorer creates a new instance of Explorer with a default exchange rates for usd.
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
A Host is an ephemeral host that can be used for testing.
func (*Host) DropSector ¶
DropSector simulates the host losing a sector by removing it from the sector store.
func (*Host) WalletAddress ¶
WalletAddress returns the host's wallet address.
type Indexer ¶
type Indexer struct {
AdminURL string
AdminPassword string
AppURL string
Admin *admin.Client
App *app.Client
// contains filtered or unexported fields
}
Indexer is a test utility combining an indexer, an http client for the indexer and useful helpers for testing.
func NewIndexer ¶
func NewIndexer(t testing.TB, c *ConsensusNode, log *zap.Logger, opts ...IndexerOpt) *Indexer
NewIndexer creates a new indexer for testing that is automatically closed up after the test is finished.
func (*Indexer) Accounts ¶
func (i *Indexer) Accounts() *accounts.AccountManager
Accounts returns the account manager for the indexer.
func (*Indexer) AddTestAccount ¶
AddTestAccount adds a test account to the indexer and funds it.
func (*Indexer) ChainManager ¶
ChainManager returns the underlying chain manager.
func (*Indexer) Contracts ¶
func (i *Indexer) Contracts() *contracts.ContractManager
Contracts returns the contract manager for the indexer.
func (*Indexer) Hosts ¶
func (i *Indexer) Hosts() *hosts.HostManager
Hosts returns the host manager for the indexer.
func (*Indexer) Signer ¶
func (idx *Indexer) Signer() rhp.FormContractSigner
Signer returns the contract signer.
func (*Indexer) Tip ¶
func (idx *Indexer) Tip() (types.ChainIndex, error)
Tip returns the current tip of the chain.
func (*Indexer) WalletAddr ¶
WalletAddr returns the address of the wallet.
type IndexerOpt ¶
type IndexerOpt func(*indexerCfg)
IndexerOpt is a functional option for configuring an indexer for testing
func WithAdvertiseURL ¶
func WithAdvertiseURL(url string) IndexerOpt
WithAdvertiseURL sets the advertise URL for the indexer.
func WithContractOptions ¶
func WithContractOptions(opts ...contracts.ContractManagerOpt) IndexerOpt
WithContractOptions allows for passing contract options to the indexer
func WithMaintenanceSettings ¶
func WithMaintenanceSettings(ms contracts.MaintenanceSettings) IndexerOpt
WithMaintenanceSettings allows for passing maintenance settings to the indexer
func WithSlabOptions ¶
func WithSlabOptions(opts ...slabs.Option) IndexerOpt
WithSlabOptions allows for passing slab options to the indexer
type Syncer ¶
type Syncer struct {
// contains filtered or unexported fields
}
Syncer is a wrapper around the syncer.Syncer that doesn't fail broadcasts when no peers are available.
func (*Syncer) BroadcastV2TransactionSet ¶
func (s *Syncer) BroadcastV2TransactionSet(index types.ChainIndex, txns []types.V2Transaction) error
BroadcastV2TransactionSet broadcasts a v2 transaction set to all peers.
type TestStore ¶
TestStore represents a postgres database for testing with some helpers for common actions in testing like adding accounts and running SQL queries.
func NewDB ¶
func NewDB(t testing.TB, maintenanceSettings contracts.MaintenanceSettings, log *zap.Logger) TestStore
NewDB creates a new postgres database for testing.
func (TestStore) AddTestAccount ¶
AddTestAccount adds an account to the database for testing.
func (TestStore) AddTestHost ¶
AddTestHost adds a host to the database for testing.
func (TestStore) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (TestStore) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (TestStore) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called. If the query selects no rows, the *Row's Scan will return ErrNoRows. Otherwise, the *Row's Scan scans the first selected row and discards the rest.