任務名稱:使用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提供了一個可以支持跨鏈交互的高性能智能合約運行平臺,每一個應用能夠獨立部署在一條鏈上,實現真正的資源隔離,內置豐富的系統合約,構建了一套豐富的鏈上經濟系統與權力自治系統。
祝您好運,編碼愉快!