Commit 1dc35eab authored by Ralph Pichler's avatar Ralph Pichler Committed by GitHub

debugapi: set received / sent to 0 if no settlements (#1213)

parent ecbb71e5
...@@ -107,6 +107,8 @@ func (s *server) peerSettlementsHandler(w http.ResponseWriter, r *http.Request) ...@@ -107,6 +107,8 @@ func (s *server) peerSettlementsHandler(w http.ResponseWriter, r *http.Request)
s.Logger.Errorf("debug api: settlements peer: can't get peer %s received settlement", peer.String()) s.Logger.Errorf("debug api: settlements peer: can't get peer %s received settlement", peer.String())
jsonhttp.InternalServerError(w, errCantSettlementsPeer) jsonhttp.InternalServerError(w, errCantSettlementsPeer)
return return
} else {
received = big.NewInt(0)
} }
} }
...@@ -121,6 +123,8 @@ func (s *server) peerSettlementsHandler(w http.ResponseWriter, r *http.Request) ...@@ -121,6 +123,8 @@ func (s *server) peerSettlementsHandler(w http.ResponseWriter, r *http.Request)
s.Logger.Errorf("debug api: settlements peer: can't get peer %s sent settlement", peer.String()) s.Logger.Errorf("debug api: settlements peer: can't get peer %s sent settlement", peer.String())
jsonhttp.InternalServerError(w, errCantSettlementsPeer) jsonhttp.InternalServerError(w, errCantSettlementsPeer)
return return
} else {
sent = big.NewInt(0)
} }
} }
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"github.com/ethersphere/bee/pkg/debugapi" "github.com/ethersphere/bee/pkg/debugapi"
"github.com/ethersphere/bee/pkg/jsonhttp" "github.com/ethersphere/bee/pkg/jsonhttp"
"github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest" "github.com/ethersphere/bee/pkg/jsonhttp/jsonhttptest"
"github.com/ethersphere/bee/pkg/settlement"
"github.com/ethersphere/bee/pkg/settlement/swap/mock" "github.com/ethersphere/bee/pkg/settlement/swap/mock"
"github.com/ethersphere/bee/pkg/swarm" "github.com/ethersphere/bee/pkg/swarm"
) )
...@@ -112,6 +113,50 @@ func TestSettlementsPeers(t *testing.T) { ...@@ -112,6 +113,50 @@ func TestSettlementsPeers(t *testing.T) {
) )
} }
func TestSettlementsPeersNoSettlements(t *testing.T) {
peer := "bff2c89e85e78c38bd89fca1acc996afb876c21bf5a8482ad798ce15f1c223fa"
noErrFunc := func(swarm.Address) (*big.Int, error) {
return big.NewInt(1000000000000000000), nil
}
errFunc := func(swarm.Address) (*big.Int, error) {
return nil, settlement.ErrPeerNoSettlements
}
t.Run("no sent", func(t *testing.T) {
testServer := newTestServer(t, testServerOptions{
SettlementOpts: []mock.Option{
mock.WithSettlementSentFunc(errFunc),
mock.WithSettlementRecvFunc(noErrFunc),
},
})
jsonhttptest.Request(t, testServer.Client, http.MethodGet, "/settlements/"+peer, http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.SettlementResponse{
Peer: peer,
SettlementSent: big.NewInt(0),
SettlementReceived: big.NewInt(1000000000000000000),
}),
)
})
t.Run("no received", func(t *testing.T) {
testServer := newTestServer(t, testServerOptions{
SettlementOpts: []mock.Option{
mock.WithSettlementSentFunc(noErrFunc),
mock.WithSettlementRecvFunc(errFunc),
},
})
jsonhttptest.Request(t, testServer.Client, http.MethodGet, "/settlements/"+peer, http.StatusOK,
jsonhttptest.WithExpectedJSONResponse(debugapi.SettlementResponse{
Peer: peer,
SettlementSent: big.NewInt(1000000000000000000),
SettlementReceived: big.NewInt(0),
}),
)
})
}
func TestSettlementsPeersError(t *testing.T) { func TestSettlementsPeersError(t *testing.T) {
peer := "bff2c89e85e78c38bd89fca1acc996afb876c21bf5a8482ad798ce15f1c223fa" peer := "bff2c89e85e78c38bd89fca1acc996afb876c21bf5a8482ad798ce15f1c223fa"
wantErr := errors.New("Error") wantErr := errors.New("Error")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment