Пример #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 CanParseAndGeneratePayToMultiSig()
        {
            var    template           = new PayToMultiSigTemplate();
            string scriptPubKey       = "1 0364bd4b02a752798342ed91c681a48793bb1c0853cbcd0b978c55e53485b8e27c 0364bd4b02a752798342ed91c681a48793bb1c0853cbcd0b978c55e53485b8e27d 2 OP_CHECKMULTISIG";
            var    scriptPubKeyResult = template.ExtractScriptPubKeyParameters(new Script(scriptPubKey));

            Assert.Equal("0364bd4b02a752798342ed91c681a48793bb1c0853cbcd0b978c55e53485b8e27c", scriptPubKeyResult.PubKeys[0].ToString());
            Assert.Equal("0364bd4b02a752798342ed91c681a48793bb1c0853cbcd0b978c55e53485b8e27d", scriptPubKeyResult.PubKeys[1].ToString());
            Assert.Equal(1, scriptPubKeyResult.SignatureCount);
            Assert.Equal(scriptPubKey, template.GenerateScriptPubKey(1, scriptPubKeyResult.PubKeys).ToString());

            var scriptSig = "0 3044022064f45a382a15d3eb5e7fe72076eec4ef0f56fde1adfd710866e729b9e5f3383d02202720a895914c69ab49359087364f06d337a2138305fbc19e20d18da78415ea9301 3044022064f45a382a15d3eb5e7fe72076eec4ef0f56fde1adfd710866e729b9e5f3383d02202720a895914c69ab49359087364f06d337a2138305fbc19e20d18da78415ea9302";

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

            Assert.Equal("3044022064f45a382a15d3eb5e7fe72076eec4ef0f56fde1adfd710866e729b9e5f3383d02202720a895914c69ab49359087364f06d337a2138305fbc19e20d18da78415ea9301", Encoders.Hex.EncodeData(result[0].ToBytes()));
            Assert.Equal("3044022064f45a382a15d3eb5e7fe72076eec4ef0f56fde1adfd710866e729b9e5f3383d02202720a895914c69ab49359087364f06d337a2138305fbc19e20d18da78415ea9302", Encoders.Hex.EncodeData(result[1].ToBytes()));

            Assert.Equal(scriptSig, template.GenerateScriptSig(result).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);
        }