public void GenerateBlocksOn_PosNetwork_ConsensusTip_IsAfterLastPowBlock_ReturnsError() { var consensusManager = new Mock <IConsensusManager>(); var header = this.network.Consensus.ConsensusFactory.CreateBlockHeader(); consensusManager.Setup(cm => cm.Tip).Returns(new ChainedHeader(header, header.GetHash(), this.network.Consensus.LastPOWBlock + 1)); this.fullNode.Setup(i => i.NodeService <IConsensusManager>(false)).Returns(consensusManager.Object); var controller = new MiningController(consensusManager.Object, this.fullNode.Object, this.loggerFactory, this.network, new Mock <IPowMining>().Object, new Mock <IWalletManager>().Object); IActionResult result = controller.Generate(new MiningRequest { BlockCount = 1 }); var errorResult = Assert.IsType <ErrorResult>(result); var errorResponse = Assert.IsType <ErrorResponse>(errorResult.Value); Assert.Single(errorResponse.Errors); ErrorModel error = errorResponse.Errors[0]; Assert.Equal(405, error.Status); Assert.Equal("Method not allowed", error.Message); Assert.Equal(string.Format(MiningController.LastPowBlockExceededMessage, this.network.Consensus.LastPOWBlock), error.Description); }
void Awake() { mInstance = this; #region EVENT SYSTEM SETUP //Listening for events EventController.getInstance().RegisterListener <MiningWorkerEventInfo>(MiningWorkerUpdate); EventController.getInstance().RegisterListener <CopperMinePurchaseEventInfo>(UnlockCopperMine); EventController.getInstance().RegisterListener <TinMinePurchaseEventInfo>(UnlockTinMine); EventController.getInstance().RegisterListener <CoalMinePurchaseEventInfo>(UnlockCoalMine); EventController.getInstance().RegisterListener <IronMinePurchaseEventInfo>(UnlockIronMine); ruei.eventGO = gameObject; #endregion #region Mine setup CopperMineGO.gameObject.SetActive(false); TinMineGO.gameObject.SetActive(false); CoalMineGO.gameObject.SetActive(false); IronMineGO.gameObject.SetActive(false); StoneProgress = StoneProgressBar.current = 0.0f; StoneProgressCap = StoneProgressBar.maximum = 10.0f; CopperProgress = CopperProgressBar.current = 0.0f; CopperProgressCap = CopperProgressBar.maximum = 20.0f; TinProgress = TinProgressBar.current = 0.0f; TinProgressCap = TinProgressBar.maximum = 50.0f; CoalProgress = CoalProgressBar.current = 0.0f; CoalProgressCap = CoalProgressBar.maximum = 100.0f; IronProgress = IronProgressBar.current = 0.0f; IronProgressCap = IronProgressBar.maximum = 200.0f; #endregion }
private void OnEnable() { rigController = FindObjectOfType <RigController>(); itemDatabase = FindObjectOfType <ItemDatabase>(); miningControllerInstance = FindObjectOfType <MiningController>(); mapDelegateHolder = FindObjectOfType <MapDelegateHolder>(); rigController.rigUpgradedActions += UpgradeARig; rigController.rackUpgradedActions += UpgradeARackOfRigs; // Populating the rig slot list and assigning IDs int i = 0; foreach (Transform child in rigSlotHolder) { rigSlots.Add(child); child.GetComponent <Rigslot>().myOrderNumber = i; i++; } // Populating the rack slots list and assigning IDs foreach (Transform child in rackSlotHolder) { rackSlots.Add(child); child.GetComponent <RackSlot>().myOrderNumber = i; child.GetComponent <RackSlot>().racksInThisGroup = 0; i++; } }
public void Generate_With_Incorrect_Block_Count_ReturnsInvalidRequest(int?blockCount) { var consensusManager = new Mock <IConsensusManager>(); consensusManager.Setup(cm => cm.Tip).Returns(new ChainedHeader(this.network.Consensus.ConsensusFactory.CreateBlockHeader(), new uint256(0), this.network.Consensus.LastPOWBlock - 1)); var controller = new MiningController(consensusManager.Object, this.fullNode.Object, this.loggerFactory, this.network, new Mock <IPowMining>().Object, new Mock <IWalletManager>().Object); IActionResult result = blockCount == null? controller.Generate(new MiningRequest()) : controller.Generate(new MiningRequest { BlockCount = (int)blockCount }); var errorResult = Assert.IsType <ErrorResult>(result); var errorResponse = Assert.IsType <ErrorResponse>(errorResult.Value); Assert.Single(errorResponse.Errors); ErrorModel error = errorResponse.Errors[0]; Assert.Equal(403, error.Status); Assert.Equal("Invalid request", error.Message); Assert.Equal("The number of blocks to mine must be higher than zero.", error.Description); }
// Use this for initialization void Start() { levelUpgrader = FindObjectOfType <LevelUpgrader>(); miningController = FindObjectOfType <MiningController>(); levelUpgrader.upgradedApartment += RefreshApartmentPurchaseUI; AssignFunctionToButton(); }
public static MiningController GetInstance() { if (mInstance == null) { Debug.Log("ABORTMINING"); GameObject go = new GameObject(); mInstance = go.AddComponent <MiningController>(); } return(mInstance); }
// Use this for initialization void Start() { rigController = FindObjectOfType <RigController>(); miningController = FindObjectOfType <MiningController>(); mainUIController = GameObject.FindGameObjectWithTag("MainUI").GetComponent <UIController>(); // I am sending the ID of the rackslot I am referring to unfoldButton.onClick.AddListener(() => mainUIController.ShowRacksSideMenu(orderNumber)); upgradeAllButton.onClick.AddListener(() => UpgradeAllRacksInThisGroup()); }
public void MiningController_Calls_GetAccount_Error_No_Wallet_Found() { Mock <IConsensusManager> consensusManager = new Mock <IConsensusManager>(); Mock <IPowMining> powMining = new Mock <IPowMining>(); this.fullNode.Setup(f => f.NodeFeature <MiningFeature>(false)).Returns(new MiningFeature(new ConnectionManagerSettings(NodeSettings.Default(this.network)), this.network, new MinerSettings(NodeSettings.Default(this.network)), NodeSettings.Default(this.network), this.loggerFactory, new Mock <ITimeSyncBehaviorState>().Object, powMining.Object, null)); MiningController controller = new MiningController(consensusManager.Object, this.fullNode.Object, this.loggerFactory, this.network, new Mock <IPowMining>().Object, new Mock <IWalletManager>().Object); Exception ex = Assert.Throws <Exception>(() => controller.GetAccount()); Assert.Equal("No wallet found", ex.Message); }
public void StopMining_ReturnsSuccess() { var consensusManager = new Mock <IConsensusManager>(); var powMining = new Mock <IPowMining>(); this.fullNode.Setup(f => f.NodeFeature <MiningFeature>(false)).Returns(new MiningFeature(new ConnectionManagerSettings(NodeSettings.Default(this.network)), this.network, new MinerSettings(NodeSettings.Default(this.network)), NodeSettings.Default(this.network), this.loggerFactory, new Mock <ITimeSyncBehaviorState>().Object, powMining.Object, null)); var controller = new MiningController(consensusManager.Object, this.fullNode.Object, this.loggerFactory, this.network, new Mock <IPowMining>().Object, new Mock <IWalletManager>().Object); IActionResult result = controller.StopMining(); Assert.NotNull(result); var okResult = Assert.IsType <OkResult>(result); Assert.NotNull(okResult); }
public void GenerateBlocksOn_PowNetwork_ReturnsSuccess() { var powNode = new Mock <IFullNode>(); var consensusManager = new Mock <IConsensusManager>(); var header = this.network.Consensus.ConsensusFactory.CreateBlockHeader(); consensusManager.Setup(cm => cm.Tip).Returns(new ChainedHeader(header, header.GetHash(), this.network.Consensus.LastPOWBlock - 1)); var walletManager = new Mock <IWalletManager>(); walletManager.Setup(f => f.GetWalletsNames()).Returns(new List <string> { wallet }); walletManager.Setup(f => f.GetAccounts(wallet)).Returns(new List <HdAccount> { new HdAccount { Name = account } }); HdAddress address = WalletTestsHelpers.CreateAddress(); walletManager.Setup(f => f.GetUnusedAddress(new WalletAccountReference(wallet, account))).Returns(address); var powMining = new Mock <IPowMining>(); powMining.Setup(f => f.GenerateBlocks(It.Is <ReserveScript>(r => r.ReserveFullNodeScript == address.Pubkey), 1, int.MaxValue)).Returns(new List <uint256> { new uint256(1255632623) }); powNode.Setup(f => f.NodeFeature <MiningFeature>(false)).Returns(new MiningFeature(new ConnectionManagerSettings(NodeSettings.Default(this.network)), KnownNetworks.RegTest, new MinerSettings(NodeSettings.Default(this.network)), NodeSettings.Default(this.network), this.loggerFactory, new Mock <ITimeSyncBehaviorState>().Object, powMining.Object, null)); var controller = new MiningController(consensusManager.Object, powNode.Object, this.loggerFactory, KnownNetworks.RegTest, powMining.Object, walletManager.Object); IActionResult result = controller.Generate(new MiningRequest { BlockCount = 1 }); powMining.VerifyAll(); walletManager.VerifyAll(); Assert.NotNull(result); var viewResult = Assert.IsType <JsonResult>(result); var resultValue = Assert.IsType <GenerateBlocksModel>(viewResult.Value); Assert.NotNull(resultValue); }
public void Generate_Blocks_When_Model_Is_Invalid_ReturnsBadRequest() { this.controller = new MiningController(this.powMining.Object, this.LoggerFactory.Object, this.walletManager.Object); this.controller.ModelState.AddModelError("key", "error message"); IActionResult result = this.controller.Generate(new MiningRequest()); var errorResult = Assert.IsType <ErrorResult>(result); var errorResponse = Assert.IsType <ErrorResponse>(errorResult.Value); Assert.Single(errorResponse.Errors); ErrorModel error = errorResponse.Errors[0]; Assert.Equal(400, error.Status); Assert.Equal("Formatting error", error.Message); Assert.Equal("error message", error.Description); }
// Use this for initialization void Start() { currentMapController = FindObjectOfType <MapController>(); itemDatabase = FindObjectOfType <ItemDatabase>(); rigController = FindObjectOfType <RigController>(); miningController = FindObjectOfType <MiningController>(); mapDelegateHolder = FindObjectOfType <MapDelegateHolder>(); if (controllingRack) { // If this UI element controls a rack, then make the button call upgrade a rack function from the rig controller upgradeButton.onClick.AddListener(() => rigController.UpgradeARack(GetComponent <RackID>().myControlID)); myRackID = GetComponent <RackID>(); } else { upgradeButton.onClick.AddListener(() => rigController.UpgradeARig(GetComponent <RigID>().myControlID)); myRigID = GetComponent <RigID>(); myRig = FindObjectOfType <ItemDatabase>().rigTypes[0]; } // If the center activate button is ON then give it a function of buying a brand new rig if (activateButton && !controllingRack) { activateButton.onClick.AddListener(() => BuyARigFromScratch()); } else { activateButton.gameObject.SetActive(false); } if (!controllingRack) { mapDelegateHolder.upgradedRigActions += UpdateMyRigUI; } else { mapDelegateHolder.upgradedRackActions += UpdateMyRackUI; } InitizalizeTheUI(); }
protected override void OnLoad(EventArgs e) { _navButtons = new Button[] { this.filesButton, this.processesButton, this.miningButton, this.trainingButton, this.settingsButton }; foreach (Button btn in _navButtons) { if (btn != null) { btn.FlatAppearance.MouseOverBackColor = btn.FlatAppearance.MouseDownBackColor = DEFAULT_SELECTED_NAV_BUTTON_BACK_COLOR; } } _navUserControls = new UserControl[] { new FilesScanningUserControl(), new ProcessesScanningUserControl(), new MiningUserControl(), new TrainingUserControl(), new SettingUserControl() }; _navButtons[(int)DEFAULT_NAV_OPTION].PerformClick(); filesScanningControler = new FilesScanningController((FilesScanningUserControl)_navUserControls[(int)NavigationOptionEnum.FILES]); processesScanningController = new ProcessesScanningController((ProcessesScanningUserControl)_navUserControls[(int)NavigationOptionEnum.PROCESSES]); miningController = new MiningController((MiningUserControl)_navUserControls[(int)NavigationOptionEnum.MINING]); trainingController = new TrainingController((TrainingUserControl)_navUserControls[(int)NavigationOptionEnum.TRAINING]); settingController = new SettingController((SettingUserControl)_navUserControls[(int)NavigationOptionEnum.SETTINGS]); _dataLocation = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "Data"); if (!Directory.Exists(_dataLocation)) { Directory.CreateDirectory(_dataLocation); } }
public void Generate_With_Incorrect_Block_Count_ReturnsInvalidRequest(int?blockCount) { this.controller = new MiningController(this.powMining.Object, this.LoggerFactory.Object, this.walletManager.Object); IActionResult result = blockCount == null? this.controller.Generate(new MiningRequest()) : this.controller.Generate(new MiningRequest { BlockCount = (int)blockCount }); var errorResult = Assert.IsType <ErrorResult>(result); var errorResponse = Assert.IsType <ErrorResponse>(errorResult.Value); Assert.Single(errorResponse.Errors); ErrorModel error = errorResponse.Errors[0]; Assert.Equal(403, error.Status); Assert.Equal("Invalid request", error.Message); Assert.Equal("The number of blocks to mine must be higher than zero.", error.Description); }
public void Generate_Blocks_ReturnsSuccess() { const string wallet = "wallet"; const string account = "account"; this.walletManager.Setup(w => w.GetWalletsNames()).Returns(new List <string> { wallet }); this.walletManager.Setup(w => w.GetAccounts(wallet)).Returns(new List <HdAccount> { new HdAccount { Name = account } }); HdAddress address = WalletTestsHelpers.CreateAddress(); this.walletManager.Setup(w => w.GetUnusedAddress(new WalletAccountReference(wallet, account))).Returns(address); this.powMining.Setup(p => p.GenerateBlocks(It.Is <ReserveScript>(r => r.ReserveFullNodeScript == address.Pubkey), 1, int.MaxValue)) .Returns(new List <uint256> { new uint256(1255632623) }); this.controller = new MiningController(this.powMining.Object, this.LoggerFactory.Object, this.walletManager.Object); IActionResult result = this.controller.Generate(new MiningRequest { BlockCount = 1 }); this.walletManager.VerifyAll(); this.powMining.VerifyAll(); Assert.NotNull(result); var viewResult = Assert.IsType <JsonResult>(result); var resultValue = Assert.IsType <GenerateBlocksModel>(viewResult.Value); Assert.NotNull(resultValue); }
public void Generate_Blocks_When_Model_Is_Invalid_ReturnsBadRequest() { var consensusManager = new Mock <IConsensusManager>(); consensusManager.Setup(cm => cm.Tip).Returns(new ChainedHeader(this.network.Consensus.ConsensusFactory.CreateBlockHeader(), new uint256(0), this.network.Consensus.LastPOWBlock - 1)); var controller = new MiningController(consensusManager.Object, this.fullNode.Object, this.loggerFactory, this.network, new Mock <IPowMining>().Object, new Mock <IWalletManager>().Object); controller.ModelState.AddModelError("key", "error message"); IActionResult result = controller.Generate(new MiningRequest()); var errorResult = Assert.IsType <ErrorResult>(result); var errorResponse = Assert.IsType <ErrorResponse>(errorResult.Value); Assert.Single(errorResponse.Errors); ErrorModel error = errorResponse.Errors[0]; Assert.Equal(400, error.Status); Assert.Equal("Formatting error", error.Message); Assert.Equal("error message", error.Description); }
public void MiningController_Calls_GetAccount_Returns_Reference_To_Wallet_Account() { Mock <IConsensusManager> consensusManager = new Mock <IConsensusManager>(); Mock <IPowMining> powMining = new Mock <IPowMining>(); var walletManager = new Mock <IWalletManager>(); walletManager.Setup(f => f.GetWalletsNames()).Returns(new List <string> { wallet }); walletManager.Setup(f => f.GetAccounts(wallet)).Returns(new List <HdAccount> { new HdAccount { Name = account } }); this.fullNode.Setup(f => f.NodeFeature <MiningFeature>(false)).Returns(new MiningFeature(new ConnectionManagerSettings(NodeSettings.Default(this.network)), this.network, new MinerSettings(NodeSettings.Default(this.network)), NodeSettings.Default(this.network), this.loggerFactory, new Mock <ITimeSyncBehaviorState>().Object, powMining.Object, null)); MiningController controller = new MiningController(consensusManager.Object, this.fullNode.Object, this.loggerFactory, this.network, new Mock <IPowMining>().Object, walletManager.Object); WalletAccountReference walletAccountReference = controller.GetAccount(); Assert.Equal(account, walletAccountReference.AccountName); Assert.Equal(wallet, walletAccountReference.WalletName); }
void Start() { miningController = GetComponent <MiningController>(); onUpdateWorload += UpdateWorkload; }
// Use this for initialization void Start() { minContr = FindObjectOfType <MiningController>(); ResetDataForNewApartment(); }
// Use this for initialization void Start() { miningController = FindObjectOfType <MiningController>(); }