-
Notifications
You must be signed in to change notification settings - Fork 741
Fix some P-chain UTs #2117
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
Fix some P-chain UTs #2117
Conversation
cf2a0f2
to
36096b7
Compare
36096b7
to
4101651
Compare
} | ||
|
||
// Test case where primary network validator is preferred to be rewarded | ||
func TestRewardValidatorPreferred(t *testing.T) { |
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 test seems to verify the same behaviour in TestRewardValidatorAccept
. Dropped
@@ -721,9 +721,9 @@ func TestRewardValidatorAccept(t *testing.T) { | |||
// Fast forward clock to time for genesis validators to leave | |||
vm.clock.Set(defaultValidateEndTime) | |||
|
|||
blk, err := vm.Builder.BuildBlock(context.Background()) // should advance 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.
PreBanff we used ApricotProposalBlocks to advance time.
Post Banff cleanup, we don't build ApricotProposalBlocks anymore (we deleted the code to do that).
Chain time is advanced by blocks timestamp, without proposal.
This test claims to issue an proposalBlock that advances time; it is instead issuing a proposal block to reward the first validator. Error is not caught because we didn't have a assertion on the block tx type.
Fix is to skip this "advance time with proposal block" section and move directly to next section where genesis validator is rewarded.
require.NoError(oracleBlk.Accept(context.Background())) | ||
// Assert block tries to reward a genesis validator | ||
rewardTx := oracleBlk.(block.Block).Txs()[0].Unsigned | ||
require.IsType(&txs.RewardValidatorTx{}, rewardTx) |
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.
let's introduce the assertion that would have make us spot the error in the first place
txID := oracleBlk.(block.Block).Txs()[0].ID() | ||
{ | ||
onAccept, ok := vm.manager.GetState(abort.ID()) | ||
onAbort, ok := vm.manager.GetState(abort.ID()) |
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.
in this test we'll reward the validator by accepting the commit block. However in this code block we check that abort block is coherent.
3657e8c
to
4101651
Compare
oracleBlk := blk.(smcon.OracleBlock) | ||
options, err := oracleBlk.Options(context.Background()) | ||
require.NoError(err) | ||
|
||
commit := options[0].(*blockexecutor.Block) | ||
abort := options[0].(*blockexecutor.Block) |
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.
preferences were wrongly flipped
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.
Maybe some cleanup of the affected tests is suggested? The amount of setup duplication suggests to me refactoring to use a table-driven approach might be a good idea.
Why this should be merged
Some P-chain UTs are wrong. They still try to advance time via an ApricotProposalBlock, which we don't even build anymore. Moreover these tests are brittle as they rely on a specifc ordering of validators to be evicted and any change to their staking duration causes the test to fail with no reason.
Thanks @joshua-kim and @marun for the discussions that brought me to find this out
How this works
Drops attempt to move time forward with proposal block (not needed anymore post Banff)
Improves assertions to be more robust
Drop a test altogether cause it's the copy of another existing one
How this was tested
Testing test is tricky. I guess manual inspection.