Ejemplo n.º 1
0
        public void ShouldPreserveOriginalTxPropertyAsPossible()
        {
            var keys    = new Key[] { new Key(), new Key(), new Key() };
            var redeem  = PayToMultiSigTemplate.Instance.GenerateScriptPubKey(3, keys.Select(k => k.PubKey).ToArray());
            var network = Network.Main;
            var funds   = CreateDummyFunds(network, keys, redeem);

            // 1. without signature nor scripts.
            var tx = CreateTxToSpendFunds(funds, keys, redeem, false, false);

            // 2. with (unsigned) scriptSig and witness.
            tx = CreateTxToSpendFunds(funds, keys, redeem, true, false);
            var psbt = new PSBT(tx, true);

            Assert.Null(psbt.Inputs[0].FinalScriptSig);             // it is not finalized since it is not signed
            Assert.Null(psbt.Inputs[1].FinalScriptWitness);         // This too
            Assert.NotNull(psbt.Inputs[2].RedeemScript);            // But it holds redeem script.
            Assert.NotNull(psbt.Inputs[3].WitnessScript);           // And witness script.
            Assert.NotNull(psbt.Inputs[5].WitnessScript);           // even in p2sh-nested-p2wsh
            Assert.NotNull(psbt.Inputs[5].RedeemScript);

            // 3. with finalized scriptSig and witness
            tx   = CreateTxToSpendFunds(funds, keys, redeem, true, true);
            psbt = new PSBT(tx, true);
            Assert.NotNull(psbt.Inputs[0].FinalScriptSig);           // it should be finalized
            Assert.NotNull(psbt.Inputs[1].FinalScriptWitness);       // p2wpkh too
            Assert.NotNull(psbt.Inputs[2].RedeemScript);             // But it holds redeem script.
            Assert.NotNull(psbt.Inputs[3].WitnessScript);            // And witness script.

            Assert.NotNull(psbt.Inputs[4].FinalScriptSig);           // Same principle holds for p2sh-nested version.
            Assert.NotNull(psbt.Inputs[4].FinalScriptWitness);
            Assert.NotNull(psbt.Inputs[5].WitnessScript);
            Assert.NotNull(psbt.Inputs[5].RedeemScript);

            Assert.Empty(psbt.Inputs[2].PartialSigs); // But it still can not hold partial_sigs
            Assert.Empty(psbt.Inputs[3].PartialSigs); // Even in p2wsh
            Assert.Empty(psbt.Inputs[5].PartialSigs); // And p2sh-p2wsh

            psbt.AddTransactions(funds);              // when we add previous outputs, it will be able to resurrect signatures.
            Assert.NotEmpty(psbt.Inputs[2].PartialSigs);
            Assert.NotEmpty(psbt.Inputs[3].PartialSigs);
            Assert.NotEmpty(psbt.Inputs[5].PartialSigs);
        }