testScripts ensures all of the passed script tests execute with the expected results with or without using a signature cache, as specified by the parameter.
(t *testing.T, tests [][]interface{}, useSigCache bool)
| 532 | // results with or without using a signature cache, as specified by the |
| 533 | // parameter. |
| 534 | func testScripts(t *testing.T, tests [][]interface{}, useSigCache bool) { |
| 535 | // Create a signature cache to use only if requested. |
| 536 | var sigCache *SigCache |
| 537 | if useSigCache { |
| 538 | sigCache = NewSigCache(10) |
| 539 | } |
| 540 | |
| 541 | for i, test := range tests { |
| 542 | // "Format is: [[wit..., amount]?, scriptSig, scriptPubKey, |
| 543 | // flags, expected_scripterror, ... comments]" |
| 544 | |
| 545 | // Skip single line comments. |
| 546 | if len(test) == 1 { |
| 547 | continue |
| 548 | } |
| 549 | |
| 550 | // Taproot entries in the latest Bitcoin Core script_tests.json rely on |
| 551 | // placeholder macros (for example #SCRIPT# and #CONTROLBLOCK#). btcd |
| 552 | // validates taproot separately via TestTaprootReferenceTests. |
| 553 | if hasTaprootScriptTest(test) { |
| 554 | continue |
| 555 | } |
| 556 | |
| 557 | // Construct a name for the test based on the comment and test |
| 558 | // data. |
| 559 | name, err := scriptTestName(test) |
| 560 | if err != nil { |
| 561 | t.Errorf("TestScripts: invalid test #%d: %v", i, err) |
| 562 | continue |
| 563 | } |
| 564 | |
| 565 | var ( |
| 566 | witness wire.TxWitness |
| 567 | inputAmt int64 |
| 568 | ) |
| 569 | |
| 570 | // When the first field of the test data is a slice it contains |
| 571 | // witness data and everything else is offset by 1 as a result. |
| 572 | witnessOffset := scriptTestWitnessOffset(test) |
| 573 | if witnessOffset != 0 { |
| 574 | witnessData := test[0].([]interface{}) |
| 575 | |
| 576 | // If this is a witness test, then the final element |
| 577 | // within the slice is the input amount, so we ignore |
| 578 | // all but the last element in order to parse the |
| 579 | // witness stack. |
| 580 | strWitnesses := witnessData[:len(witnessData)-1] |
| 581 | witness, err = parseWitnessStack(strWitnesses) |
| 582 | if err != nil { |
| 583 | t.Errorf("%s: can't parse witness; %v", name, err) |
| 584 | continue |
| 585 | } |
| 586 | |
| 587 | inputAmt, err = newAmount( |
| 588 | witnessData[len(witnessData)-1].(float64), |
| 589 | ) |
| 590 | if err != nil { |
| 591 | t.Errorf("%s: can't parse input amt: %v", |
no test coverage detected
searching dependent graphs…