channeldb: test of payment statuses transitions
This commit is contained in:
parent
7296cfb425
commit
7f6fbd4533
@ -40,6 +40,14 @@ func makeFakePayment() *OutgoingPayment {
|
||||
return fakePayment
|
||||
}
|
||||
|
||||
func makeFakePaymentHash() [32]byte {
|
||||
var paymentHash [32]byte
|
||||
rBytes, _ := randomBytes(0, 32)
|
||||
copy(paymentHash[:], rBytes)
|
||||
|
||||
return paymentHash
|
||||
}
|
||||
|
||||
// randomBytes creates random []byte with length in range [minLen, maxLen)
|
||||
func randomBytes(minLen, maxLen int) ([]byte, error) {
|
||||
randBuf := make([]byte, minLen+rand.Intn(maxLen-minLen))
|
||||
@ -195,3 +203,51 @@ func TestOutgoingPaymentWorkflow(t *testing.T) {
|
||||
len(paymentsAfterDeletion), 0)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPaymentStatusWorkflow(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
db, cleanUp, err := makeTestDB()
|
||||
defer cleanUp()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make test db: %v", err)
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
paymentHash [32]byte
|
||||
status PaymentStatus
|
||||
}{
|
||||
{
|
||||
paymentHash: makeFakePaymentHash(),
|
||||
status: StatusGrounded,
|
||||
},
|
||||
{
|
||||
paymentHash: makeFakePaymentHash(),
|
||||
status: StatusInFlight,
|
||||
},
|
||||
{
|
||||
paymentHash: makeFakePaymentHash(),
|
||||
status: StatusCompleted,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
err := db.UpdatePaymentStatus(testCase.paymentHash, testCase.status)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to put payment in DB: %v", err)
|
||||
}
|
||||
|
||||
status, err := db.FetchPaymentStatus(testCase.paymentHash)
|
||||
if err != nil {
|
||||
t.Fatalf("unable to fetch payments from DB: %v", err)
|
||||
}
|
||||
|
||||
if status != testCase.status {
|
||||
t.Fatalf("Wrong payments status after reading from DB."+
|
||||
"Got %v, want %v",
|
||||
spew.Sdump(status),
|
||||
spew.Sdump(testCase.status),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user