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

Stake instruction tests #24

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

2501babe
Copy link
Member

@2501babe 2501babe commented Dec 6, 2024

port all tests (except one that makes no sense) from monorepo stake_instruction.rs. we accomplish this by:

  • copying all tests essentially as-is
  • changing all uses of InstructionError to ProgramError
  • replacing the internals of process_instruction, process_instruction_as_one_arg, etc to use mollusk to emulate the previous raw InvokeContext creation/usage
  • changing those functions to accept a mollusk runner instead of a featureset
  • deleting all minimum delegation test_case variants. because we no longer have features, minimum delegation is hardcoded as off in the program and cannot be tested. if we ever get consensus on activating it, we can reenable by adding test_case using whatever mechanism is chosen
  • adding test_case variants for bpf stake and native stake. this ensures the same tests pass against both programs
  • slightly modifying some tests that pass in StakeHistory::default(). the details are somewhat arcane and do not (and could never possibly) occur on a live cluster, but these tests set up an invalid StakeHistory full of epoch 0 entries, which the stake history syscall rejects as invalid, when what they really want is a nonexistant stake history

there are two (and only two) places where we behave differently depending on which program is being tested. this is because we fixed a minor bug and expect to see an InvalidAccountOwner error instead of IncorrectProgramId when an owner is invalid. these can be seen by grepping for is_bpf()

@2501babe 2501babe force-pushed the stake-instruction-tests branch from 1b74c3b to e1bb8a5 Compare December 6, 2024 21:08
@2501babe 2501babe self-assigned this Dec 6, 2024
Copy link

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

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

Woohoo!

Comment on lines +51 to +64
fn mollusk_native() -> Mollusk {
let mut mollusk = Mollusk::default();
mollusk
.feature_set
.deactivate(&stake_raise_minimum_delegation_to_1_sol::id());
mollusk
}

fn mollusk_bpf() -> Mollusk {
let mut mollusk = Mollusk::new(&id(), "solana_stake_program");
mollusk
.feature_set
.deactivate(&stake_raise_minimum_delegation_to_1_sol::id());
mollusk
}

Choose a reason for hiding this comment

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

Sorry! I need to update the documentation, but you can actually use one Mollusk instance if you wanted. It doesn't map to a program anymore. new is just a convenience method to create a new instance and load a BPF program into the cache, but a Mollusk instance comes with a loaded cache and can be pointed at any program in the cache, doesn't matter if you use default or new.

The program to invoke is dictated by the instruction's program ID.

Copy link
Member Author

Choose a reason for hiding this comment

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

i believe what im doing here is correct (note that this branch uses a local version of mollusk on my machine that includes all three of my open prs). mollusk_native() loads no program so it uses the native stake program, mollusk_bpf() loads the bpf stake program which overrides the native. they have the same program id so there isnt a way to discriminate between them otherwise

Choose a reason for hiding this comment

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

Ahh I see, so the main purpose being to overwrite the stake program in the second one. Yeah, I think you've got it right then.

Comment on lines +157 to +166
create_account_shared_data_for_test(&clock::Clock::default())
} else if rewards::check_id(pubkey) {
create_account_shared_data_for_test(&rewards::Rewards::new(0.0))
} else if stake_history::check_id(pubkey) {
create_account_shared_data_for_test(&StakeHistory::default())
} else if stake_config::check_id(pubkey) {
config::create_account(0, &stake_config::Config::default())
} else if epoch_schedule::check_id(pubkey) {
create_account_shared_data_for_test(&EpochSchedule::default())
} else if rent::check_id(pubkey) {
create_account_shared_data_for_test(&Rent::default())

Choose a reason for hiding this comment

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

It's still a bit annoying to do, but you do have this API for keyed sysvar accounts available from the library:
https://github.com/buffalojoec/mollusk/blob/0c7b0edfe5788e9a6892d2c4eb60d43390c7175f/harness/src/sysvar.rs#L101-L134

@joncinque joncinque changed the base branch from master to main December 10, 2024 11:18
@2501babe 2501babe force-pushed the stake-instruction-tests branch from 3deeade to 65b7fb7 Compare December 11, 2024 04:42
@2501babe 2501babe closed this Dec 11, 2024
@2501babe 2501babe reopened this Dec 11, 2024
@2501babe
Copy link
Member Author

2501babe commented Dec 11, 2024

the branch rename seems to have dropped this prs connection to ci so im gonna merge it as-is once i can switch from local mollusk and then see what needs fixed in-flight. i think ci is still just fmt/clippy and doesnt run tests so ill have to add some workflow files anyway

edit: i didnt get ci for a new pr either so i guess we just dont have it right now, its immaterial tho since theres nothing important for ci to do yet

@2501babe 2501babe marked this pull request as ready for review December 14, 2024 19:49
@2501babe 2501babe requested a review from joncinque December 14, 2024 19:50
@2501babe 2501babe mentioned this pull request Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants