mirror of
https://github.com/getAlby/lndhub.go.git
synced 2026-01-06 14:35:36 +01:00
chore: allow 0 limits for send/receive amount/volume (#486)
* chore: allow 0 limits for send/receive amount/volume * fix: use pointers for claims * fix: tests to set default as -1 * chore: add 0 check in outgoing exceeded tests * chore: also default max account balance to -1 * chore: remove dbUri :P * chore: remove print statements * chore: add more tests for limits
This commit is contained in:
@@ -79,7 +79,7 @@ func (suite *KeySendTestSuite) TearDownSuite() {
|
||||
|
||||
func (suite *KeySendTestSuite) TestKeysendPayment() {
|
||||
suite.service.Config.ServiceFee = 1
|
||||
aliceFundingSats := 1000
|
||||
aliceFundingSats := 1500
|
||||
externalSatRequested := 500
|
||||
expectedServiceFee := 1
|
||||
//fund alice account
|
||||
@@ -99,6 +99,47 @@ func (suite *KeySendTestSuite) TestKeysendPayment() {
|
||||
}
|
||||
assert.Equal(suite.T(), int64(aliceFundingSats)-int64(externalSatRequested+int(suite.mlnd.fee)+expectedServiceFee), aliceBalance)
|
||||
suite.service.Config.ServiceFee = 0
|
||||
|
||||
var buf bytes.Buffer
|
||||
suite.service.Config.MaxSendAmount = 200
|
||||
rec := httptest.NewRecorder()
|
||||
assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&ExpectedKeySendRequestBody{
|
||||
Amount: int64(externalSatRequested),
|
||||
Destination: "123456789012345678901234567890123456789012345678901234567890abcdef",
|
||||
Memo: "key send test",
|
||||
}))
|
||||
req := httptest.NewRequest(http.MethodPost, "/keysend", &buf)
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.aliceToken))
|
||||
suite.echo.ServeHTTP(rec, req)
|
||||
//should fail because max send amount check
|
||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
||||
resp := &responses.ErrorResponse{}
|
||||
err = json.NewDecoder(rec.Body).Decode(resp)
|
||||
assert.NoError(suite.T(), err)
|
||||
assert.Equal(suite.T(), responses.SendExceededError.Message, resp.Message)
|
||||
|
||||
// check if setting zero as send amount stops
|
||||
suite.service.Config.MaxSendAmount = 0
|
||||
assert.NoError(suite.T(), json.NewEncoder(&buf).Encode(&ExpectedKeySendRequestBody{
|
||||
Amount: int64(externalSatRequested),
|
||||
Destination: "123456789012345678901234567890123456789012345678901234567890abcdef",
|
||||
Memo: "key send test",
|
||||
}))
|
||||
req = httptest.NewRequest(http.MethodPost, "/keysend", &buf)
|
||||
req.Header.Set(echo.HeaderContentType, echo.MIMEApplicationJSON)
|
||||
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", suite.aliceToken))
|
||||
suite.echo.ServeHTTP(rec, req)
|
||||
//should fail because max send amount check
|
||||
assert.Equal(suite.T(), http.StatusBadRequest, rec.Code)
|
||||
resp = &responses.ErrorResponse{}
|
||||
err = json.NewDecoder(rec.Body).Decode(resp)
|
||||
assert.NoError(suite.T(), err)
|
||||
assert.Equal(suite.T(), responses.SendExceededError.Message, resp.Message)
|
||||
|
||||
// restore default and try again, should work now
|
||||
suite.service.Config.MaxSendAmount = -1
|
||||
suite.createKeySendReq(int64(externalSatRequested), "key send test", "123456789012345678901234567890123456789012345678901234567890abcdef", suite.aliceToken)
|
||||
}
|
||||
|
||||
func (suite *KeySendTestSuite) TestKeysendPaymentNonExistentDestination() {
|
||||
|
||||
Reference in New Issue
Block a user