コード例 #1
0
 // changed from private to public: GetValidatorStatus()
 public void Test_GetValidatorStatus()
 {
     Assert.AreEqual("0x00", _apiService.GetValidatorStatus());
     _validatorStatusManager.Start(false);
     Assert.AreEqual("0x01", _apiService.GetValidatorStatus());
     _validatorStatusManager.Stop();
     Thread.Sleep(2000);
     Assert.AreEqual("0x00", _apiService.GetValidatorStatus());
     _validatorStatusManager.Start(true);
     Assert.AreEqual("0x002", _apiService.GetValidatorStatus());
 }
コード例 #2
0
        public void Test_StakeWithdraw()
        {
            _blockManager.TryBuildGenesisBlock();
            GenerateBlocks(1, 1);

            _validatorStatusManager.Start(false);
            Assert.IsTrue(_validatorStatusManager.IsStarted());
            Assert.IsFalse(_validatorStatusManager.IsWithdrawTriggered());

            int blockNum = (int)_blockManager.GetHeight();

            Assert.IsFalse(HardforkHeights.IsHardfork_9Active((ulong)blockNum));
            while (!HardforkHeights.IsHardfork_9Active((ulong)blockNum))
            {
                blockNum++;
                GenerateBlocks(blockNum, blockNum);
            }

            var systemContractReader = _container?.Resolve <ISystemContractReader>() ?? throw new Exception("Container is not loaded");
            var stake = new Money(systemContractReader.GetStake());

            Console.WriteLine($"Current stake is {stake}");
            Assert.That(stake > Money.Zero, "Stake is zero");

            _validatorStatusManager.WithdrawStakeAndStop();
            Assert.IsTrue(_validatorStatusManager.IsStarted());
            Assert.IsTrue(_validatorStatusManager.IsWithdrawTriggered());

            // Test node is the only validator, so it is a next validator always
            // and it can't withdraw its stake. TODO: test to check withdraw is working
            //GenerateBlocks(50);
            //Assert.IsFalse(_validatorStatusManager.IsStarted());
        }
コード例 #3
0
ファイル: ConsoleCommands.cs プロジェクト: LAToken/lachain
 /// <summary>
 /// Stake:
 ///  stake amount
 /// </summary>
 /// <param name="arguments"></param>
 /// <returns>stake tx hash</returns>
 public string NewStake(string[] arguments)
 {
     if (_validatorStatusManager.IsStarted())
     {
         return("ERROR: Withdraw current stake first");
     }
     if (arguments.Length == 0)
     {
         _validatorStatusManager.Start(false);
     }
     else
     {
         _validatorStatusManager.StartWithStake(Money.Parse(arguments[0]).ToUInt256());
     }
     return("Validator is started");
 }
コード例 #4
0
        public string StartValidator()
        {
            if (_privateWallet.GetWalletInstance() is null)
            {
                return("wallet_locked");
            }

            Logger.LogDebug("validator start command received");
            if (_validatorStatusManager.IsStarted())
            {
                return("withdraw previous stake first");
            }

            _validatorStatusManager.Start(false);

            return("validator_started");
        }