Documentation ¶
Index ¶
- func AssertEventsEqual(t *testing.T, expected, actual []Event)
- func GetTestScenarios() map[string]TestScenarioGenerator
- func MergeStateDeltas(deltas ...ledgercore.StateDelta) ledgercore.StateDelta
- type Event
- func AfterBlock(round basics.Round) Event
- func AfterOpcode(hasError bool) Event
- func AfterProgram(mode logic.RunMode, result ProgramResult) Event
- func AfterTxn(txnType protocol.TxType, ad transactions.ApplyData, hasError bool) Event
- func AfterTxnGroup(groupSize int, deltas *ledgercore.StateDelta, hasError bool) Event
- func BeforeBlock(round basics.Round) Event
- func BeforeOpcode() Event
- func BeforeProgram(mode logic.RunMode) Event
- func BeforeTxn(txnType protocol.TxType) Event
- func BeforeTxnGroup(groupSize int) Event
- func FlattenEvents(rows [][]Event) []Event
- func OpcodeEvents(count int, endsWithError bool) []Event
- func StripInnerTxnGroupIDsFromEvents(events []Event) []Event
- type EventType
- type ProgramResult
- type TestScenario
- type TestScenarioGenerator
- type TestScenarioInfo
- type TestScenarioOutcome
- type Tracer
- func (d *Tracer) AfterBlock(hdr *bookkeeping.BlockHeader)
- func (d *Tracer) AfterOpcode(cx *logic.EvalContext, evalError error)
- func (d *Tracer) AfterProgram(cx *logic.EvalContext, pass bool, evalError error)
- func (d *Tracer) AfterTxn(ep *logic.EvalParams, groupIndex int, ad transactions.ApplyData, ...)
- func (d *Tracer) AfterTxnGroup(ep *logic.EvalParams, deltas *ledgercore.StateDelta, evalError error)
- func (d *Tracer) BeforeBlock(hdr *bookkeeping.BlockHeader)
- func (d *Tracer) BeforeOpcode(cx *logic.EvalContext)
- func (d *Tracer) BeforeProgram(cx *logic.EvalContext)
- func (d *Tracer) BeforeTxn(ep *logic.EvalParams, groupIndex int)
- func (d *Tracer) BeforeTxnGroup(ep *logic.EvalParams)
- func (d *Tracer) DetailedEvalErrors() bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertEventsEqual ¶
AssertEventsEqual asserts that two slices of Events are equal, taking into account complex equality of StateDeltas. The arguments will be modified in-place to normalize any StateDeltas.
func GetTestScenarios ¶
func GetTestScenarios() map[string]TestScenarioGenerator
GetTestScenarios returns scenarios for testing code that invokes a logic.EvalTracer. These scenarios are all app calls which invoke inner transactions under various failure conditions. The scenarios follow this format:
- An app call transaction that spawns inners. They are: a. A basic app call transaction b. A payment transaction [grouped with c] c. A payment transaction [grouped with b]
The scenarios differ by where they fail when attempting to execute that app call. Failures are possible during each inner transaction, as well as before all inners, between the two inner groups, and after all inners. For app call failures, there are scenarios for both rejection and runtime errors, which should invoke tracer hooks slightly differently.
func MergeStateDeltas ¶
func MergeStateDeltas(deltas ...ledgercore.StateDelta) ledgercore.StateDelta
MergeStateDeltas merges multiple state deltas into one. The arguments are not modified, but the first delta is used to populate non-mergeable fields in the result.
Types ¶
type Event ¶
type Event struct { Type EventType // only for BeforeProgram and AfterProgram LogicEvalMode logic.RunMode // only for BeforeTxn and AfterTxn TxnType protocol.TxType // only for AfterTxn TxnApplyData transactions.ApplyData // only for AfterTxnGroup and AfterTxn Deltas *ledgercore.StateDelta // only for BeforeTxnGroup and AfterTxnGroup GroupSize int // only for AfterProgram Pass bool // only for AfterOpcode, AfterProgram, AfterTxn, and AfterTxnGroup HasError bool // only for BeforeBlock, AfterBlock Round basics.Round }
Event represents a logic.EvalTracer event
func AfterBlock ¶
AfterBlock creates a new Event with the type AfterBlockEvent
func AfterOpcode ¶
AfterOpcode creates a new Event with the type AfterOpcodeEvent
func AfterProgram ¶
func AfterProgram(mode logic.RunMode, result ProgramResult) Event
AfterProgram creates a new Event with the type AfterProgramEvent
func AfterTxnGroup ¶
func AfterTxnGroup(groupSize int, deltas *ledgercore.StateDelta, hasError bool) Event
AfterTxnGroup creates a new Event with the type AfterTxnGroupEvent
func BeforeBlock ¶
BeforeBlock creates a new Event with the type BeforeBlockEvent for a particular round
func BeforeOpcode ¶
func BeforeOpcode() Event
BeforeOpcode creates a new Event with the type BeforeOpcodeEvent
func BeforeProgram ¶
BeforeProgram creates a new Event with the type BeforeProgramEvent
func BeforeTxnGroup ¶
BeforeTxnGroup creates a new Event with the type BeforeTxnGroupEvent
func FlattenEvents ¶
FlattenEvents flattens a slice of slices into a single slice of Events
func OpcodeEvents ¶
OpcodeEvents returns a slice of events that represent calling `count` opcodes
func StripInnerTxnGroupIDsFromEvents ¶
StripInnerTxnGroupIDsFromEvents removes any inner transaction GroupIDs that are present in the TxnApplyData fields of the events.
type EventType ¶
type EventType string
EventType represents a type of logic.EvalTracer event
const ( // BeforeBlockEvent represents the logic.EvalTracer.BeforeBlock event BeforeBlockEvent EventType = "BeforeBlock" // BeforeTxnGroupEvent represents the logic.EvalTracer.BeforeTxnGroup event BeforeTxnGroupEvent EventType = "BeforeTxnGroup" // AfterTxnGroupEvent represents the logic.EvalTracer.AfterTxnGroup event AfterTxnGroupEvent EventType = "AfterTxnGroup" // BeforeTxnEvent represents the logic.EvalTracer.BeforeTxn event BeforeTxnEvent EventType = "BeforeTxn" // AfterTxnEvent represents the logic.EvalTracer.AfterTxn event AfterTxnEvent EventType = "AfterTxn" // BeforeProgramEvent represents the logic.EvalTracer.BeforeProgram event BeforeProgramEvent EventType = "BeforeProgram" // AfterProgramEvent represents the logic.EvalTracer.AfterProgram event AfterProgramEvent EventType = "AfterProgram" // BeforeOpcodeEvent represents the logic.EvalTracer.BeforeOpcode event BeforeOpcodeEvent EventType = "BeforeOpcode" // AfterOpcodeEvent represents the logic.EvalTracer.AfterOpcode event AfterOpcodeEvent EventType = "AfterOpcode" // AfterBlockEvent represents the logic.EvalTracer.AfterBlock event AfterBlockEvent EventType = "AfterBlock" )
type ProgramResult ¶
type ProgramResult int
ProgramResult represents the result of a program execution
const ( // ProgramResultPass represents a program that passed ProgramResultPass ProgramResult = iota // ProgramResultReject represents a program that rejected ProgramResultReject // ProgramResultError represents a program that errored ProgramResultError )
type TestScenario ¶
type TestScenario struct { Outcome TestScenarioOutcome Program string ExpectedError string FailedAt []uint64 ExpectedEvents []Event ExpectedSimulationAD transactions.ApplyData ExpectedStateDelta ledgercore.StateDelta AppBudgetAdded uint64 AppBudgetConsumed uint64 TxnAppBudgetConsumed []uint64 }
TestScenario represents a testing scenario. See GetTestScenarios for more details.
type TestScenarioGenerator ¶
type TestScenarioGenerator func(info TestScenarioInfo) TestScenario
TestScenarioGenerator is a function which instantiates a TestScenario
type TestScenarioInfo ¶
type TestScenarioInfo struct { CallingTxn transactions.Transaction SenderData ledgercore.AccountData AppAccountData ledgercore.AccountData FeeSinkData ledgercore.AccountData FeeSinkAddr basics.Address MinFee basics.MicroAlgos CreatedAppID basics.AppIndex BlockHeader bookkeeping.BlockHeader PrevTimestamp int64 }
TestScenarioInfo holds arguments used to call a TestScenarioGenerator
type TestScenarioOutcome ¶
type TestScenarioOutcome int
TestScenarioOutcome represents an outcome of a TestScenario
const ( // ApprovalOutcome indicates the scenario should approve the program ApprovalOutcome TestScenarioOutcome = iota // RejectionOutcome indicates the scenario should reject the program RejectionOutcome // ErrorOutcome indicates the scenario should error during the program ErrorOutcome )
type Tracer ¶
type Tracer struct {
Events []Event
}
Tracer is a mock tracer that implements logic.EvalTracer
func (*Tracer) AfterBlock ¶
func (d *Tracer) AfterBlock(hdr *bookkeeping.BlockHeader)
AfterBlock mocks the logic.EvalTracer.BeforeBlock method
func (*Tracer) AfterOpcode ¶
func (d *Tracer) AfterOpcode(cx *logic.EvalContext, evalError error)
AfterOpcode mocks the logic.EvalTracer.AfterOpcode method
func (*Tracer) AfterProgram ¶
func (d *Tracer) AfterProgram(cx *logic.EvalContext, pass bool, evalError error)
AfterProgram mocks the logic.EvalTracer.AfterProgram method
func (*Tracer) AfterTxn ¶
func (d *Tracer) AfterTxn(ep *logic.EvalParams, groupIndex int, ad transactions.ApplyData, evalError error)
AfterTxn mocks the logic.EvalTracer.AfterTxn method
func (*Tracer) AfterTxnGroup ¶
func (d *Tracer) AfterTxnGroup(ep *logic.EvalParams, deltas *ledgercore.StateDelta, evalError error)
AfterTxnGroup mocks the logic.EvalTracer.AfterTxnGroup method
func (*Tracer) BeforeBlock ¶
func (d *Tracer) BeforeBlock(hdr *bookkeeping.BlockHeader)
BeforeBlock mocks the logic.EvalTracer.BeforeBlock method
func (*Tracer) BeforeOpcode ¶
func (d *Tracer) BeforeOpcode(cx *logic.EvalContext)
BeforeOpcode mocks the logic.EvalTracer.BeforeOpcode method
func (*Tracer) BeforeProgram ¶
func (d *Tracer) BeforeProgram(cx *logic.EvalContext)
BeforeProgram mocks the logic.EvalTracer.BeforeProgram method
func (*Tracer) BeforeTxn ¶
func (d *Tracer) BeforeTxn(ep *logic.EvalParams, groupIndex int)
BeforeTxn mocks the logic.EvalTracer.BeforeTxn method
func (*Tracer) BeforeTxnGroup ¶
func (d *Tracer) BeforeTxnGroup(ep *logic.EvalParams)
BeforeTxnGroup mocks the logic.EvalTracer.BeforeTxnGroup method
func (*Tracer) DetailedEvalErrors ¶
DetailedEvalErrors returns true, enabling detailed errors in tests.