graph/tests: make createChannelEdge assert internally
Update createChannelEdge to take a testing handle, mark itself as a helper, and call require.NoError for funding script generation. All call sites now consume only returned values and no longer plumb an immediately-asserted error value.
This commit is contained in:
2 files changed
+34
-48
No files matched your search
+20
-30
@@ -54,11 +54,10 @@ func TestAddProof(t *testing.T) {
|
|||||||
|
|
||||||
// In order to be able to add the edge we should have a valid funding
|
// In order to be able to add the edge we should have a valid funding
|
||||||
// UTXO within the blockchain.
|
// UTXO within the blockchain.
|
||||||
script, fundingTx, _, chanID, err := createChannelEdge(
|
script, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(), 100, 0,
|
bitcoinKey2.SerializeCompressed(), 100, 0,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable create channel edge")
|
|
||||||
fundingBlock := &wire.MsgBlock{
|
fundingBlock := &wire.MsgBlock{
|
||||||
Transactions: []*wire.MsgTx{fundingTx},
|
Transactions: []*wire.MsgTx{fundingTx},
|
||||||
}
|
}
|
||||||
@@ -142,11 +141,10 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
|
|||||||
|
|
||||||
// Add the edge between the two unknown nodes to the graph, and check
|
// Add the edge between the two unknown nodes to the graph, and check
|
||||||
// that the nodes are found after the fact.
|
// that the nodes are found after the fact.
|
||||||
script, fundingTx, _, chanID, err := createChannelEdge(
|
script, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(), 10000, 500,
|
bitcoinKey2.SerializeCompressed(), 10000, 500,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to create channel edge")
|
|
||||||
fundingBlock := &wire.MsgBlock{
|
fundingBlock := &wire.MsgBlock{
|
||||||
Transactions: []*wire.MsgTx{fundingTx},
|
Transactions: []*wire.MsgTx{fundingTx},
|
||||||
}
|
}
|
||||||
@@ -223,12 +221,11 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
height := startingBlockHeight + i
|
height := startingBlockHeight + i
|
||||||
if i == 5 {
|
if i == 5 {
|
||||||
script, fundingTx, _, chanID, err := createChannelEdge(
|
script, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
chanValue, height,
|
chanValue, height,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
|
||||||
block.Transactions = append(block.Transactions,
|
block.Transactions = append(block.Transactions,
|
||||||
fundingTx)
|
fundingTx)
|
||||||
chanID1 = chanID.ToUint64()
|
chanID1 = chanID.ToUint64()
|
||||||
@@ -254,11 +251,10 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
|||||||
}
|
}
|
||||||
height := uint32(forkHeight) + i
|
height := uint32(forkHeight) + i
|
||||||
if i == 5 {
|
if i == 5 {
|
||||||
script, fundingTx, _, chanID, err := createChannelEdge(
|
script, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
chanValue, height)
|
chanValue, height)
|
||||||
require.NoError(t, err)
|
|
||||||
block.Transactions = append(block.Transactions,
|
block.Transactions = append(block.Transactions,
|
||||||
fundingTx)
|
fundingTx)
|
||||||
chanID2 = chanID.ToUint64()
|
chanID2 = chanID.ToUint64()
|
||||||
@@ -399,12 +395,11 @@ func TestDisconnectedBlocks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
height := startingBlockHeight + i
|
height := startingBlockHeight + i
|
||||||
if i == 5 {
|
if i == 5 {
|
||||||
_, fundingTx, _, chanID, err := createChannelEdge(
|
_, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
chanValue, height,
|
chanValue, height,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
|
||||||
block.Transactions = append(block.Transactions,
|
block.Transactions = append(block.Transactions,
|
||||||
fundingTx)
|
fundingTx)
|
||||||
chanID1 = chanID.ToUint64()
|
chanID1 = chanID.ToUint64()
|
||||||
@@ -429,12 +424,11 @@ func TestDisconnectedBlocks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
height := uint32(forkHeight) + i
|
height := uint32(forkHeight) + i
|
||||||
if i == 5 {
|
if i == 5 {
|
||||||
_, fundingTx, _, chanID, err := createChannelEdge(
|
_, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
chanValue, height,
|
chanValue, height,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
|
||||||
block.Transactions = append(block.Transactions,
|
block.Transactions = append(block.Transactions,
|
||||||
fundingTx)
|
fundingTx)
|
||||||
chanID2 = chanID.ToUint64()
|
chanID2 = chanID.ToUint64()
|
||||||
@@ -557,12 +551,11 @@ func TestChansClosedOfflinePruneGraph(t *testing.T) {
|
|||||||
Transactions: []*wire.MsgTx{},
|
Transactions: []*wire.MsgTx{},
|
||||||
}
|
}
|
||||||
nextHeight := startingBlockHeight + 1
|
nextHeight := startingBlockHeight + 1
|
||||||
script, fundingTx1, chanUTXO, chanID1, err := createChannelEdge(
|
script, fundingTx1, chanUTXO, chanID1 := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
chanValue, uint32(nextHeight),
|
chanValue, uint32(nextHeight),
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable create channel edge")
|
|
||||||
block102.Transactions = append(block102.Transactions, fundingTx1)
|
block102.Transactions = append(block102.Transactions, fundingTx1)
|
||||||
ctx.chain.addBlock(block102, uint32(nextHeight), rand.Uint32())
|
ctx.chain.addBlock(block102, uint32(nextHeight), rand.Uint32())
|
||||||
ctx.chain.setBestBlock(int32(nextHeight))
|
ctx.chain.setBestBlock(int32(nextHeight))
|
||||||
@@ -964,12 +957,11 @@ func TestIsStaleNode(t *testing.T) {
|
|||||||
copy(pub1[:], priv1.PubKey().SerializeCompressed())
|
copy(pub1[:], priv1.PubKey().SerializeCompressed())
|
||||||
copy(pub2[:], priv2.PubKey().SerializeCompressed())
|
copy(pub2[:], priv2.PubKey().SerializeCompressed())
|
||||||
|
|
||||||
script, fundingTx, _, chanID, err := createChannelEdge(
|
script, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
10000, 500,
|
10000, 500,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to create channel edge")
|
|
||||||
fundingBlock := &wire.MsgBlock{
|
fundingBlock := &wire.MsgBlock{
|
||||||
Transactions: []*wire.MsgTx{fundingTx},
|
Transactions: []*wire.MsgTx{fundingTx},
|
||||||
}
|
}
|
||||||
@@ -1033,12 +1025,11 @@ func TestIsKnownEdge(t *testing.T) {
|
|||||||
copy(pub1[:], priv1.PubKey().SerializeCompressed())
|
copy(pub1[:], priv1.PubKey().SerializeCompressed())
|
||||||
copy(pub2[:], priv2.PubKey().SerializeCompressed())
|
copy(pub2[:], priv2.PubKey().SerializeCompressed())
|
||||||
|
|
||||||
script, fundingTx, _, chanID, err := createChannelEdge(
|
script, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
10000, 500,
|
10000, 500,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to create channel edge")
|
|
||||||
fundingBlock := &wire.MsgBlock{
|
fundingBlock := &wire.MsgBlock{
|
||||||
Transactions: []*wire.MsgTx{fundingTx},
|
Transactions: []*wire.MsgTx{fundingTx},
|
||||||
}
|
}
|
||||||
@@ -1079,12 +1070,11 @@ func TestIsStaleEdgePolicy(t *testing.T) {
|
|||||||
copy(pub1[:], priv1.PubKey().SerializeCompressed())
|
copy(pub1[:], priv1.PubKey().SerializeCompressed())
|
||||||
copy(pub2[:], priv2.PubKey().SerializeCompressed())
|
copy(pub2[:], priv2.PubKey().SerializeCompressed())
|
||||||
|
|
||||||
script, fundingTx, _, chanID, err := createChannelEdge(
|
script, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
10000, 500,
|
10000, 500,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable to create channel edge")
|
|
||||||
fundingBlock := &wire.MsgBlock{
|
fundingBlock := &wire.MsgBlock{
|
||||||
Transactions: []*wire.MsgTx{fundingTx},
|
Transactions: []*wire.MsgTx{fundingTx},
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-18
@@ -128,9 +128,11 @@ func randEdgePolicy(t testing.TB, chanID *lnwire.ShortChannelID,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte,
|
func createChannelEdge(t testing.TB, bitcoinKey1, bitcoinKey2 []byte,
|
||||||
chanValue btcutil.Amount, fundingHeight uint32) ([]byte, *wire.MsgTx,
|
chanValue btcutil.Amount, fundingHeight uint32) ([]byte, *wire.MsgTx,
|
||||||
*wire.OutPoint, *lnwire.ShortChannelID, error) {
|
*wire.OutPoint, *lnwire.ShortChannelID) {
|
||||||
|
|
||||||
|
t.Helper()
|
||||||
|
|
||||||
fundingTx := wire.NewMsgTx(2)
|
fundingTx := wire.NewMsgTx(2)
|
||||||
script, tx, err := input.GenFundingPkScript(
|
script, tx, err := input.GenFundingPkScript(
|
||||||
@@ -138,9 +140,7 @@ func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte,
|
|||||||
bitcoinKey2,
|
bitcoinKey2,
|
||||||
int64(chanValue),
|
int64(chanValue),
|
||||||
)
|
)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
return nil, nil, nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
fundingTx.TxOut = append(fundingTx.TxOut, tx)
|
fundingTx.TxOut = append(fundingTx.TxOut, tx)
|
||||||
chanUtxo := wire.OutPoint{
|
chanUtxo := wire.OutPoint{
|
||||||
@@ -155,7 +155,7 @@ func createChannelEdge(bitcoinKey1, bitcoinKey2 []byte,
|
|||||||
TxPosition: 0,
|
TxPosition: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
return script, fundingTx, &chanUtxo, chanID, nil
|
return script, fundingTx, &chanUtxo, chanID
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockChain struct {
|
type mockChain struct {
|
||||||
@@ -429,11 +429,10 @@ func TestEdgeUpdateNotification(t *testing.T) {
|
|||||||
|
|
||||||
// First we'll create the utxo for the channel to be "closed"
|
// First we'll create the utxo for the channel to be "closed"
|
||||||
const chanValue = 10000
|
const chanValue = 10000
|
||||||
script, fundingTx, chanPoint, chanID, err := createChannelEdge(
|
script, fundingTx, chanPoint, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(), chanValue, 0,
|
bitcoinKey2.SerializeCompressed(), chanValue, 0,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable create channel edge")
|
|
||||||
|
|
||||||
// We'll also add a record for the block that included our funding
|
// We'll also add a record for the block that included our funding
|
||||||
// transaction.
|
// transaction.
|
||||||
@@ -589,12 +588,11 @@ func TestNodeUpdateNotification(t *testing.T) {
|
|||||||
// We only accept node announcements from nodes having a known channel,
|
// We only accept node announcements from nodes having a known channel,
|
||||||
// so create one now.
|
// so create one now.
|
||||||
const chanValue = 10000
|
const chanValue = 10000
|
||||||
script, fundingTx, _, chanID, err := createChannelEdge(
|
script, fundingTx, _, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
chanValue, startingBlockHeight,
|
chanValue, startingBlockHeight,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable create channel edge")
|
|
||||||
|
|
||||||
// We'll also add a record for the block that included our funding
|
// We'll also add a record for the block that included our funding
|
||||||
// transaction.
|
// transaction.
|
||||||
@@ -756,12 +754,11 @@ func TestNotificationCancellation(t *testing.T) {
|
|||||||
|
|
||||||
// We'll create the utxo for a new channel.
|
// We'll create the utxo for a new channel.
|
||||||
const chanValue = 10000
|
const chanValue = 10000
|
||||||
script, fundingTx, chanPoint, chanID, err := createChannelEdge(
|
script, fundingTx, chanPoint, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(),
|
bitcoinKey2.SerializeCompressed(),
|
||||||
chanValue, startingBlockHeight,
|
chanValue, startingBlockHeight,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable create channel edge")
|
|
||||||
|
|
||||||
// We'll also add a record for the block that included our funding
|
// We'll also add a record for the block that included our funding
|
||||||
// transaction.
|
// transaction.
|
||||||
@@ -835,12 +832,11 @@ func TestChannelCloseNotification(t *testing.T) {
|
|||||||
|
|
||||||
// First we'll create the utxo for the channel to be "closed"
|
// First we'll create the utxo for the channel to be "closed"
|
||||||
const chanValue = 10000
|
const chanValue = 10000
|
||||||
script, fundingTx, chanUtxo, chanID, err := createChannelEdge(
|
script, fundingTx, chanUtxo, chanID := createChannelEdge(
|
||||||
bitcoinKey1.SerializeCompressed(),
|
t, bitcoinKey1.SerializeCompressed(),
|
||||||
bitcoinKey2.SerializeCompressed(), chanValue,
|
bitcoinKey2.SerializeCompressed(), chanValue,
|
||||||
startingBlockHeight,
|
startingBlockHeight,
|
||||||
)
|
)
|
||||||
require.NoError(t, err, "unable create channel edge")
|
|
||||||
|
|
||||||
// We'll also add a record for the block that included our funding
|
// We'll also add a record for the block that included our funding
|
||||||
// transaction.
|
// transaction.
|
||||||
|
|||||||
Reference in new issue
Block a user