Ejemplo n.º 1
0
        public void BuildPrivateSendTransaction()
        {
            // Tx from mainnet as this is difficult to reproduce in testnet
            const decimal TotalInputAmount      = 0.00125025m;
            const decimal InputToAddressAmount  = 0.001m;
            const string  InputToAddress        = "XoASepVfo1cegWp52HS9gbcKuarLyqxsKT";
            decimal       inputTxFee            = node.CalculateTxFee(1, 2, false, true);
            const string  InputRemainingAddress = "Xjm6MySEGGmRqkTqnMfxeAscye395RV2x6";
            decimal       remainingAmount       = TotalInputAmount - (InputToAddressAmount + inputTxFee);
            // PrivateSend first needs to go to the mixing wallet, use small fee for that
            decimal redirectedTxFee     = node.CalculateTxFee(1, 2, false, false);
            decimal redirectedAmount    = TotalInputAmount - (remainingAmount + redirectedTxFee);
            var     rawTxHashesAndRawTx = node.TryGenerateRawTx(
                "d0253484a89d23fb47d5f33858dab316e2ce09806768bd68b8efdbc3e5586c2f|1",
                InputToAddressAmount, InputToAddress,
                remainingAmount, InputRemainingAddress, false, true);

            Assert.That(rawTxHashesAndRawTx.TxHashes, Has.Length.EqualTo(1));
            if (node is MockDashNode)
            {
                return;
            }
            //ncrunch: no coverage start
            Console.WriteLine("Tx Input Hash: " + rawTxHashesAndRawTx.TxHashes[0]);
            var txInput = (node as TestnetDashNode).DecodeRawTransaction(rawTxHashesAndRawTx.TxHashes[0]);

            Assert.That(txInput.Vin, Has.Count.EqualTo(1));
            Assert.That(txInput.Vout[0].N, Is.EqualTo(0));
            // Old tx used for input here also went to same donation address and has itself as chance
            Assert.That(txInput.Vout[0].Value, Is.EqualTo(0.00001m));
            Assert.That(txInput.Vout[0].ScriptPubKey.Addresses[0], Is.EqualTo(InputToAddress));
            Assert.That(txInput.Vout[1].Value, Is.EqualTo(0.00125025m));
            Assert.That(txInput.Vout[1].ScriptPubKey.Addresses[0], Is.EqualTo(InputRemainingAddress));
            Console.WriteLine("RawTx Hash: " + rawTxHashesAndRawTx.RawTx);
            var tx = (node as TestnetDashNode).DecodeRawTransaction(rawTxHashesAndRawTx.RawTx);

            Assert.That(tx.Vin, Has.Count.EqualTo(1));
            Assert.That(tx.Vin[0].TxId, Is.EqualTo(txInput.TxId));
            Assert.That(tx.Vout, Has.Count.EqualTo(2));
            // We should NOT use InputToAddress or InputToAddressAmount here, but redirect this!
            Assert.That(tx.Vout[0].ScriptPubKey.Addresses[0], Is.Not.EqualTo(InputToAddress));
            Assert.That(tx.Vout[0].Value,
                        Is.Not.EqualTo(InputToAddressAmount).And.EqualTo(redirectedAmount));
            // Remaining amount should stay unchanged
            Assert.That(tx.Vout[1].Value, Is.EqualTo(remainingAmount));
            Assert.That(tx.Vout[1].ScriptPubKey.Addresses[0], Is.EqualTo(InputRemainingAddress));
            Assert.That(tx.Vout[0].Value + tx.Vout[1].Value + redirectedTxFee,
                        Is.EqualTo(TotalInputAmount));
            //ncrunch: no coverage end
        }