** Task Name: ** Test Cases for Reconstructing Voting Contracts Using TestKit AEDPoS Extension 1915
** Task: ** Relatively large coefficient of difficulty, one day's task of a test engineer
** Award: ** 1122 ELF s (or equivalent of 1000 RMB)
Attached are issue details and tutorials, as follows:
(1) Introduction to issue: https://github.com/AElfProject/AElf/issues/1915
(2) AElf's issue solution - Chinese Community Course: https://github.com/AElfProject/AElf/issues/1846
If you are interested, you can communicate directly with the technical team on issue. Or join the developer community QQ group directly: group number: 102857654
Mission statement:
This task is based on branch refactor/vote-contract-tests, so the refactoring test cases for voting contracts of interested people need to go from sign-off dev to refactor/vote-contract-tests. (Or create a new branch on your own warehouse based on this branch.)
Check the project test/AElf.Contracts.AEDPoSExtension.Demo.Tests basically knows how to use the TestKit AEDPoS extension.
The test case DemoTest (shown below) shows how the block chain system works: select some transactions and package them into one block, each new block based on the previous block.
By using XXStub, you can invoke a specific contract method in a test case just like a specific user invoking/sending a transaction. In addition, you can use XXStub to generate transactions.
[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); } }
With this in mind, you can go to test/AElf.Contracts.Vote.AEDPoSExtension.Tests to try to reconstruct the test case for the voting contract. For test logic, just copy the logic of the current test case to AElf.Contracts.Vote.Tests.
In addition, you are welcome to refactor other system contracts (located in contract/). READMEin test/AElf.Contracts.AEDPoSExtension.Demo.Tests explains how to create test projects.
**
Project introduction:
**
AELF is a de-centralized cloud computing platform designed to help enterprises/individuals build de-distributed applications (DAPP) efficiently and conveniently using basic block chain technology. In the centralized area, we use Amazon AWS to deploy services. In the area of block chain, we can host services on AELF de-centralized cloud computing block chain network.
AELF provides a high-performance intelligent contract platform which can support cross-chain interaction. Each application can be deployed independently in a chain to achieve real resource isolation, built-in rich system contracts, and build a rich economic system and power autonomy system on the chain.
Good luck and happy coding!