TestDebugEngine checks that the StepCallback called during debug script execution contains the expected data.
(t *testing.T)
| 16 | // TestDebugEngine checks that the StepCallback called during debug script |
| 17 | // execution contains the expected data. |
| 18 | func 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…