htlcswitch/test: use single channel restore function
This commit refactors test code around channel restoration in unit tests to make it easier to use.
This commit is contained in:
2 files changed
+98
-62
No files matched your search
+24
-16
@@ -180,7 +180,7 @@ func TestChannelLinkSingleHopPayment(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup a alice-bob network.
|
||||
aliceChannel, bobChannel, cleanUp, err := createTwoClusterChannels(
|
||||
alice, bob, cleanUp, err := createTwoClusterChannels(
|
||||
btcutil.SatoshiPerBitcoin*3,
|
||||
btcutil.SatoshiPerBitcoin*5)
|
||||
if err != nil {
|
||||
@@ -188,7 +188,9 @@ func TestChannelLinkSingleHopPayment(t *testing.T) {
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
n := newTwoHopNetwork(t, aliceChannel, bobChannel, testStartingHeight)
|
||||
n := newTwoHopNetwork(
|
||||
t, alice.channel, bob.channel, testStartingHeight,
|
||||
)
|
||||
if err := n.start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -1592,7 +1594,7 @@ func (m *mockPeer) Address() net.Addr {
|
||||
|
||||
func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
||||
ChannelLink, *lnwallet.LightningChannel, chan time.Time, func() error,
|
||||
func(), chanRestoreFunc, error) {
|
||||
func(), func() (*lnwallet.LightningChannel, error), error) {
|
||||
|
||||
var chanIDBytes [8]byte
|
||||
if _, err := io.ReadFull(rand.Reader, chanIDBytes[:]); err != nil {
|
||||
@@ -1602,7 +1604,7 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
||||
chanID := lnwire.NewShortChanIDFromInt(
|
||||
binary.BigEndian.Uint64(chanIDBytes[:]))
|
||||
|
||||
aliceChannel, bobChannel, fCleanUp, restore, err := createTestChannel(
|
||||
aliceLc, bobLc, fCleanUp, err := createTestChannel(
|
||||
alicePrivKey, bobPrivKey, chanAmt, chanAmt,
|
||||
chanReserve, chanReserve, chanID,
|
||||
)
|
||||
@@ -1628,7 +1630,7 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
||||
|
||||
pCache := newMockPreimageCache()
|
||||
|
||||
aliceDb := aliceChannel.State().Db
|
||||
aliceDb := aliceLc.channel.State().Db
|
||||
aliceSwitch, err := initSwitchWithDB(testStartingHeight, aliceDb)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, nil, err
|
||||
@@ -1668,7 +1670,7 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
||||
}
|
||||
|
||||
const startingHeight = 100
|
||||
aliceLink := NewChannelLink(aliceCfg, aliceChannel)
|
||||
aliceLink := NewChannelLink(aliceCfg, aliceLc.channel)
|
||||
start := func() error {
|
||||
return aliceSwitch.AddLink(aliceLink)
|
||||
}
|
||||
@@ -1687,7 +1689,8 @@ func newSingleLinkTestHarness(chanAmt, chanReserve btcutil.Amount) (
|
||||
defer fCleanUp()
|
||||
}
|
||||
|
||||
return aliceLink, bobChannel, bticker.Force, start, cleanUp, restore, nil
|
||||
return aliceLink, bobLc.channel, bticker.Force, start, cleanUp,
|
||||
aliceLc.restore, nil
|
||||
}
|
||||
|
||||
func assertLinkBandwidth(t *testing.T, link ChannelLink,
|
||||
@@ -2546,7 +2549,9 @@ func TestChannelLinkTrimCircuitsPending(t *testing.T) {
|
||||
t.Fatalf("unable to start test harness: %v", err)
|
||||
}
|
||||
|
||||
alice := newPersistentLinkHarness(t, aliceLink, batchTicker, restore)
|
||||
alice := newPersistentLinkHarness(
|
||||
t, aliceLink, batchTicker, restore,
|
||||
)
|
||||
|
||||
// Compute the static fees that will be used to determine the
|
||||
// correctness of Alice's bandwidth when forwarding HTLCs.
|
||||
@@ -2818,7 +2823,9 @@ func TestChannelLinkTrimCircuitsNoCommit(t *testing.T) {
|
||||
t.Fatalf("unable to start test harness: %v", err)
|
||||
}
|
||||
|
||||
alice := newPersistentLinkHarness(t, aliceLink, batchTicker, restore)
|
||||
alice := newPersistentLinkHarness(
|
||||
t, aliceLink, batchTicker, restore,
|
||||
)
|
||||
|
||||
// We'll put Alice into hodl.Commit mode, such that the circuits for any
|
||||
// outgoing ADDs are opened, but the changes are not committed in the
|
||||
@@ -3980,14 +3987,15 @@ type persistentLinkHarness struct {
|
||||
batchTicker chan time.Time
|
||||
msgs chan lnwire.Message
|
||||
|
||||
restoreChan chanRestoreFunc
|
||||
restoreChan func() (*lnwallet.LightningChannel, error)
|
||||
}
|
||||
|
||||
// newPersistentLinkHarness initializes a new persistentLinkHarness and derives
|
||||
// the supporting references from the active link.
|
||||
func newPersistentLinkHarness(t *testing.T, link ChannelLink,
|
||||
batchTicker chan time.Time,
|
||||
restore chanRestoreFunc) *persistentLinkHarness {
|
||||
restore func() (*lnwallet.LightningChannel,
|
||||
error)) *persistentLinkHarness {
|
||||
|
||||
coreLink := link.(*channelLink)
|
||||
|
||||
@@ -4034,7 +4042,7 @@ func (h *persistentLinkHarness) restart(restartSwitch bool,
|
||||
// state, we will restore the persisted state to ensure we always start
|
||||
// the link in a consistent state.
|
||||
var err error
|
||||
h.channel, _, err = h.restoreChan()
|
||||
h.channel, err = h.restoreChan()
|
||||
if err != nil {
|
||||
h.t.Fatalf("unable to restore channels: %v", err)
|
||||
}
|
||||
@@ -5573,7 +5581,7 @@ func TestChannelLinkCanceledInvoice(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Setup a alice-bob network.
|
||||
aliceChannel, bobChannel, cleanUp, err := createTwoClusterChannels(
|
||||
alice, bob, cleanUp, err := createTwoClusterChannels(
|
||||
btcutil.SatoshiPerBitcoin*3,
|
||||
btcutil.SatoshiPerBitcoin*5)
|
||||
if err != nil {
|
||||
@@ -5581,7 +5589,7 @@ func TestChannelLinkCanceledInvoice(t *testing.T) {
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
n := newTwoHopNetwork(t, aliceChannel, bobChannel, testStartingHeight)
|
||||
n := newTwoHopNetwork(t, alice.channel, bob.channel, testStartingHeight)
|
||||
if err := n.start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -5638,7 +5646,7 @@ type hodlInvoiceTestCtx struct {
|
||||
|
||||
func newHodlInvoiceTestCtx(t *testing.T) (*hodlInvoiceTestCtx, error) {
|
||||
// Setup a alice-bob network.
|
||||
aliceChannel, bobChannel, cleanUp, err := createTwoClusterChannels(
|
||||
alice, bob, cleanUp, err := createTwoClusterChannels(
|
||||
btcutil.SatoshiPerBitcoin*3,
|
||||
btcutil.SatoshiPerBitcoin*5,
|
||||
)
|
||||
@@ -5646,7 +5654,7 @@ func newHodlInvoiceTestCtx(t *testing.T) (*hodlInvoiceTestCtx, error) {
|
||||
t.Fatalf("unable to create channel: %v", err)
|
||||
}
|
||||
|
||||
n := newTwoHopNetwork(t, aliceChannel, bobChannel, testStartingHeight)
|
||||
n := newTwoHopNetwork(t, alice.channel, bob.channel, testStartingHeight)
|
||||
if err := n.start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user