You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling ProgramTestContext::set_account twice for the same program address: &Pubkey, the second call gets ignored, so the account data will always be the one set on the first call. The following test illustrates the problem:
#[tokio::test]asyncfntest_upgradeable_program_account_set_program_data_account_address_works(){let program_id = Pubkey::new_unique();letmut context = ProgramTest::default().start_with_context().await;let program_data_address = Pubkey::new_unique();
context.set_account(&program_id,&upgradeable_program_account(program_data_address),);
context.set_account(&program_data_address,&program_data_account("helloworld1.so",0),);let result = simulate_transaction(&mut context, program_id).await;assert_eq!(
result.simulation_details.unwrap().logs[1],"Program log: Hello World Rust program entrypoint 1");
context.warp_to_slot(2).unwrap();let program_data_address = Pubkey::new_unique();
context.set_account(&program_id,&upgradeable_program_account(program_data_address),);
context.set_account(&program_data_address,&program_data_account("helloworld0.so",2),);
context.warp_to_slot(3).unwrap();let result = simulate_transaction(&mut context, program_id).await;assert_eq!(
result.simulation_details.unwrap().logs[1],"Program log: Hello World Rust program entrypoint 1"// TODO should be 0);}fnupgradeable_program_account(program_data_address:Pubkey) -> AccountSharedData{let account_len = UpgradeableLoaderState::size_of_program();letmut account = Account{lamports:Rent::default().minimum_balance(account_len).max(1),data:vec![0; account_len],owner: bpf_loader_upgradeable::id(),executable:true,rent_epoch:0,};
account
.set_state(&UpgradeableLoaderState::Program{programdata_address: program_data_address,}).unwrap();AccountSharedData::from(account)}fnprogram_data_account(path:&str,slot:Slot) -> AccountSharedData{let program_data = read_file(path);let program_data_len =
UpgradeableLoaderState::size_of_programdata_metadata() + program_data.len();letmut program_data_account = Account{lamports:Rent::default().minimum_balance(program_data_len).max(1),data:vec![0; program_data_len],owner: bpf_loader_upgradeable::id(),executable:true,rent_epoch:0,};
program_data_account
.set_state(&UpgradeableLoaderState::ProgramData{
slot,upgrade_authority_address:None,}).unwrap();
program_data_account.data[UpgradeableLoaderState::size_of_programdata_metadata()..].copy_from_slice(&program_data);AccountSharedData::from(program_data_account)}asyncfnsimulate_transaction(context:&mutProgramTestContext,program_id:Pubkey,) -> solana_banks_interface::BanksTransactionResultWithSimulation{let tx = Transaction::new_signed_with_payer(&[Instruction::new_with_bytes(
program_id,&[],vec![AccountMeta::new_readonly(program_id,false)],)],Some(&context.payer.pubkey()),&[&context.payer],
context.last_blockhash,);
context.banks_client.simulate_transaction(tx).await.unwrap()}
andreisilviudragnea
changed the title
ProgramTestContext::set_account called twice ignores second call
ProgramTestContext::set_account called twice with program account ignores second call
Jan 11, 2024
andreisilviudragnea
changed the title
ProgramTestContext::set_account called twice with program account ignores second call
ProgramTestContext::set_account does not update programs
Jan 14, 2024
The problem is that you are updating the program account directly, where as you should be using a deployment instruction of the loader. If you don't you will continue to see the outdated version which is cached.
Problem
When calling
ProgramTestContext::set_account
twice for the same programaddress: &Pubkey
, the second call gets ignored, so the account data will always be the one set on the first call. The following test illustrates the problem:I reproduced this bug here.
Proposed Solution
I expect the second call to
ProgramTestContext::set_account
to update the state of the program account. I proposed a solution in #34780.I reproduced this bug on Solana v1.16.25 and v1.17.15.
The text was updated successfully, but these errors were encountered: