예제 #1
0
        public async Task ProcessAsync(Block block, TransactionResult transactionResult, LogEvent logEvent)
        {
            var configurationSet = new ConfigurationSet();

            configurationSet.MergeFrom(logEvent);

            if (configurationSet.Key != BlockTransactionLimitConfigurationNameProvider.Name)
            {
                return;
            }

            var limit = new Int32Value();

            limit.MergeFrom(configurationSet.Value.ToByteArray());
            if (limit.Value < 0)
            {
                return;
            }
            await _blockTransactionLimitProvider.SetLimitAsync(new BlockIndex
            {
                BlockHash   = block.GetHash(),
                BlockHeight = block.Height
            }, limit.Value);

            Logger.LogInformation($"BlockTransactionLimit has been changed to {limit.Value}");
        }
        public async Task ProcessConfigurationAsync(ByteString byteString, BlockIndex blockIndex)
        {
            var limit = new Int32Value();

            limit.MergeFrom(byteString);
            if (limit.Value < 0)
            {
                return;
            }
            await _blockTransactionLimitProvider.SetLimitAsync(blockIndex, limit.Value);
        }
예제 #3
0
        public async Task Set_Block_Transaction_Limit_Authorized()
        {
            var proposalId = await SetBlockTransactionLimitProposalAsync(100);

            await ApproveWithMinersAsync(proposalId);

            var transactionResult = await ReleaseProposalAsync(proposalId);

            Assert.True(transactionResult.Status == TransactionResultStatus.Mined);

            var limitFromResult = new Int32Value();

            limitFromResult.MergeFrom(ConfigurationSet.Parser.ParseFrom(transactionResult.Logs[1].NonIndexed).Value);
            limitFromResult.Value.ShouldBe(100);
        }
예제 #4
0
        public async Task Get_Block_Transaction_Limit()
        {
            var proposalId = await SetBlockTransactionLimitProposalAsync(100);

            await ApproveWithMinersAsync(proposalId);
            await ReleaseProposalAsync(proposalId);

            var transactionResult =
                await ExecuteContractWithMiningAsync(ConfigurationContractAddress,
                                                     nameof(ConfigurationContainer.ConfigurationStub.GetConfiguration),
                                                     new StringValue { Value = BlockTransactionLimitConfigurationNameProvider.Name });

            Assert.True(transactionResult.Status == TransactionResultStatus.Mined);
            var limitFromResult = new Int32Value();

            limitFromResult.MergeFrom(BytesValue.Parser.ParseFrom(transactionResult.ReturnValue).Value);
            limitFromResult.Value.ShouldBe(100);
        }
        public async Task LimitCanBeSetByExecutingContract_Test()
        {
            const int targetLimit = 55;

            await DeployContractsAsync();

            var proposalId = (await _parliamentContractStub.CreateProposal.SendAsync(new CreateProposalInput
            {
                ContractMethodName = "SetConfiguration",
                ExpiredTime = TimestampHelper.GetUtcNow().AddDays(1),
                Params = new SetConfigurationInput
                {
                    Key = BlockTransactionLimitConfigurationNameProvider.Name,
                    Value = new Int32Value {
                        Value = targetLimit
                    }.ToByteString()
                }.ToByteString(),
                ToAddress = ConfigurationContractAddress,
                OrganizationAddress = await _parliamentContractStub.GetDefaultOrganizationAddress.CallAsync(new Empty())
            })).Output;
            await _parliamentContractStub.Approve.SendAsync(proposalId);

            // Before
            {
                var result = await _configurationStub.GetConfiguration.CallAsync(new StringValue
                {
                    Value = BlockTransactionLimitConfigurationNameProvider.Name
                });

                var limit = new Int32Value();
                limit.MergeFrom(BytesValue.Parser.ParseFrom(result.ToByteString()).Value);
                Assert.Equal(0, limit.Value);
            }

            var txResult = await _parliamentContractStub.Release.SendAsync(proposalId);

            var configurationSet = ConfigurationSet.Parser.ParseFrom(txResult.TransactionResult.Logs
                                                                     .First(l => l.Name == nameof(ConfigurationSet)).NonIndexed);
            var limitFromLogEvent = new Int32Value();

            limitFromLogEvent.MergeFrom(configurationSet.Value.ToByteArray());
            Assert.Equal(limitFromLogEvent.Value, targetLimit);

            // After
            {
                var result = await _configurationStub.GetConfiguration.CallAsync(new StringValue
                {
                    Value = BlockTransactionLimitConfigurationNameProvider.Name
                });

                var limit = new Int32Value();
                limit.MergeFrom(BytesValue.Parser.ParseFrom(result.ToByteString()).Value);
                Assert.Equal(targetLimit, limit.Value);
            }
            var chain = await _blockchainService.GetChainAsync();

            await _blockchainStateService.MergeBlockStateAsync(chain.BestChainHeight, chain.BestChainHash);

            var limitNum = await _blockTransactionLimitProvider.GetLimitAsync(
                new ChainContext
            {
                BlockHash   = chain.BestChainHash,
                BlockHeight = chain.BestChainHeight
            });

            Assert.Equal(55, limitNum);
        }