From 389ecb535ba500693ebe4071545ef4dbe531efdc Mon Sep 17 00:00:00 2001 From: Ononiwu Maureen Date: Thu, 14 Mar 2024 14:45:27 +0100 Subject: [PATCH] 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 --- peer/brontide_test.go | 36 +++++++++++++++++++----------------- peer/test_utils.go | 15 ++++++++------- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/peer/brontide_test.go b/peer/brontide_test.go index 8ea8846b2..5772e9679 100644 --- a/peer/brontide_test.go +++ b/peer/brontide_test.go @@ -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") diff --git a/peer/test_utils.go b/peer/test_utils.go index 05bfe6ad4..5080043a2 100644 --- a/peer/test_utils.go +++ b/peer/test_utils.go @@ -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) {