Example #1
0
        public TestDaemon(Block genesisBlock = null)
        {
            this.random = new Random();

            // initialize kernel
            this.kernel = new StandardKernel();

            // add logging module
            this.kernel.Load(new ConsoleLoggingModule());

            // create the key pair that block rewards will be sent to
            this.txManager = this.kernel.Get <TransactionManager>();
            var keyPair = this.txManager.CreateKeyPair();

            this.coinbasePrivateKey = keyPair.Item1;
            this.coinbasePublicKey  = keyPair.Item2;

            // initialize miner
            this.miner = this.kernel.Get <Miner>();

            // create and mine the genesis block
            this.genesisBlock = genesisBlock ?? MineEmptyBlock(0);

            // log startup
            this.logger = kernel.Get <Logger>();
            this.logger.Info("Starting up: {0}".Format2(DateTime.Now));

            // add storage module
            this.kernel.Load(new MemoryStorageModule());

            // add cache module
            this.kernel.Load(new CoreCacheModule());

            // initialize block view
            this.blockCache = this.kernel.Get <BlockCache>();

            // store genesis block
            this.blockCache[this.genesisBlock.Hash] = this.genesisBlock;

            // initialize unit test rules
            this.rules = this.kernel.Get <UnitTestRules>();
            this.rules.SetGenesisBlock(this.genesisBlock);
            this.kernel.Bind <RulesEnum>().ToConstant(RulesEnum.TestNet2);
            this.kernel.Bind <IBlockchainRules>().ToConstant(rules);

            // initialize the blockchain daemon
            this.kernel.Bind <CoreDaemon>().ToSelf().InSingletonScope();
            this.blockchainDaemon = this.kernel.Get <CoreDaemon>();

            // start the blockchain daemon
            this.blockchainDaemon.Start();

            // wait for initial work
            this.blockchainDaemon.ForceWorkAndWait();

            // verify initial state
            Assert.AreEqual(0, this.blockchainDaemon.TargetBlock.Height);
            Assert.AreEqual(this.genesisBlock.Hash, this.blockchainDaemon.TargetChain.LastBlockHash);
            Assert.AreEqual(this.genesisBlock.Hash, this.blockchainDaemon.CurrentChain.LastBlockHash);
        }
Example #2
0
        public TestBlocks(TestBlocks parent)
        {
            this.random             = parent.random;
            this.txManager          = parent.txManager;
            this.coinbasePrivateKey = parent.coinbasePrivateKey;
            this.coinbasePublicKey  = parent.coinbasePublicKey;

            this.miner = parent.miner;
            this.rules = parent.rules;

            this.blocks = parent.blocks.ToImmutable().ToBuilder();
            this.chain  = parent.chain.ToImmutable().ToBuilder();
        }
Example #3
0
        public TestBlocks(Block genesisBlock = null)
        {
            // create the key pair that block rewards will be sent to
            var keyPair = txManager.CreateKeyPair();

            coinbasePrivateKey = keyPair.Item1;
            coinbasePublicKey  = keyPair.Item2;

            // create and mine the genesis block
            genesisBlock = genesisBlock ?? MineEmptyBlock(UInt256.Zero);

            // initialize unit test rules
            rules = new UnitTestRules()
            {
                // disable execution of rules validation
                ValidateTransactionAction         = (_, __) => { },
                ValidationTransactionScriptAction = (_, __, ___, ____, _____) => { }
            };
            ChainParams.SetGenesisBlock(genesisBlock);

            blocks.Add(genesisBlock);
            chain.AddBlock(ChainParams.GenesisChainedHeader);
        }
Example #4
0
        public TestDaemon(Block genesisBlock = null)
        {
            this.random = new Random();

            // initialize kernel
            this.kernel = new StandardKernel();

            // add logging module
            this.kernel.Load(new ConsoleLoggingModule());

            // create the key pair that block rewards will be sent to
            this.txManager = this.kernel.Get <TransactionManager>();
            var keyPair = this.txManager.CreateKeyPair();

            this.coinbasePrivateKey = keyPair.Item1;
            this.coinbasePublicKey  = keyPair.Item2;

            // initialize miner
            this.miner = this.kernel.Get <Miner>();

            // create and mine the genesis block
            this.genesisBlock = genesisBlock ?? MineEmptyBlock(0);

            // log startup
            this.logger = kernel.Get <Logger>();
            this.logger.Info("Starting up: {0}".Format2(DateTime.Now));

            // add storage module
            this.kernel.Load(new MemoryStorageModule());

            // initialize unit test rules
            this.rules = this.kernel.Get <UnitTestRules>();
            this.rules.SetGenesisBlock(this.genesisBlock);
            this.kernel.Bind <RulesEnum>().ToConstant(RulesEnum.TestNet2);
            this.kernel.Bind <IBlockchainRules>().ToConstant(rules);

            // TODO ignore script errors in test daemon until scripting engine is completed
            this.rules.IgnoreScriptErrors = true;

            // initialize the blockchain daemon
            this.kernel.Bind <CoreDaemon>().ToSelf().InSingletonScope();
            this.coreDaemon = this.kernel.Get <CoreDaemon>();
            try
            {
                this.coreStorage = this.coreDaemon.CoreStorage;

                // start the blockchain daemon
                this.coreDaemon.Start();

                // wait for initial work
                this.coreDaemon.WaitForUpdate();

                // verify initial state
                Assert.AreEqual(0, this.coreDaemon.TargetChainHeight);
                Assert.AreEqual(this.genesisBlock.Hash, this.coreDaemon.TargetChain.LastBlockHash);
                Assert.AreEqual(this.genesisBlock.Hash, this.coreDaemon.CurrentChain.LastBlockHash);
            }
            catch (Exception)
            {
                this.coreDaemon.Dispose();
                throw;
            }
        }