コード例 #1
0
ファイル: ElectionViewTests.cs プロジェクト: zhxymh/AElf
        public async Task GetElectorVoteWithAllRecords_Test()
        {
            var voters = await UserVotesCandidate(2, 500, 100);

            var voterKeyPair = voters[0];
            //without withdraw
            var allRecords = await ElectionContractStub.GetElectorVoteWithAllRecords.CallAsync(new StringValue
            {
                Value = voterKeyPair.PublicKey.ToHex()
            });

            allRecords.ActiveVotingRecords.Count.ShouldBeGreaterThanOrEqualTo(1);
            allRecords.WithdrawnVotingRecordIds.Count.ShouldBe(0);

            //withdraw
            await NextTerm(InitialCoreDataCenterKeyPairs[0]);

            BlockTimeProvider.SetBlockTime(StartTimestamp.AddSeconds(100 * 60 * 60 * 24 + 1));
            var voteId =
                (await ElectionContractStub.GetElectorVote.CallAsync(new StringValue
            {
                Value = voterKeyPair.PublicKey.ToHex()
            })).ActiveVotingRecordIds.First();
            var executionResult = await WithdrawVotes(voterKeyPair, voteId);

            executionResult.Status.ShouldBe(TransactionResultStatus.Mined);

            allRecords = await ElectionContractStub.GetElectorVoteWithAllRecords.CallAsync(new StringValue
            {
                Value = voterKeyPair.PublicKey.ToHex()
            });

            allRecords.WithdrawnVotingRecordIds.Count.ShouldBe(1);
        }
コード例 #2
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (header_ != null)
            {
                hash ^= Header.GetHashCode();
            }
            hash ^= predictionObstacle_.GetHashCode();
            if (PerceptionErrorCode != 0)
            {
                hash ^= PerceptionErrorCode.GetHashCode();
            }
            if (StartTimestamp != 0D)
            {
                hash ^= StartTimestamp.GetHashCode();
            }
            if (EndTimestamp != 0D)
            {
                hash ^= EndTimestamp.GetHashCode();
            }
            if (intent_ != null)
            {
                hash ^= Intent.GetHashCode();
            }
            if (scenario_ != null)
            {
                hash ^= Scenario.GetHashCode();
            }
            return(hash);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (HasStartTimestamp)
            {
                hash ^= StartTimestamp.GetHashCode();
            }
            if (HasEndTimestamp)
            {
                hash ^= EndTimestamp.GetHashCode();
            }
            if (HasRegion)
            {
                hash ^= Region.GetHashCode();
            }
            if (HasBatchNum)
            {
                hash ^= BatchNum.GetHashCode();
            }
            if (HasBatchSize)
            {
                hash ^= BatchSize.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #4
0
        public async Task Election_ChangeVotingOption_With_Expire_Vote_Test()
        {
            var voter      = VoterKeyPairs.First();
            var voteAmount = 100;
            var lockTime   = 120 * 60 * 60 * 24;
            var candidate  = ValidationDataCenterKeyPairs.First();

            await AnnounceElectionAsync(candidate);
            await VoteToCandidate(voter, candidate.PublicKey.ToHex(), lockTime, voteAmount);

            var electionVoteItemId = await ElectionContractStub.GetMinerElectionVotingItemId.CallAsync(new Empty());

            var voteIdOfVoter = await VoteContractStub.GetVotingIds.CallAsync(new GetVotingIdsInput
            {
                Voter        = Address.FromPublicKey(voter.PublicKey),
                VotingItemId = electionVoteItemId
            });

            var voteId = voteIdOfVoter.ActiveVotes[0];

            BlockTimeProvider.SetBlockTime(StartTimestamp.AddSeconds(lockTime + 1));
            var changeOptionRet = await ChangeVoteOption(voter, voteId, candidate.PublicKey.ToHex());

            changeOptionRet.Status.ShouldBe(TransactionResultStatus.Failed);
            changeOptionRet.Error.ShouldContain("This vote already expired");
        }
コード例 #5
0
        /// <summary>尝试分析</summary>
        /// <param name="id"></param>
        /// <param name="time">时间</param>
        /// <param name="workerId">节点</param>
        /// <param name="sequence">序列号</param>
        /// <returns></returns>
        public virtual Boolean TryParse(Int64 id, out DateTime time, out Int32 workerId, out Int32 sequence)
        {
            time     = StartTimestamp.AddMilliseconds(id >> (10 + 12));
            workerId = (Int32)((id >> 12) & 0x3FF);
            sequence = (Int32)(id & 0x0FFF);

            return(true);
        }
コード例 #6
0
        /// <summary>
        /// Build a string based on this class' info, error and debug messages and the exception strings
        /// </summary>
        /// <returns>A string representing the properties of this class</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Orchestrator Report (" + StartTimestamp.ToString() + " - " + DateTime.Now.ToString() + ")");
            sb.Append(base.ToString());

            return(sb.ToString());
        }
コード例 #7
0
ファイル: Session.cs プロジェクト: liveswitch/liveswitch-mux
 private string ProcessOutputFileName(string outputFileName)
 {
     return(outputFileName
            .Replace("{applicationId}", ApplicationId)
            .Replace("{channelId}", ChannelId)
            .Replace("{sessionId}", Id.ToString())
            .Replace("{startTimestamp}", StartTimestamp.ToString(Iso8601FileSafeFormat))
            .Replace("{stopTimestamp}", StopTimestamp.ToString(Iso8601FileSafeFormat)));
 }
コード例 #8
0
        protected async Task NextRound(ECKeyPair keyPair)
        {
            var miner = GetConsensusContractTester(keyPair);
            var round = await miner.GetCurrentRoundInformation.CallAsync(new Empty());

            round.GenerateNextRoundInformation(
                StartTimestamp.ToDateTime().AddMilliseconds(round.TotalMilliseconds()).ToTimestamp(), StartTimestamp,
                out var nextRound);
            await miner.NextRound.SendAsync(nextRound);
        }
コード例 #9
0
ファイル: ElectionTests.cs プロジェクト: wymoon2690/AElf
        public async Task ElectionContract_Withdraw_Test()
        {
            const int amount   = 1000;
            const int lockTime = 120 * 60 * 60 * 24;

            var candidateKeyPair = ValidationDataCenterKeyPairs[0];

            await AnnounceElectionAsync(candidateKeyPair);

            var voterKeyPair  = VoterKeyPairs[0];
            var beforeBalance = await GetNativeTokenBalance(voterKeyPair.PublicKey);

            // Vote
            {
                var transactionResult =
                    await VoteToCandidate(voterKeyPair, candidateKeyPair.PublicKey.ToHex(), lockTime, amount);

                transactionResult.Status.ShouldBe(TransactionResultStatus.Mined);
            }

            var voteId =
                (await ElectionContractStub.GetElectorVote.CallAsync(new StringInput
            {
                Value = voterKeyPair.PublicKey.ToHex()
            })).ActiveVotingRecordIds.First();

            await NextTerm(InitialCoreDataCenterKeyPairs[0]);

            BlockTimeProvider.SetBlockTime(StartTimestamp.AddSeconds(lockTime + 1));

            // Withdraw
            {
                var executionResult = await WithdrawVotes(voterKeyPair, voteId);

                executionResult.Status.ShouldBe(TransactionResultStatus.Mined);
            }

            // Profit
            var voter = GetProfitContractTester(voterKeyPair);
            await voter.ClaimProfits.SendAsync(new ClaimProfitsInput { SchemeId = ProfitItemsIds[ProfitType.CitizenWelfare] });

            // Check ELF token balance
            {
                var balance = await GetNativeTokenBalance(voterKeyPair.PublicKey);

                balance.ShouldBe(beforeBalance);
            }

            // Check VOTE token balance.
            {
                var balance = await GetVoteTokenBalance(voterKeyPair.PublicKey);

                balance.ShouldBe(0);
            }
        }
コード例 #10
0
        /// <summary>
        /// Return a XML representation of this object.
        /// </summary>
        public XElement ToXML()

        => new XElement(OCPPNS.OCPPv1_6_CS + "startTransactionRequest",

                        new XElement(OCPPNS.OCPPv1_6_CS + "connectorId", ConnectorId),
                        new XElement(OCPPNS.OCPPv1_6_CS + "idTag", IdTag.ToString()),
                        new XElement(OCPPNS.OCPPv1_6_CS + "timestamp", StartTimestamp.ToIso8601()),
                        new XElement(OCPPNS.OCPPv1_6_CS + "meterStart", MeterStart),

                        ReservationId.HasValue
                       ? new XElement(OCPPNS.OCPPv1_6_CS + "reservationId", ReservationId.Value)
                       : null

                        );
コード例 #11
0
        /// <summary>
        /// Return the HashCode of this object.
        /// </summary>
        /// <returns>The HashCode of this object.</returns>
        public override Int32 GetHashCode()
        {
            unchecked
            {
                return(ConnectorId.GetHashCode() * 13 ^
                       IdTag.GetHashCode() * 11 ^
                       StartTimestamp.GetHashCode() * 7 ^
                       MeterStart.GetHashCode() * 5 ^

                       (ReservationId.HasValue
                            ? ReservationId.GetHashCode()
                            : 0));
            }
        }
コード例 #12
0
        public override int GetHashCode()
        {
            var hash = SRState.GetHashCode() ^
                       // LastStateChangeTicks.GetHashCode() ^  // NOPE. This changes too often.
                       StartTimestamp.GetHashCode() ^
                       PercentComplete ^ ElapsedTimeSeconds.GetHashCode() ^ TimeRemainingSeconds.GetHashCode() ^
                       TotalSteps ^ CurrentStep ^ RetryCounter ^ UncommittedEditCounter ^ ErrorCode ^
                       PreviousRunTotalMilliseconds.GetHashCode() ^ ProjectCode.GetHashCode();

            if (ErrorMessage != null)
            {
                hash ^= ErrorMessage.GetHashCode();
            }
            return(hash);
        }
コード例 #13
0
        /// <summary>
        /// Compares two start transaction requests for equality.
        /// </summary>
        /// <param name="StartTransactionRequest">A start transaction request to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public override Boolean Equals(StartTransactionRequest StartTransactionRequest)
        {
            if (StartTransactionRequest is null)
            {
                return(false);
            }

            return(ConnectorId.Equals(StartTransactionRequest.ConnectorId) &&
                   IdTag.Equals(StartTransactionRequest.IdTag) &&
                   StartTimestamp.Equals(StartTransactionRequest.StartTimestamp) &&
                   MeterStart.Equals(StartTransactionRequest.MeterStart) &&

                   ((!ReservationId.HasValue && !StartTransactionRequest.ReservationId.HasValue) ||
                    (ReservationId.HasValue && StartTransactionRequest.ReservationId.HasValue && ReservationId.Equals(StartTransactionRequest.ReservationId))));
        }
コード例 #14
0
        /// <summary>
        /// Return a JSON representation of this object.
        /// </summary>
        /// <param name="CustomStartTransactionRequestSerializer">A delegate to serialize custom start transaction requests.</param>
        public JObject ToJSON(CustomJObjectSerializerDelegate <StartTransactionRequest> CustomStartTransactionRequestSerializer = null)
        {
            var JSON = JSONObject.Create(

                new JProperty("connectorId", ConnectorId.ToString()),
                new JProperty("idTag", IdTag.ToString()),
                new JProperty("timestamp", StartTimestamp.ToIso8601()),
                new JProperty("meterStart", MeterStart),

                ReservationId.HasValue
                               ? new JProperty("reservationId", ReservationId.Value.ToString())
                               : null

                );

            return(CustomStartTransactionRequestSerializer != null
                       ? CustomStartTransactionRequestSerializer(this, JSON)
                       : JSON);
        }
コード例 #15
0
 public override string ToString()
 {
     return
         ($"{GetType().Name}\n" +
          $"\tClientId: {ClientId.ToString()}\n" +
          $"\tDetails: {Details}\n" +
          $"\tState: {State}\n" +
          $"\tStartTimestamp: {StartTimestamp.ToString()}\n" +
          $"\tEndTimestamp: {EndTimestamp.ToString()}\n" +
          $"\tLargeImageKey: {LargeImageKey}\n" +
          $"\tLargeImageText: {LargeImageText}\n" +
          $"\tSmallImageKey: {SmallImageKey}\n" +
          $"\tSmallImageText: {SmallImageText}\n" +
          $"\tPartyId: {PartyId}\n" +
          $"\tPartySize: {PartySize.ToString()}\n" +
          $"\tPartyMax: {PartyMax.ToString()}\n" +
          $"\tMatchSecret: {MatchSecret}\n" +
          $"\tSpectateSecret: {SpectateSecret}\n" +
          $"\tJoinSecret: {JoinSecret}\n" +
          $"\tInstance: {Instance.ToString()}\n"
         );
 }
コード例 #16
0
ファイル: NewsBanner.cs プロジェクト: Vanaheimr/UsersAPI
        /// <summary>
        /// Return a JSON representation of this object.
        /// </summary>
        /// <param name="Embedded">Whether this data is embedded into another data structure.</param>
        /// <param name="IncludeCryptoHash">Include the crypto hash value of this object.</param>
        public JObject ToJSON(Boolean Embedded          = false,
                              InfoStatus ExpandTags     = InfoStatus.ShowIdOnly,
                              InfoStatus ExpandAuthorId = InfoStatus.ShowIdOnly,
                              Boolean IncludeCryptoHash = false)

        => JSONObject.Create(

            new JProperty("@id", Id.ToString()),

            !Embedded
                       ? new JProperty("@context", JSONLDContext.ToString())
                       : null,

            new JProperty("text", Text.ToJSON()),

            new JProperty("startTimestamp", StartTimestamp.ToIso8601()),
            new JProperty("endTimestamp", EndTimestamp.ToIso8601()),
            new JProperty("author", JSONObject.Create(
                              new JProperty("@id", Author.Id.ToString()),
                              new JProperty("name", Author.Name)
                              ))

            );
コード例 #17
0
        internal async Task InitializeAElfConsensus()
        {
            {
                var result = await AEDPoSContractStub.InitialAElfConsensusContract.SendAsync(
                    new InitialAElfConsensusContractInput
                {
                    TimeEachTerm          = 604800L,
                    MinerIncreaseInterval = BingoGameContractTestConstants.MinerIncreaseInterval
                });

                CheckResult(result.TransactionResult);
            }
            {
                var result = await AEDPoSContractStub.FirstRound.SendAsync(
                    new MinerList
                {
                    Pubkeys = { InitialCoreDataCenterKeyPairs.Select(p => ByteString.CopyFrom(p.PublicKey)) }
                }.GenerateFirstRoundOfNewTerm(BingoGameContractTestConstants.MiningInterval,
                                              StartTimestamp.ToDateTime()));

                CheckResult(result.TransactionResult);
            }
        }
コード例 #18
0
ファイル: PirateSession.cs プロジェクト: GuojieChen/PirateX
 public DateTime StartAt()
 {
     return(StartTimestamp.ConvertToDateTime());
 }