diff --git a/p2p/pkg/rpc/bidder/service.go b/p2p/pkg/rpc/bidder/service.go index 7b3eb4cce..0d5db387f 100644 --- a/p2p/pkg/rpc/bidder/service.go +++ b/p2p/pkg/rpc/bidder/service.go @@ -197,7 +197,8 @@ func (s *Service) SendBid( } if bid.SlashAmount == "" { - bid.SlashAmount = "0" + s.logger.Info("slash amount is empty in bid, using bid amount as slash amount", "bid amount", bid.Amount) + bid.SlashAmount = bid.Amount } var optBuf []byte diff --git a/p2p/pkg/rpc/bidder/service_test.go b/p2p/pkg/rpc/bidder/service_test.go index 537f42243..7f8bc7105 100644 --- a/p2p/pkg/rpc/bidder/service_test.go +++ b/p2p/pkg/rpc/bidder/service_test.go @@ -565,6 +565,56 @@ func TestSendBid(t *testing.T) { } } +func TestSendBidSlashAmount(t *testing.T) { + t.Parallel() + + client := startServer(t) + + t.Run("slash amount not specified - should default to bid amount", func(t *testing.T) { + rcv, err := client.SendBid(context.Background(), &bidderapiv1.Bid{ + TxHashes: []string{common.HexToHash("0x0000ab").Hex()[2:]}, + Amount: "1000000000000000000", + SlashAmount: "", + BlockNumber: 1, + DecayStartTimestamp: 10, + DecayEndTimestamp: 20, + RevertingTxHashes: []string{}, + }) + if err != nil { + t.Fatalf("error sending bid: %v", err) + } + preconf, err := rcv.Recv() + if err != nil { + t.Fatalf("error receiving preconf: %v", err) + } + if preconf.SlashAmount != "1000000000000000000" { + t.Fatalf("expected slash amount to default to bid amount 1000000000000000000, got %s", preconf.SlashAmount) + } + }) + + t.Run("slash amount specified - should use provided amount", func(t *testing.T) { + rcv, err := client.SendBid(context.Background(), &bidderapiv1.Bid{ + TxHashes: []string{common.HexToHash("0x0000ab").Hex()[2:]}, + Amount: "1000000000000000000", + SlashAmount: "500000000000000000", + BlockNumber: 1, + DecayStartTimestamp: 10, + DecayEndTimestamp: 20, + RevertingTxHashes: []string{}, + }) + if err != nil { + t.Fatalf("error sending bid: %v", err) + } + preconf, err := rcv.Recv() + if err != nil { + t.Fatalf("error receiving preconf: %v", err) + } + if preconf.SlashAmount != "500000000000000000" { + t.Fatalf("expected slash amount 500000000000000000, got %s", preconf.SlashAmount) + } + }) +} + func TestClaimSlashedFunds(t *testing.T) { t.Parallel()