public async Task UpdateValue_Success()
        {
            TesterManager.InitialTesters();

            await InitialConsensus_Success();

            var roundInfo = await TesterManager.Testers[0].GetCurrentRoundInformation();

            var input = new ToUpdate
            {
                RoundId                  = roundInfo.RoundId,
                Signature                = Hash.Generate(),
                OutValue                 = Hash.Generate(),
                ProducedBlocks           = 1,
                ActualMiningTime         = DateTime.UtcNow.Add(TimeSpan.FromSeconds(4)).ToTimestamp(),
                SupposedOrderOfNextRound = 1,
                PromiseTinyBlocks        = 2,
                PreviousInValue          = Hash.Generate(),
                MinersPreviousInValues   =
                {
                    { TesterManager.Testers[0].PublicKey, Hash.Generate() }
                }
            };

            var transactionResult = await TesterManager.Testers[0].ExecuteConsensusContractMethodWithMiningAsync(
                nameof(ConsensusContract.UpdateValue), input);

            transactionResult.Status.ShouldBe(TransactionResultStatus.Mined);
        }
Exemple #2
0
        public override Empty UpdateValue(ToUpdate input)
        {
            Assert(TryToGetCurrentRoundInformation(out var round), "Round information not found.");

            Assert(input.RoundId == round.RoundId, "Round Id not matched.");

            var publicKey = Context.RecoverPublicKey().ToHex();

            round.RealTimeMinersInformation[publicKey].Signature                = input.Signature;
            round.RealTimeMinersInformation[publicKey].OutValue                 = input.OutValue;
            round.RealTimeMinersInformation[publicKey].PromisedTinyBlocks       = input.PromiseTinyBlocks;
            round.RealTimeMinersInformation[publicKey].ActualMiningTime         = input.ActualMiningTime;
            round.RealTimeMinersInformation[publicKey].SupposedOrderOfNextRound = input.SupposedOrderOfNextRound;
            round.RealTimeMinersInformation[publicKey].FinalOrderOfNextRound    = input.SupposedOrderOfNextRound;
            round.RealTimeMinersInformation[publicKey].ProducedBlocks           = input.ProducedBlocks;

            round.RealTimeMinersInformation[publicKey].EncryptedInValues.Add(input.EncryptedInValues);
            foreach (var decryptedPreviousInValue in input.DecryptedPreviousInValues)
            {
                round.RealTimeMinersInformation[decryptedPreviousInValue.Key].DecryptedPreviousInValues
                .Add(publicKey, decryptedPreviousInValue.Value);
            }

            foreach (var previousInValue in input.MinersPreviousInValues)
            {
                if (previousInValue.Key == publicKey)
                {
                    continue;
                }

                var filledValue = round.RealTimeMinersInformation[previousInValue.Key].PreviousInValue;
                if (filledValue != null && filledValue != previousInValue.Value)
                {
                    Context.LogDebug(() => $"Something wrong happened to previous in value of {previousInValue.Key}.");
                }

                round.RealTimeMinersInformation[previousInValue.Key].PreviousInValue = previousInValue.Value;
            }

            foreach (var tuneOrder in input.TuneOrderInformation)
            {
                LogVerbose(
                    $"Will tune {tuneOrder.Key} order from {round.RealTimeMinersInformation[tuneOrder.Key].FinalOrderOfNextRound} to {tuneOrder.Value}");
                round.RealTimeMinersInformation[tuneOrder.Key].FinalOrderOfNextRound = tuneOrder.Value;
            }

            LogVerbose($"Previous in value published by {publicKey} himself is {input.PreviousInValue.ToHex()}");
            // For first round of each term, no one need to publish in value.
            if (input.PreviousInValue != Hash.Empty)
            {
                round.RealTimeMinersInformation[publicKey].PreviousInValue = input.PreviousInValue;
            }

            Assert(TryToUpdateRoundInformation(round), "Failed to update round information.");

            TryToFindLIB();
            return(new Empty());
        }
Exemple #3
0
        public void UpdateObjects(Player player)
        {
            ToUpdate.Clear();

            Creatures.FilterDead();
            Items.FilterDead();

            ToUpdate.Where(o => !o.IsDead).ToList().ForEach(o => o.Update(player));
        }
Exemple #4
0
        // Called when a portal is triggered.
        public static void ChangeRoom(Room newRoom, Vector2 newPosition)
        {
            if (newRoom != CurrentRoom)
            {
                // Clear out the lists because they will be repopulated for the new room.
                ToUpdate.Clear();
                ToDraw.Clear();
                InputManager.RegisteredActors.Clear();

                CurrentRoom = newRoom;

                FocusObject.OnCreate(); // This is normally called in the constructor to add the object to lists.
            }
            FocusObject.Body.Position = newPosition;
        }
        public async Task UpdateValue_Failed()
        {
            TesterManager.InitialTesters();

            //invalid round number
            var input = new ToUpdate
            {
                RoundId = 1234
            };

            var transactionResult = await TesterManager.Testers[0].ExecuteConsensusContractMethodWithMiningAsync(
                nameof(ConsensusContract.UpdateValue), input);

            transactionResult.Status.ShouldBe(TransactionResultStatus.Failed);
            transactionResult.Error.Contains("Round information not found").ShouldBeTrue();
        }