itest: refactor testTaproot

This commit is contained in:
yyforyongyu 2022-08-25 20:50:55 +08:00
parent 8ba5f399d3
commit 0176d58b85
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
6 changed files with 564 additions and 738 deletions

View File

@ -177,3 +177,16 @@ func (h *HarnessRPC) VerifyMessageSigner(
return resp
}
// ComputeInputScript makes a RPC call to the node's SignerClient and asserts.
func (h *HarnessRPC) ComputeInputScript(
req *signrpc.SignReq) *signrpc.InputScriptResp {
ctxt, cancel := context.WithTimeout(h.runCtx, DefaultTimeout)
defer cancel()
resp, err := h.Signer.ComputeInputScript(ctxt, req)
h.NoError(err, "ComputeInputScript")
return resp
}

View File

@ -465,4 +465,8 @@ var allTestCasesTemp = []*lntemp.TestCase{
Name: "cpfp",
TestFunc: testCPFP,
},
{
Name: "taproot",
TestFunc: testTaproot,
},
}

View File

@ -1126,34 +1126,6 @@ func assertPsbtFundSignSpend(ht *lntemp.HarnessTest, alice *node.HarnessNode,
ht.Miner.AssertTxInBlock(block, &finalTxHash)
}
// deriveInternalKey derives a signing key and returns its descriptor, full
// derivation path and parsed public key.
func deriveInternalKeyOld(ctx context.Context, t *harnessTest,
alice *lntest.HarnessNode) (*signrpc.KeyDescriptor, *btcec.PublicKey,
[]uint32) {
// For the next step, we need a public key. Let's use a special family
// for this.
keyDesc, err := alice.WalletKitClient.DeriveNextKey(
ctx, &walletrpc.KeyReq{KeyFamily: testTaprootKeyFamily},
)
require.NoError(t.t, err)
// The DeriveNextKey returns a key from the internal 1017 scope.
fullDerivationPath := []uint32{
hdkeychain.HardenedKeyStart + keychain.BIP0043Purpose,
hdkeychain.HardenedKeyStart + harnessNetParams.HDCoinType,
hdkeychain.HardenedKeyStart + uint32(keyDesc.KeyLoc.KeyFamily),
0,
uint32(keyDesc.KeyLoc.KeyIndex),
}
parsedPubKey, err := btcec.ParsePubKey(keyDesc.RawKeyBytes)
require.NoError(t.t, err)
return keyDesc, parsedPubKey, fullDerivationPath
}
// deriveInternalKey derives a signing key and returns its descriptor, full
// derivation path and parsed public key.
func deriveInternalKey(ht *lntemp.HarnessTest,

File diff suppressed because it is too large Load Diff

View File

@ -24,10 +24,6 @@ var allTestCases = []*testCase{
name: "remote signer",
test: testRemoteSigner,
},
{
name: "taproot",
test: testTaproot,
},
{
name: "taproot coop close",
test: testTaprootCoopClose,

View File

@ -8,9 +8,7 @@ import (
"time"
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/rpcclient"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/go-errors/errors"
"github.com/lightningnetwork/lnd/input"
@ -468,31 +466,3 @@ func findTxAtHeight(t *harnessTest, height int32,
return nil
}
// getOutputIndex returns the output index of the given address in the given
// transaction.
func getOutputIndex(t *harnessTest, miner *lntest.HarnessMiner,
txid *chainhash.Hash, addr string) int {
t.t.Helper()
// We'll then extract the raw transaction from the mempool in order to
// determine the index of the p2tr output.
tx, err := miner.Client.GetRawTransaction(txid)
require.NoError(t.t, err)
p2trOutputIndex := -1
for i, txOut := range tx.MsgTx().TxOut {
_, addrs, _, err := txscript.ExtractPkScriptAddrs(
txOut.PkScript, miner.ActiveNet,
)
require.NoError(t.t, err)
if addrs[0].String() == addr {
p2trOutputIndex = i
}
}
require.Greater(t.t, p2trOutputIndex, -1)
return p2trOutputIndex
}