Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
axelKingsley committed Nov 6, 2024
1 parent bef390a commit a5439ec
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
36 changes: 20 additions & 16 deletions op-e2e/interop/interop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,13 +278,14 @@ func TestInteropBlockBuilding(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
// Send an executing message, but with different payload.
// We expect the miner to be unable to include this tx, and confirmation to thus time out.
_, err := s2.ExecuteMessage(ctx, chainB, "Alice", identifier, bobAddr, invalidPayload)
require.NotNil(t, err)
require.ErrorIs(t, err, ctx.Err())
if s2.(*interopE2ESystem).config.mempoolFiltering {
require.ErrorIs(t, ctx.Err(), gethCore.ErrTxFilteredOut)
// We expect the traqnsaction to be filtered out by the mempool if mempool filtering is enabled.
// nothing is returned, but in ExecuteMessage the ErrTxFilteredOut error is checked when sending the tx.
s2.ExecuteMessage(ctx, chainB, "Alice", identifier, bobAddr, invalidPayload, gethCore.ErrTxFilteredOut)
} else {
// We expect the miner to be unable to include this tx, and confirmation to thus time out, if mempool filtering is disabled.
_, err := s2.ExecuteMessage(ctx, chainB, "Alice", identifier, bobAddr, invalidPayload, nil)
require.ErrorIs(t, err, ctx.Err())
require.ErrorIs(t, ctx.Err(), context.DeadlineExceeded)
}
}
Expand All @@ -295,22 +296,25 @@ func TestInteropBlockBuilding(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
// Send an executing message with the correct identifier / payload
rec, err := s2.ExecuteMessage(ctx, chainB, "Alice", identifier, bobAddr, msgPayload)
rec, err := s2.ExecuteMessage(ctx, chainB, "Alice", identifier, bobAddr, msgPayload, nil)
require.NoError(t, err, "expecting tx to be confirmed")
t.Logf("confirmed executing msg in block %s", rec.BlockNumber)
}
t.Log("Done")
}

config := SuperSystemConfig{
mempoolFiltering: false,
}
// run once without mempool filtering to observe the miner behavior
setupAndRun(t, config, test)
t.Run("without mempool filtering", func(t *testing.T) {
config := SuperSystemConfig{
mempoolFiltering: false,
}
setupAndRun(t, config, test)
})

config = SuperSystemConfig{
mempoolFiltering: true,
}
// run again with mempool filtering to observe the behavior of the mempool filter
setupAndRun(t, config, test)
t.Run("with mempool filtering", func(t *testing.T) {
config := SuperSystemConfig{
mempoolFiltering: true,
}
// run again with mempool filtering to observe the behavior of the mempool filter
setupAndRun(t, config, test)
})
}
13 changes: 12 additions & 1 deletion op-e2e/interop/supersystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type SuperSystem interface {
msgIdentifier supervisortypes.Identifier,
target common.Address,
message []byte,
expectedError error,
) (*types.Receipt, error)
// Access a contract on a network by name
Contract(network string, contractName string) interface{}
Expand Down Expand Up @@ -726,13 +727,18 @@ func (s *interopE2ESystem) SendL2Tx(
newApply)
}

// ExecuteMessage calls the CrossL2Inbox executeMessage function
// it uses the L2's chain ID, username key, and geth client.
// expectedError represents the error returned by `ExecuteMessage` if it is expected.
// the returned err is related to `WaitMined`
func (s *interopE2ESystem) ExecuteMessage(
ctx context.Context,
id string,
sender string,
msgIdentifier supervisortypes.Identifier,
target common.Address,
message []byte,
expectedError error,
) (*types.Receipt, error) {
secret := s.UserKey(id, sender)
auth, err := bind.NewKeyedTransactorWithChainID(&secret, s.l2s[id].chainID)
Expand All @@ -751,7 +757,12 @@ func (s *interopE2ESystem) ExecuteMessage(
ChainId: msgIdentifier.ChainID.ToBig(),
}
tx, err := contract.InboxTransactor.ExecuteMessage(auth, identifier, target, message)
require.NoError(s.t, err)
if expectedError != nil {
require.ErrorContains(s.t, err, expectedError.Error())
return nil, nil
} else {
require.NoError(s.t, err)
}
s.logger.Info("Executing message", "tx", tx.Hash(), "to", tx.To(), "target", target, "data", hexutil.Bytes(tx.Data()))
return bind.WaitMined(ctx, s.L2GethClient(id), tx)
}
Expand Down

0 comments on commit a5439ec

Please sign in to comment.