peer: Change createTestPeer name.

In this function `createTestPeer` is changed to
`createTestPeerWithChannel`. This is useful in coming commits where we
decouple the process of creating test peer from the function.

Signed-off-by: Ononiwu Maureen <maureen.ononiwu@outlook.com>
This commit is contained in:
Ononiwu Maureen 2024-03-14 14:45:27 +01:00 committed by Ononiwu Maureen
parent e8a1d4876e
commit 389ecb535b
No known key found for this signature in database
GPG Key ID: 82470E85193AD2DA
2 changed files with 27 additions and 24 deletions

View File

@ -48,7 +48,7 @@ func TestPeerChannelClosureShutdownResponseLinkRemoved(t *testing.T) {
mockSwitch := &mockMessageSwitch{}
alicePeer, bobChan, err := createTestPeer(
alicePeer, bobChan, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, noUpdate, mockSwitch,
)
require.NoError(t, err, "unable to create test channels")
@ -96,7 +96,7 @@ func TestPeerChannelClosureAcceptFeeResponder(t *testing.T) {
mockSwitch := &mockMessageSwitch{}
alicePeer, bobChan, err := createTestPeer(
alicePeer, bobChan, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, noUpdate, mockSwitch,
)
require.NoError(t, err, "unable to create test channels")
@ -201,7 +201,7 @@ func TestPeerChannelClosureAcceptFeeInitiator(t *testing.T) {
mockSwitch := &mockMessageSwitch{}
alicePeer, bobChan, err := createTestPeer(
alicePeer, bobChan, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, noUpdate, mockSwitch,
)
require.NoError(t, err, "unable to create test channels")
@ -325,7 +325,7 @@ func TestPeerChannelClosureFeeNegotiationsResponder(t *testing.T) {
mockSwitch := &mockMessageSwitch{}
alicePeer, bobChan, err := createTestPeer(
alicePeer, bobChan, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, noUpdate, mockSwitch,
)
require.NoError(t, err, "unable to create test channels")
@ -512,7 +512,7 @@ func TestPeerChannelClosureFeeNegotiationsInitiator(t *testing.T) {
mockSwitch := &mockMessageSwitch{}
alicePeer, bobChan, err := createTestPeer(
alicePeer, bobChan, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, noUpdate, mockSwitch,
)
require.NoError(t, err, "unable to create test channels")
@ -840,7 +840,7 @@ func TestCustomShutdownScript(t *testing.T) {
mockSwitch := &mockMessageSwitch{}
// Open a channel.
alicePeer, bobChan, err := createTestPeer(
alicePeer, bobChan, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, test.update,
mockSwitch,
)
@ -1195,7 +1195,7 @@ func TestUpdateNextRevocation(t *testing.T) {
broadcastTxChan := make(chan *wire.MsgTx)
mockSwitch := &mockMessageSwitch{}
alicePeer, bobChan, err := createTestPeer(
alicePeer, bobChan, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, noUpdate, mockSwitch,
)
require.NoError(err, "unable to create test channels")
@ -1412,7 +1412,7 @@ func TestHandleRemovePendingChannel(t *testing.T) {
func TestStartupWriteMessageRace(t *testing.T) {
t.Parallel()
// Set up parameters for createTestPeer.
// Set up parameters for createTestPeerWithChannel.
notifier := &mock.ChainNotifier{
SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
@ -1421,17 +1421,18 @@ func TestStartupWriteMessageRace(t *testing.T) {
broadcastTxChan := make(chan *wire.MsgTx)
mockSwitch := &mockMessageSwitch{}
// Use a callback to extract the channel created by createTestPeer, so
// we can mark it borked below. We can't mark it borked within the
// callback, since the channel hasn't been saved to the DB yet when the
// callback executes.
// Use a callback to extract the channel created by
// createTestPeerWithChannel, so we can mark it borked below.
// We can't mark it borked within the callback, since the channel hasn't
// been saved to the DB yet when the callback executes.
var channel *channeldb.OpenChannel
getChannels := func(a, b *channeldb.OpenChannel) {
channel = a
}
// createTestPeer creates a peer and a channel with that peer.
peer, _, err := createTestPeer(
// createTestPeerWithChannel creates a peer and a channel with that
// peer.
peer, _, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, getChannels, mockSwitch,
)
require.NoError(t, err, "unable to create test channel")
@ -1516,7 +1517,7 @@ func TestStartupWriteMessageRace(t *testing.T) {
func TestRemovePendingChannel(t *testing.T) {
t.Parallel()
// Set up parameters for createTestPeer.
// Set up parameters for createTestPeerWithChannel.
notifier := &mock.ChainNotifier{
SpendChan: make(chan *chainntnfs.SpendDetail),
EpochChan: make(chan *chainntnfs.BlockEpoch),
@ -1525,8 +1526,9 @@ func TestRemovePendingChannel(t *testing.T) {
broadcastTxChan := make(chan *wire.MsgTx)
mockSwitch := &mockMessageSwitch{}
// createTestPeer creates a peer and a channel with that peer.
peer, _, err := createTestPeer(
// createTestPeerWithChannel creates a peer and a channel with that
// peer.
peer, _, err := createTestPeerWithChannel(
t, notifier, broadcastTxChan, noUpdate, mockSwitch,
)
require.NoError(t, err, "unable to create test channel")

View File

@ -48,15 +48,16 @@ var (
testKeyLoc = keychain.KeyLocator{Family: keychain.KeyFamilyNodeKey}
)
// noUpdate is a function which can be used as a parameter in createTestPeer to
// call the setup code with no custom values on the channels set up.
// noUpdate is a function which can be used as a parameter in
// createTestPeerWithChannel to call the setup code with no custom values on
// the channels set up.
var noUpdate = func(a, b *channeldb.OpenChannel) {}
// createTestPeer creates a channel between two nodes, and returns a peer for
// one of the nodes, together with the channel seen from both nodes. It takes
// an updateChan function which can be used to modify the default values on
// the channel states for each peer.
func createTestPeer(t *testing.T, notifier chainntnfs.ChainNotifier,
// createTestPeerWithChannel creates a channel between two nodes, and returns a
// peer for one of the nodes, together with the channel seen from both nodes.
// It takes an updateChan function which can be used to modify the default
// values on the channel states for each peer.
func createTestPeerWithChannel(t *testing.T, notifier chainntnfs.ChainNotifier,
publTx chan *wire.MsgTx, updateChan func(a, b *channeldb.OpenChannel),
mockSwitch *mockMessageSwitch) (
*Brontide, *lnwallet.LightningChannel, error) {