mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
chancloser: rewrite tests in terms of new ChanCloser methods
This commit is contained in:
parent
f81e7ada4c
commit
704eb84bcb
1 changed files with 43 additions and 35 deletions
|
@ -192,7 +192,7 @@ func (m *mockChannel) CompleteCooperativeClose(localSig,
|
||||||
proposedFee btcutil.Amount,
|
proposedFee btcutil.Amount,
|
||||||
_ ...lnwallet.ChanCloseOpt) (*wire.MsgTx, btcutil.Amount, error) {
|
_ ...lnwallet.ChanCloseOpt) (*wire.MsgTx, btcutil.Amount, error) {
|
||||||
|
|
||||||
return nil, 0, nil
|
return &wire.MsgTx{}, 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockChannel) LocalBalanceDust() bool {
|
func (m *mockChannel) LocalBalanceDust() bool {
|
||||||
|
@ -396,7 +396,7 @@ func TestMaxFeeBailOut(t *testing.T) {
|
||||||
FeeSatoshis: absoluteFee * 2,
|
FeeSatoshis: absoluteFee * 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := chanCloser.ProcessCloseMsg(closeMsg)
|
_, err := chanCloser.ReceiveClosingSigned(*closeMsg)
|
||||||
|
|
||||||
switch isInitiator {
|
switch isInitiator {
|
||||||
// If we're the initiator, then we expect an error at
|
// If we're the initiator, then we expect an error at
|
||||||
|
@ -472,13 +472,6 @@ func TestParseUpfrontShutdownAddress(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertType[T any](t *testing.T, typ any) T {
|
|
||||||
value, ok := typ.(T)
|
|
||||||
require.True(t, ok)
|
|
||||||
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestTaprootFastClose tests that we are able to properly execute a fast close
|
// TestTaprootFastClose tests that we are able to properly execute a fast close
|
||||||
// (skip negotiation) for taproot channels.
|
// (skip negotiation) for taproot channels.
|
||||||
func TestTaprootFastClose(t *testing.T) {
|
func TestTaprootFastClose(t *testing.T) {
|
||||||
|
@ -535,27 +528,39 @@ func TestTaprootFastClose(t *testing.T) {
|
||||||
|
|
||||||
// Bob will then process this message. As he's the responder, he should
|
// Bob will then process this message. As he's the responder, he should
|
||||||
// only send the shutdown message back to Alice.
|
// only send the shutdown message back to Alice.
|
||||||
bobMsgs, closeFinished, err := bobCloser.ProcessCloseMsg(msg)
|
oShutdown, err := bobCloser.ReceiveShutdown(*msg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, closeFinished)
|
oClosingSigned, err := bobCloser.BeginNegotiation()
|
||||||
require.Len(t, bobMsgs, 1)
|
require.NoError(t, err)
|
||||||
require.IsType(t, &lnwire.Shutdown{}, bobMsgs[0])
|
tx, _ := bobCloser.ClosingTx()
|
||||||
|
require.Nil(t, tx)
|
||||||
|
require.True(t, oShutdown.IsSome())
|
||||||
|
require.True(t, oClosingSigned.IsNone())
|
||||||
|
|
||||||
|
bobShutdown := oShutdown.UnsafeFromSome()
|
||||||
|
|
||||||
// Alice should process the shutdown message, and create a closing
|
// Alice should process the shutdown message, and create a closing
|
||||||
// signed of her own.
|
// signed of her own.
|
||||||
aliceMsgs, closeFinished, err := aliceCloser.ProcessCloseMsg(bobMsgs[0])
|
oShutdown, err = aliceCloser.ReceiveShutdown(bobShutdown)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, closeFinished)
|
oClosingSigned, err = aliceCloser.BeginNegotiation()
|
||||||
require.Len(t, aliceMsgs, 1)
|
require.NoError(t, err)
|
||||||
require.IsType(t, &lnwire.ClosingSigned{}, aliceMsgs[0])
|
tx, _ = aliceCloser.ClosingTx()
|
||||||
|
require.Nil(t, tx)
|
||||||
|
require.True(t, oShutdown.IsNone())
|
||||||
|
require.True(t, oClosingSigned.IsSome())
|
||||||
|
|
||||||
|
aliceClosingSigned := oClosingSigned.UnsafeFromSome()
|
||||||
|
|
||||||
// Next, Bob will process the closing signed message, and send back a
|
// Next, Bob will process the closing signed message, and send back a
|
||||||
// new one that should match exactly the offer Alice sent.
|
// new one that should match exactly the offer Alice sent.
|
||||||
bobMsgs, closeFinished, err = bobCloser.ProcessCloseMsg(aliceMsgs[0])
|
oClosingSigned, err = bobCloser.ReceiveClosingSigned(aliceClosingSigned)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, closeFinished)
|
tx, _ = bobCloser.ClosingTx()
|
||||||
require.Len(t, aliceMsgs, 1)
|
require.NotNil(t, tx)
|
||||||
require.IsType(t, &lnwire.ClosingSigned{}, bobMsgs[0])
|
require.True(t, oClosingSigned.IsSome())
|
||||||
|
|
||||||
|
bobClosingSigned := oClosingSigned.UnsafeFromSome()
|
||||||
|
|
||||||
// At this point, Bob has accepted the offer, so he can broadcast the
|
// At this point, Bob has accepted the offer, so he can broadcast the
|
||||||
// closing transaction, and considers the channel closed.
|
// closing transaction, and considers the channel closed.
|
||||||
|
@ -563,38 +568,41 @@ func TestTaprootFastClose(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Bob's fee proposal should exactly match Alice's initial fee.
|
// Bob's fee proposal should exactly match Alice's initial fee.
|
||||||
aliceOffer := assertType[*lnwire.ClosingSigned](t, aliceMsgs[0])
|
require.Equal(
|
||||||
bobOffer := assertType[*lnwire.ClosingSigned](t, bobMsgs[0])
|
t, aliceClosingSigned.FeeSatoshis, bobClosingSigned.FeeSatoshis,
|
||||||
require.Equal(t, aliceOffer.FeeSatoshis, bobOffer.FeeSatoshis)
|
)
|
||||||
|
|
||||||
// If we modify Bob's offer, and try to have Alice process it, then she
|
// If we modify Bob's offer, and try to have Alice process it, then she
|
||||||
// should reject it.
|
// should reject it.
|
||||||
ogOffer := bobOffer.FeeSatoshis
|
ogOffer := bobClosingSigned.FeeSatoshis
|
||||||
bobOffer.FeeSatoshis /= 2
|
bobClosingSigned.FeeSatoshis /= 2
|
||||||
|
|
||||||
_, _, err = aliceCloser.ProcessCloseMsg(bobOffer)
|
_, err = aliceCloser.ReceiveClosingSigned(bobClosingSigned)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Contains(t, err.Error(), "was not accepted")
|
require.Contains(t, err.Error(), "was not accepted")
|
||||||
|
|
||||||
// We'll now restore the original offer before passing it on to Alice.
|
// We'll now restore the original offer before passing it on to Alice.
|
||||||
bobOffer.FeeSatoshis = ogOffer
|
bobClosingSigned.FeeSatoshis = ogOffer
|
||||||
|
|
||||||
// If we use the original offer, then Alice should accept this message,
|
// If we use the original offer, then Alice should accept this message,
|
||||||
// and finalize the shutdown process. We expect a message here as Alice
|
// and finalize the shutdown process. We expect a message here as Alice
|
||||||
// will echo back the final message.
|
// will echo back the final message.
|
||||||
aliceMsgs, closeFinished, err = aliceCloser.ProcessCloseMsg(bobMsgs[0])
|
oClosingSigned, err = aliceCloser.ReceiveClosingSigned(bobClosingSigned)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, closeFinished)
|
tx, _ = aliceCloser.ClosingTx()
|
||||||
require.Len(t, aliceMsgs, 1)
|
require.NotNil(t, tx)
|
||||||
require.IsType(t, &lnwire.ClosingSigned{}, aliceMsgs[0])
|
require.True(t, oClosingSigned.IsSome())
|
||||||
|
|
||||||
|
aliceClosingSigned = oClosingSigned.UnsafeFromSome()
|
||||||
|
|
||||||
// Alice should now also broadcast her closing transaction.
|
// Alice should now also broadcast her closing transaction.
|
||||||
_, err = lnutils.RecvOrTimeout(broadcastSignal, time.Second*1)
|
_, err = lnutils.RecvOrTimeout(broadcastSignal, time.Second*1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Finally, Bob will process Alice's echo message, and conclude.
|
// Finally, Bob will process Alice's echo message, and conclude.
|
||||||
bobMsgs, closeFinished, err = bobCloser.ProcessCloseMsg(aliceMsgs[0])
|
oClosingSigned, err = bobCloser.ReceiveClosingSigned(aliceClosingSigned)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, closeFinished)
|
tx, _ = bobCloser.ClosingTx()
|
||||||
require.Len(t, bobMsgs, 0)
|
require.NotNil(t, tx)
|
||||||
|
require.True(t, oClosingSigned.IsNone())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue