Skip to content

Commit

Permalink
fix race condition for feature test, and fix simulated backend endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhen1997 committed Aug 12, 2024
1 parent 8b45996 commit ae734e9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
23 changes: 9 additions & 14 deletions core/chains/evm/client/simulated_backend_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,22 +703,17 @@ func (c *SimulatedBackendClient) ethGetHeaderByNumber(ctx context.Context, resul
}

func (c *SimulatedBackendClient) LatestFinalizedBlock(ctx context.Context) (*evmtypes.Head, error) {
var block *types.Header
if blk := c.b.Blockchain().CurrentFinalBlock(); blk != nil {
block = blk
} else if blk = c.b.Blockchain().CurrentBlock(); blk != nil {
block = blk
} else {
return nil, fmt.Errorf("SimulatedBackendClient failed to find latest finalized block")
if block := c.b.Blockchain().CurrentFinalBlock(); block != nil {
return &evmtypes.Head{
EVMChainID: ubig.NewI(c.chainId.Int64()),
Hash: block.Hash(),
Number: block.Number.Int64(),
ParentHash: block.ParentHash,
Timestamp: time.Unix(int64(block.Time), 0),
}, nil
}

return &evmtypes.Head{
EVMChainID: ubig.NewI(c.chainId.Int64()),
Hash: block.Hash(),
Number: block.Number.Int64(),
ParentHash: block.ParentHash,
Timestamp: time.Unix(int64(block.Time), 0),
}, nil
return nil, fmt.Errorf("SimulatedBackendClient failed to find latest finalized block")
}

func (c *SimulatedBackendClient) ethGetLogs(ctx context.Context, result interface{}, args ...interface{}) error {
Expand Down
7 changes: 7 additions & 0 deletions core/internal/features/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ func TestIntegration_AsyncEthTx(t *testing.T) {
t.Parallel()
operatorContracts := setupOperatorContracts(t)
b := operatorContracts.sim
b.Blockchain().SetFinalized(b.Blockchain().CurrentBlock())

t.Run("with FailOnRevert enabled, run succeeds when transaction is successful", func(t *testing.T) {
app, sendingAddr, o := setupAppForEthTx(t, operatorContracts)
Expand Down Expand Up @@ -536,6 +537,8 @@ observationSource = """

testutils.WaitForLogMessage(t, o, "Sending transaction")
b.Commit() // Needs at least two confirmations
time.Sleep(1 * time.Second)
b.Blockchain().SetFinalized(b.Blockchain().CurrentBlock())
b.Commit() // Needs at least two confirmations
b.Commit() // Needs at least two confirmations
testutils.WaitForLogMessage(t, o, "Resume run success")
Expand Down Expand Up @@ -582,6 +585,8 @@ observationSource = """

testutils.WaitForLogMessage(t, o, "Sending transaction")
b.Commit() // Needs at least two confirmations
time.Sleep(1 * time.Second)
b.Blockchain().SetFinalized(b.Blockchain().CurrentBlock())
b.Commit() // Needs at least two confirmations
b.Commit() // Needs at least two confirmations
testutils.WaitForLogMessage(t, o, "Resume run success")
Expand Down Expand Up @@ -620,6 +625,8 @@ observationSource = """

testutils.WaitForLogMessage(t, o, "Sending transaction")
b.Commit() // Needs at least two confirmations
time.Sleep(1 * time.Second)
b.Blockchain().SetFinalized(b.Blockchain().CurrentBlock())
b.Commit() // Needs at least two confirmations
b.Commit() // Needs at least two confirmations
testutils.WaitForLogMessage(t, o, "Resume run success")
Expand Down

0 comments on commit ae734e9

Please sign in to comment.