Skip to content

Commit

Permalink
Fix chain reader test flake and make it faster (#12138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilija42 authored Feb 22, 2024
1 parent 0b0d40f commit 8c01c7d
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions core/services/relay/evm/chain_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ func TestChainReader(t *testing.T) {
it := &chainReaderInterfaceTester{}
RunChainReaderInterfaceTests(t, it)
RunChainReaderInterfaceTests(t, commontestutils.WrapChainReaderTesterForLoop(it))

t.Run("Dynamically typed topics can be used to filter and have type correct in return", func(t *testing.T) {
it.Setup(t)

// bind event before firing it to avoid log poller race
ctx := testutils.Context(t)
cr := it.GetChainReader(t)
require.NoError(t, cr.Bind(ctx, it.GetBindings(t)))

anyString := "foo"
tx, err := it.evmTest.LatestValueHolderTransactor.TriggerEventWithDynamicTopic(it.auth, anyString)
require.NoError(t, err)
it.sim.Commit()
it.incNonce()
it.awaitTx(t, tx)
ctx := testutils.Context(t)

cr := it.GetChainReader(t)
require.NoError(t, cr.Bind(ctx, it.GetBindings(t)))

input := struct{ Field string }{Field: anyString}
tp := cr.(clcommontypes.ContractTypeProvider)
Expand All @@ -84,20 +86,24 @@ func TestChainReader(t *testing.T) {

t.Run("Multiple topics can filter together", func(t *testing.T) {
it.Setup(t)

// bind event before firing it to avoid log poller race
ctx := testutils.Context(t)
cr := it.GetChainReader(t)
require.NoError(t, cr.Bind(ctx, it.GetBindings(t)))

triggerFourTopics(t, it, int32(1), int32(2), int32(3))
triggerFourTopics(t, it, int32(2), int32(2), int32(3))
triggerFourTopics(t, it, int32(1), int32(3), int32(3))
triggerFourTopics(t, it, int32(1), int32(2), int32(4))

ctx := testutils.Context(t)
cr := it.GetChainReader(t)
require.NoError(t, cr.Bind(ctx, it.GetBindings(t)))
var latest struct{ Field1, Field2, Field3 int32 }
params := struct{ Field1, Field2, Field3 int32 }{Field1: 1, Field2: 2, Field3: 3}

time.Sleep(it.MaxWaitTimeForEvents())
require.Eventually(t, func() bool {
return cr.GetLatestValue(ctx, AnyContractName, triggerWithAllTopics, params, &latest) == nil
}, it.MaxWaitTimeForEvents(), time.Millisecond*10)

require.NoError(t, cr.GetLatestValue(ctx, AnyContractName, triggerWithAllTopics, params, &latest))
assert.Equal(t, int32(1), latest.Field1)
assert.Equal(t, int32(2), latest.Field2)
assert.Equal(t, int32(3), latest.Field3)
Expand Down

0 comments on commit 8c01c7d

Please sign in to comment.