Beispiel #1
0
        public void CanStartStakingViaAPI()
        {
            try
            {
                using (NodeBuilder builder = NodeBuilder.Create())
                {
                    CoreNode nodeA = builder.CreateStratisPosNode(false, fullNodeBuilder =>
                    {
                        fullNodeBuilder
                        .UseStratisConsensus()
                        .UseBlockStore()
                        .UseMempool()
                        .UseWallet()
                        .AddPowPosMining()
                        .UseApi()
                        .AddRPC();
                    });

                    builder.StartAll();

                    var fullNode = nodeA.FullNode;
                    var ApiURI   = fullNode.Settings.ApiUri;

                    Assert.NotNull(fullNode.NodeService <PosMinting>(true));

                    using (Node nodeB = nodeA.CreateNodeClient())
                    {
                        WalletManager walletManager = fullNode.NodeService <IWalletManager>() as WalletManager;

                        // create the wallet
                        var model = new StartStakingRequest {
                            Name = "apitest", Password = "******"
                        };
                        var mnemonic = walletManager.CreateWallet(model.Password, model.Name);

                        var content  = new StringContent(model.ToString(), Encoding.UTF8, "application/json");
                        var response = client.PostAsync(ApiURI + "api/miner/startstaking", content).GetAwaiter().GetResult();
                        Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);

                        var responseText = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                        Assert.Equal("", responseText);

                        MiningRPCController controller = fullNode.NodeService <MiningRPCController>();
                        GetStakingInfoModel info       = controller.GetStakingInfo();

                        Assert.NotNull(info);
                        Assert.True(info.Enabled);
                        Assert.False(info.Staking);
                    }
                }
            }
            finally
            {
                // Revert global side-effects of StratisBitcoinPosRunner.InitStratisRegTest()
                Block.BlockSignature  = false;
                Transaction.TimeStamp = false;
            }
        }
        public void TestSegwitActivation()
        {
            using (NodeBuilder builder = NodeBuilder.Create(version: "0.15.1"))
            {
                CoreNode coreNode = builder.CreateNode(false);

                coreNode.ConfigParameters.AddOrReplace("debug", "1");
                coreNode.ConfigParameters.AddOrReplace("printtoconsole", "0");
                coreNode.Start();

                CoreNode node1 = builder.CreateStratisPowNode(true, fullNodeBuilder =>
                {
                    fullNodeBuilder
                    .UseConsensus()
                    .UseBlockStore()
                    .UseMempool()
                    .UseBlockNotification()
                    .UseTransactionNotification()
                    .AddMining()
                    .UseWallet()
                    .UseApi()
                    .AddRPC();
                });

                WalletManager wm1 = node1.FullNode.NodeService <IWalletManager>() as WalletManager;
                wm1.CreateWallet("Test1", "alice1");

                RPCClient rpc1    = node1.CreateRPCClient();
                RPCClient coreRpc = coreNode.CreateRPCClient();

                coreRpc.AddNode(node1.Endpoint, false);
                rpc1.AddNode(coreNode.Endpoint, false);

                coreRpc.Generate(450);

                BIP9DeploymentsArray bip9Constants = node1.FullNode.Network.Consensus.BIP9Deployments;
                ConsensusLoop        consensusLoop = node1.FullNode.NodeService <ConsensusLoop>();
                ThresholdState[]     bip9State     = consensusLoop.NodeDeployments.BIP9.GetStates(node1.FullNode.Chain.Tip.Previous);

                Money     amount       = new Money(5.0m, MoneyUnit.BTC);
                HdAddress destination1 = wm1.GetUnusedAddress(new WalletAccountReference("alice1", "account 0"));

                coreRpc.SendToAddress(BitcoinAddress.Create(destination1.Address, Network.RegTest), amount);

                coreRpc.Generate(1);

                Assert.Equal(ThresholdState.Active, bip9State.GetValue((int)BIP9Deployments.Segwit));
            }
        }
Beispiel #3
0
        public void GetStakingInfo_StartStaking()
        {
            string    dir      = AssureEmptyDir("TestData/GetStakingInfoActionTests/GetStakingInfo_StartStaking");
            IFullNode fullNode = this.BuildStakingNode(dir, false);
            var       node     = fullNode as FullNode;

            Task.Run(() =>
            {
                fullNode.Run();
            });

            INodeLifetime nodeLifetime = fullNode.NodeService <INodeLifetime>();

            nodeLifetime.ApplicationStarted.WaitHandle.WaitOne();
            MiningRPCController controller = fullNode.Services.ServiceProvider.GetService <MiningRPCController>();

            WalletManager walletManager = node.NodeService <IWalletManager>() as WalletManager;

            var password = "******";

            // create the wallet
            var mnemonic = walletManager.CreateWallet(password, "test");


            Assert.NotNull(fullNode.NodeService <PosMinting>(true));

            GetStakingInfoModel info = controller.GetStakingInfo();

            Assert.NotNull(info);
            Assert.False(info.Enabled);
            Assert.False(info.Staking);

            controller.StartStaking("test", "test");

            info = controller.GetStakingInfo();

            Assert.NotNull(info);
            Assert.True(info.Enabled);
            Assert.False(info.Staking);

            nodeLifetime.StopApplication();
            nodeLifetime.ApplicationStopped.WaitHandle.WaitOne();
            fullNode.Dispose();
        }
Beispiel #4
0
        public void GetStakingInfo_StartStaking()
        {
            using (var dir = TestDirectory.Create())
            {
                IFullNode fullNode = StratisBitcoinPosRunner.BuildStakingNode(dir.FolderName, false);
                var       node     = fullNode as FullNode;

                var fullNodeRunTask = fullNode.RunAsync();

                INodeLifetime nodeLifetime = fullNode.NodeService <INodeLifetime>();
                nodeLifetime.ApplicationStarted.WaitHandle.WaitOne();
                MiningRPCController controller = fullNode.Services.ServiceProvider.GetService <MiningRPCController>();

                WalletManager walletManager = node.NodeService <IWalletManager>() as WalletManager;

                var password = "******";

                // create the wallet
                var mnemonic = walletManager.CreateWallet(password, "test");


                Assert.NotNull(fullNode.NodeService <PosMinting>(true));

                GetStakingInfoModel info = controller.GetStakingInfo();

                Assert.NotNull(info);
                Assert.False(info.Enabled);
                Assert.False(info.Staking);

                controller.StartStaking("test", "test");

                info = controller.GetStakingInfo();

                Assert.NotNull(info);
                Assert.True(info.Enabled);
                Assert.False(info.Staking);

                nodeLifetime.StopApplication();
                nodeLifetime.ApplicationStopped.WaitHandle.WaitOne();
                fullNode.Dispose();

                Assert.False(fullNodeRunTask.IsFaulted);
            }
        }
        public void CanStartStakingViaAPI()
        {
            try
            {
                var fullNode = this.apiTestsFixture.stratisStakeNode.FullNode;
                var apiURI   = fullNode.NodeService <ApiSettings>().ApiUri;

                Assert.NotNull(fullNode.NodeService <IPosMinting>(true));

                using (client = new HttpClient())
                {
                    WalletManager walletManager = fullNode.NodeService <IWalletManager>() as WalletManager;

                    // create the wallet
                    var model = new StartStakingRequest {
                        Name = "apitest", Password = "******"
                    };
                    var mnemonic = walletManager.CreateWallet(model.Password, model.Name);

                    var content  = new StringContent(model.ToString(), Encoding.UTF8, "application/json");
                    var response = client.PostAsync(apiURI + "api/miner/startstaking", content).GetAwaiter().GetResult();
                    Assert.Equal(System.Net.HttpStatusCode.OK, response.StatusCode);

                    var responseText = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                    Assert.Equal("", responseText);

                    MiningRPCController controller = fullNode.NodeService <MiningRPCController>();
                    GetStakingInfoModel info       = controller.GetStakingInfo();

                    Assert.NotNull(info);
                    Assert.True(info.Enabled);
                    Assert.False(info.Staking);
                }
            }
            finally
            {
                this.Dispose();
            }
        }