interfacetests

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: MIT Imports: 17 Imported by: 1

README

This folder contains tests for interfaces that should be run by all implementations.

Note that this kind of testing is normally called contract testing, but that term is overloaded in the smartcontractkit repositories to refer to tests for smart contracts. As such, we will be calling it interface testing, although that term sometimes refers to a slightly different kind of test, we feel that it accurately represents what we are testing and will cause less confusion overall.

Documentation

Index

Constants

View Source
const (
	AnyValueToReadWithoutAnArgument             = uint64(3)
	AnyDifferentValueToReadWithoutAnArgument    = uint64(1990)
	MethodTakingLatestParamsReturningTestStruct = "GetLatestValues"
	MethodReturningUint64                       = "GetPrimitiveValue"
	MethodReturningAlterableUint64              = "GetAlterablePrimitiveValue"
	MethodReturningUint64Slice                  = "GetSliceValue"
	MethodReturningSeenStruct                   = "GetSeenStruct"
	MethodSettingStruct                         = "addTestStruct"
	MethodSettingUint64                         = "setAlterablePrimitiveValue"
	MethodTriggeringEvent                       = "triggerEvent"
	EventName                                   = "SomeEvent"
	EventNameField                              = EventName + ".Field"
	ProtoTest                                   = "ProtoTest"
	ProtoTestIntComparator                      = ProtoTest + ".IntComparator"
	ProtoTestStringComparator                   = ProtoTest + ".StringComparator"
	EventWithFilterName                         = "SomeEventToFilter"
	AnyContractName                             = "TestContract"
	AnySecondContractName                       = "Not" + AnyContractName
)
View Source
const (
	TestItemType            = "TestItem"
	TestItemSliceType       = "TestItemSliceType"
	TestItemArray1Type      = "TestItemArray1Type"
	TestItemArray2Type      = "TestItemArray2Type"
	TestItemWithConfigExtra = "TestItemWithConfigExtra"
	NilType                 = "NilType"
)
View Source
const AnyExtraValue = 3

Variables

View Source
var AnySliceToReadWithoutAnArgument = []uint64{3, 4}

Functions

func BindingsByName added in v0.3.0

func BindingsByName(bindings []types.BoundContract, name string) []types.BoundContract

func Compare added in v0.3.0

func Compare[T cmp.Ordered](a, b T, op primitives.ComparisonOperator) bool

func RunCodecInterfaceFuzzTests

func RunCodecInterfaceFuzzTests(f *testing.F, tester CodecInterfaceTester)

func RunCodecInterfaceTests

func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester)

func RunCodecWithStrictArgsInterfaceTest

func RunCodecWithStrictArgsInterfaceTest(t *testing.T, tester CodecInterfaceTester)

RunCodecWithStrictArgsInterfaceTest is meant to be used by codecs that don't pad They can assure that the right argument size is verified. Padding makes that harder/impossible to verify for come codecs. However, the extra verification is nice to have when possible.

func RunContractReaderInterfaceTests added in v0.2.2

func RunContractReaderInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], mockRun bool)

func SubmitTransactionToCW added in v0.2.2

func SubmitTransactionToCW[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], method string, args any, contract types.BoundContract, status types.TransactionStatus) string

SubmitTransactionToCW submits a transaction to the ChainWriter and waits for it to reach the given status.

func WaitForTransactionStatus added in v0.2.2

func WaitForTransactionStatus[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], txID string, status types.TransactionStatus, mockRun bool) error

WaitForTransactionStatus waits for a transaction to reach the given status.

Types

type BasicTester

type BasicTester[T any] interface {
	Setup(t T)
	Name() string
	GetAccountBytes(i int) []byte
}

type BatchCallEntry

type BatchCallEntry map[types.BoundContract]ContractBatchEntry

type ChainComponentsInterfaceTester added in v0.2.2

type ChainComponentsInterfaceTester[T TestingT[T]] interface {
	BasicTester[T]
	GetContractReader(t T) types.ContractReader
	GetChainWriter(t T) types.ChainWriter
	GetBindings(t T) []types.BoundContract
	// DirtyContracts signals to the underlying tester than the test contracts are dirty, i.e. the state has been changed such that
	// new, fresh contracts should be deployed. This usually happens after a value is written to the contract via
	// the ChainWriter.
	DirtyContracts()
	MaxWaitTimeForEvents() time.Duration
	// GenerateBlocksTillConfidenceLevel is only used by the internal common tests, all other tests can/should
	// rely on the ChainWriter waiting for actual blocks to be mined.
	GenerateBlocksTillConfidenceLevel(t T, contractName, readName string, confidenceLevel primitives.ConfidenceLevel)
}

type CodecInterfaceTester

type CodecInterfaceTester interface {
	BasicTester[*testing.T]
	EncodeFields(t *testing.T, request *EncodeRequest) []byte
	GetCodec(t *testing.T) types.Codec

	// IncludeArrayEncodingSizeEnforcement is here in case there's no way to have fixed arrays in the encoded values
	IncludeArrayEncodingSizeEnforcement() bool
}

type ContractBatchEntry

type ContractBatchEntry []ReadEntry

type EncodeRequest

type EncodeRequest struct {
	TestStructs  []TestStruct
	ExtraField   bool
	MissingField bool
	TestOn       string
}

type ExpectedGetLatestValueArgs

type ExpectedGetLatestValueArgs struct {
	ContractName, ReadName string
	ConfidenceLevel        primitives.ConfidenceLevel
	Params, ReturnVal      any
}

func (ExpectedGetLatestValueArgs) String

type FilterEventParams

type FilterEventParams struct {
	Field int32
}

type InnerDynamicTestStruct added in v0.3.0

type InnerDynamicTestStruct struct {
	I int
	S string
}

type InnerStaticTestStruct added in v0.3.0

type InnerStaticTestStruct struct {
	I int
	A []byte
}

type LatestParams

type LatestParams struct {
	// I should be > 0
	I int
}

type MidLevelDynamicTestStruct added in v0.3.0

type MidLevelDynamicTestStruct struct {
	FixedBytes [2]byte
	Inner      InnerDynamicTestStruct
}

type MidLevelStaticTestStruct added in v0.3.0

type MidLevelStaticTestStruct struct {
	FixedBytes [2]byte
	Inner      InnerStaticTestStruct
}

type PrimitiveArgs added in v0.2.2

type PrimitiveArgs struct {
	Value uint64
}

type ReadEntry

type ReadEntry struct {
	Name        string
	ReturnValue any
}

type TestStruct

type TestStruct struct {
	Field               *int32
	OracleID            commontypes.OracleID
	OracleIDs           [32]commontypes.OracleID
	Account             []byte
	Accounts            [][]byte
	DifferentField      string
	BigField            *big.Int
	NestedDynamicStruct MidLevelDynamicTestStruct
	NestedStaticStruct  MidLevelStaticTestStruct
}

func CreateTestStruct

func CreateTestStruct[T any](i int, tester BasicTester[T]) TestStruct

type TestStructMissingField

type TestStructMissingField struct {
	DifferentField      string
	OracleID            commontypes.OracleID
	OracleIDs           [32]commontypes.OracleID
	Account             []byte
	Accounts            [][]byte
	BigField            *big.Int
	NestedDynamicStruct MidLevelDynamicTestStruct
	NestedStaticStruct  MidLevelStaticTestStruct
}

type TestStructWithExtraField

type TestStructWithExtraField struct {
	TestStruct
	ExtraField int
}

type TestingT

type TestingT[T any] interface {
	tests.TestingT
	Failed() bool
	Run(name string, f func(t T)) bool
}

Jump to

Keyboard shortcuts

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