forked from lightningnetwork/lnd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
witness_beacon_test.go
57 lines (44 loc) · 1.22 KB
/
witness_beacon_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package lnd
import (
"testing"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/htlcswitch"
"github.com/lightningnetwork/lnd/htlcswitch/hop"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/stretchr/testify/require"
)
// TestWitnessBeaconIntercept tests that the beacon passes on subscriptions to
// the interceptor correctly.
func TestWitnessBeaconIntercept(t *testing.T) {
var interceptedFwd htlcswitch.InterceptedForward
interceptor := func(fwd htlcswitch.InterceptedForward) error {
interceptedFwd = fwd
return nil
}
p := newPreimageBeacon(
&mockWitnessCache{}, interceptor,
)
preimage := lntypes.Preimage{1, 2, 3}
hash := preimage.Hash()
subscription, err := p.SubscribeUpdates(
lnwire.NewShortChanIDFromInt(1),
&channeldb.HTLC{
RHash: hash,
},
&hop.Payload{},
[]byte{2},
)
require.NoError(t, err)
defer subscription.CancelSubscription()
require.NoError(t, interceptedFwd.Settle(preimage))
update := <-subscription.WitnessUpdates
require.Equal(t, preimage, update)
}
type mockWitnessCache struct {
witnessCache
}
func (w *mockWitnessCache) AddSha256Witnesses(
preimages ...lntypes.Preimage) error {
return nil
}