Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodino committed Jun 20, 2024
1 parent 0e4c0cb commit 8e06599
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
39 changes: 39 additions & 0 deletions packages/relayer/pkg/mock/event_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"math/rand"
"net/http"
"time"

"github.com/morkid/paginate"
"github.com/taikoxyz/taiko-mono/packages/relayer"
Expand Down Expand Up @@ -62,6 +63,44 @@ func (r *EventRepository) UpdateStatus(ctx context.Context, id int, status relay
return nil
}

func (r *EventRepository) UpdateFeesAndProfitability(
ctx context.Context,
id int, opts relayer.UpdateFeesAndProfitabilityOpts,
) error {
var event *relayer.Event

var index int

// Find the event by ID
for i, e := range r.events {
if e.ID == id {
event = e
index = i

break
}
}

if event == nil {
return nil // Or return an appropriate error if the event is not found
}

// Update the event fields
event.Fee = &opts.Fee
event.DestChainBaseFee = &opts.DestChainBaseFee
event.GasTipCap = &opts.GasTipCap
event.GasLimit = &opts.GasLimit
event.IsProfitable = &opts.IsProfitable
event.EstimatedOnchainFee = &opts.EstimatedOnchainFee
currentTime := time.Now().UTC()
event.IsProfitableEvaluatedAt = &currentTime

// Save the updated event back to the slice
r.events[index] = event

return nil
}

func (r *EventRepository) FindAllByAddress(
ctx context.Context,
req *http.Request,
Expand Down
6 changes: 5 additions & 1 deletion packages/relayer/pkg/repo/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ func (r *EventRepository) Save(ctx context.Context, opts relayer.SaveEventOpts)
return e, nil
}

func (r *EventRepository) UpdateFeesAndProfitability(ctx context.Context, id int, opts relayer.UpdateFeesAndProfitabilityOpts) error {
func (r *EventRepository) UpdateFeesAndProfitability(
ctx context.Context,
id int,
opts relayer.UpdateFeesAndProfitabilityOpts,
) error {
e := &relayer.Event{}
if err := r.db.GormDB().Where("id = ?", id).First(e).Error; err != nil {
return errors.Wrap(err, "r.db.First")
Expand Down
5 changes: 5 additions & 0 deletions packages/relayer/processor/is_profitable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func Test_isProfitable(t *testing.T) {
p := newTestProcessor(true)

tests := []struct {
id int
name string
fee uint64
gasLimit uint64
Expand All @@ -20,6 +21,7 @@ func Test_isProfitable(t *testing.T) {
wantErr error
}{
{
0,
"zeroProcessingFee",
0,
1,
Expand All @@ -29,6 +31,7 @@ func Test_isProfitable(t *testing.T) {
errImpossible,
},
{
1,
"profitable",
600000000600001,
600000,
Expand All @@ -38,6 +41,7 @@ func Test_isProfitable(t *testing.T) {
nil,
},
{
2,
"unprofitable",
590000000600000,
600000,
Expand All @@ -52,6 +56,7 @@ func Test_isProfitable(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
profitable, err := p.isProfitable(
context.Background(),
tt.id,
tt.fee,
tt.gasLimit,
tt.baseFee,
Expand Down
1 change: 1 addition & 0 deletions packages/relayer/processor/process_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func Test_sendProcessMessageCall(t *testing.T) {

_, err := p.sendProcessMessageCall(
context.Background(),
1,
&bridge.BridgeMessageSent{
Message: bridge.IBridgeMessage{
Id: 1,
Expand Down

0 comments on commit 8e06599

Please sign in to comment.