htlcswitch: update tests to account for new API changes
This commit is contained in:
parent
dbe76a1507
commit
e34850c7af
@ -17,6 +17,7 @@ import (
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
@ -1445,6 +1446,11 @@ func newSingleLinkTestHarness(chanAmt btcutil.Amount) (ChannelLink, func(), erro
|
||||
}
|
||||
)
|
||||
|
||||
pCache := &mockPreimageCache{
|
||||
// hash -> preimage
|
||||
preimageMap: make(map[[32]byte][]byte),
|
||||
}
|
||||
|
||||
aliceCfg := ChannelLinkConfig{
|
||||
FwrdingPolicy: globalPolicy,
|
||||
Peer: &alicePeer,
|
||||
@ -1454,8 +1460,12 @@ func newSingleLinkTestHarness(chanAmt btcutil.Amount) (ChannelLink, func(), erro
|
||||
return obfuscator, lnwire.CodeNone
|
||||
},
|
||||
GetLastChannelUpdate: mockGetChanUpdateMessage,
|
||||
Registry: invoiveRegistry,
|
||||
BlockEpochs: globalEpoch,
|
||||
PreimageCache: pCache,
|
||||
UpdateContractSignals: func(*contractcourt.ContractSignals) error {
|
||||
return nil
|
||||
},
|
||||
Registry: invoiveRegistry,
|
||||
BlockEpochs: globalEpoch,
|
||||
}
|
||||
|
||||
const startingHeight = 100
|
||||
@ -2327,3 +2337,5 @@ func TestChannelLinkRejectDuplicatePayment(t *testing.T) {
|
||||
t.Fatal("error haven't been received")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(roasbeef): add test for re-sending after hodl mode, to settle any lingering
|
||||
|
@ -16,6 +16,7 @@ import (
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
@ -25,6 +26,35 @@ import (
|
||||
"github.com/roasbeef/btcutil"
|
||||
)
|
||||
|
||||
type mockPreimageCache struct {
|
||||
sync.Mutex
|
||||
preimageMap map[[32]byte][]byte
|
||||
}
|
||||
|
||||
func (m *mockPreimageCache) LookupPreimage(hash []byte) ([]byte, bool) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
var h [32]byte
|
||||
copy(h[:], hash)
|
||||
|
||||
p, ok := m.preimageMap[h]
|
||||
return p, ok
|
||||
}
|
||||
|
||||
func (m *mockPreimageCache) AddPreimage(preimage []byte) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
m.preimageMap[sha256.Sum256(preimage[:])] = preimage
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockPreimageCache) SubcribeUpdates() *contractcourt.WitnessSubcription {
|
||||
return nil
|
||||
}
|
||||
|
||||
type mockFeeEstimator struct {
|
||||
byteFeeIn chan btcutil.Amount
|
||||
weightFeeIn chan btcutil.Amount
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/contractcourt"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/shachain"
|
||||
@ -261,13 +262,20 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
||||
aliceSigner := &mockSigner{aliceKeyPriv}
|
||||
bobSigner := &mockSigner{bobKeyPriv}
|
||||
|
||||
channelAlice, err := lnwallet.NewLightningChannel(aliceSigner,
|
||||
nil, estimator, aliceChannelState)
|
||||
pCache := &mockPreimageCache{
|
||||
// hash -> preimage
|
||||
preimageMap: make(map[[32]byte][]byte),
|
||||
}
|
||||
|
||||
channelAlice, err := lnwallet.NewLightningChannel(
|
||||
aliceSigner, nil, pCache, aliceChannelState,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
channelBob, err := lnwallet.NewLightningChannel(bobSigner, nil,
|
||||
estimator, bobChannelState)
|
||||
channelBob, err := lnwallet.NewLightningChannel(
|
||||
bobSigner, nil, pCache, bobChannelState,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
@ -311,7 +319,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
||||
}
|
||||
|
||||
newAliceChannel, err := lnwallet.NewLightningChannel(aliceSigner,
|
||||
nil, estimator, aliceStoredChannel)
|
||||
nil, nil, aliceStoredChannel)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Errorf("unable to create new channel: %v",
|
||||
err)
|
||||
@ -336,7 +344,7 @@ func createTestChannel(alicePrivKey, bobPrivKey []byte,
|
||||
}
|
||||
|
||||
newBobChannel, err := lnwallet.NewLightningChannel(bobSigner, nil,
|
||||
estimator, bobStoredChannel)
|
||||
nil, bobStoredChannel)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Errorf("unable to create new channel: %v",
|
||||
err)
|
||||
@ -717,6 +725,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
|
||||
pCache := &mockPreimageCache{
|
||||
// hash -> preimage
|
||||
preimageMap: make(map[[32]byte][]byte),
|
||||
}
|
||||
|
||||
globalPolicy := ForwardingPolicy{
|
||||
MinHTLC: lnwire.NewMSatFromSatoshis(5),
|
||||
BaseFee: lnwire.NewMSatFromSatoshis(1),
|
||||
@ -744,7 +757,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
Registry: aliceServer.registry,
|
||||
BlockEpochs: aliceEpoch,
|
||||
FeeEstimator: feeEstimator,
|
||||
SyncStates: true,
|
||||
PreimageCache: pCache,
|
||||
UpdateContractSignals: func(*contractcourt.ContractSignals) error {
|
||||
return nil
|
||||
},
|
||||
SyncStates: true,
|
||||
},
|
||||
aliceChannel,
|
||||
startingHeight,
|
||||
@ -752,6 +769,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
if err := aliceServer.htlcSwitch.addLink(aliceChannelLink); err != nil {
|
||||
t.Fatalf("unable to add alice channel link: %v", err)
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
<-aliceChannelLink.(*channelLink).htlcUpdates
|
||||
}
|
||||
}()
|
||||
|
||||
bobFirstEpochChan := make(chan *chainntnfs.BlockEpoch)
|
||||
bobFirstEpoch := &chainntnfs.BlockEpochEvent{
|
||||
@ -773,7 +795,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
Registry: bobServer.registry,
|
||||
BlockEpochs: bobFirstEpoch,
|
||||
FeeEstimator: feeEstimator,
|
||||
SyncStates: true,
|
||||
PreimageCache: pCache,
|
||||
UpdateContractSignals: func(*contractcourt.ContractSignals) error {
|
||||
return nil
|
||||
},
|
||||
SyncStates: true,
|
||||
},
|
||||
firstBobChannel,
|
||||
startingHeight,
|
||||
@ -781,6 +807,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
if err := bobServer.htlcSwitch.addLink(firstBobChannelLink); err != nil {
|
||||
t.Fatalf("unable to add first bob channel link: %v", err)
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
<-firstBobChannelLink.(*channelLink).htlcUpdates
|
||||
}
|
||||
}()
|
||||
|
||||
bobSecondEpochChan := make(chan *chainntnfs.BlockEpoch)
|
||||
bobSecondEpoch := &chainntnfs.BlockEpochEvent{
|
||||
@ -802,7 +833,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
Registry: bobServer.registry,
|
||||
BlockEpochs: bobSecondEpoch,
|
||||
FeeEstimator: feeEstimator,
|
||||
SyncStates: true,
|
||||
PreimageCache: pCache,
|
||||
UpdateContractSignals: func(*contractcourt.ContractSignals) error {
|
||||
return nil
|
||||
},
|
||||
SyncStates: true,
|
||||
},
|
||||
secondBobChannel,
|
||||
startingHeight,
|
||||
@ -810,6 +845,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
if err := bobServer.htlcSwitch.addLink(secondBobChannelLink); err != nil {
|
||||
t.Fatalf("unable to add second bob channel link: %v", err)
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
<-secondBobChannelLink.(*channelLink).htlcUpdates
|
||||
}
|
||||
}()
|
||||
|
||||
carolBlockEpoch := make(chan *chainntnfs.BlockEpoch)
|
||||
carolEpoch := &chainntnfs.BlockEpochEvent{
|
||||
@ -831,7 +871,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
Registry: carolServer.registry,
|
||||
BlockEpochs: carolEpoch,
|
||||
FeeEstimator: feeEstimator,
|
||||
SyncStates: true,
|
||||
PreimageCache: pCache,
|
||||
UpdateContractSignals: func(*contractcourt.ContractSignals) error {
|
||||
return nil
|
||||
},
|
||||
SyncStates: true,
|
||||
},
|
||||
carolChannel,
|
||||
startingHeight,
|
||||
@ -839,6 +883,11 @@ func newThreeHopNetwork(t testing.TB, aliceChannel, firstBobChannel,
|
||||
if err := carolServer.htlcSwitch.addLink(carolChannelLink); err != nil {
|
||||
t.Fatalf("unable to add carol channel link: %v", err)
|
||||
}
|
||||
go func() {
|
||||
for {
|
||||
<-carolChannelLink.(*channelLink).htlcUpdates
|
||||
}
|
||||
}()
|
||||
|
||||
return &threeHopNetwork{
|
||||
aliceServer: aliceServer,
|
||||
|
Loading…
Reference in New Issue
Block a user