channeldb: remove math/rand from tests
This commit removes random invoice state selection when testing FetchAllInvoicesWithPaymentHash.
This commit is contained in:
parent
eae45f9ad9
commit
9b60685961
@ -2,7 +2,6 @@ package channeldb
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
mrand "math/rand"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@ -416,23 +415,25 @@ func TestFetchAllInvoicesWithPaymentHash(t *testing.T) {
|
|||||||
t.Fatalf("expected empty list as a result, got: %v", empty)
|
t.Fatalf("expected empty list as a result, got: %v", empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now populate the DB and check if we can get all invoices with their
|
|
||||||
// payment hashes as expected.
|
|
||||||
const numInvoices = 20
|
|
||||||
testPendingInvoices := make(map[lntypes.Hash]*Invoice)
|
|
||||||
testAllInvoices := make(map[lntypes.Hash]*Invoice)
|
|
||||||
|
|
||||||
states := []ContractState{
|
states := []ContractState{
|
||||||
ContractOpen, ContractSettled, ContractCanceled, ContractAccepted,
|
ContractOpen, ContractSettled, ContractCanceled, ContractAccepted,
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := lnwire.MilliSatoshi(1); i <= numInvoices; i++ {
|
numInvoices := len(states) * 2
|
||||||
invoice, err := randInvoice(i)
|
testPendingInvoices := make(map[lntypes.Hash]*Invoice)
|
||||||
|
testAllInvoices := make(map[lntypes.Hash]*Invoice)
|
||||||
|
|
||||||
|
// Now populate the DB and check if we can get all invoices with their
|
||||||
|
// payment hashes as expected.
|
||||||
|
for i := 1; i <= numInvoices; i++ {
|
||||||
|
invoice, err := randInvoice(lnwire.MilliSatoshi(i))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create invoice: %v", err)
|
t.Fatalf("unable to create invoice: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
invoice.State = states[mrand.Intn(len(states))]
|
// Set the contract state of the next invoice such that there's an equal
|
||||||
|
// number for all possbile states.
|
||||||
|
invoice.State = states[i%len(states)]
|
||||||
paymentHash := invoice.Terms.PaymentPreimage.Hash()
|
paymentHash := invoice.Terms.PaymentPreimage.Hash()
|
||||||
|
|
||||||
if invoice.State != ContractSettled && invoice.State != ContractCanceled {
|
if invoice.State != ContractSettled && invoice.State != ContractCanceled {
|
||||||
|
Loading…
Reference in New Issue
Block a user