simulator

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 46 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)

Functions

func GetAccount

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

func GetTxnState

func GetTxnState[V any, T interface{ Get() (V, error) }](sim *Simulator, txid *url.TxID, state func(*database.Transaction) T) V

func InitFromSnapshot

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

func NormalizeEnvelope

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

func QueryUrl

func QueryUrl[T any](s *Simulator, url *url.URL, prove bool) T

Types

type ExecEntry

type ExecEntry struct {
	BlockIndex uint64

	Partition  *config.Partition
	Database   database.Beginner
	Executor   *block.Executor
	API        *client.Client
	Validators [][]byte

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

func (*ExecEntry) Begin

func (x *ExecEntry) Begin(writable bool) *database.Batch

func (ExecEntry) Errorf

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

func (ExecEntry) Fatalf

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

func (ExecEntry) Logf

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

func (*ExecEntry) SetObserver

func (x *ExecEntry) SetObserver(observer database.Observer)

func (*ExecEntry) Submit

func (x *ExecEntry) Submit(pretend bool, envelopes ...*messaging.Envelope) []*chain.Delivery

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.

func (*ExecEntry) Submit2

func (x *ExecEntry) Submit2(pretend bool, deliveries []*chain.Delivery)

func (*ExecEntry) Update

func (x *ExecEntry) Update(fn func(*database.Batch) error) error

func (*ExecEntry) View

func (x *ExecEntry) View(fn func(*database.Batch) error) error

type ResponseSubmit added in v1.1.1

type ResponseSubmit struct {
	Code         uint32
	Data         []byte
	Log          string
	Info         string
	Codespace    string
	MempoolError string
}

ResponseSubmit is the response from a call to Submit.

type Simulator

type Simulator struct {
	Logger     log.Logger
	Partitions []config.Partition
	Executors  map[string]*ExecEntry
	// contains filtered or unexported fields
}

func New

func New(t TB, bvnCount int) *Simulator

func NewWith

func NewWith(t TB, opts SimulatorOptions) *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) CreateLiteTokenAccount

func (s *Simulator) CreateLiteTokenAccount(key []byte, token *url.URL, credits, tokens uint64) *url.URL

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

func (s *Simulator) InitFromGenesis()

func (*Simulator) InitFromGenesisWith

func (s *Simulator) InitFromGenesisWith(values *core.GlobalValues)

func (*Simulator) InitFromSnapshot

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 ...*messaging.Envelope) []*messaging.Envelope

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

func (*Simulator) NewServer

func (s *Simulator) NewServer() http.Handler

func (*Simulator) Partition

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

func (*Simulator) PartitionFor

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

func (*Simulator) Router

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

func (*Simulator) RunAndReset

func (s *Simulator) RunAndReset(fn func())

RunAndReset runs everything in a batch (which is discarded) then resets the simulator state.

func (*Simulator) Services

func (s *Simulator) Services() *simService

Services returns the simulator's API v3 implementation.

func (*Simulator) SetRouteFor

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

func (*Simulator) Setup

func (sim *Simulator) Setup(opts SimulatorOptions)

func (*Simulator) Submit

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

Submit routes and submits each envelope.

func (*Simulator) SubmitAndExecuteBlock

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

SubmitAndExecuteBlock executes a block with the envelopes.

func (*Simulator) SubmitTo

func (s *Simulator) SubmitTo(partition string, envelope *messaging.Envelope) error

SubmitTo submits the envelope to a specific partition.

func (*Simulator) UpdateAccount

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

func (*Simulator) WaitForTransaction

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

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 ...*messaging.Envelope) ([]*protocol.TransactionStatus, []*protocol.Transaction)

type SimulatorOptions

type SimulatorOptions struct {
	BvnCount        int
	LogLevels       string
	OpenDB          func(partition string, nodeIndex int, logger log.Logger) *database.Database
	FactomAddresses func() (io.Reader, error)
	Snapshots       []func() (ioutil2.SectionReader, error)
}

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