lntest+itest: continue removing direct call to Miner

This commit is contained in:
yyforyongyu authored and yyforyongyu committed 2024-07-23 21:30:07 +08:00
1 parent 976bb37972
commit 6bd8baea38
18 files changed
+124 -93

No files matched your search

+3 -3
View File
@@ -433,10 +433,10 @@ func (h *HarnessTest) Subtest(t *testing.T) *HarnessTest {
st.feeService.Reset()
// Record block height.
_, startHeight := h.Miner.GetBestBlock()
_, startHeight := h.GetBestBlock()
st.Cleanup(func() {
_, endHeight := h.Miner.GetBestBlock()
_, endHeight := h.GetBestBlock()
st.Logf("finished test: %s, start height=%d, end height=%d, "+
"mined blocks=%d", st.manager.currentTestCase,
@@ -2158,7 +2158,7 @@ func (h *HarnessTest) SendCoins(a, b *node.HarnessNode,
TargetConf: 6,
}
a.RPC.SendCoins(sendReq)
tx := h.Miner.GetNumTxsFromMempool(1)[0]
tx := h.GetNumTxsFromMempool(1)[0]
return tx
}
+2 -2
View File
@@ -2568,7 +2568,7 @@ func (h *HarnessTest) AssertClosingTxInMempool(cp *lnrpc.ChannelPoint,
// Get the closing tx from the mempool.
op := h.OutPointFromChannelPoint(cp)
closeTx := h.Miner.AssertOutpointInMempool(op)
closeTx := h.AssertOutpointInMempool(op)
return closeTx
}
@@ -2582,7 +2582,7 @@ func (h *HarnessTest) MineClosingTx(cp *lnrpc.ChannelPoint) *wire.MsgTx {
// Get the closing tx from the mempool.
op := h.OutPointFromChannelPoint(cp)
closeTx := h.Miner.AssertOutpointInMempool(op)
closeTx := h.AssertOutpointInMempool(op)
// Mine a block to confirm the closing transaction and potential anchor
// sweep.
+36 -5
View File
@@ -80,7 +80,7 @@ func (h *HarnessTest) MineBlocksAndAssertNumTxes(num uint32,
// If we expect transactions to be included in the blocks we'll mine,
// we wait here until they are seen in the miner's mempool.
txids := h.Miner.AssertNumTxsInMempool(numTxs)
txids := h.AssertNumTxsInMempool(numTxs)
// Mine blocks.
blocks := h.Miner.MineBlocksSlow(num)
@@ -118,7 +118,7 @@ func (h *HarnessTest) DisconnectMiner() {
// cleanMempool mines blocks till the mempool is empty and asserts all active
// nodes have synced to the chain.
func (h *HarnessTest) cleanMempool() {
_, startHeight := h.Miner.GetBestBlock()
_, startHeight := h.GetBestBlock()
// Mining the blocks slow to give `lnd` more time to sync.
var bestBlock *wire.MsgBlock
@@ -126,7 +126,7 @@ func (h *HarnessTest) cleanMempool() {
// If mempool is empty, exit.
mem := h.Miner.GetRawMempool()
if len(mem) == 0 {
_, height := h.Miner.GetBestBlock()
_, height := h.GetBestBlock()
h.Logf("Mined %d blocks when cleanup the mempool",
height-startHeight)
@@ -157,7 +157,7 @@ func (h *HarnessTest) cleanMempool() {
// TODO(yy): remove this workaround when syncing blocks are unified in all the
// subsystems.
func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) {
_, startHeight := h.Miner.GetBestBlock()
_, startHeight := h.GetBestBlock()
err := wait.NoError(func() error {
resp := hn.RPC.PendingChannels()
@@ -169,7 +169,7 @@ func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) {
"close channel to be zero")
}
_, height := h.Miner.GetBestBlock()
_, height := h.GetBestBlock()
h.Logf("Mined %d blocks while waiting for force closed "+
"channel to be resolved", height-startHeight)
@@ -179,6 +179,21 @@ func (h *HarnessTest) mineTillForceCloseResolved(hn *node.HarnessNode) {
require.NoErrorf(h, err, "assert force close resolved timeout")
}
// AssertTxInMempool asserts a given transaction can be found in the mempool.
func (h *HarnessTest) AssertTxInMempool(txid *chainhash.Hash) *wire.MsgTx {
return h.Miner.AssertTxInMempool(txid)
}
// AssertTxNotInMempool asserts a given transaction cannot be found in the
// mempool. It assumes the mempool is not empty.
//
// NOTE: this should be used after `AssertTxInMempool` to ensure the tx has
// entered the mempool before. Otherwise it might give false positive and the
// tx may enter the mempool after the check.
func (h *HarnessTest) AssertTxNotInMempool(txid chainhash.Hash) *wire.MsgTx {
return h.Miner.AssertTxNotInMempool(txid)
}
// AssertNumTxsInMempool polls until finding the desired number of transactions
// in the provided miner's mempool. It will asserrt if this number is not met
// after the given timeout.
@@ -186,9 +201,25 @@ func (h *HarnessTest) AssertNumTxsInMempool(n int) []*chainhash.Hash {
return h.Miner.AssertNumTxsInMempool(n)
}
// AssertOutpointInMempool asserts a given outpoint can be found in the mempool.
func (h *HarnessTest) AssertOutpointInMempool(op wire.OutPoint) *wire.MsgTx {
return h.Miner.AssertOutpointInMempool(op)
}
// AssertTxInBlock asserts that a given txid can be found in the passed block.
func (h *HarnessTest) AssertTxInBlock(block *wire.MsgBlock,
txid *chainhash.Hash) {
h.Miner.AssertTxInBlock(block, txid)
}
// GetNumTxsFromMempool polls until finding the desired number of transactions
// in the miner's mempool and returns the full transactions to the caller.
func (h *HarnessTest) GetNumTxsFromMempool(n int) []*wire.MsgTx {
return h.Miner.GetNumTxsFromMempool(n)
}
// GetBestBlock makes a RPC request to miner and asserts.
func (h *HarnessTest) GetBestBlock() (*chainhash.Hash, int32) {
return h.Miner.GetBestBlock()
}