mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 18:10:34 +01:00
9a6bb19770
Messages: - UpdateFulfillHTLC - UpdateFee - UpdateFailMalformedHTLC - UpdateFailHTLC - UpdateAddHTLC - Shutdown - RevokeAndAck - ReplyShortChanIDsEnd - ReplyChannelRange - QueryShortChanIDs - QueryChannelRange - NodeAnnouncement - Init - GossipTimestampRange - FundingSigned - FundingLocked - FundingCreated - CommitSig - ClosingSigned - ChannelUpdate - ChannelReestablish - ChannelAnnouncement - AnnounceSignatures lnwire: update quickcheck tests, use constant for Error multi: update unit tests to pass deep equal assertions with messages In this commit, we update a series of unit tests in the code base to now pass due to the new wire message encode/decode logic. In many instances, we'll now manually set the extra bytes to an empty byte slice to avoid comparisons that fail due to one message having an empty byte slice and the other having a nil pointer.
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package channeldb
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"reflect"
|
|
|
|
"github.com/davecgh/go-spew/spew"
|
|
"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 {
|
|
t.Fatalf("failed to make test database: %s", err)
|
|
}
|
|
defer cleanup()
|
|
|
|
proof1 := NewWaitingProof(true, &lnwire.AnnounceSignatures{
|
|
NodeSignature: wireSig,
|
|
BitcoinSignature: wireSig,
|
|
ExtraOpaqueData: make([]byte, 0),
|
|
})
|
|
|
|
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.Fatalf("wrong proof retrieved: expected %v, got %v",
|
|
spew.Sdump(proof1), spew.Sdump(proof2))
|
|
}
|
|
|
|
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")
|
|
}, func() {}); err != nil && err != ErrWaitingProofNotFound {
|
|
t.Fatal(err)
|
|
}
|
|
}
|