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