Skip to content
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

Remove duplicate genesis creations in P-chain unit tests #3318

Merged
merged 29 commits into from
Aug 23, 2024

Conversation

StephenButtolph
Copy link
Contributor

@StephenButtolph StephenButtolph commented Aug 21, 2024

Why this should be merged

There are currently 6 instances of the same (slightly modified) piece of code. This unifies all of them with the genesistest.New function.

How this works

  • Almost a pure refactor, this removes one test vector instance that depended on txID sorting (which wasn't useful).

How this was tested

  • CI

@StephenButtolph StephenButtolph self-assigned this Aug 21, 2024
@StephenButtolph StephenButtolph added testing This primarily focuses on testing acp103 labels Aug 21, 2024
@StephenButtolph StephenButtolph added this to the v1.11.11 milestone Aug 21, 2024
@StephenButtolph StephenButtolph marked this pull request as draft August 21, 2024 17:36
Comment on lines -518 to -524
// Staker2's end time matches staker5's start time, so typically
// the block builder would produce a ProposalBlock to remove
// staker2 when advancing the time. However, this test injects
// staker0 into the staker set artificially to advance the time.
// This means that staker2 is not removed by the ProposalBlock
// when advancing the 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.

This comment is describing that the behavior of this test makes assumptions on the hash ordering of txID for staker0 and staker2. This is not useful to test as it is currently written imo, so decided to remove it.

@@ -137,7 +138,7 @@ func TestRewardValidatorTxExecuteOnCommit(t *testing.T) {

onCommitBalance, err := avax.GetBalance(env.state, stakeOwners)
require.NoError(err)
require.Equal(oldBalance+stakerToRemove.Weight+27697, onCommitBalance)
require.Equal(oldBalance+stakerToRemove.Weight+38944, onCommitBalance)
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 is a terrible test. But out-of-scope for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) What does this magic number signify?

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 magic number is signifying the staking rewards that the genesis validator will receive. The reason this number changes is because the genesis staking duration was increased from 20 days to 28 days (because 28 days was used in most other places)

@@ -754,71 +750,3 @@ func buildVM(t *testing.T) (*VM, ids.ID, error) {

return vm, testSubnet1.ID(), nil
}

func buildCustomGenesis(avaxAssetID ids.ID) ([]byte, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

1

// Returns:
// 1) The genesis state
// 2) The byte representation of the default genesis for tests
func defaultGenesis(t *testing.T, avaxAssetID ids.ID) (*api.BuildGenesisArgs, []byte) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

2

@@ -342,60 +320,3 @@ func defaultFx(t *testing.T, clk *mockable.Clock, log logging.Logger, isBootstra
}
return res
}

func buildGenesisTest(t *testing.T, ctx *snow.Context) []byte {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

3

@@ -372,69 +347,6 @@ func defaultFx(clk *mockable.Clock, log logging.Logger, isBootstrapped bool) fx.
return res
}

func buildGenesisTest(ctx *snow.Context) []byte {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

4

@@ -322,66 +302,3 @@ func defaultFx(clk *mockable.Clock, log logging.Logger, isBootstrapped bool) fx.
}
return res
}

func buildGenesisTest(ctx *snow.Context) []byte {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

5


buildGenesisResponse := api.BuildGenesisReply{}
platformvmSS := api.StaticService{}
require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

6

@StephenButtolph StephenButtolph marked this pull request as ready for review August 22, 2024 23:19
@StephenButtolph StephenButtolph changed the title Increase funds in test genesis Remove duplicate genesis creations in P-chain unit tests Aug 22, 2024
vms/platformvm/block/builder/helpers_test.go Show resolved Hide resolved
vms/platformvm/genesis/genesistest/genesis.go Show resolved Hide resolved
vms/platformvm/genesis/genesistest/genesis.go Show resolved Hide resolved
vms/platformvm/validator_set_property_test.go Show resolved Hide resolved
vms/platformvm/txs/executor/proposal_tx_executor_test.go Outdated Show resolved Hide resolved
vms/platformvm/vm_test.go Show resolved Hide resolved
vms/platformvm/vm_test.go Outdated Show resolved Hide resolved
@StephenButtolph StephenButtolph added this pull request to the merge queue Aug 23, 2024
Merged via the queue into master with commit 85ab969 Aug 23, 2024
21 checks passed
@StephenButtolph StephenButtolph deleted the increase-funds-in-test-genesis branch August 23, 2024 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
acp103 testing This primarily focuses on testing
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants