Exemplo n.º 1
0
        protected virtual async Task TestDelegate(int level, Data.Models.Delegate delegat, Protocol proto)
        {
            var remote = await Rpc.GetDelegateAsync(level, delegat.Address);

            if (remote.RequiredInt64("balance") != delegat.Balance)
            {
                throw new Exception($"Diagnostics failed: wrong balance {delegat.Address}");
            }

            if (remote.RequiredBool("deactivated") != !delegat.Staked)
            {
                throw new Exception($"Diagnostics failed: wrong delegate state {delegat.Address}");
            }

            var deactivationCycle = (delegat.DeactivationLevel - 1) >= proto.FirstLevel
                ? proto.GetCycle(delegat.DeactivationLevel - 1)
                : (await Cache.Blocks.GetAsync(delegat.DeactivationLevel - 1)).Cycle;

            if (remote.RequiredInt32("grace_period") != deactivationCycle)
            {
                throw new Exception($"Diagnostics failed: wrong delegate grace period {delegat.Address}");
            }

            if (remote.RequiredInt64("staking_balance") != delegat.StakingBalance)
            {
                throw new Exception($"Diagnostics failed: wrong staking balance {delegat.Address}");
            }

            var frozenBalances = remote.RequiredArray("frozen_balance_by_cycle").EnumerateArray();

            if ((frozenBalances.Any() ? frozenBalances.Sum(x => GetDeposits(x)) : 0) != delegat.FrozenDeposits)
            {
                throw new Exception($"Diagnostics failed: wrong frozen deposits {delegat.Address}");
            }

            if ((frozenBalances.Any() ? frozenBalances.Sum(x => x.RequiredInt64("rewards")) : 0) != delegat.FrozenRewards)
            {
                throw new Exception($"Diagnostics failed: wrong frozen rewards {delegat.Address}");
            }

            if ((frozenBalances.Any() ? frozenBalances.Sum(x => x.RequiredInt64("fees")) : 0) != delegat.FrozenFees)
            {
                throw new Exception($"Diagnostics failed: wrong frozen fees {delegat.Address}");
            }

            TestDelegatorsCount(remote, delegat);
        }