mocktracer

package
v0.0.0-...-ff2c966 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssertEventsEqual

func AssertEventsEqual(t *testing.T, expected, actual []Event)

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:

  1. 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

func AfterBlock(round basics.Round) Event

AfterBlock creates a new Event with the type AfterBlockEvent

func AfterOpcode

func AfterOpcode(hasError bool) Event

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 AfterTxn

func AfterTxn(txnType protocol.TxType, ad transactions.ApplyData, hasError bool) Event

AfterTxn creates a new Event with the type AfterTxnEvent

func AfterTxnGroup

func AfterTxnGroup(groupSize int, deltas *ledgercore.StateDelta, hasError bool) Event

AfterTxnGroup creates a new Event with the type AfterTxnGroupEvent

func BeforeBlock

func BeforeBlock(round basics.Round) Event

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

func BeforeProgram(mode logic.RunMode) Event

BeforeProgram creates a new Event with the type BeforeProgramEvent

func BeforeTxn

func BeforeTxn(txnType protocol.TxType) Event

BeforeTxn creates a new Event with the type BeforeTxnEvent

func BeforeTxnGroup

func BeforeTxnGroup(groupSize int) Event

BeforeTxnGroup creates a new Event with the type BeforeTxnGroupEvent

func FlattenEvents

func FlattenEvents(rows [][]Event) []Event

FlattenEvents flattens a slice of slices into a single slice of Events

func OpcodeEvents

func OpcodeEvents(count int, endsWithError bool) []Event

OpcodeEvents returns a slice of events that represent calling `count` opcodes

func StripInnerTxnGroupIDsFromEvents

func StripInnerTxnGroupIDsFromEvents(events []Event) []Event

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

Jump to

Keyboard shortcuts

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