Exemple #1
0
        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 StringInput
            {
                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 StringInput
            {
                Value = voterKeyPair.PublicKey.ToHex()
            })).ActiveVotingRecordIds.First();
            var executionResult = await WithdrawVotes(voterKeyPair, voteId);

            executionResult.Status.ShouldBe(TransactionResultStatus.Mined);

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

            allRecords.WithdrawnVotingRecordIds.Count.ShouldBe(1);
        }
Exemple #2
0
        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);
            }
        }