Skip to content

Commit

Permalink
Updated new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silaslenihan committed Dec 17, 2024
1 parent 17370c5 commit 37a466b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 20 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ func runContractReaderByIDQueryKey(t *testing.T) {
func(t *testing.T) {
t.Parallel()
fake := &fakeContractReader{}
fakeCW := &fakeContractWriter{}
fakeCW := &fakeContractWriter{cr: fake}
tester := &fakeContractReaderInterfaceTester{impl: fake}
tester.Setup(t)

Expand Down Expand Up @@ -1210,7 +1210,7 @@ func runContractReaderByIDQueryKey(t *testing.T) {
func(t *testing.T) {
t.Parallel()
fake := &fakeContractReader{}
fakeCW := &fakeContractWriter{}
fakeCW := &fakeContractWriter{cr: fake}

tester := &fakeContractReaderInterfaceTester{impl: fake}
tester.Setup(t)
Expand Down
42 changes: 24 additions & 18 deletions pkg/types/interfacetests/chain_components_interface_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ func runQueryKeysInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterf
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
cw := tester.GetContractWriter(t)

bindings := tester.GetBindings(t)

require.NoError(t, cr.Bind(ctx, bindings))
boundContract := BindingsByName(bindings, AnyContractName)[0]

expectedSequenceData := createMixedEventTypeSequence(t, tester, boundContract)
expectedSequenceData := createMixedEventTypeSequence(t, tester, cw, boundContract)

ts := &TestStruct{}
require.Eventually(t, func() bool {
Expand Down Expand Up @@ -181,7 +183,7 @@ func runQueryKeysInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterf
bindings := tester.GetBindings(t)
bound := BindingsByName(bindings, AnyContractName)[0]

require.NoError(t, cr.Bind(ctx, tester.GetBindings(t)))
require.NoError(t, cr.Bind(ctx, bindings))

contractFilter := types.ContractKeyFilter{
Contract: bound,
Expand All @@ -204,12 +206,13 @@ func runQueryKeysInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterf
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
cw := tester.GetContractWriter(t)
bindings := tester.GetBindings(t)

require.NoError(t, cr.Bind(ctx, bindings))
bound := BindingsByName(bindings, AnyContractName)[0]

expectedSequenceData := createMixedEventTypeSequence(t, tester, bound)
expectedSequenceData := createMixedEventTypeSequence(t, tester, cw, bound)

var value values.Value
require.Eventually(t, func() bool {
Expand Down Expand Up @@ -268,12 +271,15 @@ func runQueryKeysInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterf
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
cw := tester.GetContractWriter(t)

bindings := tester.GetBindings(t)

require.NoError(t, cr.Bind(ctx, bindings))
boundContract := BindingsByName(bindings, AnyContractName)[0]

expectedSequenceData := createMixedEventTypeSequence(t, tester, boundContract)
expectedSequenceData := createMixedEventTypeSequence(t, tester, cw, boundContract)
fmt.Println("expectedSequenceData", expectedSequenceData)

ts := &TestStruct{}
require.Eventually(t, func() bool {
Expand Down Expand Up @@ -321,6 +327,7 @@ func runQueryKeysInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterf
Test: func(t T) {
ctx := tests.Context(t)
cr := tester.GetContractReader(t)
cw := tester.GetContractWriter(t)
bindings := tester.GetBindings(t)

require.NoError(t, cr.Bind(ctx, bindings))
Expand All @@ -330,26 +337,26 @@ func runQueryKeysInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterf

ts1 := CreateTestStruct[T](0, tester)
expectedSequenceData = append(expectedSequenceData, &ts1)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed)
ts2 := CreateTestStruct[T](1, tester)
expectedSequenceData = append(expectedSequenceData, &ts2)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed)

ds1 := SomeDynamicTopicEvent{Field: "1"}
expectedSequenceData = append(expectedSequenceData, &ds1)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEventWithDynamicTopic, ds1, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEventWithDynamicTopic, ds1, boundContract, types.Unconfirmed)

ts3 := CreateTestStruct[T](2, tester)
expectedSequenceData = append(expectedSequenceData, &ts3)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed)

ds2 := SomeDynamicTopicEvent{Field: "2"}
expectedSequenceData = append(expectedSequenceData, &ds2)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEventWithDynamicTopic, ds2, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEventWithDynamicTopic, ds2, boundContract, types.Unconfirmed)

ts4 := CreateTestStruct[T](3, tester)
expectedSequenceData = append(expectedSequenceData, &ts4)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEvent, ts4, boundContract, types.Finalized)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEvent, ts4, boundContract, types.Finalized)

require.Eventually(t, func() bool {
var allSequences []sequenceWithKey
Expand Down Expand Up @@ -402,32 +409,31 @@ func runQueryKeysInterfaceTests[T TestingT[T]](t T, tester ChainComponentsInterf
RunTests(t, tester, tests)
}

func createMixedEventTypeSequence[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], boundContract types.BoundContract) []any {
func createMixedEventTypeSequence[T TestingT[T]](t T, tester ChainComponentsInterfaceTester[T], cw types.ContractWriter, boundContract types.BoundContract) []any {
var expectedSequenceData []any

ts1 := CreateTestStruct[T](0, tester)
expectedSequenceData = append(expectedSequenceData, &ts1)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEvent, ts1, boundContract, types.Unconfirmed)
ts2 := CreateTestStruct[T](1, tester)
expectedSequenceData = append(expectedSequenceData, &ts2)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEvent, ts2, boundContract, types.Unconfirmed)

ds1 := SomeDynamicTopicEvent{Field: "1"}
expectedSequenceData = append(expectedSequenceData, &ds1)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEventWithDynamicTopic, ds1, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEventWithDynamicTopic, ds1, boundContract, types.Unconfirmed)

ts3 := CreateTestStruct[T](2, tester)
expectedSequenceData = append(expectedSequenceData, &ts3)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEvent, ts3, boundContract, types.Unconfirmed)

ds2 := SomeDynamicTopicEvent{Field: "2"}
expectedSequenceData = append(expectedSequenceData, &ds2)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEventWithDynamicTopic, ds2, boundContract, types.Unconfirmed)
_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEventWithDynamicTopic, ds2, boundContract, types.Unconfirmed)

ts4 := CreateTestStruct[T](3, tester)
expectedSequenceData = append(expectedSequenceData, &ts4)
_ = SubmitTransactionToCW(t, tester, MethodTriggeringEvent, ts4, boundContract, types.Unconfirmed)

_ = SubmitTransactionToCW(t, tester, cw, MethodTriggeringEvent, ts4, boundContract, types.Unconfirmed)
return expectedSequenceData
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/types/interfacetests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ type TestingT[T any] interface {
// 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]) {
t.Run(tester.Name(), func(t T) {
for _, test := range tests {
if !tester.IsDisabled(test.Name) {
t.Run(test.Name, func(t T) {
tester.Setup(t)
test.Test(t)
})
}
}
})
}

func RunTestsInParllel[T TestingT[T]](t T, tester BasicTester[T], tests []Testcase[T]) {
t.Run(tester.Name(), func(t T) {
tester.Setup(t)
for _, test := range tests {
Expand Down

0 comments on commit 37a466b

Please sign in to comment.