From a6cdb8b84452dfb0ae3f0951a529a45e9b78be77 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Wed, 19 Feb 2014 16:52:11 -0600 Subject: [PATCH] Add tests for multisig with zero required sigs. --- script_test.go | 61 +++++++++++++++++++++ test_coverage.txt | 132 +++++++++++++++++++++++----------------------- 2 files changed, 128 insertions(+), 65 deletions(-) diff --git a/script_test.go b/script_test.go index e03743b4..14061dd5 100644 --- a/script_test.go +++ b/script_test.go @@ -1118,6 +1118,67 @@ var txTests = []txTest{ nSigOps: 0, // multisig is in the pkScript! scriptInfoErr: btcscript.StackErrNonPushOnly, }, + // taken from tx b2d93dfd0b2c1a380e55e76a8d9cb3075dec9f4474e9485be008c337fd62c1f7 + // on testnet + // multisig with zero required signatures + { + name: "CheckMultiSig zero required signatures", + tx: &btcwire.MsgTx{ + Version: 1, + TxIn: []*btcwire.TxIn{ + { + PreviousOutpoint: btcwire.OutPoint{ + Hash: btcwire.ShaHash([32]byte{ + 0x37, 0xb1, 0x7d, 0x76, + 0x38, 0x51, 0xcd, 0x1a, + 0xb0, 0x4a, 0x42, 0x44, + 0x63, 0xd4, 0x13, 0xc4, + 0xee, 0x5c, 0xf6, 0x13, + 0x04, 0xc7, 0xfd, 0x76, + 0x97, 0x7b, 0xea, 0x7f, + 0xce, 0x07, 0x57, 0x05, + }), + Index: 0, + }, + SignatureScript: []byte{ + btcscript.OP_0, + btcscript.OP_DATA_37, + btcscript.OP_0, + btcscript.OP_DATA_33, + 0x02, 0x4a, 0xb3, 0x3c, 0x3a, + 0x54, 0x7a, 0x37, 0x29, 0x3e, + 0xb8, 0x75, 0xb4, 0xbb, 0xdb, + 0xd4, 0x73, 0xe9, 0xd4, 0xba, + 0xfd, 0xf3, 0x56, 0x87, 0xe7, + 0x97, 0x44, 0xdc, 0xd7, 0x0f, + 0x6e, 0x4d, 0xe2, + btcscript.OP_1, + btcscript.OP_CHECKMULTISIG, + }, + Sequence: 4294967295, + }, + }, + TxOut: []*btcwire.TxOut{}, + LockTime: 0, + }, + pkScript: []byte{ + btcscript.OP_HASH160, + btcscript.OP_DATA_20, + 0x2c, 0x6b, 0x10, 0x7f, 0xdf, 0x10, 0x6f, 0x22, 0x6f, + 0x3f, 0xa3, 0x27, 0xba, 0x36, 0xd6, 0xe3, 0xca, 0xc7, + 0x3d, 0xf0, + btcscript.OP_EQUAL, + }, + idx: 0, + bip16: true, + nSigOps: 1, + scriptInfo: btcscript.ScriptInfo{ + PkScriptClass: btcscript.ScriptHashTy, + NumInputs: 2, + ExpectedInputs: 1, + SigOps: 1, + }, + }, // tx e5779b9e78f9650debc2893fd9636d827b26b4ddfa6a8172fe8708c924f5c39d // First P2SH transaction in the blockchain { diff --git a/test_coverage.txt b/test_coverage.txt index a115226d..3fa16760 100644 --- a/test_coverage.txt +++ b/test_coverage.txt @@ -1,146 +1,148 @@ +github.com/conformal/btcscript/opcode.go opcodeCheckMultiSig 100.00% (62/62) github.com/conformal/btcscript/script.go Script.Step 100.00% (37/37) github.com/conformal/btcscript/script.go parseScriptTemplate 100.00% (30/30) github.com/conformal/btcscript/address.go ExtractPkScriptAddrs 100.00% (27/27) github.com/conformal/btcscript/script.go CalcScriptInfo 100.00% (25/25) github.com/conformal/btcscript/opcode.go parsedOpcode.bytes 100.00% (23/23) -github.com/conformal/btcscript/stack.go asInt 100.00% (21/21) github.com/conformal/btcscript/script.go NewScript 100.00% (21/21) -github.com/conformal/btcscript/opcode.go parsedOpcode.print 100.00% (16/16) +github.com/conformal/btcscript/stack.go asInt 100.00% (21/21) github.com/conformal/btcscript/script.go signatureScriptCustomReader 100.00% (16/16) +github.com/conformal/btcscript/opcode.go parsedOpcode.print 100.00% (16/16) github.com/conformal/btcscript/stack.go Stack.nipN 100.00% (14/14) github.com/conformal/btcscript/stack.go fromInt 100.00% (14/14) github.com/conformal/btcscript/opcode.go opcodeWithin 100.00% (13/13) -github.com/conformal/btcscript/script.go isMultiSig 100.00% (13/13) github.com/conformal/btcscript/script.go GetPreciseSigOpCount 100.00% (13/13) -github.com/conformal/btcscript/opcode.go opcodeNotIf 100.00% (11/11) +github.com/conformal/btcscript/script.go isMultiSig 100.00% (13/13) github.com/conformal/btcscript/opcode.go opcodeIf 100.00% (11/11) -github.com/conformal/btcscript/opcode.go opcodeBoolAnd 100.00% (10/10) -github.com/conformal/btcscript/stack.go Stack.Tuck 100.00% (10/10) -github.com/conformal/btcscript/opcode.go opcodeMax 100.00% (10/10) -github.com/conformal/btcscript/opcode.go opcodeMin 100.00% (10/10) -github.com/conformal/btcscript/opcode.go opcodeGreaterThanOrEqual 100.00% (10/10) -github.com/conformal/btcscript/opcode.go opcodeLessThanOrEqual 100.00% (10/10) -github.com/conformal/btcscript/opcode.go opcodeGreaterThan 100.00% (10/10) -github.com/conformal/btcscript/opcode.go opcodeLessThan 100.00% (10/10) -github.com/conformal/btcscript/opcode.go opcodeNumNotEqual 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeNotIf 100.00% (11/11) github.com/conformal/btcscript/opcode.go opcodeNumEqual 100.00% (10/10) +github.com/conformal/btcscript/stack.go Stack.Tuck 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeBoolAnd 100.00% (10/10) github.com/conformal/btcscript/opcode.go opcodeBoolOr 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeNumNotEqual 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeLessThan 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeGreaterThan 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeLessThanOrEqual 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeGreaterThanOrEqual 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeMin 100.00% (10/10) +github.com/conformal/btcscript/opcode.go opcodeMax 100.00% (10/10) github.com/conformal/btcscript/script.go getSigOpCount 100.00% (10/10) github.com/conformal/btcscript/stack.go Stack.OverN 100.00% (9/9) -github.com/conformal/btcscript/stack.go Stack.SwapN 100.00% (9/9) -github.com/conformal/btcscript/script.go DisasmString 100.00% (9/9) github.com/conformal/btcscript/stack.go Stack.RotN 100.00% (9/9) -github.com/conformal/btcscript/opcode.go opcodeEqual 100.00% (8/8) -github.com/conformal/btcscript/stack.go Stack.DupN 100.00% (8/8) +github.com/conformal/btcscript/script.go DisasmString 100.00% (9/9) +github.com/conformal/btcscript/stack.go Stack.SwapN 100.00% (9/9) +github.com/conformal/btcscript/script.go PayToAddrScript 100.00% (8/8) github.com/conformal/btcscript/opcode.go opcodeAdd 100.00% (8/8) github.com/conformal/btcscript/opcode.go opcodeSub 100.00% (8/8) -github.com/conformal/btcscript/script.go PayToAddrScript 100.00% (8/8) +github.com/conformal/btcscript/stack.go Stack.DupN 100.00% (8/8) +github.com/conformal/btcscript/opcode.go opcodeEqual 100.00% (8/8) +github.com/conformal/btcscript/stack.go Stack.DropN 100.00% (7/7) github.com/conformal/btcscript/opcode.go opcodeRoll 100.00% (7/7) github.com/conformal/btcscript/script.go unparseScript 100.00% (7/7) -github.com/conformal/btcscript/script.go typeOfScript 100.00% (7/7) -github.com/conformal/btcscript/stack.go Stack.DropN 100.00% (7/7) -github.com/conformal/btcscript/opcode.go opcodeNot 100.00% (7/7) github.com/conformal/btcscript/opcode.go opcode0NotEqual 100.00% (7/7) +github.com/conformal/btcscript/script.go typeOfScript 100.00% (7/7) +github.com/conformal/btcscript/opcode.go opcodeNot 100.00% (7/7) github.com/conformal/btcscript/opcode.go opcodePick 100.00% (7/7) +github.com/conformal/btcscript/opcode.go opcodeVerify 100.00% (6/6) +github.com/conformal/btcscript/opcode.go opcodeEndif 100.00% (6/6) github.com/conformal/btcscript/opcode.go parsedOpcode.conditional 100.00% (6/6) github.com/conformal/btcscript/opcode.go opcodeIfDup 100.00% (6/6) github.com/conformal/btcscript/opcode.go opcodeElse 100.00% (6/6) -github.com/conformal/btcscript/opcode.go opcodeEndif 100.00% (6/6) -github.com/conformal/btcscript/opcode.go opcodeVerify 100.00% (6/6) -github.com/conformal/btcscript/script.go Script.validPC 100.00% (5/5) +github.com/conformal/btcscript/opcode.go opcodeSize 100.00% (5/5) github.com/conformal/btcscript/script.go Script.DisasmScript 100.00% (5/5) -github.com/conformal/btcscript/opcode.go opcodeFromAltStack 100.00% (5/5) -github.com/conformal/btcscript/opcode.go opcodeToAltStack 100.00% (5/5) +github.com/conformal/btcscript/script.go Script.validPC 100.00% (5/5) +github.com/conformal/btcscript/opcode.go parsedOpcode.exec 100.00% (5/5) github.com/conformal/btcscript/opcode.go opcode1Add 100.00% (5/5) github.com/conformal/btcscript/opcode.go opcode1Sub 100.00% (5/5) github.com/conformal/btcscript/opcode.go opcodeNegate 100.00% (5/5) github.com/conformal/btcscript/opcode.go opcodeAbs 100.00% (5/5) -github.com/conformal/btcscript/opcode.go opcodeSize 100.00% (5/5) -github.com/conformal/btcscript/opcode.go parsedOpcode.exec 100.00% (5/5) -github.com/conformal/btcscript/stack.go Stack.PickN 100.00% (5/5) -github.com/conformal/btcscript/opcode.go opcodeRipemd160 100.00% (5/5) +github.com/conformal/btcscript/script.go removeOpcode 100.00% (5/5) +github.com/conformal/btcscript/stack.go Stack.RollN 100.00% (5/5) github.com/conformal/btcscript/opcode.go opcodeSha1 100.00% (5/5) +github.com/conformal/btcscript/opcode.go opcodeRipemd160 100.00% (5/5) github.com/conformal/btcscript/opcode.go opcodeSha256 100.00% (5/5) github.com/conformal/btcscript/opcode.go opcodeHash160 100.00% (5/5) github.com/conformal/btcscript/opcode.go opcodeHash256 100.00% (5/5) -github.com/conformal/btcscript/script.go removeOpcode 100.00% (5/5) +github.com/conformal/btcscript/stack.go Stack.PickN 100.00% (5/5) github.com/conformal/btcscript/script.go removeOpcodeByData 100.00% (5/5) -github.com/conformal/btcscript/stack.go Stack.RollN 100.00% (5/5) -github.com/conformal/btcscript/opcode.go opcodeCheckMultiSigVerify 100.00% (4/4) -github.com/conformal/btcscript/opcode.go opcodeEqualVerify 100.00% (4/4) -github.com/conformal/btcscript/opcode.go opcodeNumEqualVerify 100.00% (4/4) -github.com/conformal/btcscript/script.go isPushOnly 100.00% (4/4) +github.com/conformal/btcscript/opcode.go opcodeToAltStack 100.00% (5/5) +github.com/conformal/btcscript/opcode.go opcodeFromAltStack 100.00% (5/5) github.com/conformal/btcscript/script.go IsPayToScriptHash 100.00% (4/4) -github.com/conformal/btcscript/opcode.go opcodePushData 100.00% (4/4) -github.com/conformal/btcscript/script.go getStack 100.00% (4/4) github.com/conformal/btcscript/stack.go Stack.PopBool 100.00% (4/4) -github.com/conformal/btcscript/script.go Script.curPC 100.00% (4/4) -github.com/conformal/btcscript/stack.go Stack.PeekInt 100.00% (4/4) +github.com/conformal/btcscript/opcode.go opcodeNumEqualVerify 100.00% (4/4) github.com/conformal/btcscript/stack.go asBool 100.00% (4/4) -github.com/conformal/btcscript/script.go GetScriptClass 100.00% (4/4) -github.com/conformal/btcscript/stack.go Stack.PeekBool 100.00% (4/4) -github.com/conformal/btcscript/script.go isNullData 100.00% (4/4) -github.com/conformal/btcscript/script.go Script.DisasmPC 100.00% (4/4) -github.com/conformal/btcscript/stack.go Stack.PopInt 100.00% (4/4) +github.com/conformal/btcscript/opcode.go opcodeEqualVerify 100.00% (4/4) github.com/conformal/btcscript/stack.go Stack.PeekByteArray 100.00% (4/4) +github.com/conformal/btcscript/script.go Script.DisasmPC 100.00% (4/4) +github.com/conformal/btcscript/opcode.go opcodePushData 100.00% (4/4) +github.com/conformal/btcscript/script.go GetScriptClass 100.00% (4/4) +github.com/conformal/btcscript/stack.go Stack.PeekInt 100.00% (4/4) +github.com/conformal/btcscript/script.go getStack 100.00% (4/4) +github.com/conformal/btcscript/stack.go Stack.PeekBool 100.00% (4/4) +github.com/conformal/btcscript/script.go Script.curPC 100.00% (4/4) +github.com/conformal/btcscript/stack.go Stack.PopInt 100.00% (4/4) +github.com/conformal/btcscript/opcode.go opcodeCheckMultiSigVerify 100.00% (4/4) +github.com/conformal/btcscript/script.go isPushOnly 100.00% (4/4) +github.com/conformal/btcscript/script.go isNullData 100.00% (4/4) +github.com/conformal/btcscript/script.go scriptUInt16 100.00% (3/3) +github.com/conformal/btcscript/script.go scriptUInt32 100.00% (3/3) +github.com/conformal/btcscript/stack.go fromBool 100.00% (3/3) github.com/conformal/btcscript/script.go ScriptClass.String 100.00% (3/3) github.com/conformal/btcscript/script.go setStack 100.00% (3/3) -github.com/conformal/btcscript/stack.go fromBool 100.00% (3/3) -github.com/conformal/btcscript/script.go scriptUInt16 100.00% (3/3) github.com/conformal/btcscript/script.go scriptUInt8 100.00% (3/3) -github.com/conformal/btcscript/script.go scriptUInt32 100.00% (3/3) -github.com/conformal/btcscript/stack.go Stack.Depth 100.00% (2/2) +github.com/conformal/btcscript/script.go isSmallInt 100.00% (3/3) +github.com/conformal/btcscript/script.go asSmallInt 100.00% (3/3) +github.com/conformal/btcscript/stack.go Stack.NipN 100.00% (2/2) github.com/conformal/btcscript/opcode.go opcodeFalse 100.00% (2/2) github.com/conformal/btcscript/opcode.go opcode1Negate 100.00% (2/2) github.com/conformal/btcscript/opcode.go opcodeN 100.00% (2/2) github.com/conformal/btcscript/opcode.go opcodeDepth 100.00% (2/2) github.com/conformal/btcscript/opcode.go calcHash 100.00% (2/2) github.com/conformal/btcscript/opcode.go opcodeCodeSeparator 100.00% (2/2) -github.com/conformal/btcscript/stack.go Stack.NipN 100.00% (2/2) +github.com/conformal/btcscript/stack.go Stack.Depth 100.00% (2/2) github.com/conformal/btcscript/script.go GetSigOpCount 100.00% (2/2) github.com/conformal/btcscript/script.go PayToPubKeyHashScript 100.00% (2/2) github.com/conformal/btcscript/script.go PayToScriptHashScript 100.00% (2/2) +github.com/conformal/btcscript/log.go init 100.00% (1/1) +github.com/conformal/btcscript/stack.go Stack.PopByteArray 100.00% (1/1) github.com/conformal/btcscript/stack.go Stack.PushInt 100.00% (1/1) -github.com/conformal/btcscript/script.go Script.subScript 100.00% (1/1) github.com/conformal/btcscript/stack.go Stack.PushByteArray 100.00% (1/1) github.com/conformal/btcscript/opcode.go init 100.00% (1/1) -github.com/conformal/btcscript/log.go newLogClosure 100.00% (1/1) github.com/conformal/btcscript/script.go Script.GetStack 100.00% (1/1) github.com/conformal/btcscript/script.go Script.SetStack 100.00% (1/1) github.com/conformal/btcscript/script.go Script.GetAltStack 100.00% (1/1) -github.com/conformal/btcscript/log.go init 100.00% (1/1) +github.com/conformal/btcscript/script.go Script.SetAltStack 100.00% (1/1) +github.com/conformal/btcscript/log.go newLogClosure 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeNop 100.00% (1/1) -github.com/conformal/btcscript/stack.go Stack.PushBool 100.00% (1/1) github.com/conformal/btcscript/script.go SignatureScript 100.00% (1/1) github.com/conformal/btcscript/log.go DisableLog 100.00% (1/1) -github.com/conformal/btcscript/stack.go Stack.PopByteArray 100.00% (1/1) -github.com/conformal/btcscript/script.go Script.SetAltStack 100.00% (1/1) -github.com/conformal/btcscript/opcode.go calcHash160 100.00% (1/1) +github.com/conformal/btcscript/stack.go Stack.PushBool 100.00% (1/1) +github.com/conformal/btcscript/script.go Script.subScript 100.00% (1/1) github.com/conformal/btcscript/script.go isPubkey 100.00% (1/1) github.com/conformal/btcscript/script.go isPubkeyHash 100.00% (1/1) github.com/conformal/btcscript/script.go isScriptHash 100.00% (1/1) +github.com/conformal/btcscript/opcode.go calcHash160 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeTuck 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeSwap 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeRot 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeOver 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeNip 100.00% (1/1) -github.com/conformal/btcscript/opcode.go opcodeDup 100.00% (1/1) github.com/conformal/btcscript/script.go parseScript 100.00% (1/1) +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 opcode2Dup 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcode2Swap 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcode2Rot 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcode2Over 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcode3Dup 100.00% (1/1) -github.com/conformal/btcscript/opcode.go opcode2Dup 100.00% (1/1) -github.com/conformal/btcscript/opcode.go opcode2Drop 100.00% (1/1) +github.com/conformal/btcscript/opcode.go opcodeDisabled 100.00% (1/1) github.com/conformal/btcscript/script.go Script.disasm 100.00% (1/1) +github.com/conformal/btcscript/opcode.go opcode2Drop 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeReturn 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeInvalid 100.00% (1/1) github.com/conformal/btcscript/opcode.go opcodeReserved 100.00% (1/1) -github.com/conformal/btcscript/opcode.go opcodeDisabled 100.00% (1/1) -github.com/conformal/btcscript/opcode.go opcodeCheckMultiSig 98.28% (57/58) -github.com/conformal/btcscript/opcode.go opcodeCheckSig 90.62% (29/32) +github.com/conformal/btcscript/opcode.go opcodeCheckSig 90.00% (27/30) github.com/conformal/btcscript/script.go expectedInputs 85.71% (6/7) github.com/conformal/btcscript/script.go calcScriptHash 82.05% (32/39) github.com/conformal/btcscript/script.go Script.CheckErrorCondition 78.57% (11/14) @@ -149,7 +151,7 @@ github.com/conformal/btcscript/script.go Script.Execute 44.44% (8/18) github.com/conformal/btcscript/log.go SetLogWriter 0.00% (0/10) github.com/conformal/btcscript/script.go CalcMultiSigStats 0.00% (0/8) github.com/conformal/btcscript/script.go IsPushOnlyScript 0.00% (0/4) -github.com/conformal/btcscript/log.go logClosure.String 0.00% (0/1) github.com/conformal/btcscript/log.go UseLogger 0.00% (0/1) -github.com/conformal/btcscript --------------------------- 95.08% (967/1017) +github.com/conformal/btcscript/log.go logClosure.String 0.00% (0/1) +github.com/conformal/btcscript --------------------------- 95.22% (976/1025)