MCPcopy Create free account
hub / github.com/btcsuite/btcd / TestDebugEngine

Function TestDebugEngine

txscript/engine_debug_test.go:18–178  ·  view source on GitHub ↗

TestDebugEngine checks that the StepCallback called during debug script execution contains the expected data.

(t *testing.T)

Source from the content-addressed store, hash-verified

16// TestDebugEngine checks that the StepCallback called during debug script
17// execution contains the expected data.
18func TestDebugEngine(t *testing.T) {
19 t.Parallel()
20
21 // We'll generate a private key and a signature for the tx.
22 privKey, err := btcec.NewPrivateKey()
23 require.NoError(t, err)
24
25 internalKey := privKey.PubKey()
26
27 // We use a simple script that will utilize both the stack and alt
28 // stack in order to test the step callback, and wrap it in a taproot
29 // witness script.
30 builder := NewScriptBuilder()
31 builder.AddData([]byte{0xab})
32 builder.AddOp(OP_TOALTSTACK)
33 builder.AddData(schnorr.SerializePubKey(internalKey))
34 builder.AddOp(OP_CHECKSIG)
35 builder.AddOp(OP_VERIFY)
36 builder.AddOp(OP_1)
37 pkScript, err := builder.Script()
38 require.NoError(t, err)
39
40 tapLeaf := NewBaseTapLeaf(pkScript)
41 tapScriptTree := AssembleTaprootScriptTree(tapLeaf)
42
43 ctrlBlock := tapScriptTree.LeafMerkleProofs[0].ToControlBlock(
44 internalKey,
45 )
46
47 tapScriptRootHash := tapScriptTree.RootNode.TapHash()
48 outputKey := ComputeTaprootOutputKey(
49 internalKey, tapScriptRootHash[:],
50 )
51 p2trScript, err := PayToTaprootScript(outputKey)
52 require.NoError(t, err)
53
54 testTx := wire.NewMsgTx(2)
55 testTx.AddTxIn(&wire.TxIn{
56 PreviousOutPoint: wire.OutPoint{
57 Index: 1,
58 },
59 })
60 txOut := &wire.TxOut{
61 Value: 1e8, PkScript: p2trScript,
62 }
63 testTx.AddTxOut(txOut)
64
65 prevFetcher := NewCannedPrevOutputFetcher(
66 txOut.PkScript, txOut.Value,
67 )
68 sigHashes := NewTxSigHashes(testTx, prevFetcher)
69
70 sig, err := RawTxInTapscriptSignature(
71 testTx, sigHashes, 0, txOut.Value,
72 txOut.PkScript, tapLeaf,
73 SigHashDefault, privKey,
74 )
75 require.NoError(t, err)

Callers

nothing calls this directly

Calls 15

AddDataMethod · 0.95
AddOpMethod · 0.95
ScriptMethod · 0.95
AddTxInMethod · 0.95
AddTxOutMethod · 0.95
CopyMethod · 0.95
NewScriptBuilderFunction · 0.85
NewBaseTapLeafFunction · 0.85
ComputeTaprootOutputKeyFunction · 0.85
PayToTaprootScriptFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…