示例#1
0
        public void CanManageMoney()
        {
            WalletTester tester = new WalletTester();
            Chain        chain  = new Chain(Network.Main);

            //Change C,A,U
            tester.GiveMoney("1.0", chain);
            Assert.True(tester.UpdateWallet(chain));
            tester.AssertPools(
                "+1.00",
                "+1.00",
                "+1.00");
            Assert.False(tester.UpdateWallet(chain));

            //Change U
            var rcv = tester.GiveMoney("0.1", null);

            tester.AssertPools(
                "+1.00",
                "+1.00",
                "+1.00+0.10");

            tester.AppendBlock(rcv, chain);
            //Change C,A
            Assert.True(tester.UpdateWallet(chain));
            tester.AssertPools(
                "+1.00+0.10",
                "+1.00+0.10",
                "+1.00+0.10");

            //Change A,U
            var pay = tester.Pay("0.1", false, null);

            tester.AssertPools(
                "+1.00+0.10",
                "+1.00+0.10-0.10",
                "+1.00+0.10-0.10");

            //Chance C
            tester.AppendBlock(pay, chain);
            tester.UpdateWallet(chain);
            tester.AssertPools(
                "+1.00+0.10-0.10",
                "+1.00+0.10-0.10",
                "+1.00+0.10-0.10");

            Assert.False(tester.UpdateWallet(chain));
        }
示例#2
0
        public void CanManageMoney()
        {
            WalletTester tester = new WalletTester();
            Chain chain = new Chain(Network.Main);
            //Change C,A,U
            tester.GiveMoney("1.0", chain);
            Assert.True(tester.UpdateWallet(chain));
            tester.AssertPools(
                "+1.00",
                "+1.00",
                "+1.00");
            Assert.False(tester.UpdateWallet(chain));

            //Change U
            var rcv = tester.GiveMoney("0.1", null);
            tester.AssertPools(
                "+1.00",
                "+1.00",
                "+1.00+0.10");

            tester.AppendBlock(rcv, chain);
            //Change C,A
            Assert.True(tester.UpdateWallet(chain));
            tester.AssertPools(
                "+1.00+0.10",
                "+1.00+0.10",
                "+1.00+0.10");

            //Change A,U
            var pay = tester.Pay("0.1", false, null);
            tester.AssertPools(
                "+1.00+0.10",
                "+1.00+0.10-0.10",
                "+1.00+0.10-0.10");

            //Chance C
            tester.AppendBlock(pay, chain);
            tester.UpdateWallet(chain);
            tester.AssertPools(
                "+1.00+0.10-0.10",
                "+1.00+0.10-0.10",
                "+1.00+0.10-0.10");

            Assert.False(tester.UpdateWallet(chain));
        }
示例#3
0
        public void CanManageMoneyInFork()
        {
            WalletTester tester = new WalletTester();
            var          chain  = new Chain(Network.Main);
            var          fork   = new Chain(Network.Main);

            //Change C,A,U
            tester.GiveMoney("1.0", chain, fork);
            tester.GiveMoney("2.0", chain, fork);
            tester.GiveMoney("3.0", chain, fork);
            var four = tester.GiveMoney("4.0", fork);

            tester.UpdateWallet(fork);
            tester.AssertPools(
                "+1.00+2.00+3.00+4.00",
                "+1.00+2.00+3.00+4.00",
                "+1.00+2.00+3.00+4.00");

            //4.0 canceled
            tester.UpdateWallet(chain);
            tester.AssertPools(
                "+1.00+2.00+3.00+4.00-4.00",
                "+1.00+2.00+3.00+4.00-4.00",
                "+1.00+2.00+3.00+4.00");         //4.0 is in mempool


            //4.0 re introduced
            tester.UpdateWallet(fork);
            tester.AssertPools(
                "+1.00+2.00+3.00+4.00-4.00+4.00",
                "+1.00+2.00+3.00+4.00-4.00+4.00",
                "+1.00+2.00+3.00+4.00");

            //4.0 canceled, 5.0 intro
            tester.GiveMoney("5.0", chain);
            tester.UpdateWallet(chain);
            tester.AssertPools(
                "+1.00+2.00+3.00+4.00-4.00+4.00-4.00+5.00",
                "+1.00+2.00+3.00+4.00-4.00+4.00-4.00+5.00",
                "+1.00+2.00+3.00+4.00+5.00");


            //spend all
            tester.Pay(tester.Wallet.Accounts.Confirmed.Balance, true, chain);
            tester.UpdateWallet(chain);
            Assert.Equal(Money.Zero, tester.Wallet.Accounts.Confirmed.Balance);
            Assert.Equal(Money.Zero, tester.Wallet.Accounts.Available.Balance);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Unconfirmed.Balance);

            //the canceled transaction (forked) become confirmed
            tester.AppendBlock(four, chain);
            tester.UpdateWallet(chain);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Confirmed.Balance);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Available.Balance);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Unconfirmed.Balance);

            var unconfirmedSpent = tester.Pay(Money.Parse("4.00"), true, null);

            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Confirmed.Balance);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Available.Balance);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Unconfirmed.Balance);

            tester.AppendBlock(unconfirmedSpent, chain);
            tester.UpdateWallet(chain);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Confirmed.Balance);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Available.Balance);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Unconfirmed.Balance);
        }
示例#4
0
        public void CanManageMoneyInFork()
        {
            WalletTester tester = new WalletTester();
            var chain = new Chain(Network.Main);
            var fork = new Chain(Network.Main);
            //Change C,A,U
            tester.GiveMoney("1.0", chain, fork);
            tester.GiveMoney("2.0", chain, fork);
            tester.GiveMoney("3.0", chain, fork);
            var four = tester.GiveMoney("4.0", fork);

            tester.UpdateWallet(fork);
            tester.AssertPools(
                "+1.00+2.00+3.00+4.00",
                "+1.00+2.00+3.00+4.00",
                "+1.00+2.00+3.00+4.00");

            //4.0 canceled
            tester.UpdateWallet(chain);
            tester.AssertPools(
            "+1.00+2.00+3.00+4.00-4.00",
            "+1.00+2.00+3.00+4.00-4.00",
            "+1.00+2.00+3.00+4.00"); //4.0 is in mempool

            //4.0 re introduced
            tester.UpdateWallet(fork);
            tester.AssertPools(
            "+1.00+2.00+3.00+4.00-4.00+4.00",
            "+1.00+2.00+3.00+4.00-4.00+4.00",
            "+1.00+2.00+3.00+4.00");

            //4.0 canceled, 5.0 intro
            tester.GiveMoney("5.0", chain);
            tester.UpdateWallet(chain);
            tester.AssertPools(
            "+1.00+2.00+3.00+4.00-4.00+4.00-4.00+5.00",
            "+1.00+2.00+3.00+4.00-4.00+4.00-4.00+5.00",
            "+1.00+2.00+3.00+4.00+5.00");

            //spend all
            tester.Pay(tester.Wallet.Accounts.Confirmed.Balance, true, chain);
            tester.UpdateWallet(chain);
            Assert.Equal(Money.Zero, tester.Wallet.Accounts.Confirmed.Balance);
            Assert.Equal(Money.Zero, tester.Wallet.Accounts.Available.Balance);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Unconfirmed.Balance);

            //the canceled transaction (forked) become confirmed
            tester.AppendBlock(four, chain);
            tester.UpdateWallet(chain);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Confirmed.Balance);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Available.Balance);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Unconfirmed.Balance);

            var unconfirmedSpent = tester.Pay(Money.Parse("4.00"), true, null);
            Assert.Equal(Money.Parse("4.00"), tester.Wallet.Accounts.Confirmed.Balance);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Available.Balance);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Unconfirmed.Balance);

            tester.AppendBlock(unconfirmedSpent, chain);
            tester.UpdateWallet(chain);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Confirmed.Balance);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Available.Balance);
            Assert.Equal(Money.Parse("0.00"), tester.Wallet.Accounts.Unconfirmed.Balance);
        }