2017-05-05 19:43:11 +03:00
|
|
|
package channeldb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"reflect"
|
|
|
|
|
|
|
|
"github.com/go-errors/errors"
|
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestWaitingProofStore tests add/get/remove functions of the waiting proof
|
|
|
|
// storage.
|
|
|
|
func TestWaitingProofStore(t *testing.T) {
|
2017-06-17 01:59:20 +03:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-06-24 13:50:11 +03:00
|
|
|
db, cleanup, err := MakeTestDB()
|
2017-05-05 19:43:11 +03:00
|
|
|
if err != nil {
|
2019-09-12 16:49:11 +03:00
|
|
|
t.Fatalf("failed to make test database: %s", err)
|
2017-05-05 19:43:11 +03:00
|
|
|
}
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
proof1 := NewWaitingProof(true, &lnwire.AnnounceSignatures{
|
2018-01-31 07:19:40 +03:00
|
|
|
NodeSignature: wireSig,
|
|
|
|
BitcoinSignature: wireSig,
|
2017-05-05 19:43:11 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
store, err := NewWaitingProofStore(db)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to create the waiting proofs storage: %v",
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := store.Add(proof1); err != nil {
|
|
|
|
t.Fatalf("unable add proof to storage: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
proof2, err := store.Get(proof1.Key())
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable retrieve proof from storage: %v", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(proof1, proof2) {
|
|
|
|
t.Fatal("wrong proof retrieved")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := store.Get(proof1.OppositeKey()); err != ErrWaitingProofNotFound {
|
|
|
|
t.Fatalf("proof shouldn't be found: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := store.Remove(proof1.Key()); err != nil {
|
|
|
|
t.Fatalf("unable remove proof from storage: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := store.ForAll(func(proof *WaitingProof) error {
|
|
|
|
return errors.New("storage should be empty")
|
2020-10-20 17:18:40 +03:00
|
|
|
}, func() {}); err != nil && err != ErrWaitingProofNotFound {
|
2017-05-05 19:43:11 +03:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|