harness

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenesisTime = time.Date(2022, 7, 1, 0, 0, 0, 0, time.UTC)

GenesisTime is 2022-7-1 0:00 UTC.

Functions

func DnHeight added in v1.2.0

func DnHeight(v uint64) dnHeightOnPart

func MajorBlock added in v1.2.0

func MajorBlock(v uint64) majorHeightOnPart

func QueryAccountAs

func QueryAccountAs[T protocol.Account](h *Harness, scope *url.URL) T

QueryAccountAs calls Harness.QueryAccountAs with a new T and returns that value.

func Recordings added in v1.2.0

func Recordings(tb testing.TB) simulator.RecordingFunc

func Sig

func Sig(id *url.TxID) sigCond

Sig defines a condition on a signature.

func Txn

func Txn(id *url.TxID) txnCond

Txn defines a condition on a transaction.

Types

type BlockStep

type BlockStep <-chan api.Event

BlockStep implements Stepper by waiting for a block event.

func (BlockStep) Step

func (s BlockStep) Step() error

Step processes events until there is an error or a block event.

type Condition

type Condition interface {
	Satisfied(*Harness) bool
	Format(prefix, suffix string) string
}

A Condition is a function that is used by Harness.StepUntil to wait until some condition is met.

type EnvelopeBuilder

type EnvelopeBuilder interface {
	Done() (*messaging.Envelope, error)
}

EnvelopeBuilder builds an envelope.

type Harness

type Harness struct {
	TB testing.TB

	VerboseConditions bool
	// contains filtered or unexported fields
}

Harness is a test harness.

func New

func New(tb testing.TB, services Services, stepper Stepper) *Harness

New returns a new Harness with the given services and stepper.

func (*Harness) BuildAndSubmit

func (h *Harness) BuildAndSubmit(b EnvelopeBuilder) []*protocol.TransactionStatus

BuildAndSubmit builds and submits the envelope.

func (*Harness) BuildAndSubmitSuccessfully

func (h *Harness) BuildAndSubmitSuccessfully(b EnvelopeBuilder) []*protocol.TransactionStatus

BuildAndSubmitSuccessfully builds and submits the envelope and asserts that all transactions and signatures succeeded.

func (*Harness) BuildAndSubmitTxn

func (h *Harness) BuildAndSubmitTxn(b EnvelopeBuilder) *protocol.TransactionStatus

BuildAndSubmitTxn builds and submits a single transaction.

func (*Harness) BuildAndSubmitTxnSuccessfully

func (h *Harness) BuildAndSubmitTxnSuccessfully(b EnvelopeBuilder) *protocol.TransactionStatus

BuildAndSubmitTxnSuccessfully builds and submits a single transaction and asserts that it and its signatures succeeded.

func (*Harness) Network

func (h *Harness) Network() api.NetworkService

Network returns the Harness's service as an api.NetworkService.

func (*Harness) NetworkStatus

func (h *Harness) NetworkStatus(opts api.NetworkStatusOptions) *api.NetworkStatus

NetworkStatus calls the Harness's service, failing if the call returns an error.

func (*Harness) Query

func (h *Harness) Query() api.Querier2

Query returns the Harness's service as an api.Querier2.

func (*Harness) QueryAccount

func (h *Harness) QueryAccount(scope *url.URL, query *api.DefaultQuery) *api.AccountRecord

QueryAccount queries the Harness's service, passing the given arguments. QueryAccount fails if Query returns an error. See api.Querier2.QueryAccount.

func (*Harness) QueryAccountAs

func (h *Harness) QueryAccountAs(scope *url.URL, query *api.DefaultQuery, target any) *api.AccountRecord

QueryAccountAs queries the Harness's service, passing the given arguments. QueryAccountAs fails if Query returns an error. See api.Querier2.QueryAccountAs.

func (*Harness) QueryAccountChains

func (h *Harness) QueryAccountChains(scope *url.URL, query *api.ChainQuery) *api.RecordRange[*api.ChainRecord]

QueryAccountChains queries the Harness's service, passing the given arguments. QueryAccountChains fails if Query returns an error. See api.Querier2.QueryAccountChains.

func (*Harness) QueryChain

func (h *Harness) QueryChain(scope *url.URL, query *api.ChainQuery) *api.ChainRecord

QueryChain queries the Harness's service, passing the given arguments. QueryChain fails if Query returns an error. See api.Querier2.QueryChain.

func (*Harness) QueryChainEntries

func (h *Harness) QueryChainEntries(scope *url.URL, query *api.ChainQuery) *api.RecordRange[*api.ChainEntryRecord[api.Record]]

QueryChainEntries queries the Harness's service, passing the given arguments. QueryChainEntries fails if Query returns an error. See api.Querier2.QueryChainEntries.

func (*Harness) QueryChainEntry

func (h *Harness) QueryChainEntry(scope *url.URL, query *api.ChainQuery) *api.ChainEntryRecord[api.Record]

QueryChainEntry queries the Harness's service, passing the given arguments. QueryChainEntry fails if Query returns an error. See api.Querier2.QueryChainEntry.

func (*Harness) QueryDataEntries

func (h *Harness) QueryDataEntries(scope *url.URL, query *api.DataQuery) *api.RecordRange[*api.ChainEntryRecord[*api.MessageRecord[*messaging.TransactionMessage]]]

QueryDataEntries queries the Harness's service, passing the given arguments. QueryDataEntries fails if Query returns an error. See api.Querier2.QueryDataEntries.

func (*Harness) QueryDataEntry

func (h *Harness) QueryDataEntry(scope *url.URL, query *api.DataQuery) *api.ChainEntryRecord[*api.MessageRecord[*messaging.TransactionMessage]]

QueryDataEntry queries the Harness's service, passing the given arguments. QueryDataEntry fails if Query returns an error. See api.Querier2.QueryDataEntry.

func (*Harness) QueryDirectory

func (h *Harness) QueryDirectory(scope *url.URL, query *api.DirectoryQuery) *api.RecordRange[*api.AccountRecord]

QueryDirectory queries the Harness's service, passing the given arguments. QueryDirectory fails if Query returns an error. See api.Querier2.QueryDirectory.

func (*Harness) QueryDirectoryUrls

func (h *Harness) QueryDirectoryUrls(scope *url.URL, query *api.DirectoryQuery) *api.RecordRange[*api.UrlRecord]

QueryDirectoryUrls queries the Harness's service, passing the given arguments. QueryDirectoryUrls fails if Query returns an error. See api.Querier2.QueryDirectoryUrls.

func (*Harness) QueryIndexChainEntries

func (h *Harness) QueryIndexChainEntries(scope *url.URL, query *api.ChainQuery) *api.RecordRange[*api.ChainEntryRecord[*api.IndexEntryRecord]]

QueryIndexChainEntries queries the Harness's service, passing the given arguments. QueryIndexChainEntries fails if Query returns an error. See api.Querier2.QueryIndexChainEntries.

func (*Harness) QueryIndexChainEntry

func (h *Harness) QueryIndexChainEntry(scope *url.URL, query *api.ChainQuery) *api.ChainEntryRecord[*api.IndexEntryRecord]

QueryIndexChainEntry queries the Harness's service, passing the given arguments. QueryIndexChainEntry fails if Query returns an error. See api.Querier2.QueryIndexChainEntry.

func (*Harness) QueryMainChainEntries

func (h *Harness) QueryMainChainEntries(scope *url.URL, query *api.ChainQuery) *api.RecordRange[*api.ChainEntryRecord[*api.MessageRecord[*messaging.TransactionMessage]]]

QueryMainChainEntries queries the Harness's service, passing the given arguments. QueryMainChainEntries fails if Query returns an error. See api.Querier2.QueryMainChainEntries.

func (*Harness) QueryMainChainEntry

func (h *Harness) QueryMainChainEntry(scope *url.URL, query *api.ChainQuery) *api.ChainEntryRecord[*api.MessageRecord[*messaging.TransactionMessage]]

QueryMainChainEntry queries the Harness's service, passing the given arguments. QueryMainChainEntry fails if Query returns an error. See api.Querier2.QueryMainChainEntry.

func (*Harness) QueryMajorBlock

func (h *Harness) QueryMajorBlock(scope *url.URL, query *api.BlockQuery) *api.MajorBlockRecord

QueryMajorBlock queries the Harness's service, passing the given arguments. QueryMajorBlock fails if Query returns an error. See api.Querier2.QueryMajorBlock.

func (*Harness) QueryMajorBlocks

func (h *Harness) QueryMajorBlocks(scope *url.URL, query *api.BlockQuery) *api.RecordRange[*api.MajorBlockRecord]

QueryMajorBlocks queries the Harness's service, passing the given arguments. QueryMajorBlocks fails if Query returns an error. See api.Querier2.QueryMajorBlocks.

func (*Harness) QueryMessage

func (h *Harness) QueryMessage(txid *url.TxID, query *api.DefaultQuery) *api.MessageRecord[messaging.Message]

QueryMessage queries the Harness's service, passing the given arguments. QueryMessage fails if Query returns an error. See api.Querier2.QueryMessage.

func (*Harness) QueryMinorBlock

func (h *Harness) QueryMinorBlock(scope *url.URL, query *api.BlockQuery) *api.MinorBlockRecord

QueryMinorBlock queries the Harness's service, passing the given arguments. QueryMinorBlock fails if Query returns an error. See api.Querier2.QueryMinorBlock.

func (*Harness) QueryMinorBlocks

func (h *Harness) QueryMinorBlocks(scope *url.URL, query *api.BlockQuery) *api.RecordRange[*api.MinorBlockRecord]

QueryMinorBlocks queries the Harness's service, passing the given arguments. QueryMinorBlocks fails if Query returns an error. See api.Querier2.QueryMinorBlocks.

func (*Harness) QueryPending

func (h *Harness) QueryPending(scope *url.URL, query *api.PendingQuery) *api.RecordRange[*api.MessageRecord[*messaging.TransactionMessage]]

QueryPending queries the Harness's service, passing the given arguments. QueryPending fails if Query returns an error. See api.Querier2.QueryPending.

func (*Harness) QueryPendingIds

func (h *Harness) QueryPendingIds(scope *url.URL, query *api.PendingQuery) *api.RecordRange[*api.TxIDRecord]

QueryPendingIds queries the Harness's service, passing the given arguments. QueryPendingIds fails if Query returns an error. See api.Querier2.QueryPendingIds.

func (*Harness) QuerySignature

func (h *Harness) QuerySignature(txid *url.TxID, query *api.DefaultQuery) *api.MessageRecord[*messaging.SignatureMessage]

QuerySignature queries the Harness's service, passing the given arguments. QuerySignature fails if Query returns an error. See api.Querier2.QuerySignature.

func (*Harness) QuerySignatureChainEntries

func (h *Harness) QuerySignatureChainEntries(scope *url.URL, query *api.ChainQuery) *api.RecordRange[*api.ChainEntryRecord[*api.MessageRecord[messaging.Message]]]

QuerySignatureChainEntries queries the Harness's service, passing the given arguments. QuerySignatureChainEntries fails if Query returns an error. See api.Querier2.QuerySignatureChainEntries.

func (*Harness) QuerySignatureChainEntry

func (h *Harness) QuerySignatureChainEntry(scope *url.URL, query *api.ChainQuery) *api.ChainEntryRecord[*api.MessageRecord[messaging.Message]]

QuerySignatureChainEntry queries the Harness's service, passing the given arguments. QuerySignatureChainEntry fails if Query returns an error. See api.Querier2.QuerySignatureChainEntry.

func (*Harness) QueryTransaction

func (h *Harness) QueryTransaction(txid *url.TxID, query *api.DefaultQuery) *api.MessageRecord[*messaging.TransactionMessage]

QueryTransaction queries the Harness's service, passing the given arguments. QueryTransaction fails if Query returns an error. See api.Querier2.QueryTransaction.

func (*Harness) QueryTransactionChains

func (h *Harness) QueryTransactionChains(scope *url.TxID, query *api.ChainQuery) *api.RecordRange[*api.ChainEntryRecord[api.Record]]

QueryTransactionChains queries the Harness's service, passing the given arguments. QueryTransactionChains fails if Query returns an error. See api.Querier2.QueryTransactionChains.

func (*Harness) SearchForAnchor

func (h *Harness) SearchForAnchor(scope *url.URL, search *api.AnchorSearchQuery) *api.RecordRange[*api.ChainEntryRecord[api.Record]]

SearchForAnchor queries the Harness's service, passing the given arguments. SearchForAnchor fails if Query returns an error. See api.Querier2.SearchForAnchor.

func (*Harness) SearchForDelegate

func (h *Harness) SearchForDelegate(scope *url.URL, search *api.DelegateSearchQuery) *api.RecordRange[*api.KeyRecord]

SearchForDelegate queries the Harness's service, passing the given arguments. SearchForDelegate fails if Query returns an error. See api.Querier2.SearchForDelegate.

func (*Harness) SearchForMessage

func (h *Harness) SearchForMessage(ctx context.Context, hash [32]byte) *api.RecordRange[*api.TxIDRecord]

SearchForTransactionHash queries the Harness's service, passing the given arguments. SearchForTransactionHash fails if Query returns an error. See api.Querier2.SearchForTransactionHash.

func (*Harness) SearchForPublicKey

func (h *Harness) SearchForPublicKey(scope *url.URL, search *api.PublicKeySearchQuery) *api.RecordRange[*api.KeyRecord]

SearchForPublicKey queries the Harness's service, passing the given arguments. SearchForPublicKey fails if Query returns an error. See api.Querier2.SearchForPublicKey.

func (*Harness) SearchForPublicKeyHash

func (h *Harness) SearchForPublicKeyHash(scope *url.URL, search *api.PublicKeyHashSearchQuery) *api.RecordRange[*api.KeyRecord]

SearchForPublicKeyHash queries the Harness's service, passing the given arguments. SearchForPublicKeyHash fails if Query returns an error. See api.Querier2.SearchForPublicKeyHash.

func (*Harness) Step

func (h *Harness) Step()

Step calls the stepper once.

func (*Harness) StepN

func (h *Harness) StepN(n int)

StepN calls the stepper N times.

func (*Harness) StepUntil

func (h *Harness) StepUntil(conditions ...Condition)

StepUntil calls the stepper until all conditions are satisfied. StepUntil fails if the conditions are not met within 50 steps.

func (*Harness) StepUntilN added in v1.1.1

func (h *Harness) StepUntilN(n int, conditions ...Condition)

StepUntilN calls the stepper until all conditions are satisfied. StepUntilN fails if the conditions are not met within N steps.

func (*Harness) Submit

func (h *Harness) Submit(envelope *messaging.Envelope) []*protocol.TransactionStatus

Submit submits the envelope.

func (*Harness) SubmitSuccessfully

func (h *Harness) SubmitSuccessfully(envelope *messaging.Envelope) []*protocol.TransactionStatus

SubmitSuccessfully submits the envelope and asserts that all transactions and signatures succeeded.

func (*Harness) SubmitTxn

func (h *Harness) SubmitTxn(envelope *messaging.Envelope) *protocol.TransactionStatus

SubmitTxn submits a single transaction.

func (*Harness) SubmitTxnSuccessfully

func (h *Harness) SubmitTxnSuccessfully(envelope *messaging.Envelope) *protocol.TransactionStatus

SubmitTxnSuccessfully submits a single transaction and asserts that it and its signatures succeeded.

func (*Harness) Verify

func (h *Harness) Verify(conditions ...Condition)

type Services

type Services interface {
	api.Querier
	api.Submitter
	api.NetworkService
}

Services defines the services required by the harness.

type Sim

type Sim struct {
	Harness
	S *simulator.Simulator
}

Sim is a Harness with some extra simulator-specific features.

func NewSim

func NewSim(tb testing.TB, database simulator.OpenDatabaseFunc, init *accumulated.NetworkInit, snapshot simulator.SnapshotFunc) *Sim

NewSim creates a simulator with the given database, network initialization, and snapshot function and calls NewSimWith.

func NewSimWith

func NewSimWith(tb testing.TB, s *simulator.Simulator) *Sim

NewSimWith creates a Harness for the given simulator instance and wraps it as a Sim.

func (*Sim) Database

func (s *Sim) Database(partition string) database.Updater

Database calls Simulator.Database.

func (*Sim) DatabaseFor

func (s *Sim) DatabaseFor(account *url.URL) database.Updater

DatabaseFor calls Simulator.DatabaseFor.

func (*Sim) Partitions

func (s *Sim) Partitions() []*protocol.PartitionInfo

Partitions calls Simulator.Partitions.

func (*Sim) Router

func (s *Sim) Router() *simulator.Router

Router calls Simulator.Router.

func (*Sim) SetBlockHook

func (s *Sim) SetBlockHook(partition string, fn simulator.BlockHookFunc)

SetBlockHook calls Simulator.SetBlockHook.

func (*Sim) SetBlockHookFor

func (s *Sim) SetBlockHookFor(account *url.URL, fn simulator.BlockHookFunc)

SetBlockHookFor calls Simulator.SetBlockHookFor.

func (*Sim) SetNodeBlockHook added in v1.1.1

func (s *Sim) SetNodeBlockHook(partition string, fn simulator.NodeBlockHookFunc)

SetNodeBlockHook calls Simulator.SetNodeBlockHook.

func (*Sim) SetNodeBlockHookFor added in v1.1.1

func (s *Sim) SetNodeBlockHookFor(account *url.URL, fn simulator.NodeBlockHookFunc)

SetNodeBlockHookFor calls Simulator.SetNodeBlockHookFor.

func (*Sim) SetRoute

func (s *Sim) SetRoute(account *url.URL, partition string)

SetRoute calls Simulator.SetRoute.

func (*Sim) SetSubmitHook

func (s *Sim) SetSubmitHook(partition string, fn simulator.SubmitHookFunc)

SetSubmitHook calls Simulator.SetSubmitHook.

func (*Sim) SetSubmitHookFor

func (s *Sim) SetSubmitHookFor(account *url.URL, fn simulator.SubmitHookFunc)

SetSubmitHookFor calls Simulator.SetSubmitHookFor.

func (*Sim) SignWithNode

func (s *Sim) SignWithNode(partition string, i int) signing.Signer

SignWithNode calls Simulator.SignWithNode.

func (*Sim) SubmitTo

func (s *Sim) SubmitTo(partition string, envelope *messaging.Envelope) ([]*protocol.TransactionStatus, error)

type Stepper

type Stepper interface {
	Step() error
}

Stepper steps the simulation or waits for a block to complete.

type TimeStep

type TimeStep time.Duration

TimeStep implements Stepper by sleeping.

func (TimeStep) Step

func (t TimeStep) Step() error

Step waits for some duration.

type True

type True func(*Harness) bool

func (True) Format

func (f True) Format(prefix, suffix string) string

func (True) Satisfied

func (f True) Satisfied(h *Harness) bool

Jump to

Keyboard shortcuts

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