Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BCFR-967 - Basic support for method writing and reading - Add logic to enable/disable test cases for chain components common test suite #829

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/codec/encodings/type_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func (t *interfaceTesterBase) GetAccountString(i int) string {

type bigEndianInterfaceTester struct {
interfaceTesterBase
TestSelectionSupport
lenient bool
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func TestCodecClient(t *testing.T) {

type fakeCodecInterfaceTester struct {
interfaceTesterBase
interfacetests.TestSelectionSupport
impl types.Codec
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ func makeEncoder() cbor.EncMode {

type fakeContractReaderInterfaceTester struct {
interfaceTesterBase
TestSelectionSupport
impl types.ContractReader
cw fakeChainWriter
}
Expand Down
160 changes: 102 additions & 58 deletions pkg/types/interfacetests/chain_components_interface_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,48 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/values"
)

// GetLatestValue method
const (
ContractReaderGetLatestValueAsValuesDotValue = "Gets the latest value as a values.Value"
ContractReaderGetLatestValueNoArgumentsAndPrimitiveReturnAsValuesDotValue = "Get latest value without arguments and with primitive return as a values.Value"
ContractReaderGetLatestValueNoArgumentsAndSliceReturnAsValueDotValue = "Get latest value without arguments and with slice return as a values.Value"
ContractReaderGetLatestValue = "Gets the latest value"
ContractReaderGetLatestValueWithPrimitiveReturn = "Get latest value without arguments and with primitive return"
ContractReaderGetLatestValueBasedOnConfidenceLevel = "Get latest value based on confidence level"
ContractReaderGetLatestValueFromMultipleContractsNamesSameFunction = "Get latest value allows multiple contract names to have the same function "
ContractReaderGetLatestValueWithModifiersUsingOwnMapstrctureOverrides = "Get latest value wraps config with modifiers using its own mapstructure overrides"
ContractReaderGetLatestValueNoArgumentsAndSliceReturn = "Get latest value without arguments and with slice return"
)

// GetLatestValue event
const (
ContractReaderGetLatestValueGetsLatestForEvent = "Get latest value gets latest event"
ContractReaderGetLatestValueBasedOnConfidenceLevelForEvent = "Get latest event based on provided confidence level"
ContractReaderGetLatestValueReturnsNotFoundWhenNotTriggeredForEvent = "Get latest value returns not found if event was never triggered"
ContractReaderGetLatestValueWithFilteringForEvent = "Get latest value gets latest event with filtering"
)

// BatchGet
const (
ContractReaderBatchGetLatestValue = "BatchGetLatestValues works"
ContractReaderBatchGetLatestValueNoArgumentsPrimitiveReturn = "BatchGetLatestValues works without arguments and with primitive return"
ContractReaderBatchGetLatestValueMultipleContractNamesSameFunction = "BatchGetLatestValues allows multiple contract names to have the same function Name"
ContractReaderBatchGetLatestValueNoArgumentsWithSliceReturn = "BatchGetLatestValue without arguments and with slice return"
ContractReaderBatchGetLatestValueWithModifiersOwnMapstructureOverride = "BatchGetLatestValues wraps config with modifiers using its own mapstructure overrides"
ContractReaderBatchGetLatestValueDifferentParamsResultsRetainOrder = "BatchGetLatestValues supports same read with different params and results retain order from request"
ContractReaderBatchGetLatestValueDifferentParamsResultsRetainOrderMultipleContracts = "BatchGetLatestValues supports same read with different params and results retain order from request even with multiple contracts"
ContractReaderBatchGetLatestValueSetsErrorsProperly = "BatchGetLatestValues sets errors properly"
)

// Query key
const (
ContractReaderQueryKeyNotFound = "QueryKey returns not found if sequence never happened"
ContractReaderQueryKeyReturnsData = "QueryKey returns sequence data properly"
ContractReaderQueryKeyReturnsDataAsValuesDotValue = "QueryKey returns sequence data properly as values.Value"
ContractReaderQueryKeyCanFilterWithValueComparator = "QueryKey can filter data with value comparator"
ContractReaderQueryKeyCanLimitResultsWithCursor = "QueryKey can limit results with cursor"
)

type ChainComponentsInterfaceTester[T TestingT[T]] interface {
BasicTester[T]
GetContractReader(t T) types.ContractReader
Expand Down Expand Up @@ -63,10 +105,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: ContractReaderGetLatestValueAsValuesDotValue,
Test: func(t T) {
ctx := tests.Context(t)
firstItem := CreateTestStruct(0, tester)

Expand Down Expand Up @@ -106,8 +149,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: ContractReaderGetLatestValueNoArgumentsAndPrimitiveReturnAsValuesDotValue,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -127,8 +170,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: ContractReaderGetLatestValueNoArgumentsAndSliceReturnAsValueDotValue,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -147,8 +190,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch
},
},
{
name: "Gets the latest value",
test: func(t T) {
Name: ContractReaderGetLatestValue,
Test: func(t T) {
ctx := tests.Context(t)
firstItem := CreateTestStruct(0, tester)

Expand Down Expand Up @@ -177,8 +220,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: ContractReaderGetLatestValueWithPrimitiveReturn,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -193,8 +236,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch
},
},
{
name: "Get latest value based on confidence level",
test: func(t T) {
Name: ContractReaderGetLatestValueBasedOnConfidenceLevel,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -233,8 +276,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: ContractReaderGetLatestValueFromMultipleContractsNamesSameFunction,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -249,8 +292,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: ContractReaderGetLatestValueNoArgumentsAndSliceReturn,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -265,8 +308,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: ContractReaderGetLatestValueWithModifiersUsingOwnMapstrctureOverrides,
Test: func(t T) {
ctx := tests.Context(t)
testStruct := CreateTestStruct(0, tester)
testStruct.BigField = nil
Expand All @@ -290,8 +333,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch
},
},
{
name: "Get latest value gets latest event",
test: func(t T) {
Name: ContractReaderGetLatestValueGetsLatestForEvent,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -314,8 +357,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch
},
},
{
name: "Get latest event based on provided confidence level",
test: func(t T) {
Name: ContractReaderGetLatestValueBasedOnConfidenceLevelForEvent,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -350,8 +393,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: ContractReaderGetLatestValueReturnsNotFoundWhenNotTriggeredForEvent,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -365,8 +408,8 @@ func runContractReaderGetLatestValueInterfaceTests[T TestingT[T]](t T, tester Ch
},
},
{
name: "Get latest value gets latest event with filtering",
test: func(t T) {
Name: ContractReaderGetLatestValueWithFilteringForEvent,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -396,14 +439,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: ContractReaderBatchGetLatestValue,
Test: func(t T) {
// setup test data
firstItem := CreateTestStruct(1, tester)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -439,8 +483,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes
},
},
{
name: "BatchGetLatestValues works without arguments and with primitive return",
test: func(t T) {
Name: ContractReaderBatchGetLatestValueNoArgumentsPrimitiveReturn,
Test: func(t T) {
// setup call data
var primitiveReturnValue uint64
batchGetLatestValuesRequest := make(types.BatchGetLatestValuesRequest)
Expand Down Expand Up @@ -470,8 +514,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: ContractReaderBatchGetLatestValueMultipleContractNamesSameFunction,
Test: func(t T) {
var primitiveReturnValueAnyContract, primitiveReturnValueAnySecondContract uint64
batchGetLatestValuesRequest := make(types.BatchGetLatestValuesRequest)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -500,8 +544,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes
},
},
{
name: "BatchGetLatestValue without arguments and with slice return",
test: func(t T) {
Name: ContractReaderBatchGetLatestValueNoArgumentsWithSliceReturn,
Test: func(t T) {
// setup call data
var sliceReturnValue []uint64
batchGetLatestValueRequest := make(types.BatchGetLatestValuesRequest)
Expand All @@ -524,8 +568,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: ContractReaderBatchGetLatestValueWithModifiersOwnMapstructureOverride,
Test: func(t T) {
// setup call data
testStruct := CreateTestStruct(0, tester)
testStruct.BigField = nil
Expand Down Expand Up @@ -556,8 +600,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: ContractReaderBatchGetLatestValueDifferentParamsResultsRetainOrder,
Test: func(t T) {
batchCallEntry := make(BatchCallEntry)
batchGetLatestValueRequest := make(types.BatchGetLatestValuesRequest)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -592,8 +636,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: ContractReaderBatchGetLatestValueDifferentParamsResultsRetainOrderMultipleContracts,
Test: func(t T) {
batchCallEntry := make(BatchCallEntry)
batchGetLatestValueRequest := make(types.BatchGetLatestValuesRequest)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -640,8 +684,8 @@ func runContractReaderBatchGetLatestValuesInterfaceTests[T TestingT[T]](t T, tes
},
},
{
name: "BatchGetLatestValues sets errors properly",
test: func(t T) {
Name: ContractReaderBatchGetLatestValueSetsErrorsProperly,
Test: func(t T) {
batchGetLatestValueRequest := make(types.BatchGetLatestValuesRequest)
bindings := tester.GetBindings(t)
bound1 := BindingsByName(bindings, AnyContractName)[0]
Expand Down Expand Up @@ -674,14 +718,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: ContractReaderQueryKeyNotFound,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -696,8 +740,8 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa
},
},
{
name: "QueryKey returns sequence data properly",
test: func(t T) {
Name: ContractReaderQueryKeyReturnsData,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand All @@ -719,8 +763,8 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa
},
},
{
name: "QueryKey returns sequence data properly as values.Value",
test: func(t T) {
Name: ContractReaderQueryKeyReturnsDataAsValuesDotValue,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -759,8 +803,8 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa
},
},
{
name: "QueryKey can filter data with value comparator",
test: func(t T) {
Name: ContractReaderQueryKeyCanFilterWithValueComparator,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -795,8 +839,8 @@ func runQueryKeyInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterfa
},
},
{
name: "QueryKey can limit results with cursor",
test: func(t T) {
Name: ContractReaderQueryKeyCanLimitResultsWithCursor,
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
bindings := tester.GetBindings(t)
Expand Down Expand Up @@ -847,7 +891,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 {
Expand Down
Loading
Loading