public void TestStorage()
        {
            var temp = new FileInfo(Path.GetTempFileName());

            try
            {
                Console.WriteLine(temp.FullName);
                var         networkParams = NetworkParameters.UnitTests();
                var         to            = new EcKey().ToAddress(networkParams);
                StoredBlock b1;
                using (var store = new BoundedOverheadBlockStore(networkParams, temp))
                {
                    // Check the first block in a new store is the genesis block.
                    var genesis = store.GetChainHead();
                    Assert.AreEqual(networkParams.GenesisBlock, genesis.Header);

                    // Build a new block.
                    b1 = genesis.Build(genesis.Header.CreateNextBlock(to).CloneAsHeader());
                    store.Put(b1);
                    store.SetChainHead(b1);
                }
                // Check we can get it back out again if we rebuild the store object.
                using (var store = new BoundedOverheadBlockStore(networkParams, temp))
                {
                    var b2 = store.Get(b1.Header.Hash);
                    Assert.AreEqual(b1, b2);
                    // Check the chain head was stored correctly also.
                    Assert.AreEqual(b1, store.GetChainHead());
                }
            }
            finally
            {
                temp.Delete();
            }
        }
Esempio n. 2
0
 public void SetUp()
 {
     _unitTestParams = NetworkParameters.UnitTests();
     _wallet         = new Wallet(_unitTestParams);
     _wallet.AddKey(new EcKey());
     _chainBlockStore = new MemoryBlockStore(_unitTestParams);
     _chain           = new BlockChain(_unitTestParams, _wallet, _chainBlockStore);
     _coinbaseTo      = _wallet.Keychain[0].ToAddress(_unitTestParams);
     _someOtherGuy    = new EcKey().ToAddress(_unitTestParams);
 }
Esempio n. 3
0
        public void SetUp()
        {
            _unitTestParams = NetworkParameters.UnitTests();
            _blockStore     = new MemoryBlockStore(_unitTestParams);
            _blockChain     = new BlockChain(_unitTestParams, new Wallet(_unitTestParams), _blockStore);
            var address = new PeerAddress(IPAddress.Loopback);

            _control         = new Mock <NetworkConnection>();
            _conn            = _control.Object;
            _peer            = new Peer(_unitTestParams, address, _blockChain);
            _peer.Connection = _conn;
        }
Esempio n. 4
0
        public void SetUp()
        {
            _testNetChainBlockStore = new MemoryBlockStore(_testNet);
            _testNetChain           = new BlockChain(_testNet, new Wallet(_testNet), _testNetChainBlockStore);
            _unitTestParams         = NetworkParameters.UnitTests();
            _wallet = new Wallet(_unitTestParams);
            _wallet.AddKey(new EcKey());

            ResetBlockStore();
            _chain = new BlockChain(_unitTestParams, _wallet, _blockStore);

            _coinbaseTo = _wallet.Keychain[0].ToAddress(_unitTestParams);
        }
Esempio n. 5
0
        public void TestProofOfWork()
        {
            // This params accepts any difficulty target.
            var @params = NetworkParameters.UnitTests();
            var block   = new Block(@params, _blockBytes);

            block.Nonce = 12346;
            try
            {
                block.Verify();
                Assert.Fail();
            }
            catch (VerificationException)
            {
                // Expected.
            }
            // Blocks contain their own difficulty target. The BlockChain verification mechanism is what stops real blocks
            // from containing artificially weak difficulties.
            block.DifficultyTarget = Block.EasiestDifficultyTarget;
            // Now it should pass.
            block.Verify();
            // Break the nonce again at the lower difficulty level so we can try solving for it.
            block.Nonce = 1;
            try
            {
                block.Verify();
                Assert.Fail();
            }
            catch (VerificationException)
            {
                // Expected to fail as the nonce is no longer correct.
            }
            // Should find an acceptable nonce.
            block.Solve();
            block.Verify();
            Assert.AreEqual(block.Nonce, 2);
        }