add unit test to reproduce issue

This commit is contained in:
kiwiidb
2023-05-05 11:27:05 +02:00
parent 79b99c9aa4
commit 7f7853605d

View File

@@ -3,6 +3,7 @@ package integration_tests
import (
"bytes"
"context"
"encoding/hex"
"encoding/json"
"fmt"
"log"
@@ -87,6 +88,20 @@ func (suite *InvoiceTestSuite) TestAddInvoiceForNonExistingUser() {
nonExistingLogin := suite.aliceLogin.Login + "abc"
suite.createInvoiceReqError(10, "test invoice without token", nonExistingLogin)
}
func (suite *InvoiceTestSuite) TestPreimageEntropy() {
user, _ := suite.service.FindUserByLogin(context.Background(), suite.aliceLogin.Login)
preimageChars := map[byte]int{}
for i := 0; i < 1000; i++ {
inv, err := suite.service.AddIncomingInvoice(context.Background(), user.ID, 10, "test entropy", "")
assert.NoError(suite.T(), err)
primgBytes, _ := hex.DecodeString(inv.Preimage)
for _, char := range primgBytes {
preimageChars[char] += 1
}
}
//check that we use all possible byte values
assert.Equal(suite.T(), 255, len(preimageChars))
}
func TestInvoiceSuite(t *testing.T) {
suite.Run(t, new(InvoiceTestSuite))