Skip to content

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

Merged
merged 17 commits into from
Oct 17, 2023
Merged

Fix some P-chain UTs #2117

merged 17 commits into from
Oct 17, 2023

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Sep 29, 2023

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.

@abi87 abi87 requested review from marun and joshua-kim September 29, 2023 08:05
@abi87 abi87 force-pushed the fix_platformVM_UTs branch 2 times, most recently from cf2a0f2 to 36096b7 Compare September 29, 2023 08:37
@abi87 abi87 force-pushed the fix_platformVM_UTs branch from 36096b7 to 4101651 Compare September 29, 2023 08:37
}

// Test case where primary network validator is preferred to be rewarded
func TestRewardValidatorPreferred(t *testing.T) {
Copy link
Contributor Author

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

@abi87 abi87 self-assigned this Sep 29, 2023
@abi87 abi87 added this to the v1.10.12 milestone Sep 29, 2023
@@ -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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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())
Copy link
Contributor Author

@abi87 abi87 Sep 29, 2023

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.

@abi87 abi87 requested a review from ceyonur as a code owner September 29, 2023 10:13
@abi87 abi87 force-pushed the fix_platformVM_UTs branch from 3657e8c to 4101651 Compare September 29, 2023 10:15
oracleBlk := blk.(smcon.OracleBlock)
options, err := oracleBlk.Options(context.Background())
require.NoError(err)

commit := options[0].(*blockexecutor.Block)
abort := options[0].(*blockexecutor.Block)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preferences were wrongly flipped

@abi87 abi87 changed the base branch from dev to fix_platformVM_UTs_2 September 29, 2023 12:23
Base automatically changed from fix_platformVM_UTs_2 to dev September 29, 2023 16:37
Copy link
Contributor

@marun marun left a 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.

@StephenButtolph StephenButtolph modified the milestones: v1.10.12, v1.10.13 Oct 5, 2023
@abi87 abi87 requested a review from dhrubabasu October 11, 2023 20:33
@StephenButtolph StephenButtolph added vm This involves virtual machines testing This primarily focuses on testing cleanup Code quality improvement labels Oct 17, 2023
@StephenButtolph StephenButtolph added this pull request to the merge queue Oct 17, 2023
Merged via the queue into dev with commit 4da9491 Oct 17, 2023
@StephenButtolph StephenButtolph deleted the fix_platformVM_UTs branch October 17, 2023 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement testing This primarily focuses on testing vm This involves virtual machines
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants