public void GetStakingInfo_StakingEnabled() { string dir = AssureEmptyDir("TestData/GetStakingInfoActionTests/GetStakingInfo_StakingEnabled"); IFullNode fullNode = this.BuildStakingNode(dir); Task.Run(() => { fullNode.Run(); }); INodeLifetime nodeLifetime = fullNode.NodeService <INodeLifetime>(); nodeLifetime.ApplicationStarted.WaitHandle.WaitOne(); MiningRPCController controller = fullNode.Services.ServiceProvider.GetService <MiningRPCController>(); Assert.NotNull(fullNode.NodeService <PosMinting>(true)); GetStakingInfoModel info = controller.GetStakingInfo(); Assert.NotNull(info); Assert.True(info.Enabled); Assert.False(info.Staking); nodeLifetime.StopApplication(); nodeLifetime.ApplicationStopped.WaitHandle.WaitOne(); fullNode.Dispose(); }
public void GetStakingInfo_StakingEnabled() { using (var dir = TestDirectory.Create()) { IFullNode fullNode = PurpleBitcoinPosRunner.BuildStakingNode(dir.FolderName); var fullNodeRunTask = fullNode.RunAsync(); INodeLifetime nodeLifetime = fullNode.NodeService <INodeLifetime>(); nodeLifetime.ApplicationStarted.WaitHandle.WaitOne(); MiningRPCController controller = fullNode.Services.ServiceProvider.GetService <MiningRPCController>(); Assert.NotNull(fullNode.NodeService <IPosMinting>(true)); GetStakingInfoModel 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 GetStakingInfo_WithoutPosMinting_ReturnsEmptyStakingInfoModel() { this.controller = new MiningRPCController(this.powMining.Object, this.fullNode.Object, this.LoggerFactory.Object, this.walletManager.Object, null); var result = this.controller.GetStakingInfo(true); Assert.Equal(JsonConvert.SerializeObject(new GetStakingInfoModel()), JsonConvert.SerializeObject(result)); }
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 MiningRPCControllerTest(MiningRPCControllerFixture fixture) { this.fixture = fixture; this.powMining = new Mock <IPowMining>(); this.fullNode = new Mock <IFullNode>(); this.posMinting = new Mock <IPosMinting>(); this.walletManager = new Mock <IWalletManager>(); this.timeSyncBehaviorState = new Mock <ITimeSyncBehaviorState>(); this.fullNode.Setup(f => f.NodeService <IWalletManager>(false)) .Returns(this.walletManager.Object); this.controller = new MiningRPCController(this.powMining.Object, this.fullNode.Object, this.LoggerFactory.Object, this.walletManager.Object, this.posMinting.Object); }
public MiningRPCControllerTest(MiningRPCControllerFixture fixture) { this.fixture = fixture; this.powMining = new Mock <IPowMining>(); this.fullNode = new Mock <IFullNode>(); this.posMinting = new Mock <IPosMinting>(); this.walletManager = new Mock <IWalletManager>(); this.connectionManager = new Mock <IConnectionManager>(); this.chain = new Mock <ConcurrentChain>(); this.fullNode.Setup(f => f.NodeService <IWalletManager>(false)) .Returns(this.walletManager.Object); this.controller = new MiningRPCController(this.powMining.Object, this.fullNode.Object, this.connectionManager.Object, this.chain.Object, this.LoggerFactory.Object, this.walletManager.Object, this.posMinting.Object); }
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(); }
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(); } }