任务名称:使用TestKit AEDPoS扩展 #1915 重构投票合约的测试用例git
任务:难度系数相对较大,一个测试工程师一天的任务量 奖励:1122个ELF (或者等值1000人民币)github
附上issue详情和教程,以下:网络
① issue介绍:github.com/AElfProject…async
② AElf的issue解决方案-中文社区教程:github.com/AElfProject…分布式
若有兴趣,能够在issue上直接跟技术团队沟通。或者直接加入开发者社区QQ群:群号:102857654性能
任务说明:区块链
这个任务是基于分支refactor/vote-contract-tests,因此有兴趣的人投票合同的重构测试用例须要从签他支dev到refactor/vote-contract-tests。(或者根据此分支在您本身的仓库上建立一个新分支。)测试
检查项目test/AElf.Contracts.AEDPoSExtension.Demo.Tests基本知道如何使用TestKit AEDPoS扩展。 测试用例DemoTest(以下图所示)显示了区块链系统的工做原理:选择一些事务而后将它们打包到一个块,每一个新块都基于前一个块。 经过使用XXStub,您能够像调用/发送事务的特定用户同样调用测试用例中的特定合同方法。此外,您能够XXStub用于生成交易。this
[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解释了如何建立测试项目。
项目介绍:
AELF是一个去中心化的云计算平台,旨在帮助企业/我的高效便捷地使用基础区块链技术构建去分布式应用(DAPP)。在中心化领域中,咱们使用亚马逊AWS部署服务,在区块链领域中,能够将服务托管在AELF去中心化云计算区块链网络上。
AELF提供了一个可以支持跨链交互的高性能智能合约运行平台,每一个应用能够独立部署在一条链上,实现真正的资源隔离,内置丰富的系统合约,构建了一套丰富的链上经济系统与权力自治系统。
祝您好运,编码愉快!