BitSharper.Test.TestUtils.CreateFakeTx C# (CSharp) Method

CreateFakeTx() public static method

public static CreateFakeTx ( NetworkParameters @params, ulong nanocoins, Address to ) : Transaction
@params NetworkParameters
nanocoins ulong
to Address
return Transaction
        public static Transaction CreateFakeTx(NetworkParameters @params, ulong nanocoins, Address to)
        {
            var t = new Transaction(@params);
            var o1 = new TransactionOutput(@params, t, nanocoins, to);
            t.AddOutput(o1);
            // Make a previous tx simply to send us sufficient coins. This prev tx is not really valid but it doesn't
            // matter for our purposes.
            var prevTx = new Transaction(@params);
            var prevOut = new TransactionOutput(@params, prevTx, nanocoins, to);
            prevTx.AddOutput(prevOut);
            // Connect it.
            t.AddInput(prevOut);
            return t;
        }

Usage Example

Example #1
0
        public void BasicSpending()
        {
            // We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
            var v1 = Utils.ToNanoCoins(1, 0);
            var t1 = TestUtils.CreateFakeTx(_params, v1, _myAddress);

            _wallet.Receive(t1, null, BlockChain.NewBlockType.BestChain);
            Assert.AreEqual(v1, _wallet.GetBalance());
            Assert.AreEqual(1, _wallet.GetPoolSize(Wallet.Pool.Unspent));
            Assert.AreEqual(1, _wallet.GetPoolSize(Wallet.Pool.All));

            var k2 = new EcKey();
            var v2 = Utils.ToNanoCoins(0, 50);
            var t2 = _wallet.CreateSend(k2.ToAddress(_params), v2);

            Assert.AreEqual(1, _wallet.GetPoolSize(Wallet.Pool.Unspent));
            Assert.AreEqual(1, _wallet.GetPoolSize(Wallet.Pool.All));

            // Do some basic sanity checks.
            Assert.AreEqual(1, t2.Inputs.Count);
            Assert.AreEqual(_myAddress, t2.Inputs[0].ScriptSig.FromAddress);

            // We have NOT proven that the signature is correct!

            _wallet.ConfirmSend(t2);
            Assert.AreEqual(1, _wallet.GetPoolSize(Wallet.Pool.Pending));
            Assert.AreEqual(1, _wallet.GetPoolSize(Wallet.Pool.Spent));
            Assert.AreEqual(2, _wallet.GetPoolSize(Wallet.Pool.All));
        }
All Usage Examples Of BitSharper.Test.TestUtils::CreateFakeTx