lnd.xprv/channeldb/waitingproof_test.go
Olaoluwa Osuntokun 5e9166e478
channeldb: use raw pub keys and signatures directly in vertex/edge structs
In this commit, we make an API change that’s meant to reduce the amount
of garbage we generate when doing pathfinding or syncing nodes with our
latest graph state. Before this commit, we would always have to fully
decode the public key and signatures when reading a edge or vertex
struct. For the edges, we may need several EC operations to fully
decode all the pubkeys. This has been seen to generate a ton of
garbage, as well as slow down path finding a good bit.

To remedy this, we’ll now only ever read the *raw* bytes from disk. In
the event that we actually need to verify a signature (or w/e), only
*then* will we fully decode everything.
2018-02-06 20:14:31 -08:00

60 lines
1.3 KiB
Go

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) {
t.Parallel()
db, cleanup, err := makeTestDB()
if err != nil {
}
defer cleanup()
proof1 := NewWaitingProof(true, &lnwire.AnnounceSignatures{
NodeSignature: wireSig,
BitcoinSignature: wireSig,
})
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")
}); err != nil && err != ErrWaitingProofNotFound {
t.Fatal(err)
}
}