Beispiel #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());
        }
Beispiel #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);
        }
Beispiel #3
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();
        }