Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Khalil Claybon <[email protected]>
  • Loading branch information
corverroos and kc1116 committed Oct 18, 2024
1 parent b330cd7 commit 1a58425
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions relayer/app/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// Sender uses txmgr to send transactions a specific destination chain.
type onSubmitFunc func(context.Context, *ethtypes.Transaction, *ethtypes.Receipt, xchain.Submission)

// Sender uses txmgr to send transactions a specific destination chain.
// Sender uses txmgr to send transactions to a specific destination chain.
type Sender struct {
network netconf.ID
txMgr txmgr.TxManager
Expand Down Expand Up @@ -108,7 +108,7 @@ func (s Sender) SendAsync(ctx context.Context, sub xchain.Submission) <-chan err
}

if s.txMgr == nil {
return returnErr(errors.New("tx mgr not found", "dest_chain_id", sub.DestChainID))
return returnErr(errors.New("tx mgr not found [BUG]", "dest_chain_id", sub.DestChainID))
} else if sub.DestChainID != s.chain.ID {
return returnErr(errors.New("unexpected destination chain [BUG]",
"got", sub.DestChainID, "expect", s.chain.ID))
Expand Down
16 changes: 11 additions & 5 deletions relayer/app/sender_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (

var errSentAsync = errors.New("sent async")

//go:generate go test . -run TestSendAsync -count=1000

func TestSendAsync(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down Expand Up @@ -63,9 +65,11 @@ func TestSendAsync(t *testing.T) {
// Ensure nonces were reserved sequentially.
require.EqualValues(t, total, txMgr.ReservedNonces())

// Trigger each send and ensure expected result (errSentAsync)
// Complete all sends
txMgr.CompleteSends(total)

// Ensure expected result (errSentAsync)
for _, resp := range resps {
txMgr.MineNext()
require.ErrorIs(t, <-resp, errSentAsync)
}
}
Expand All @@ -74,7 +78,7 @@ var _ txmgr.TxManager = (*mockTxMgr)(nil)

func newMockTxMgr() *mockTxMgr {
return &mockTxMgr{
sends: make(chan txmgr.TxCandidate, 1),
sends: make(chan txmgr.TxCandidate),
}
}

Expand All @@ -91,8 +95,10 @@ func (m *mockTxMgr) Send(_ context.Context, candidate txmgr.TxCandidate) (*types
return nil, nil, errSentAsync
}

func (m *mockTxMgr) MineNext() txmgr.TxCandidate {
return <-m.sends
func (m *mockTxMgr) CompleteSends(expected int) {
for range expected {
<-m.sends
}
}

func (m *mockTxMgr) From() common.Address {
Expand Down

0 comments on commit 1a58425

Please sign in to comment.