interfacetests

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MIT Imports: 13 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"
	EventName                                   = "SomeEvent"
	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 RunChainReaderInterfaceTests added in v0.2.0

func RunChainReaderInterfaceTests[T TestingT[T]](t T, tester ChainReaderInterfaceTester[T])

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.

Types

type BasicTester

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

type ChainReaderInterfaceTester added in v0.2.0

type ChainReaderInterfaceTester[T TestingT[T]] interface {
	BasicTester[T]
	GetChainReader(t T) types.ContractReader
	// SetTestStructLatestValue is expected to return the same bound contract and method in the same test
	// Any setup required for this should be done in Setup.
	// The contract should take a LatestParams as the params and return the nth TestStruct set
	SetTestStructLatestValue(t T, testStruct *TestStruct)
	// SetUintLatestValue is expected to return the same bound contract and method in the same test
	// Any setup required for this should be done in Setup.
	// The contract should take a uint64 as the params and returns the same.
	// forCall is used to attach value to a call, this is useful in chain specific test since in chain agnostic tests we can just use hard coded readName constants.
	SetUintLatestValue(t T, val uint64, forCall ExpectedGetLatestValueArgs)
	TriggerEvent(t T, testStruct *TestStruct)
	GetBindings(t T) []types.BoundContract
	// GenerateBlocksTillConfidenceLevel raises confidence level to the provided level for a specific read.
	GenerateBlocksTillConfidenceLevel(t T, contractName, readName string, confidenceLevel primitives.ConfidenceLevel)
	MaxWaitTimeForEvents() time.Duration
}

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 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 InnerTestStruct added in v0.2.0

type InnerTestStruct struct {
	I int
	S string
}

type LatestParams

type LatestParams struct {
	I int
}

type MidLevelTestStruct added in v0.2.0

type MidLevelTestStruct struct {
	FixedBytes [2]byte
	Inner      InnerTestStruct
}

type TestStruct

type TestStruct struct {
	Field          *int32
	DifferentField string
	OracleID       commontypes.OracleID
	OracleIDs      [32]commontypes.OracleID
	Account        []byte
	Accounts       [][]byte
	BigField       *big.Int
	NestedStruct   MidLevelTestStruct
}

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
	NestedStruct   MidLevelTestStruct
}

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