示例#1
0
        public void GetSigOpCount()
        {
            // Test CScript::GetSigOpCount()
            Script s1 = new Script();
            Assert.Equal(s1.GetSigOpCount(false), 0U);
            Assert.Equal(s1.GetSigOpCount(true), 0U);

            uint160 dummy = new uint160(0);
            s1 = s1 + OpcodeType.OP_1 + dummy.ToBytes() + dummy.ToBytes() + OpcodeType.OP_2 + OpcodeType.OP_CHECKMULTISIG;
            Assert.Equal(s1.GetSigOpCount(true), 2U);
            s1 = s1 + OpcodeType.OP_IF + OpcodeType.OP_CHECKSIG + OpcodeType.OP_ENDIF;
            Assert.Equal(s1.GetSigOpCount(true), 3U);
            Assert.Equal(s1.GetSigOpCount(false), 21U);

            var payToScript = new PayToScriptHashTemplate();
            Script p2sh = payToScript.GenerateScriptPubKey(s1);
            Script scriptSig = payToScript.GenerateScriptSig(new[] { (Op)OpcodeType.OP_0 }, s1);
            Assert.Equal(p2sh.GetSigOpCount(scriptSig), 3U);

            var multiSig = new PayToMultiSigTemplate();
            PubKey[] keys = Enumerable.Range(0, 3).Select(_ => new Key(true).PubKey).ToArray();

            Script s2 = multiSig.GenerateScriptPubKey(1, keys);
            Assert.Equal(s2.GetSigOpCount(true), 3U);
            Assert.Equal(s2.GetSigOpCount(false), 20U);

            p2sh = payToScript.GenerateScriptPubKey(s2);
            Assert.Equal(p2sh.GetSigOpCount(true), 0U);
            Assert.Equal(p2sh.GetSigOpCount(false), 0U);
            Script scriptSig2 = new Script();
            scriptSig2 = scriptSig2 + OpcodeType.OP_1 + dummy.ToBytes() + dummy.ToBytes() + s2.ToRawScript();
            Assert.Equal(p2sh.GetSigOpCount(scriptSig2), 3U);
        }
示例#2
0
        public void CanParseAndGeneratePayToScript()
        {
            var template = new PayToScriptHashTemplate();
            var redeem   = "1 0364bd4b02a752798342ed91c681a48793bb1c0853cbcd0b978c55e53485b8e27c 0364bd4b02a752798342ed91c681a48793bb1c0853cbcd0b978c55e53485b8e27d 2 OP_CHECKMULTISIG";

            var scriptPubkey = "OP_HASH160 b5b88dd9befc9236915fcdbb7fd50052df50c855 OP_EQUAL";

            var scriptSig = "3044022064f45a382a15d3eb5e7fe72076eec4ef0f56fde1adfd710866e729b9e5f3383d02202720a895914c69ab49359087364f06d337a2138305fbc19e20d18da78415ea9301 51210364bd4b02a752798342ed91c681a48793bb1c0853cbcd0b978c55e53485b8e27c210364bd4b02a752798342ed91c681a48793bb1c0853cbcd0b978c55e53485b8e27d52ae";

            var pubParams = template.ExtractScriptPubKeyParameters(new Script(scriptPubkey));

            Assert.Equal("b5b88dd9befc9236915fcdbb7fd50052df50c855", pubParams.ToString());
            Assert.Equal(scriptPubkey, template.GenerateScriptPubKey(pubParams).ToString());

            var sigParams = template.ExtractScriptSigParameters(new Script(scriptSig));

            Assert.Equal("3044022064f45a382a15d3eb5e7fe72076eec4ef0f56fde1adfd710866e729b9e5f3383d02202720a895914c69ab49359087364f06d337a2138305fbc19e20d18da78415ea9301", Encoders.Hex.EncodeData(sigParams.Signatures[0].ToBytes()));
            Assert.Equal(redeem, sigParams.RedeemScript.ToString());
            Assert.Equal(scriptSig, template.GenerateScriptSig(sigParams.Signatures, sigParams.RedeemScript).ToString());
        }
示例#3
0
        public void GetSigOpCount()
        {
            // Test CScript::GetSigOpCount()
            Script s1 = new Script();

            Assert.Equal(s1.GetSigOpCount(false), 0U);
            Assert.Equal(s1.GetSigOpCount(true), 0U);

            uint160 dummy = new uint160(0);

            s1 = s1 + OpcodeType.OP_1 + dummy.ToBytes() + dummy.ToBytes() + OpcodeType.OP_2 + OpcodeType.OP_CHECKMULTISIG;
            Assert.Equal(s1.GetSigOpCount(true), 2U);
            s1 = s1 + OpcodeType.OP_IF + OpcodeType.OP_CHECKSIG + OpcodeType.OP_ENDIF;
            Assert.Equal(s1.GetSigOpCount(true), 3U);
            Assert.Equal(s1.GetSigOpCount(false), 21U);

            var    payToScript = new PayToScriptHashTemplate();
            Script p2sh        = payToScript.GenerateScriptPubKey(s1);
            Script scriptSig   = payToScript.GenerateScriptSig(new[] { (Op)OpcodeType.OP_0 }, s1);

            Assert.Equal(p2sh.GetSigOpCount(scriptSig), 3U);

            var multiSig = new PayToMultiSigTemplate();

            PubKey[] keys = Enumerable.Range(0, 3).Select(_ => new Key(true).PubKey).ToArray();

            Script s2 = multiSig.GenerateScriptPubKey(1, keys);

            Assert.Equal(s2.GetSigOpCount(true), 3U);
            Assert.Equal(s2.GetSigOpCount(false), 20U);

            p2sh = payToScript.GenerateScriptPubKey(s2);
            Assert.Equal(p2sh.GetSigOpCount(true), 0U);
            Assert.Equal(p2sh.GetSigOpCount(false), 0U);
            Script scriptSig2 = new Script();

            scriptSig2 = scriptSig2 + OpcodeType.OP_1 + dummy.ToBytes() + dummy.ToBytes() + s2.ToRawScript();
            Assert.Equal(p2sh.GetSigOpCount(scriptSig2), 3U);
        }