Exemplo n.º 1
0
        public TestBlocks Fork(int rollbackCount = 0)
        {
            var fork = new TestBlocks(this);

            fork.Rollback(rollbackCount);
            return(fork);
        }
Exemplo n.º 2
0
        public TestDaemon(Block genesisBlock = null, INinjectModule loggingModule = null, INinjectModule[] storageModules = null)
        {
            // initialize storage folder
            this.baseDirectoryCleanup = TempDirectory.CreateTempDirectory(out this.baseDirectory);

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

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

            // log startup
            this.logger = LogManager.GetCurrentClassLogger();
            this.logger.Info($"Starting up: {DateTime.Now}");

            // initialize test blocks
            this.testBlocks = new TestBlocks(genesisBlock);

            // add storage module
            this.kernel.Load(storageModules ?? new[] { new MemoryStorageModule() });

            // initialize unit test rules, allow validation methods to run
            testBlocks.Rules.ValidateTransactionAction = null;
            testBlocks.Rules.ValidationTransactionScriptAction = null;
            this.kernel.Bind<ChainType>().ToConstant(ChainType.Regtest);
            this.kernel.Bind<ICoreRules>().ToConstant(testBlocks.Rules);
            this.kernel.Bind<IChainParams>().ToConstant(testBlocks.ChainParams);

            // by default, don't run scripts in unit tests
            testBlocks.Rules.IgnoreScripts = 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(testBlocks.ChainParams.GenesisBlock.Hash, this.coreDaemon.TargetChain.LastBlock.Hash);
                Assert.AreEqual(testBlocks.ChainParams.GenesisBlock.Hash, this.coreDaemon.CurrentChain.LastBlock.Hash);
            }
            catch (Exception)
            {
                this.coreDaemon.Dispose();
                throw;
            }
        }
Exemplo n.º 3
0
        public TestDaemon(Block genesisBlock = null, INinjectModule loggingModule = null, INinjectModule[] storageModules = null)
        {
            // initialize storage folder
            this.baseDirectoryCleanup = TempDirectory.CreateTempDirectory(out this.baseDirectory);

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

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

            // log startup
            this.logger = LogManager.GetCurrentClassLogger();
            this.logger.Info($"Starting up: {DateTime.Now}");

            // initialize test blocks
            this.testBlocks = new TestBlocks(genesisBlock);

            // add storage module
            this.kernel.Load(storageModules ?? new[] { new MemoryStorageModule() });

            // initialize unit test rules, allow validation methods to run
            testBlocks.Rules.ValidateTransactionAction         = null;
            testBlocks.Rules.ValidationTransactionScriptAction = null;
            this.kernel.Bind <ChainType>().ToConstant(ChainType.Regtest);
            this.kernel.Bind <ICoreRules>().ToConstant(testBlocks.Rules);
            this.kernel.Bind <IChainParams>().ToConstant(testBlocks.ChainParams);

            // by default, don't run scripts in unit tests
            testBlocks.Rules.IgnoreScripts = 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(testBlocks.ChainParams.GenesisBlock.Hash, this.coreDaemon.TargetChain.LastBlock.Hash);
                Assert.AreEqual(testBlocks.ChainParams.GenesisBlock.Hash, this.coreDaemon.CurrentChain.LastBlock.Hash);
            }
            catch (Exception)
            {
                this.coreDaemon.Dispose();
                throw;
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
 public TestBlocks Fork(int rollbackCount = 0)
 {
     var fork = new TestBlocks(this);
     fork.Rollback(rollbackCount);
     return fork;
 }