From c2c9a94ab04f7fd5684583d250642595590d6806 Mon Sep 17 00:00:00 2001 From: Pablo La Greca Date: Mon, 28 Oct 2024 16:11:19 -0300 Subject: [PATCH] BCFR-967 - Basic support for method writing and reading - Add logic to enable/disable test cases for chain components common test suites --- pkg/codec/encodings/type_codec_test.go | 1 + .../contractreader/codec_test.go | 1 + .../contractreader/contract_reader_test.go | 1 + .../chain_components_interface_tests.go | 152 +++++++++++------- .../interfacetests/codec_interface_tests.go | 96 +++++------ pkg/types/interfacetests/utils.go | 53 ++++-- 6 files changed, 184 insertions(+), 120 deletions(-) diff --git a/pkg/codec/encodings/type_codec_test.go b/pkg/codec/encodings/type_codec_test.go index 19dadff2c..874819ff2 100644 --- a/pkg/codec/encodings/type_codec_test.go +++ b/pkg/codec/encodings/type_codec_test.go @@ -139,6 +139,7 @@ func (t *interfaceTesterBase) GetAccountString(i int) string { type bigEndianInterfaceTester struct { interfaceTesterBase + TestSelectionSupport lenient bool } diff --git a/pkg/loop/internal/relayer/pluginprovider/contractreader/codec_test.go b/pkg/loop/internal/relayer/pluginprovider/contractreader/codec_test.go index c54696871..d47269ca0 100644 --- a/pkg/loop/internal/relayer/pluginprovider/contractreader/codec_test.go +++ b/pkg/loop/internal/relayer/pluginprovider/contractreader/codec_test.go @@ -95,6 +95,7 @@ func TestCodecClient(t *testing.T) { type fakeCodecInterfaceTester struct { interfaceTesterBase + interfacetests.TestSelectionSupport impl types.Codec } diff --git a/pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go b/pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go index d5496add8..0b27ff341 100644 --- a/pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go +++ b/pkg/loop/internal/relayer/pluginprovider/contractreader/contract_reader_test.go @@ -297,6 +297,7 @@ func makeEncoder() cbor.EncMode { type fakeContractReaderInterfaceTester struct { interfaceTesterBase + TestSelectionSupport impl types.ContractReader cw fakeChainWriter } diff --git a/pkg/types/interfacetests/chain_components_interface_tests.go b/pkg/types/interfacetests/chain_components_interface_tests.go index 676ba4536..5d02b8078 100644 --- a/pkg/types/interfacetests/chain_components_interface_tests.go +++ b/pkg/types/interfacetests/chain_components_interface_tests.go @@ -16,6 +16,40 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/values" ) +// GetLatestValue method +const GetLatestValueAsValuesDotValue = "Gets the latest value as a values.Value" +const GetLatestValueNoArgumentsAndPrimitiveReturnAsValuesDotValue = "Get latest value without arguments and with primitive return as a values.Value" +const GetLatestValueNoArgumentsAndSliceReturnAsValueDotValue = "Get latest value without arguments and with slice return as a values.Value" +const GetLatestValue = "Gets the latest value" +const GetLatestValueWithPrimitiveReturn = "Get latest value without arguments and with primitive return" +const GetLatestValueBasedOnConfidenceLevel = "Get latest value based on confidence level" +const GetLatestValueFromMultipleContractsNamesSameFunction = "Get latest value allows multiple contract names to have the same function " +const GetLatestValueWithModifiersUsingOwnMapstrctureOverrides = "Get latest value wraps config with modifiers using its own mapstructure overrides" +const GetLatestValueNoArgumentsAndSliceReturn = "Get latest value without arguments and with slice return" + +// GetLatestValue event +const GetLatestValueGetsLatestForEvent = "Get latest value gets latest event" +const GetLatestValueBasedOnConfidenceLevelForEvent = "Get latest event based on provided confidence level" +const GetLatestValueReturnsNotFoundWhenNotTriggeredForEvent = "Get latest value returns not found if event was never triggered" +const GetLatestValueWithFilteringForEvent = "Get latest value gets latest event with filtering" + +// BatchGet +const BatchGetLatestValue = "BatchGetLatestValues works" +const BatchGetLatestValueNoArgumentsPrimitiveReturn = "BatchGetLatestValues works without arguments and with primitive return" +const BatchGetLatestValueMultipleContractNamesSameFunction = "BatchGetLatestValues allows multiple contract names to have the same function Name" +const BatchGetLatestValueNoArgumentsWithSliceReturn = "BatchGetLatestValue without arguments and with slice return" +const BatchGetLatestValueWithModifiersOwnMapstructureOverride = "BatchGetLatestValues wraps config with modifiers using its own mapstructure overrides" +const BatchGetLatestValueDifferentParamsResultsRetainOrder = "BatchGetLatestValues supports same read with different params and results retain order from request" +const BatchGetLatestValueDifferentParamsResultsRetainOrderMultipleContracts = "BatchGetLatestValues supports same read with different params and results retain order from request even with multiple contracts" +const BatchGetLatestValueSetsErrorsProperly = "BatchGetLatestValues sets errors properly" + +// Query key +const QueryKeyNotFound = "QueryKey returns not found if sequence never happened" +const QueryKeyReturnsData = "QueryKey returns sequence data properly" +const QueryKeyReturnsDataAsValuesDotValue = "QueryKey returns sequence data properly as values.Value" +const QueryKeyCanFilterWithValueComparator = "QueryKey can filter data with value comparator" +const QueryKeyCanLimitResultsWithCursor = "QueryKey can limit results with cursor" + type ChainComponentsInterfaceTester[T TestingT[T]] interface { BasicTester[T] GetContractReader(t T) types.ContractReader @@ -63,10 +97,11 @@ func RunContractReaderInterfaceTests[T TestingT[T]](t T, tester ChainComponentsI } func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], mockRun bool) { - tests := []testcase[T]{ + + tests := []Testcase[T]{ { - name: "Gets the latest value as a values.Value", - test: func(t T) { + Name: GetLatestValueAsValuesDotValue, + Test: func(t T) { ctx := tests.Context(t) firstItem := CreateTestStruct(0, tester) @@ -106,8 +141,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, { - name: "Get latest value without arguments and with primitive return as a values.Value", - test: func(t T) { + Name: GetLatestValueNoArgumentsAndPrimitiveReturnAsValuesDotValue, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -127,8 +162,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value without arguments and with slice return as a values.Value", - test: func(t T) { + Name: GetLatestValueNoArgumentsAndSliceReturnAsValueDotValue, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -147,8 +182,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Gets the latest value", - test: func(t T) { + Name: GetLatestValue, + Test: func(t T) { ctx := tests.Context(t) firstItem := CreateTestStruct(0, tester) @@ -177,8 +212,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value without arguments and with primitive return", - test: func(t T) { + Name: GetLatestValueWithPrimitiveReturn, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -193,8 +228,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value based on confidence level", - test: func(t T) { + Name: GetLatestValueBasedOnConfidenceLevel, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -233,8 +268,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value allows multiple contract names to have the same function name", - test: func(t T) { + Name: GetLatestValueFromMultipleContractsNamesSameFunction, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -249,8 +284,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value without arguments and with slice return", - test: func(t T) { + Name: GetLatestValueNoArgumentsAndSliceReturn, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -265,8 +300,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value wraps config with modifiers using its own mapstructure overrides", - test: func(t T) { + Name: GetLatestValueWithModifiersUsingOwnMapstrctureOverrides, + Test: func(t T) { ctx := tests.Context(t) testStruct := CreateTestStruct(0, tester) testStruct.BigField = nil @@ -290,8 +325,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value gets latest event", - test: func(t T) { + Name: GetLatestValueGetsLatestForEvent, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -314,8 +349,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest event based on provided confidence level", - test: func(t T) { + Name: GetLatestValueBasedOnConfidenceLevelForEvent, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -350,8 +385,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value returns not found if event was never triggered", - test: func(t T) { + Name: GetLatestValueReturnsNotFoundWhenNotTriggeredForEvent, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -365,8 +400,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, { - name: "Get latest value gets latest event with filtering", - test: func(t T) { + Name: GetLatestValueWithFilteringForEvent, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -396,14 +431,15 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch }, }, } - runTests(t, tester, tests) + RunTests(t, tester, tests) } func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], mockRun bool) { - testCases := []testcase[T]{ + + testCases := []Testcase[T]{ { - name: "BatchGetLatestValues works", - test: func(t T) { + Name: BatchGetLatestValue, + Test: func(t T) { // setup test data firstItem := CreateTestStruct(1, tester) bindings := tester.GetBindings(t) @@ -439,8 +475,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes }, }, { - name: "BatchGetLatestValues works without arguments and with primitive return", - test: func(t T) { + Name: BatchGetLatestValueNoArgumentsPrimitiveReturn, + Test: func(t T) { // setup call data var primitiveReturnValue uint64 batchGetLatestValuesRequest := make(types.BatchGetLatestValuesRequest) @@ -470,8 +506,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes }, }, { - name: "BatchGetLatestValues allows multiple contract names to have the same function Name", - test: func(t T) { + Name: BatchGetLatestValueMultipleContractNamesSameFunction, + Test: func(t T) { var primitiveReturnValueAnyContract, primitiveReturnValueAnySecondContract uint64 batchGetLatestValuesRequest := make(types.BatchGetLatestValuesRequest) bindings := tester.GetBindings(t) @@ -500,8 +536,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes }, }, { - name: "BatchGetLatestValue without arguments and with slice return", - test: func(t T) { + Name: BatchGetLatestValueNoArgumentsWithSliceReturn, + Test: func(t T) { // setup call data var sliceReturnValue []uint64 batchGetLatestValueRequest := make(types.BatchGetLatestValuesRequest) @@ -524,8 +560,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes }, }, { - name: "BatchGetLatestValues wraps config with modifiers using its own mapstructure overrides", - test: func(t T) { + Name: BatchGetLatestValueWithModifiersOwnMapstructureOverride, + Test: func(t T) { // setup call data testStruct := CreateTestStruct(0, tester) testStruct.BigField = nil @@ -556,8 +592,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes }, }, { - name: "BatchGetLatestValues supports same read with different params and results retain order from request", - test: func(t T) { + Name: BatchGetLatestValueDifferentParamsResultsRetainOrder, + Test: func(t T) { batchCallEntry := make(BatchCallEntry) batchGetLatestValueRequest := make(types.BatchGetLatestValuesRequest) bindings := tester.GetBindings(t) @@ -592,8 +628,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes }, }, { - name: "BatchGetLatestValues supports same read with different params and results retain order from request even with multiple contracts", - test: func(t T) { + Name: BatchGetLatestValueDifferentParamsResultsRetainOrderMultipleContracts, + Test: func(t T) { batchCallEntry := make(BatchCallEntry) batchGetLatestValueRequest := make(types.BatchGetLatestValuesRequest) bindings := tester.GetBindings(t) @@ -640,8 +676,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes }, }, { - name: "BatchGetLatestValues sets errors properly", - test: func(t T) { + Name: BatchGetLatestValueSetsErrorsProperly, + Test: func(t T) { batchGetLatestValueRequest := make(types.BatchGetLatestValuesRequest) bindings := tester.GetBindings(t) bound1 := BindingsByName(bindings, AnyContractName)[0] @@ -674,14 +710,14 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes }, }, } - runTests(t, tester, testCases) + RunTests(t, tester, testCases) } func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T]) { - tests := []testcase[T]{ + tests := []Testcase[T]{ { - name: "QueryKey returns not found if sequence never happened", - test: func(t T) { + Name: QueryKeyNotFound, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -696,8 +732,8 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa }, }, { - name: "QueryKey returns sequence data properly", - test: func(t T) { + Name: QueryKeyReturnsData, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -719,8 +755,8 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa }, }, { - name: "QueryKey returns sequence data properly as values.Value", - test: func(t T) { + Name: QueryKeyReturnsDataAsValuesDotValue, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -759,8 +795,8 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa }, }, { - name: "QueryKey can filter data with value comparator", - test: func(t T) { + Name: QueryKeyCanFilterWithValueComparator, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -795,8 +831,8 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa }, }, { - name: "QueryKey can limit results with cursor", - test: func(t T) { + Name: QueryKeyCanLimitResultsWithCursor, + Test: func(t T) { ctx := tests.Context(t) cr := tester.GetContractReader(t) bindings := tester.GetBindings(t) @@ -847,7 +883,7 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa }, } - runTests(t, tester, tests) + RunTests(t, tester, tests) } func BindingsByName(bindings []types.BoundContract, name string) []types.BoundContract { diff --git a/pkg/types/interfacetests/codec_interface_tests.go b/pkg/types/interfacetests/codec_interface_tests.go index 42cf5fd1d..9a90c7352 100644 --- a/pkg/types/interfacetests/codec_interface_tests.go +++ b/pkg/types/interfacetests/codec_interface_tests.go @@ -38,10 +38,10 @@ const ( ) func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { - tests := []testcase[*testing.T]{ + tests := []Testcase[*testing.T]{ { - name: "Encodes and decodes a single item", - test: func(t *testing.T) { + Name: "Encodes and decodes a single item", + Test: func(t *testing.T) { ctx := tests.Context(t) item := CreateTestStruct[*testing.T](0, tester) req := &EncodeRequest{TestStructs: []TestStruct{item}, TestOn: TestItemType} @@ -58,8 +58,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encodes compatible types", - test: func(t *testing.T) { + Name: "Encodes compatible types", + Test: func(t *testing.T) { ctx := tests.Context(t) item := CreateTestStruct[*testing.T](0, tester) req := &EncodeRequest{TestStructs: []TestStruct{item}, TestOn: TestItemType} @@ -87,8 +87,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encodes compatible maps", - test: func(t *testing.T) { + Name: "Encodes compatible maps", + Test: func(t *testing.T) { ctx := tests.Context(t) item := CreateTestStruct[*testing.T](0, tester) req := &EncodeRequest{TestStructs: []TestStruct{item}, TestOn: TestItemType} @@ -133,8 +133,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encode returns an error if a field is not provided", - test: func(t *testing.T) { + Name: "Encode returns an error if a field is not provided", + Test: func(t *testing.T) { ctx := tests.Context(t) ts := CreateTestStruct[*testing.T](0, tester) item := &TestStructMissingField{ @@ -154,8 +154,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encodes and decodes a slice", - test: func(t *testing.T) { + Name: "Encodes and decodes a slice", + Test: func(t *testing.T) { ctx := tests.Context(t) item1 := CreateTestStruct[*testing.T](0, tester) item2 := CreateTestStruct[*testing.T](1, tester) @@ -174,8 +174,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encodes and decodes a slices with one element", - test: func(t *testing.T) { + Name: "Encodes and decodes a slices with one element", + Test: func(t *testing.T) { ctx := tests.Context(t) item1 := CreateTestStruct[*testing.T](0, tester) items := []TestStruct{item1} @@ -194,8 +194,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encodes and decodes an array", - test: func(t *testing.T) { + Name: "Encodes and decodes an array", + Test: func(t *testing.T) { ctx := tests.Context(t) item1 := CreateTestStruct[*testing.T](0, tester) item2 := CreateTestStruct[*testing.T](1, tester) @@ -215,8 +215,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encodes and decodes an arrays with one element", - test: func(t *testing.T) { + Name: "Encodes and decodes an arrays with one element", + Test: func(t *testing.T) { ctx := tests.Context(t) item1 := CreateTestStruct[*testing.T](0, tester) items := [1]TestStruct{item1} @@ -235,8 +235,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Returns an error if type is undefined", - test: func(t *testing.T) { + Name: "Returns an error if type is undefined", + Test: func(t *testing.T) { ctx := tests.Context(t) item := CreateTestStruct[*testing.T](0, tester) codec := tester.GetCodec(t) @@ -249,8 +249,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Returns an error encoding if arrays are the too small to encode", - test: func(t *testing.T) { + Name: "Returns an error encoding if arrays are the too small to encode", + Test: func(t *testing.T) { ctx := tests.Context(t) if !tester.IncludeArrayEncodingSizeEnforcement() { return @@ -265,8 +265,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Returns an error encoding if arrays are the too large to encode", - test: func(t *testing.T) { + Name: "Returns an error encoding if arrays are the too large to encode", + Test: func(t *testing.T) { ctx := tests.Context(t) if !tester.IncludeArrayEncodingSizeEnforcement() { return @@ -282,8 +282,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "GetMaxEncodingSize returns errors for unknown types", - test: func(t *testing.T) { + Name: "GetMaxEncodingSize returns errors for unknown types", + Test: func(t *testing.T) { ctx := tests.Context(t) cr := tester.GetCodec(t) _, err := cr.GetMaxEncodingSize(ctx, 10, "not"+TestItemType) @@ -291,8 +291,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "GetMaxDecodingSize returns errors for unknown types", - test: func(t *testing.T) { + Name: "GetMaxDecodingSize returns errors for unknown types", + Test: func(t *testing.T) { ctx := tests.Context(t) cr := tester.GetCodec(t) _, err := cr.GetMaxDecodingSize(ctx, 10, "not"+TestItemType) @@ -300,8 +300,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Decode respects config", - test: func(t *testing.T) { + Name: "Decode respects config", + Test: func(t *testing.T) { ctx := tests.Context(t) cr := tester.GetCodec(t) original := CreateTestStruct[*testing.T](0, tester) @@ -319,8 +319,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encode respects config", - test: func(t *testing.T) { + Name: "Encode respects config", + Test: func(t *testing.T) { ctx := tests.Context(t) cr := tester.GetCodec(t) modified := CreateTestStruct[*testing.T](0, tester) @@ -337,8 +337,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encode allows nil params to be encoded, either as empty encoding or with prefix", - test: func(t *testing.T) { + Name: "Encode allows nil params to be encoded, either as empty encoding or with prefix", + Test: func(t *testing.T) { ctx := tests.Context(t) cr := tester.GetCodec(t) _, err := cr.Encode(ctx, nil, NilType) @@ -346,8 +346,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encode does not panic on nil field", - test: func(t *testing.T) { + Name: "Encode does not panic on nil field", + Test: func(t *testing.T) { ctx := tests.Context(t) cr := tester.GetCodec(t) nilArgs := &TestStruct{ @@ -366,8 +366,8 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, { - name: "Encode returns an error if the item isn't compatible", - test: func(t *testing.T) { + Name: "Encode returns an error if the item isn't compatible", + Test: func(t *testing.T) { ctx := tests.Context(t) cr := tester.GetCodec(t) notTestStruct := &MidLevelDynamicTestStruct{} @@ -376,7 +376,7 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { }, }, } - runTests(t, tester, tests) + RunTests(t, tester, tests) } // RunCodecWithStrictArgsInterfaceTest is meant to be used by codecs that don't pad @@ -386,10 +386,10 @@ func RunCodecInterfaceTests(t *testing.T, tester CodecInterfaceTester) { func RunCodecWithStrictArgsInterfaceTest(t *testing.T, tester CodecInterfaceTester) { RunCodecInterfaceTests(t, tester) - tests := []testcase[*testing.T]{ + tests := []Testcase[*testing.T]{ { - name: "Gives an error decoding extra fields on an item", - test: func(t *testing.T) { + Name: "Gives an error decoding extra fields on an item", + Test: func(t *testing.T) { ctx := tests.Context(t) item := CreateTestStruct[*testing.T](0, tester) req := &EncodeRequest{ @@ -404,8 +404,8 @@ func RunCodecWithStrictArgsInterfaceTest(t *testing.T, tester CodecInterfaceTest }, }, { - name: "Gives an error decoding missing fields on an item", - test: func(t *testing.T) { + Name: "Gives an error decoding missing fields on an item", + Test: func(t *testing.T) { ctx := tests.Context(t) item := CreateTestStruct[*testing.T](0, tester) req := &EncodeRequest{ @@ -420,8 +420,8 @@ func RunCodecWithStrictArgsInterfaceTest(t *testing.T, tester CodecInterfaceTest }, }, { - name: "Gives an error decoding extra fields on a slice", - test: func(t *testing.T) { + Name: "Gives an error decoding extra fields on a slice", + Test: func(t *testing.T) { ctx := tests.Context(t) items := []TestStruct{CreateTestStruct[*testing.T](0, tester)} req := &EncodeRequest{ @@ -436,8 +436,8 @@ func RunCodecWithStrictArgsInterfaceTest(t *testing.T, tester CodecInterfaceTest }, }, { - name: "Gives an error decoding missing fields on an slice", - test: func(t *testing.T) { + Name: "Gives an error decoding missing fields on an slice", + Test: func(t *testing.T) { ctx := tests.Context(t) items := []TestStruct{CreateTestStruct[*testing.T](0, tester)} req := &EncodeRequest{ @@ -453,5 +453,5 @@ func RunCodecWithStrictArgsInterfaceTest(t *testing.T, tester CodecInterfaceTest }, } - runTests(t, tester, tests) + RunTests(t, tester, tests) } diff --git a/pkg/types/interfacetests/utils.go b/pkg/types/interfacetests/utils.go index 0cb10a7a8..41c2eb242 100644 --- a/pkg/types/interfacetests/utils.go +++ b/pkg/types/interfacetests/utils.go @@ -21,11 +21,30 @@ type BasicTester[T any] interface { Name() string GetAccountBytes(i int) []byte GetAccountString(i int) string + IsDisabled(testID string) bool + DisableTests(testIDs []string) } -type testcase[T any] struct { - name string - test func(t T) +type TestSelectionSupport struct { + disabledTests map[string]bool +} + +func (t TestSelectionSupport) IsDisabled(testID string) bool { + return t.disabledTests[testID] +} + +func (t *TestSelectionSupport) DisableTests(testIDs []string) { + if t.disabledTests == nil { + t.disabledTests = map[string]bool{} + } + for _, testID := range testIDs { + t.disabledTests[testID] = true + } +} + +type Testcase[T any] struct { + Name string + Test func(t T) } type TestingT[T any] interface { @@ -34,12 +53,16 @@ type TestingT[T any] interface { Run(name string, f func(t T)) bool } -func runTests[T TestingT[T]](t T, tester BasicTester[T], tests []testcase[T]) { +// Tests execution utility function that will consider enabled / disabled test cases according to +// Basic Tester configuration. +func RunTests[T TestingT[T]](t T, tester BasicTester[T], tests []Testcase[T]) { for _, test := range tests { - t.Run(test.name+" for "+tester.Name(), func(t T) { - tester.Setup(t) - test.test(t) - }) + if !tester.IsDisabled(test.Name) { + t.Run(test.Name+" for "+tester.Name(), func(t T) { + tester.Setup(t) + test.Test(t) + }) + } } } @@ -208,12 +231,14 @@ type FilterEventParams struct { Field int32 } -type BatchCallEntry map[types.BoundContract]ContractBatchEntry -type ContractBatchEntry []ReadEntry -type ReadEntry struct { - Name string - ReturnValue any -} +type ( + BatchCallEntry map[types.BoundContract]ContractBatchEntry + ContractBatchEntry []ReadEntry + ReadEntry struct { + Name string + ReturnValue any + } +) func CreateTestStruct[T any](i int, tester BasicTester[T]) TestStruct { s := fmt.Sprintf("field%v", i)