simulator

package
v0.8.1-beta Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckTx

func CheckTx(t TB, db *database.Database, exec *Executor, delivery *chain.Delivery) (protocol.TransactionResult, error)

func GetAccount added in v1.0.0

func GetAccount[T protocol.Account](sim *Simulator, accountUrl *url.URL) T

func InitFromSnapshot added in v1.0.0

func InitFromSnapshot(t TB, db *database.Database, exec *Executor, filename string)

func InitGenesis

func InitGenesis(t TB, exec *Executor, genesisTime time.Time, netValMap genesis.NetworkValidatorMap) genesis.Bootstrap

func NormalizeEnvelope

func NormalizeEnvelope(t TB, envelope *protocol.Envelope) []*chain.Delivery

func Query

func Query(t TB, db *database.Database, exec *Executor, req query.Request, prove bool) interface{}

Types

type ExecEntry

type ExecEntry struct {
	Subnet   *config.Subnet
	Database *database.Database
	Executor *block.Executor

	API        *client.Client
	Validators [][]byte

	// SubmitHook can be used to control how envelopes are submitted to the
	// subnet. It is not safe to change SubmitHook concurrently with calls to
	// Submit.
	SubmitHook func([]*protocol.Envelope) []*protocol.Envelope
	// contains filtered or unexported fields
}

func (ExecEntry) Errorf added in v1.0.0

func (t ExecEntry) Errorf(format string, args ...interface{})

func (ExecEntry) Fatalf added in v1.0.0

func (t ExecEntry) Fatalf(format string, args ...interface{})

func (ExecEntry) Logf added in v1.0.0

func (t ExecEntry) Logf(format string, args ...interface{})

func (*ExecEntry) Submit

func (x *ExecEntry) Submit(envelopes ...*protocol.Envelope)

Submit adds the envelopes to the next block's queue.

By adding transactions to the next block and swaping queues when a block is executed, we roughly simulate the process Tendermint uses to build blocks.

type Simulator

type Simulator struct {
	Logger    log.Logger
	Subnets   []config.Subnet
	Executors map[string]*ExecEntry

	LogLevels string
	// contains filtered or unexported fields
}

func New

func New(t TB, bvnCount int) *Simulator

func (*Simulator) CreateAccount

func (s *Simulator) CreateAccount(account protocol.Account)

func (*Simulator) CreateIdentity

func (s *Simulator) CreateIdentity(identityUrl *url.URL, pubKey ...[]byte)

func (*Simulator) CreateKeyBook

func (s *Simulator) CreateKeyBook(bookUrl *url.URL, pubKey ...[]byte)

func (*Simulator) CreateKeyPage

func (s *Simulator) CreateKeyPage(bookUrl *url.URL, pubKey ...[]byte)

func (Simulator) Errorf

func (t Simulator) Errorf(format string, args ...interface{})

func (*Simulator) ExecuteBlock

func (s *Simulator) ExecuteBlock(statusChan chan<- *protocol.TransactionStatus)

ExecuteBlock executes a block after submitting envelopes. If a status channel is provided, statuses will be sent to the channel as transactions are executed. Once the block is complete, the status channel will be closed (if provided).

func (*Simulator) ExecuteBlocks

func (s *Simulator) ExecuteBlocks(n int)

ExecuteBlocks executes a number of blocks. This is useful for things like waiting for a block to be anchored.

func (Simulator) Fatalf

func (t Simulator) Fatalf(format string, args ...interface{})

func (*Simulator) InitFromGenesis added in v1.0.0

func (s *Simulator) InitFromGenesis()

func (*Simulator) InitFromSnapshot added in v1.0.0

func (s *Simulator) InitFromSnapshot(filename func(string) string)

func (Simulator) Logf

func (t Simulator) Logf(format string, args ...interface{})

func (*Simulator) MustSubmitAndExecuteBlock

func (s *Simulator) MustSubmitAndExecuteBlock(envelopes ...*protocol.Envelope) []*protocol.Envelope

MustSubmitAndExecuteBlock executes a block with the envelopes and fails the test if any envelope fails.

func (*Simulator) Query

func (s *Simulator) Query(url *url.URL, req query.Request, prove bool) interface{}

func (*Simulator) Router

func (s *Simulator) Router() routing.Router

func (*Simulator) SetRouteFor

func (s *Simulator) SetRouteFor(account *url.URL, subnet string)

func (*Simulator) Setup added in v1.0.0

func (sim *Simulator) Setup(bvnCount int)

func (*Simulator) Submit

func (s *Simulator) Submit(envelopes ...*protocol.Envelope) ([]*protocol.Envelope, error)

func (*Simulator) SubmitAndExecuteBlock

func (s *Simulator) SubmitAndExecuteBlock(envelopes ...*protocol.Envelope) ([]*protocol.TransactionStatus, error)

SubmitAndExecuteBlock executes a block with the envelopes.

func (*Simulator) Subnet

func (s *Simulator) Subnet(id string) *ExecEntry

func (*Simulator) SubnetFor

func (s *Simulator) SubnetFor(url *url.URL) *ExecEntry

func (*Simulator) UpdateAccount

func (s *Simulator) UpdateAccount(accountUrl *url.URL, fn func(account protocol.Account))

func (*Simulator) WaitForTransaction added in v1.0.0

func (s *Simulator) WaitForTransaction(statusCheck func(*protocol.TransactionStatus) bool, txnHash []byte, n int) *ExecEntry

func (*Simulator) WaitForTransactionFlow

func (s *Simulator) WaitForTransactionFlow(statusCheck func(*protocol.TransactionStatus) bool, txnHash []byte) ([]*protocol.TransactionStatus, []*protocol.Transaction)

func (*Simulator) WaitForTransactions

func (s *Simulator) WaitForTransactions(status func(*protocol.TransactionStatus) bool, envelopes ...*protocol.Envelope) ([]*protocol.TransactionStatus, []*protocol.Transaction)

type TB

type TB interface {
	Name() string
	Log(...interface{})
	Fail()
	FailNow()
	Helper()
}

Jump to

Keyboard shortcuts

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