-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnitTests working for Akka ConsensusService #475
Conversation
I think that unit testing on consensus is completely necessary! good job @igormcoelho |
I agree Erik, moved TimeProvider to Neo.Time namespace, so timing can be easily shared (and tested) for the whole project. |
neo/Consensus/ConsensusContext.cs
Outdated
public Dictionary<UInt256, Transaction> Transactions; | ||
public byte[][] Signatures; | ||
public byte[] ExpectedView; | ||
public DateTime block_received_time { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have TimeProvider
, can we move block_received_time
back to ConsensusService
? I did not see this variable used in ConsensusContext
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh! I lost my review, sorry for the delay Erik. In fact, we need manipulate block_received_time on unit tests... but one point I think now is that, could we use PrevHeader.Timestamp to replace block_received_time? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't use PrevHeader.Timestamp
because the system time of different nodes may be different.
You can control block_received_time
through TimeProvider
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you Erik, one less thing to control. Moving it back to Service.
What do you think @erikzhang? I guess we have agreed in most points now. One thing we haven't discussed is the Log system. I moved it to ConsensusContext, what is not ideal in my opinion. I'm thinking of moving it back (since I'm not using this info right now), so we can minimize the changes and try to pass this to master. What do you think? As soon as we have this on master, we can start creating tests to many interesting scenarios, including the fork situation. |
neo/Consensus/ConsensusContext.cs
Outdated
|
||
public ConsensusContext(Wallet wallet) | ||
{ | ||
this.wallet = wallet; | ||
} | ||
|
||
public bool RejectTx(Transaction tx, bool verify) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section needs to be moved back to ConsensusService
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! Now I think I can do it without breaking encapsulation.
Ok @erikzhang, moved RejectTx logic back to ConsensusService and also the Log function. The currently failing test is now depending only on this small fix: #498 |
Ok, back to normality, tests are running fine. |
This PR is not meant to be directly accepted, my intention is just to discuss how we could efficiently port Unit Tests for Consensus code (perhaps in several PR, what is best to the community).
This sample here uses official Akka TestKit, and it is already capable of starting consensus in a given time period (01/01/1968 00:00:00), simulating a specific block height (=2), an internal state (index=2 changeview=0), and making it propose an specific block header. The PrepareRequest message was successfully received.
An example of the output (consensus logs are also captured in unit tests):
I had to do some changes, I'll highlight the most fundamental ones:
Please take a look @erikzhang , @shargon, @vncoelho, @PeterLinX , I believe we can advance much faster in consensus issues by having a tool like this.