Documentation ¶
Index ¶
- Variables
- func GetAccount[T protocol.Account](sim *Simulator, accountUrl *url.URL) T
- func GetTxnState[V any, T interface{ ... }](sim *Simulator, txid *url.TxID, state func(*database.Transaction) T) V
- func InitFromSnapshot(t TB, db database.Beginner, exec *Executor, filename string)
- func NormalizeEnvelope(t TB, envelope *protocol.Envelope) []*chain.Delivery
- func QueryUrl[T any](s *Simulator, url *url.URL, prove bool) T
- type ExecEntry
- func (x *ExecEntry) Begin(writable bool) *database.Batch
- func (t ExecEntry) Errorf(format string, args ...interface{})
- func (t ExecEntry) Fatalf(format string, args ...interface{})
- func (t ExecEntry) Logf(format string, args ...interface{})
- func (x *ExecEntry) Submit(pretend bool, envelopes ...*protocol.Envelope) []*chain.Delivery
- func (x *ExecEntry) Submit2(pretend bool, deliveries []*chain.Delivery)
- func (x *ExecEntry) Update(fn func(*database.Batch) error) error
- func (x *ExecEntry) View(fn func(*database.Batch) error) error
- type Simulator
- func (s *Simulator) CreateAccount(account protocol.Account)
- func (s *Simulator) CreateIdentity(identityUrl *url.URL, pubKey ...[]byte)
- func (s *Simulator) CreateKeyBook(bookUrl *url.URL, pubKey ...[]byte)
- func (s *Simulator) CreateKeyPage(bookUrl *url.URL, pubKey ...[]byte)
- func (s *Simulator) CreateLiteTokenAccount(key []byte, token *url.URL, credits, tokens uint64) *url.URL
- func (t Simulator) Errorf(format string, args ...interface{})
- func (s *Simulator) ExecuteBlock(statusChan chan<- *protocol.TransactionStatus)
- func (s *Simulator) ExecuteBlocks(n int)
- func (t Simulator) Fatalf(format string, args ...interface{})
- func (s *Simulator) InitFromGenesis()
- func (s *Simulator) InitFromGenesisWith(values *core.GlobalValues)
- func (s *Simulator) InitFromSnapshot(filename func(string) string)
- func (t Simulator) Logf(format string, args ...interface{})
- func (s *Simulator) MustSubmitAndExecuteBlock(envelopes ...*protocol.Envelope) []*protocol.Envelope
- func (s *Simulator) NewServer() http.Handler
- func (s *Simulator) Partition(id string) *ExecEntry
- func (s *Simulator) PartitionFor(url *url.URL) *ExecEntry
- func (s *Simulator) Router() routing.Router
- func (s *Simulator) RunAndReset(fn func())
- func (s *Simulator) SetRouteFor(account *url.URL, partition string)
- func (sim *Simulator) Setup(opts SimulatorOptions)
- func (s *Simulator) Submit(envelopes ...*protocol.Envelope) ([]*protocol.Envelope, error)
- func (s *Simulator) SubmitAndExecuteBlock(envelopes ...*protocol.Envelope) ([]*protocol.TransactionStatus, error)
- func (s *Simulator) UpdateAccount(accountUrl *url.URL, fn func(account protocol.Account))
- func (s *Simulator) WaitForTransaction(statusCheck func(*protocol.TransactionStatus) bool, txnHash []byte, n int) (*protocol.Transaction, *protocol.TransactionStatus, []*url.TxID)
- func (s *Simulator) WaitForTransactionFlow(statusCheck func(*protocol.TransactionStatus) bool, txnHash []byte) ([]*protocol.TransactionStatus, []*protocol.Transaction)
- func (s *Simulator) WaitForTransactions(status func(*protocol.TransactionStatus) bool, envelopes ...*protocol.Envelope) ([]*protocol.TransactionStatus, []*protocol.Transaction)
- type SimulatorOptions
- type TB
Constants ¶
This section is empty.
Variables ¶
var GenesisTime = time.Date(2022, 7, 1, 0, 0, 0, 0, time.UTC)
Functions ¶
func GetAccount ¶ added in v1.0.0
func GetTxnState ¶ added in v1.0.0
func InitFromSnapshot ¶ added in v1.0.0
func NormalizeEnvelope ¶
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) 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) Submit ¶
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 Partitions []config.Partition Executors map[string]*ExecEntry // contains filtered or unexported fields }
func NewWith ¶ added in v1.0.0
func NewWith(t TB, opts SimulatorOptions) *Simulator
func (*Simulator) CreateAccount ¶
func (*Simulator) CreateIdentity ¶
func (*Simulator) CreateKeyBook ¶
func (*Simulator) CreateKeyPage ¶
func (*Simulator) CreateLiteTokenAccount ¶ added in v1.0.0
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 ¶
ExecuteBlocks executes a number of blocks. This is useful for things like waiting for a block to be anchored.
func (*Simulator) InitFromGenesis ¶ added in v1.0.0
func (s *Simulator) InitFromGenesis()
func (*Simulator) InitFromGenesisWith ¶ added in v1.0.0
func (s *Simulator) InitFromGenesisWith(values *core.GlobalValues)
func (*Simulator) InitFromSnapshot ¶ added in v1.0.0
func (*Simulator) MustSubmitAndExecuteBlock ¶
MustSubmitAndExecuteBlock executes a block with the envelopes and fails the test if any envelope fails.
func (*Simulator) PartitionFor ¶ added in v1.0.0
func (*Simulator) RunAndReset ¶ added in v1.0.0
func (s *Simulator) RunAndReset(fn func())
RunAndReset runs everything in a batch (which is discarded) then resets the simulator state.
func (*Simulator) Setup ¶ added in v1.0.0
func (sim *Simulator) Setup(opts SimulatorOptions)
func (*Simulator) SubmitAndExecuteBlock ¶
func (s *Simulator) SubmitAndExecuteBlock(envelopes ...*protocol.Envelope) ([]*protocol.TransactionStatus, error)
SubmitAndExecuteBlock executes a block with the envelopes.
func (*Simulator) UpdateAccount ¶
func (*Simulator) WaitForTransaction ¶ added in v1.0.0
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 ...*protocol.Envelope) ([]*protocol.TransactionStatus, []*protocol.Transaction)