You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This task is based on branch refactor/vote-contract-tests, so anyone interested in refactoring test cases of Vote Contract need to checkout his branch from dev to refactor/vote-contract-tests. (Or create a new branch on your own repo based on this branch.)
Check project test/AElf.Contracts.AEDPoSExtension.Demo.Tests to know basically how to use TestKit AEDPoS extension.
Test case DemoTest (shown bellow) shows how a blockchain system works: choose some transactions then package them to a block, every new block is based on previous block.
By using XXStub, you can act like a specific user calling / sending a transaction to call a method of specific contract in test case. Also, you can use XXStub for generating transactions.
[Fact]publicasync Task DemoTest(){// Check round information after initialization.{varround=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(newList<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.{vartokenInfo=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.{varround=await ConsensusStub.GetCurrentRoundInformation.CallAsync(new Empty());
round.RealTimeMinersInformation.Values.Count(m => m.OutValue !=null).ShouldBe(2);}await BlockMiningService.MineBlockAsync(newList<Transaction>());{varround=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(vari=0;i<3;i++){await BlockMiningService.MineBlockAsync(newList<Transaction>());}// Check round number.{varround=await ConsensusStub.GetCurrentRoundInformation.CallAsync(new Empty());
round.RoundNumber.ShouldBe(2);}// 6 more blocks will end second round.for(vari=0;i<6;i++){await BlockMiningService.MineBlockAsync(newList<Transaction>());}// Check round number.{varround=await ConsensusStub.GetCurrentRoundInformation.CallAsync(new Empty());
round.RoundNumber.ShouldBe(3);}}
After knowing this, you can go to test/AElf.Contracts.Vote.AEDPoSExtension.Tests and try to refactor test cases of Vote Contract. For the logic of testing, just copy logic of current test cases in AElf.Contracts.Vote.Tests should be enough.
Also, refactoring of other system contracts (located in contract/) is welcomed. README in test/AElf.Contracts.AEDPoSExtension.Demo.Tests explains how to create a test project.
The text was updated successfully, but these errors were encountered:
EanCuznaivy
changed the title
[Developer community] Refactor test cases of Vote Contract using test kit AEDPoS extension
[Developer community] Refactor test cases of Vote Contract using TestKit AEDPoS extension
Jul 22, 2019
This task is based on branch
refactor/vote-contract-tests
, so anyone interested in refactoring test cases of Vote Contract need to checkout his branch fromdev
torefactor/vote-contract-tests
. (Or create a new branch on your own repo based on this branch.)Check project
test/AElf.Contracts.AEDPoSExtension.Demo.Tests
to know basically how to use TestKit AEDPoS extension.Test case
DemoTest
(shown bellow) shows how a blockchain system works: choose some transactions then package them to a block, every new block is based on previous block.By using
XXStub
, you can act like a specific user calling / sending a transaction to call a method of specific contract in test case. Also, you can useXXStub
for generating transactions.After knowing this, you can go to
test/AElf.Contracts.Vote.AEDPoSExtension.Tests
and try to refactor test cases of Vote Contract. For the logic of testing, just copy logic of current test cases inAElf.Contracts.Vote.Tests
should be enough.Also, refactoring of other system contracts (located in
contract/
) is welcomed.README
intest/AElf.Contracts.AEDPoSExtension.Demo.Tests
explains how to create a test project.The text was updated successfully, but these errors were encountered: