From 4692d64f68fb145a2f4f97cf51bd32593b9ec87d Mon Sep 17 00:00:00 2001 From: "Owain G. Ainsworth" Date: Tue, 18 Jun 2013 23:36:44 +0100 Subject: [PATCH] permit tests expect fail for nonspecified return code. Use this to test the pubkey paths in checksig which return btcec errors which we don't define. all of the other active tests know the return code we need. --- script_test.go | 220 ++++++++++++++++++++++++++++++++++++++++++++-- test_coverage.txt | 4 +- 2 files changed, 215 insertions(+), 9 deletions(-) diff --git a/script_test.go b/script_test.go index 463344d8..9f65969a 100644 --- a/script_test.go +++ b/script_test.go @@ -12,12 +12,13 @@ import ( ) type txTest struct { - name string - tx *btcwire.MsgTx - pkScript []byte // output script of previous tx - idx int - bip16 bool - err error + name string + tx *btcwire.MsgTx + pkScript []byte // output script of previous tx + idx int + bip16 bool + err error + shouldFail bool } var txTests = []txTest{ @@ -221,6 +222,207 @@ var txTests = []txTest{ idx: 0, err: btcscript.StackErrScriptFailed, }, + txTest{ + name: "CheckSig invalid signature", + tx: &btcwire.MsgTx{ + Version: 1, + TxIn: []*btcwire.TxIn{ + &btcwire.TxIn{ + PreviousOutpoint: btcwire.OutPoint{ + Hash: btcwire.ShaHash([32]byte{ + 0xc9, 0x97, 0xa5, 0xe5, + 0x6e, 0x10, 0x41, 0x02, + 0xfa, 0x20, 0x9c, 0x6a, + 0x85, 0x2d, 0xd9, 0x06, + 0x60, 0xa2, 0x0b, 0x2d, + 0x9c, 0x35, 0x24, 0x23, + 0xed, 0xce, 0x25, 0x85, + 0x7f, 0xcd, 0x37, 0x04, + }), + Index: 0, + }, + // Signature has length fiddled to + // fail parsing. + SignatureScript: []uint8{ + btcscript.OP_DATA_71, + 0x30, 0x45, 0x02, 0x20, 0x4e, + 0x45, 0xe1, 0x69, 0x32, 0xb8, + 0xaf, 0x51, 0x49, 0x61, 0xa1, + 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, + 0x3f, 0x4f, 0x77, 0x32, 0xe9, + 0xd6, 0x24, 0xc6, 0xc6, 0x15, + 0x48, 0xab, 0x5f, 0xb8, 0xcd, + 0x41, 0x02, 0x20, 0x18, 0x15, + 0x22, 0xec, 0x8e, 0xca, 0x07, + 0xde, 0x48, 0x60, 0xa4, 0xac, + 0xdd, 0x12, 0x90, 0x9d, 0x83, + 0x1c, 0xc5, 0x6c, 0xbb, 0xac, + 0x46, 0x22, 0x08, 0x22, 0x21, + 0xa8, 0x76, 0x8d, 0x1d, 0x09, + 0x01, + }, + + Sequence: 4294967295, + }, + }, + TxOut: []*btcwire.TxOut{ + &btcwire.TxOut{ + Value: 1000000000, + PkScript: []byte{ + btcscript.OP_DATA_65, + 0x04, 0xae, 0x1a, 0x62, 0xfe, + 0x09, 0xc5, 0xf5, 0x1b, 0x13, + 0x90, 0x5f, 0x07, 0xf0, 0x6b, + 0x99, 0xa2, 0xf7, 0x15, 0x9b, + 0x22, 0x25, 0xf3, 0x74, 0xcd, + 0x37, 0x8d, 0x71, 0x30, 0x2f, + 0xa2, 0x84, 0x14, 0xe7, 0xaa, + 0xb3, 0x73, 0x97, 0xf5, 0x54, + 0xa7, 0xdf, 0x5f, 0x14, 0x2c, + 0x21, 0xc1, 0xb7, 0x30, 0x3b, + 0x8a, 0x06, 0x26, 0xf1, 0xba, + 0xde, 0xd5, 0xc7, 0x2a, 0x70, + 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, + btcscript.OP_CHECKSIG, + }, + }, + &btcwire.TxOut{ + Value: 4000000000, + PkScript: []byte{ + btcscript.OP_DATA_65, + 0x04, 0x11, 0xdb, 0x93, 0xe1, + 0xdc, 0xdb, 0x8a, 0x01, 0x6b, + 0x49, 0x84, 0x0f, 0x8c, 0x53, + 0xbc, 0x1e, 0xb6, 0x8a, 0x38, + 0x2e, 0x97, 0xb1, 0x48, 0x2e, + 0xca, 0xd7, 0xb1, 0x48, 0xa6, + 0x90, 0x9a, 0x5c, 0xb2, 0xe0, + 0xea, 0xdd, 0xfb, 0x84, 0xcc, + 0xf9, 0x74, 0x44, 0x64, 0xf8, + 0x2e, 0x16, 0x0b, 0xfa, 0x9b, + 0x8b, 0x64, 0xf9, 0xd4, 0xc0, + 0x3f, 0x99, 0x9b, 0x86, 0x43, + 0xf6, 0x56, 0xb4, 0x12, 0xa3, + btcscript.OP_CHECKSIG, + }, + }, + }, + LockTime: 0, + }, + pkScript: []byte{ + btcscript.OP_DATA_65, + 0x04, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, + 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, + 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, + 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, + 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, + 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, + 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, + 0x12, 0xa3, btcscript.OP_CHECKSIG, + }, + idx: 0, + shouldFail: true, + }, + txTest{ + name: "CheckSig invalid pubkey", + tx: &btcwire.MsgTx{ + Version: 1, + TxIn: []*btcwire.TxIn{ + &btcwire.TxIn{ + PreviousOutpoint: btcwire.OutPoint{ + Hash: btcwire.ShaHash([32]byte{ + 0xc9, 0x97, 0xa5, 0xe5, + 0x6e, 0x10, 0x41, 0x02, + 0xfa, 0x20, 0x9c, 0x6a, + 0x85, 0x2d, 0xd9, 0x06, + 0x60, 0xa2, 0x0b, 0x2d, + 0x9c, 0x35, 0x24, 0x23, + 0xed, 0xce, 0x25, 0x85, + 0x7f, 0xcd, 0x37, 0x04, + }), + Index: 0, + }, + SignatureScript: []uint8{ + btcscript.OP_DATA_71, + 0x30, 0x44, 0x02, 0x20, 0x4e, + 0x45, 0xe1, 0x69, 0x32, 0xb8, + 0xaf, 0x51, 0x49, 0x61, 0xa1, + 0xd3, 0xa1, 0xa2, 0x5f, 0xdf, + 0x3f, 0x4f, 0x77, 0x32, 0xe9, + 0xd6, 0x24, 0xc6, 0xc6, 0x15, + 0x48, 0xab, 0x5f, 0xb8, 0xcd, + 0x41, 0x02, 0x20, 0x18, 0x15, + 0x22, 0xec, 0x8e, 0xca, 0x07, + 0xde, 0x48, 0x60, 0xa4, 0xac, + 0xdd, 0x12, 0x90, 0x9d, 0x83, + 0x1c, 0xc5, 0x6c, 0xbb, 0xac, + 0x46, 0x22, 0x08, 0x22, 0x21, + 0xa8, 0x76, 0x8d, 0x1d, 0x09, + 0x01, + }, + + Sequence: 4294967295, + }, + }, + TxOut: []*btcwire.TxOut{ + &btcwire.TxOut{ + Value: 1000000000, + PkScript: []byte{ + btcscript.OP_DATA_65, + 0x04, 0xae, 0x1a, 0x62, 0xfe, + 0x09, 0xc5, 0xf5, 0x1b, 0x13, + 0x90, 0x5f, 0x07, 0xf0, 0x6b, + 0x99, 0xa2, 0xf7, 0x15, 0x9b, + 0x22, 0x25, 0xf3, 0x74, 0xcd, + 0x37, 0x8d, 0x71, 0x30, 0x2f, + 0xa2, 0x84, 0x14, 0xe7, 0xaa, + 0xb3, 0x73, 0x97, 0xf5, 0x54, + 0xa7, 0xdf, 0x5f, 0x14, 0x2c, + 0x21, 0xc1, 0xb7, 0x30, 0x3b, + 0x8a, 0x06, 0x26, 0xf1, 0xba, + 0xde, 0xd5, 0xc7, 0x2a, 0x70, + 0x4f, 0x7e, 0x6c, 0xd8, 0x4c, + btcscript.OP_CHECKSIG, + }, + }, + &btcwire.TxOut{ + Value: 4000000000, + PkScript: []byte{ + btcscript.OP_DATA_65, + 0x04, 0x11, 0xdb, 0x93, 0xe1, + 0xdc, 0xdb, 0x8a, 0x01, 0x6b, + 0x49, 0x84, 0x0f, 0x8c, 0x53, + 0xbc, 0x1e, 0xb6, 0x8a, 0x38, + 0x2e, 0x97, 0xb1, 0x48, 0x2e, + 0xca, 0xd7, 0xb1, 0x48, 0xa6, + 0x90, 0x9a, 0x5c, 0xb2, 0xe0, + 0xea, 0xdd, 0xfb, 0x84, 0xcc, + 0xf9, 0x74, 0x44, 0x64, 0xf8, + 0x2e, 0x16, 0x0b, 0xfa, 0x9b, + 0x8b, 0x64, 0xf9, 0xd4, 0xc0, + 0x3f, 0x99, 0x9b, 0x86, 0x43, + 0xf6, 0x56, 0xb4, 0x12, 0xa3, + btcscript.OP_CHECKSIG, + }, + }, + }, + LockTime: 0, + }, + // pubkey header magic byte has been changed to parse wrong. + pkScript: []byte{ + btcscript.OP_DATA_65, + 0x02, 0x11, 0xdb, 0x93, 0xe1, 0xdc, 0xdb, 0x8a, 0x01, + 0x6b, 0x49, 0x84, 0x0f, 0x8c, 0x53, 0xbc, 0x1e, 0xb6, + 0x8a, 0x38, 0x2e, 0x97, 0xb1, 0x48, 0x2e, 0xca, 0xd7, + 0xb1, 0x48, 0xa6, 0x90, 0x9a, 0x5c, 0xb2, 0xe0, 0xea, + 0xdd, 0xfb, 0x84, 0xcc, 0xf9, 0x74, 0x44, 0x64, 0xf8, + 0x2e, 0x16, 0x0b, 0xfa, 0x9b, 0x8b, 0x64, 0xf9, 0xd4, + 0xc0, 0x3f, 0x99, 0x9b, 0x86, 0x43, 0xf6, 0x56, 0xb4, + 0x12, 0xa3, btcscript.OP_CHECKSIG, + }, + idx: 0, + shouldFail: true, + }, // tx 599e47a8114fe098103663029548811d2651991b62397e057f0c863c2bc9f9ea // uses checksig with SigHashNone. txTest{ @@ -766,13 +968,17 @@ func testTx(t *testing.T, test txTest) { err = engine.Execute() if err != nil { + // failed means no specified error + if test.shouldFail == true { + return + } if err != test.err { t.Errorf("Failed to validate %s tx: %v expected %v", test.name, err, test.err) } return } - if test.err != nil { + if test.err != nil || test.shouldFail == true { t.Errorf("%s: expected failure: %v, succeeded", test.name, test.err) } diff --git a/test_coverage.txt b/test_coverage.txt index 228313be..3ccca669 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -114,13 +114,13 @@ github.com/conformal/btcscript/opcode.go opcodeDup 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeDrop 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeNop 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeCheckMultiSig 96.43% (54/56) +github.com/conformal/btcscript/opcode.go opcodeCheckSig 96.15% (25/26) github.com/conformal/btcscript/script.go NewScript 95.24% (20/21) github.com/conformal/btcscript/address.go ScriptToAddress 94.92% (56/59) github.com/conformal/btcscript/script.go parseScript 93.75% (30/32) github.com/conformal/btcscript/script.go Script.Step 89.19% (33/37) github.com/conformal/btcscript/stack.go fromInt 87.50% (14/16) github.com/conformal/btcscript/script.go typeOfScript 83.33% (5/6) -github.com/conformal/btcscript/opcode.go opcodeCheckSig 80.77% (21/26) github.com/conformal/btcscript/opcode.go parsedOpcode.exec 80.00% (4/5) github.com/conformal/btcscript/script.go Script.DisasmScript 80.00% (4/5) github.com/conformal/btcscript/opcode.go opcodeCheckSigVerify 75.00% (3/4) @@ -135,5 +135,5 @@ github.com/conformal/btcscript/script.go Script.validPC 60.00% (3/5) github.com/conformal/btcscript/script.go Script.Execute 44.44% (8/18) github.com/conformal/btcscript/log.go SetLogWriter 0.00% (0/7) github.com/conformal/btcscript/log.go logClosure.String 0.00% (0/1) -github.com/conformal/btcscript -------------------------- 92.55% (832/899) +github.com/conformal/btcscript -------------------------- 92.99% (836/899)