interfacetests

package
v0.0.0-...-47b5856 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2024 License: MIT Imports: 11 Imported by: 0

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"
	DifferentMethodReturningUint64              = "GetDifferentPrimitiveValue"
	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

func RunChainReaderInterfaceTests(t *testing.T, tester ChainReaderInterfaceTester)

func RunChainReaderWithStrictArgsInterfaceTest

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

RunChainReaderWithStrictArgsInterfaceTest 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 RunCodecInterfaceFuzzTests

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

func RunCodecInterfaceTests

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

Types

type BasicTester

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

type ChainReaderInterfaceTester

type ChainReaderInterfaceTester interface {
	BasicTester
	GetChainReader(t *testing.T) types.ChainReader

	// SetLatestValue 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
	SetLatestValue(t *testing.T, testStruct *TestStruct)
	TriggerEvent(t *testing.T, testStruct *TestStruct)
	GetBindings(t *testing.T) []types.BoundContract
	MaxWaitTimeForEvents() time.Duration
}

type CodecInterfaceTester

type CodecInterfaceTester interface {
	BasicTester
	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 FilterEventParams

type FilterEventParams struct {
	Field int32
}

type InnerTestStruct

type InnerTestStruct struct {
	I int
	S string
}

type LatestParams

type LatestParams struct {
	I int
}

type MidLevelTestStruct

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(i int, tester BasicTester) 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
}

Jump to

Keyboard shortcuts

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