Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
fix: mocks and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
P1sar committed Jul 27, 2023
1 parent 3f18e63 commit 7e184c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions relayer/message/message_processors_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package message

import (
"context"
"math/big"
"testing"
)
Expand All @@ -15,7 +16,7 @@ func TestAdjustDecimalsForERC20AmountMessageProcessor(t *testing.T) {
a.Bytes(), // 145.5567 tokens
},
}
err := AdjustDecimalsForERC20AmountMessageProcessor(map[uint8]uint64{1: 18, 2: 2})(msg)
err := AdjustDecimalsForERC20AmountMessageProcessor(map[uint8]uint64{1: 18, 2: 2})(context.Background(), msg)
if err != nil {
t.Fatal()
}
Expand All @@ -30,7 +31,7 @@ func TestAdjustDecimalsForERC20AmountMessageProcessor(t *testing.T) {
big.NewInt(14555).Bytes(), // 145.55 tokens from 2nd chain
},
}
err = AdjustDecimalsForERC20AmountMessageProcessor(map[uint8]uint64{1: 18, 2: 2})(msg2)
err = AdjustDecimalsForERC20AmountMessageProcessor(map[uint8]uint64{1: 18, 2: 2})(context.Background(), msg2)
if err != nil {
t.Fatal()
}
Expand Down
8 changes: 4 additions & 4 deletions relayer/mock/relayer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions relayer/relayer_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package relayer

import (
"context"
"fmt"
"math/big"
"testing"
Expand Down Expand Up @@ -50,7 +51,7 @@ func (s *RouteTestSuite) TestAdjustDecimalsForERC20AmountMessageProcessor() {
a.Bytes(), // 145.5567 tokens
},
}
err := message.AdjustDecimalsForERC20AmountMessageProcessor(map[uint8]uint64{1: 18, 2: 2})(msg)
err := message.AdjustDecimalsForERC20AmountMessageProcessor(map[uint8]uint64{1: 18, 2: 2})(context.Background(), msg)
s.Nil(err)
amount := new(big.Int).SetBytes(msg.Payload[0].([]byte))
if amount.Cmp(big.NewInt(14555)) != 0 {
Expand All @@ -65,7 +66,7 @@ func (s *RouteTestSuite) TestLogsErrorIfMessageProcessorReturnsError() {
relayer := NewRelayer(
[]RelayedChain{},
s.mockMetrics,
func(m *message.Message) error { return fmt.Errorf("error") },
func(ctx context.Context, m *message.Message) error { return fmt.Errorf("error") },
)
relayer.addRelayedChain(s.mockRelayedChain)

Expand All @@ -78,11 +79,11 @@ func (s *RouteTestSuite) TestWriteFail() {
s.mockMetrics.EXPECT().TrackDepositMessage(gomock.Any())
s.mockMetrics.EXPECT().TrackExecutionError(gomock.Any())
s.mockRelayedChain.EXPECT().DomainID().Return(uint8(1)).Times(3)
s.mockRelayedChain.EXPECT().Write(gomock.Any()).Return(fmt.Errorf("error"))
s.mockRelayedChain.EXPECT().Write(gomock.Any(), gomock.Any()).Return(fmt.Errorf("error"))
relayer := NewRelayer(
[]RelayedChain{},
s.mockMetrics,
func(m *message.Message) error { return nil },
func(ctx context.Context, m *message.Message) error { return nil },
)
relayer.addRelayedChain(s.mockRelayedChain)

Expand All @@ -95,11 +96,11 @@ func (s *RouteTestSuite) TestWritesToDestChainIfMessageValid() {
s.mockMetrics.EXPECT().TrackDepositMessage(gomock.Any())
s.mockMetrics.EXPECT().TrackSuccessfulExecutionLatency(gomock.Any())
s.mockRelayedChain.EXPECT().DomainID().Return(uint8(1)).Times(2)
s.mockRelayedChain.EXPECT().Write(gomock.Any())
s.mockRelayedChain.EXPECT().Write(gomock.Any(), gomock.Any())
relayer := NewRelayer(
[]RelayedChain{},
s.mockMetrics,
func(m *message.Message) error { return nil },
func(ctx context.Context, m *message.Message) error { return nil },
)
relayer.addRelayedChain(s.mockRelayedChain)

Expand Down

0 comments on commit 7e184c7

Please sign in to comment.