CreateFakeBlock() публичный статический Метод

public static CreateFakeBlock ( NetworkParameters @params, IBlockStore blockStore ) : BlockPair
@params NetworkParameters
blockStore IBlockStore
Результат BlockPair
Пример #1
0
        public void TestRunUnconnectedBlock()
        {
            var b1 = TestUtils.CreateFakeBlock(_unitTestParams, _blockStore).Block;

            _blockChain.Add(b1);

            var prev  = TestUtils.MakeSolvedTestBlock(_unitTestParams, _blockStore);
            var block = TestUtils.MakeSolvedTestBlock(_unitTestParams, prev);

            _control.Setup(x => x.ReadMessage()).Returns(() => block, ReadFinalMessage).Verifiable();

            var message = CaptureGetBlocksMessage();

            RunPeerAndVerify();

            var expectedLocator = new List <Sha256Hash>();

            expectedLocator.Add(b1.Hash);
            expectedLocator.Add(_unitTestParams.GenesisBlock.Hash);

            Assert.AreEqual(message.Value.Locator, expectedLocator);
            Assert.AreEqual(message.Value.StopHash, block.Hash);
        }
Пример #2
0
        public void Balance()
        {
            // Receive 5 coins then half a coin.
            var v1       = Utils.ToNanoCoins(5, 0);
            var v2       = Utils.ToNanoCoins(0, 50);
            var t1       = TestUtils.CreateFakeTx(_params, v1, _myAddress);
            var t2       = TestUtils.CreateFakeTx(_params, v2, _myAddress);
            var b1       = TestUtils.CreateFakeBlock(_params, _blockStore, t1).StoredBlock;
            var b2       = TestUtils.CreateFakeBlock(_params, _blockStore, t2).StoredBlock;
            var expected = Utils.ToNanoCoins(5, 50);

            _wallet.Receive(t1, b1, BlockChain.NewBlockType.BestChain);
            _wallet.Receive(t2, b2, BlockChain.NewBlockType.BestChain);
            Assert.AreEqual(expected, _wallet.GetBalance());

            // Now spend one coin.
            var v3    = Utils.ToNanoCoins(1, 0);
            var spend = _wallet.CreateSend(new EcKey().ToAddress(_params), v3);

            _wallet.ConfirmSend(spend);

            // Available and estimated balances should not be the same. We don't check the exact available balance here
            // because it depends on the coin selection algorithm.
            Assert.AreEqual(Utils.ToNanoCoins(4, 50), _wallet.GetBalance(Wallet.BalanceType.Estimated));
            Assert.IsFalse(_wallet.GetBalance(Wallet.BalanceType.Available).Equals(
                               _wallet.GetBalance(Wallet.BalanceType.Estimated)));

            // Now confirm the transaction by including it into a block.
            var b3 = TestUtils.CreateFakeBlock(_params, _blockStore, spend).StoredBlock;

            _wallet.Receive(spend, b3, BlockChain.NewBlockType.BestChain);

            // Change is confirmed. We started with 5.50 so we should have 4.50 left.
            var v4 = Utils.ToNanoCoins(4, 50);

            Assert.AreEqual(v4, _wallet.GetBalance(Wallet.BalanceType.Available));
        }