Example #1
0
        public async Task <Hash> RequestRandomNumberWithCommitmentSchemeTest()
        {
            await BlockMiningService.MineBlockToNextRoundAsync();

            var dict = await DeployCommitmentSchemeContract();

            CommitmentSchemeStub =
                GetTester <CommitmentSchemeContractContainer.CommitmentSchemeContractStub>(dict.First().Value,
                                                                                           SampleECKeyPairs.KeyPairs[0]);

            var commitment = Hash.FromMessage(Secret);
            var requestTx  = CommitmentSchemeStub.RequestRandomNumber.GetTransaction(commitment);
            await BlockMiningService.MineBlockAsync(new List <Transaction> {
                requestTx
            });

            var requestTrace      = TransactionTraceProvider.GetTransactionTrace(requestTx.GetHash());
            var randomNumberOrder = new RandomNumberOrder();

            randomNumberOrder.MergeFrom(requestTrace.ReturnValue);
            randomNumberOrder.BlockHeight.ShouldBePositive();
            randomNumberOrder.TokenHash.ShouldBe(commitment);

            return(requestTx.GetHash());
        }
Example #2
0
        public async Task RequestRandomNumberTest()
        {
            await BlockMiningService.MineBlockToNextRoundAsync();

            await BlockMiningService.MineBlockToNextRoundAsync();

            await BlockMiningService.MineBlockToNextRoundAsync();

            await BlockMiningService.MineBlockToNextRoundAsync();

            await BlockMiningService.MineBlockToNextRoundAsync();

            await BlockMiningService.MineBlockToNextRoundAsync();

            var requestTx      = ConsensusStub.RequestRandomNumber.GetTransaction(new Hash());
            var refBlockNumber = requestTx.RefBlockNumber;
            await BlockMiningService.MineBlockAsync(new List <Transaction>
            {
                requestTx
            });

            var requestTrace      = TransactionTraceProvider.GetTransactionTrace(requestTx.GetHash());
            var randomNumberOrder = new RandomNumberOrder();

            randomNumberOrder.MergeFrom(requestTrace.ReturnValue);
            var targetBlockNumber = randomNumberOrder.BlockHeight;

            targetBlockNumber.ShouldBeLessThan(refBlockNumber + 100);
        }
        internal async Task ParliamentReachAnAgreementAsync(CreateProposalInput createProposalInput)
        {
            var createProposalTx = ParliamentStubs.First().CreateProposal.GetTransaction(createProposalInput);
            await BlockMiningService.MineBlockAsync(new List <Transaction>
            {
                createProposalTx
            });

            var proposalId = new Hash();

            proposalId.MergeFrom(TransactionTraceProvider.GetTransactionTrace(createProposalTx.GetHash()).ReturnValue);
            var approvals = new List <Transaction>();

            foreach (var stub in ParliamentStubs)
            {
                approvals.Add(stub.Approve.GetTransaction(proposalId));
            }

            await BlockMiningService.MineBlockAsync(approvals);

            await ParliamentStubs.First().Release.SendAsync(proposalId);
        }
Example #4
0
        public async Task GetRandomNumberWithCommitmentSchemeTest()
        {
            var txHash = await RequestRandomNumberWithCommitmentSchemeTest();

            var requestTrace      = TransactionTraceProvider.GetTransactionTrace(txHash);
            var randomNumberOrder = new RandomNumberOrder();

            randomNumberOrder.MergeFrom(requestTrace.ReturnValue);
            await BlockMiningService.MineBlockAsync(randomNumberOrder.BlockHeight);

            var getTx = CommitmentSchemeStub.GetRandomNumber.GetTransaction(Secret);
            await BlockMiningService.MineBlockAsync(new List <Transaction>
            {
                getTx
            });

            var getTrace     = TransactionTraceProvider.GetTransactionTrace(getTx.GetHash());
            var randomNumber = new Hash();

            randomNumber.MergeFrom(getTrace.ReturnValue);
            randomNumber.Value.ShouldNotBeEmpty();
        }