zoukankan      html  css  js  c++  java
  • 【AELF开发者社区任务活动】c#任务-使用TestKit AEDPoS扩展 #1915 重构投票合约的测试用例

    任务名称:使用TestKit AEDPoS扩展 #1915 重构投票合约的测试用例

    难度:难度系数相对较大,一个测试工程师一天的任务量

    奖励:1122个ELF (或者等值1000人民币)

    附上issue详情和教程,如下:

     ① issue介绍:https://github.com/AElfProject/AElf/issues/1915

    ② AElf的issue解决方案-中文社区教程:https://github.com/AElfProject/AElf/issues/1846

    如有兴趣,可以在issue上直接跟技术团队沟通。或者直接加入开发者社区QQ群:群号:102857654

     

    任务说明:

    这个任务是基于分支refactor/vote-contract-tests,所以有兴趣的人投票合同的重构测试用例需要从签他支dev到refactor/vote-contract-tests。(或者根据此分支在您自己的仓库上创建一个新分支。)

    检查项目test/AElf.Contracts.AEDPoSExtension.Demo.Tests基本知道如何使用TestKit AEDPoS扩展。 测试用例DemoTest(如下图所示)显示了区块链系统的工作原理:选择一些事务然后将它们打包到一个块,每个新块都基于前一个块。 通过使用XXStub,您可以像调用/发送事务的特定用户一样调用测试用例中的特定合同方法。此外,您可以XXStub用于生成交易。

            [Fact]
            public async Task DemoTest()
            {
                // Check round information after initialization.
                {
                    var round = await ConsensusStub.GetCurrentRoundInformation.CallAsync(new Empty());
                    round.RoundNumber.ShouldBe(1);
                    round.TermNumber.ShouldBe(1);
                    round.RealTimeMinersInformation.Count.ShouldBe(AEDPoSExtensionConstants.InitialKeyPairCount);
                }
    
                // We can use this method process testing.
                // Basically this will produce one block with no transaction.
                await BlockMiningService.MineBlockAsync();
                
                // And this will produce one block with one transaction.
                // This transaction will call Create method of Token Contract.
                await BlockMiningService.MineBlockAsync(new List<Transaction>
                {
                    TokenStub.Create.GetTransaction(new CreateInput
                    {
                        Symbol = "ELF",
                        Decimals = 8,
                        TokenName = "Test",
                        Issuer = Address.FromPublicKey(SampleECKeyPairs.KeyPairs[0].PublicKey),
                        IsBurnable = true,
                        TotalSupply = 1_000_000_000_00000000
                    })
                });
                
                // Check whether previous Create transaction successfully executed.
                {
                    var tokenInfo = await TokenStub.GetTokenInfo.CallAsync(new GetTokenInfoInput {Symbol = "ELF"});
                    tokenInfo.Symbol.ShouldBe("ELF");
                }
    
                // Next steps will check whether the AEDPoS process is correct.
                // Now 2 miners produced block during first round, so there should be 2 miners' OutValue isn't null.
                {
                    var round = await ConsensusStub.GetCurrentRoundInformation.CallAsync(new Empty());
                    round.RealTimeMinersInformation.Values.Count(m => m.OutValue != null).ShouldBe(2);
                }
    
                await BlockMiningService.MineBlockAsync(new List<Transaction>());
    
                {
                    var round = await ConsensusStub.GetCurrentRoundInformation.CallAsync(new Empty());
                    round.RealTimeMinersInformation.Values.Count(m => m.OutValue != null).ShouldBe(3);
                }
    
                // Currently we have 5 miners, and before this line, 3 miners already produced blocks.
                // 3 more blocks will end current round.
                for (var i = 0; i < 3; i++)
                {
                    await BlockMiningService.MineBlockAsync(new List<Transaction>());
                }
    
                // Check round number.
                {
                    var round = await ConsensusStub.GetCurrentRoundInformation.CallAsync(new Empty());
                    round.RoundNumber.ShouldBe(2);
                }
                
                // 6 more blocks will end second round.
                for (var i = 0; i < 6; i++)
                {
                    await BlockMiningService.MineBlockAsync(new List<Transaction>());
                }
                
                // Check round number.
                {
                    var round = await ConsensusStub.GetCurrentRoundInformation.CallAsync(new Empty());
                    round.RoundNumber.ShouldBe(3);
                }
            }
    知道这一点后,您可以去test/AElf.Contracts.Vote.AEDPoSExtension.Tests尝试重构投票合同的测试用例。对于测试逻辑,只需复制当前测试用例的逻辑即可AElf.Contracts.Vote.Tests

    此外,欢迎重构其他系统合同(位于其中contract/)。READMEin test/AElf.Contracts.AEDPoSExtension.Demo.Tests解释了如何创建测试项目。

  • 相关阅读:
    DevExpress VCL for Delphi 各版本收集下载
    Delphi XE 5,Rad Studio XE 5 官方下载(附破解),更新 Update 1,Help Update 1
    PostMessage 向Windows窗口发送Alt组合键
    Windows XP UDF 2.5 补丁,播放蓝光ISO光盘必备
    60个开发者不容错过的免费资源库
    [转]游戏多开的原理
    Delphi加载驱动
    窗口截图
    Drectx 3D窗口后台截图
    利用进程ID获取主线程ID
  • 原文地址:https://www.cnblogs.com/aelf/p/11233771.html
Copyright © 2011-2022 走看看