Skip to content

Commit

Permalink
lntest+itest: make Miner a private instance
Browse files Browse the repository at this point in the history
  • Loading branch information
yyforyongyu committed Jun 5, 2024
1 parent f1f8f85 commit 4a57b36
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 50 deletions.
2 changes: 1 addition & 1 deletion itest/lnd_nonstd_sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func testNonStdSweepInner(ht *lntest.HarnessTest, address string) {

// Fetch the vsize of the transaction so we can determine if the
// transaction pays >= 1 sat/vbyte.
rawTx := ht.Miner.GetRawTransactionVerbose(txid)
rawTx := ht.Miner().GetRawTransactionVerbose(txid)

// Require fee >= vbytes.
require.True(ht, fee >= int(rawTx.Vsize))
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_open_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func testOpenChannelAfterReorg(ht *lntest.HarnessTest) {
// Create a temp miner.
tempMiner := ht.SpawnTempMiner()

miner := ht.Miner
miner := ht.Miner()
alice, bob := ht.Alice, ht.Bob

// Create a new channel that requires 1 confs before it's considered
Expand Down
4 changes: 2 additions & 2 deletions itest/lnd_rest_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func wsTestCaseSubscription(ht *lntest.HarnessTest) {
}()

// Mine a block and make sure we get a message for it.
blockHashes := ht.Miner.GenerateBlocks(1)
blockHashes := ht.Miner().GenerateBlocks(1)
select {
case msg := <-msgChan:
require.Equal(
Expand Down Expand Up @@ -388,7 +388,7 @@ func wsTestCaseSubscriptionMacaroon(ht *lntest.HarnessTest) {
}()

// Mine a block and make sure we get a message for it.
blockHashes := ht.Miner.GenerateBlocks(1)
blockHashes := ht.Miner().GenerateBlocks(1)
select {
case msg := <-msgChan:
require.Equal(
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_revocation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func revokedCloseRetributionRemoteHodlCase(ht *lntest.HarnessTest,
// NOTE: We don't use `ht.GetRawTransaction`
// which asserts a txid must be found as the HTLC
// spending txes might be aggregated.
tx, err := ht.Miner.Client.GetRawTransaction(txid)
tx, err := ht.Miner().Client.GetRawTransaction(txid)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions itest/lnd_sweep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {

// Remember the force close height so we can calculate the deadline
// height.
_, forceCloseHeight := ht.Miner.GetBestBlock()
_, forceCloseHeight := ht.GetBestBlock()

// Bob should have two pending sweeps,
// - anchor sweeping from his local commitment.
Expand Down Expand Up @@ -304,7 +304,7 @@ func testSweepCPFPAnchorOutgoingTimeout(ht *lntest.HarnessTest) {
//
// Once out of the above loop, we expect to be 2 blocks before the CPFP
// deadline.
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
require.Equal(ht, int(anchorDeadline-2), int(currentHeight))

// Mine one more block, we'd use up all the CPFP budget.
Expand Down Expand Up @@ -512,7 +512,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
forceCloseHeight := htlc.ExpirationHeight - goToChainDelta

// Mine till the goToChainHeight is reached.
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
numBlocks := forceCloseHeight - uint32(currentHeight)
ht.MineEmptyBlocks(int(numBlocks))

Expand Down Expand Up @@ -641,7 +641,7 @@ func testSweepCPFPAnchorIncomingTimeout(ht *lntest.HarnessTest) {
//
// Once out of the above loop, we expect to be 2 blocks before the CPFP
// deadline.
_, currentHeight = ht.Miner.GetBestBlock()
_, currentHeight = ht.GetBestBlock()
require.Equal(ht, int(anchorDeadline-2), int(currentHeight))

// Mine one more block, we'd use up all the CPFP budget.
Expand Down Expand Up @@ -1380,7 +1380,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
//
// TODO(yy): assert they are equal once blocks are synced via
// `blockbeat`.
_, currentHeight := ht.Miner.GetBestBlock()
_, currentHeight := ht.GetBestBlock()
actualDeadline := int32(pendingSweepBob.DeadlineHeight) - currentHeight
if actualDeadline != int32(deadlineB) {
ht.Logf("!!! Found unsynced block between sweeper and "+
Expand Down Expand Up @@ -1438,7 +1438,7 @@ func testSweepCommitOutputAndAnchor(ht *lntest.HarnessTest) {
//
// TODO(yy): assert they are equal once blocks are synced via
// `blockbeat`.
_, currentHeight = ht.Miner.GetBestBlock()
_, currentHeight = ht.GetBestBlock()
actualDeadline = int32(aliceCommit.DeadlineHeight) - currentHeight
if actualDeadline != int32(deadlineA) {
ht.Logf("!!! Found unsynced block between Alice's sweeper and "+
Expand Down
2 changes: 1 addition & 1 deletion itest/lnd_taproot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func testTaprootSendCoinsKeySpendBip86(ht *lntest.HarnessTest,

// Assert this is a segwit v1 address that starts with bcrt1p.
require.Contains(
ht, p2trResp.Address, ht.Miner.ActiveNet.Bech32HRPSegwit+"1p",
ht, p2trResp.Address, ht.Miner().ActiveNet.Bech32HRPSegwit+"1p",
)

// Send the coins from Alice's wallet to her own, but to the new p2tr
Expand Down
26 changes: 13 additions & 13 deletions lntest/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ type HarnessTest struct {
// Embed the standbyNodes so we can easily access them via `ht.Alice`.
standbyNodes

// Miner is a reference to a running full node that can be used to
// miner is a reference to a running full node that can be used to
// create new blocks on the network.
Miner *miner.HarnessMiner
miner *miner.HarnessMiner

// manager handles the start and stop of a given node.
manager *nodeManager
Expand Down Expand Up @@ -188,7 +188,7 @@ func (h *HarnessTest) Start(chain node.BackendConfig,
h.manager.feeServiceURL = h.feeService.URL()

// Assemble the miner.
h.Miner = miner
h.miner = miner
}

// ChainBackendName returns the chain backend name used in the test.
Expand Down Expand Up @@ -254,7 +254,7 @@ func (h *HarnessTest) createAndSendOutput(target *node.HarnessNode,
PkScript: addrScript,
Value: int64(amt),
}
h.Miner.SendOutput(output, defaultMinerFeeRate)
h.miner.SendOutput(output, defaultMinerFeeRate)
}

// SetupRemoteSigningStandbyNodes starts the initial seeder nodes within the
Expand Down Expand Up @@ -371,7 +371,7 @@ func (h *HarnessTest) Stop() {
h.stopChainBackend()

// Stop the miner.
h.Miner.Stop()
h.miner.Stop()
}

// RunTestCase executes a harness test case. Any errors or panics will be
Expand Down Expand Up @@ -414,7 +414,7 @@ func (h *HarnessTest) Subtest(t *testing.T) *HarnessTest {
st := &HarnessTest{
T: t,
manager: h.manager,
Miner: h.Miner,
miner: h.miner,
standbyNodes: h.standbyNodes,
feeService: h.feeService,
lndErrorChan: make(chan error, lndErrorChanSize),
Expand All @@ -424,7 +424,7 @@ func (h *HarnessTest) Subtest(t *testing.T) *HarnessTest {
st.runCtx, st.cancel = context.WithCancel(h.runCtx)

// Inherit the subtest for the miner.
st.Miner.T = st.T
st.miner.T = st.T

// Reset the standby nodes.
st.resetStandbyNodes(t)
Expand Down Expand Up @@ -467,7 +467,7 @@ func (h *HarnessTest) Subtest(t *testing.T) *HarnessTest {
st.shutdownNonStandbyNodes()

// We require the mempool to be cleaned from the test.
require.Empty(st, st.Miner.GetRawMempool(), "mempool not "+
require.Empty(st, st.miner.GetRawMempool(), "mempool not "+
"cleaned, please mine blocks to clean them all.")

// Finally, cancel the run context. We have to do it here
Expand Down Expand Up @@ -1293,7 +1293,7 @@ func (h *HarnessTest) CloseChannelAssertPending(hn *node.HarnessNode,
pendingClose.ClosePending.Txid)

// Assert the closing tx is in the mempool.
h.Miner.AssertTxInMempool(closeTxid)
h.miner.AssertTxInMempool(closeTxid)

return stream, closeTxid
}
Expand Down Expand Up @@ -1391,7 +1391,7 @@ func (h *HarnessTest) fundCoins(amt btcutil.Amount, target *node.HarnessNode,
PkScript: addrScript,
Value: int64(amt),
}
h.Miner.SendOutput(output, defaultMinerFeeRate)
h.miner.SendOutput(output, defaultMinerFeeRate)

// Encode the pkScript in hex as this the format that it will be
// returned via rpc.
Expand Down Expand Up @@ -1898,7 +1898,7 @@ func (h *HarnessTest) CalculateTxFee(tx *wire.MsgTx) btcutil.Amount {
var balance btcutil.Amount
for _, in := range tx.TxIn {
parentHash := in.PreviousOutPoint.Hash
rawTx := h.Miner.GetRawTransaction(&parentHash)
rawTx := h.miner.GetRawTransaction(&parentHash)
parent := rawTx.MsgTx()
value := parent.TxOut[in.PreviousOutPoint.Index].Value

Expand Down Expand Up @@ -2116,12 +2116,12 @@ func (h *HarnessTest) ReceiveChannelEvent(
func (h *HarnessTest) GetOutputIndex(txid *chainhash.Hash, addr string) int {
// We'll then extract the raw transaction from the mempool in order to
// determine the index of the p2tr output.
tx := h.Miner.GetRawTransaction(txid)
tx := h.miner.GetRawTransaction(txid)

p2trOutputIndex := -1
for i, txOut := range tx.MsgTx().TxOut {
_, addrs, _, err := txscript.ExtractPkScriptAddrs(
txOut.PkScript, h.Miner.ActiveNet,
txOut.PkScript, h.miner.ActiveNet,
)
require.NoError(h, err)

Expand Down
Loading

0 comments on commit 4a57b36

Please sign in to comment.