htlcswitch/test: assert on replied failure message
This commit is contained in:
parent
dcf7a8b871
commit
cb85095ab0
@ -334,6 +334,7 @@ var _ hop.Iterator = (*mockHopIterator)(nil)
|
|||||||
// encodes the failure and do not makes any onion obfuscation.
|
// encodes the failure and do not makes any onion obfuscation.
|
||||||
type mockObfuscator struct {
|
type mockObfuscator struct {
|
||||||
ogPacket *sphinx.OnionPacket
|
ogPacket *sphinx.OnionPacket
|
||||||
|
failure lnwire.FailureMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMockObfuscator initializes a dummy mockObfuscator used for testing.
|
// NewMockObfuscator initializes a dummy mockObfuscator used for testing.
|
||||||
@ -366,6 +367,8 @@ func (o *mockObfuscator) Reextract(
|
|||||||
func (o *mockObfuscator) EncryptFirstHop(failure lnwire.FailureMessage) (
|
func (o *mockObfuscator) EncryptFirstHop(failure lnwire.FailureMessage) (
|
||||||
lnwire.OpaqueReason, error) {
|
lnwire.OpaqueReason, error) {
|
||||||
|
|
||||||
|
o.failure = failure
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
if err := lnwire.EncodeFailure(&b, failure, 0); err != nil {
|
if err := lnwire.EncodeFailure(&b, failure, 0); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1336,6 +1336,7 @@ func TestSkipIneligibleLinksMultiHopForward(t *testing.T) {
|
|||||||
// Alice.
|
// Alice.
|
||||||
preimage := [sha256.Size]byte{1}
|
preimage := [sha256.Size]byte{1}
|
||||||
rhash := fastsha256.Sum256(preimage[:])
|
rhash := fastsha256.Sum256(preimage[:])
|
||||||
|
obfuscator := NewMockObfuscator()
|
||||||
packet = &htlcPacket{
|
packet = &htlcPacket{
|
||||||
incomingChanID: aliceChannelLink.ShortChanID(),
|
incomingChanID: aliceChannelLink.ShortChanID(),
|
||||||
incomingHTLCID: 0,
|
incomingHTLCID: 0,
|
||||||
@ -1344,7 +1345,7 @@ func TestSkipIneligibleLinksMultiHopForward(t *testing.T) {
|
|||||||
PaymentHash: rhash,
|
PaymentHash: rhash,
|
||||||
Amount: 1,
|
Amount: 1,
|
||||||
},
|
},
|
||||||
obfuscator: NewMockObfuscator(),
|
obfuscator: obfuscator,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The request to forward should fail as
|
// The request to forward should fail as
|
||||||
@ -1353,6 +1354,11 @@ func TestSkipIneligibleLinksMultiHopForward(t *testing.T) {
|
|||||||
t.Fatalf("forwarding should have failed due to inactive link")
|
t.Fatalf("forwarding should have failed due to inactive link")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
failure := obfuscator.(*mockObfuscator).failure
|
||||||
|
if _, ok := failure.(*lnwire.FailTemporaryChannelFailure); !ok {
|
||||||
|
t.Fatalf("unexpected failure %T", failure)
|
||||||
|
}
|
||||||
|
|
||||||
if s.circuits.NumOpen() != 0 {
|
if s.circuits.NumOpen() != 0 {
|
||||||
t.Fatal("wrong amount of circuits")
|
t.Fatal("wrong amount of circuits")
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user