2026-03-04 18:42:33 +03:00
|
|
|
#![expect(
|
|
|
|
|
clippy::tests_outside_test_module,
|
|
|
|
|
reason = "We don't care about these in tests"
|
|
|
|
|
)]
|
|
|
|
|
|
2026-06-09 16:02:56 +03:00
|
|
|
use std::{io::Write as _, time::Duration};
|
2025-12-31 04:02:25 +03:00
|
|
|
|
|
|
|
|
use anyhow::Result;
|
2026-06-01 17:10:46 -03:00
|
|
|
use common::transaction::LeeTransaction;
|
refactor(integration_tests): cleaning up long functions (#533)
* refactoring integration_tests::keys
* refactor integration_tests: extract new_account/send/restored_private_account helpers
Move repeated account-creation and transfer boilerplate into four public
helpers in integration_tests/src/lib.rs (new_account, send,
restored_private_account, assert_public_account_restored), then apply them
across keys.rs, ata.rs, auth_transfer/public.rs, auth_transfer/private.rs,
token.rs, and amm.rs. Net result: -816 lines of boilerplate.
* Additional refactors
* refactor(integration_tests): apply shared helpers to remaining test files
Use account_balance, get_account, new_account, send, and sync_private
helpers in public.rs, pinata.rs, private_pda.rs, program_deployment.rs,
and token.rs to reduce boilerplate and improve consistency.
2026-07-01 12:13:51 -04:00
|
|
|
use integration_tests::{TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, get_account, new_account};
|
2025-12-31 04:02:25 +03:00
|
|
|
use log::info;
|
2026-03-13 22:38:23 +03:00
|
|
|
use sequencer_service_rpc::RpcClient as _;
|
2025-12-31 04:02:25 +03:00
|
|
|
use tokio::test;
|
2026-07-01 19:06:52 +03:00
|
|
|
use wallet::{cli::Command, config::WalletConfigOverrides};
|
2025-12-31 04:02:25 +03:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
async fn deploy_and_execute_program() -> Result<()> {
|
|
|
|
|
let mut ctx = TestContext::new().await?;
|
|
|
|
|
|
2026-06-09 16:02:56 +03:00
|
|
|
let claimer = test_programs::claimer();
|
|
|
|
|
let mut tempfile = tempfile::NamedTempFile::new()?;
|
|
|
|
|
tempfile.write_all(claimer.elf())?;
|
|
|
|
|
|
|
|
|
|
let binary_filepath = tempfile.path().to_owned();
|
2025-12-31 04:02:25 +03:00
|
|
|
|
|
|
|
|
let command = Command::DeployProgram {
|
|
|
|
|
binary_filepath: binary_filepath.clone(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
|
|
|
|
|
refactor(integration_tests): cleaning up long functions (#533)
* refactoring integration_tests::keys
* refactor integration_tests: extract new_account/send/restored_private_account helpers
Move repeated account-creation and transfer boilerplate into four public
helpers in integration_tests/src/lib.rs (new_account, send,
restored_private_account, assert_public_account_restored), then apply them
across keys.rs, ata.rs, auth_transfer/public.rs, auth_transfer/private.rs,
token.rs, and amm.rs. Net result: -816 lines of boilerplate.
* Additional refactors
* refactor(integration_tests): apply shared helpers to remaining test files
Use account_balance, get_account, new_account, send, and sync_private
helpers in public.rs, pinata.rs, private_pda.rs, program_deployment.rs,
and token.rs to reduce boilerplate and improve consistency.
2026-07-01 12:13:51 -04:00
|
|
|
let account_id = new_account(&mut ctx, false, None).await?;
|
2026-03-27 21:43:28 +03:00
|
|
|
|
|
|
|
|
let nonces = ctx.wallet().get_accounts_nonces(vec![account_id]).await?;
|
|
|
|
|
let private_key = ctx
|
|
|
|
|
.wallet()
|
|
|
|
|
.get_account_public_signing_key(account_id)
|
|
|
|
|
.unwrap();
|
2026-06-09 16:02:56 +03:00
|
|
|
let message =
|
|
|
|
|
lee::public_transaction::Message::try_new(claimer.id(), vec![account_id], nonces, ())?;
|
2026-06-01 17:10:46 -03:00
|
|
|
let witness_set = lee::public_transaction::WitnessSet::for_message(&message, &[private_key]);
|
|
|
|
|
let transaction = lee::PublicTransaction::new(message, witness_set);
|
2026-03-13 22:38:23 +03:00
|
|
|
let _response = ctx
|
|
|
|
|
.sequencer_client()
|
2026-06-01 17:10:46 -03:00
|
|
|
.send_transaction(LeeTransaction::Public(transaction))
|
2026-03-13 22:38:23 +03:00
|
|
|
.await?;
|
2025-12-31 04:02:25 +03:00
|
|
|
|
|
|
|
|
info!("Waiting for next block creation");
|
2026-01-29 22:20:42 +03:00
|
|
|
// Waiting for long time as it may take some time for such a big transaction to be included in a
|
|
|
|
|
// block
|
|
|
|
|
tokio::time::sleep(Duration::from_secs(2 * TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
2025-12-31 04:02:25 +03:00
|
|
|
|
refactor(integration_tests): cleaning up long functions (#533)
* refactoring integration_tests::keys
* refactor integration_tests: extract new_account/send/restored_private_account helpers
Move repeated account-creation and transfer boilerplate into four public
helpers in integration_tests/src/lib.rs (new_account, send,
restored_private_account, assert_public_account_restored), then apply them
across keys.rs, ata.rs, auth_transfer/public.rs, auth_transfer/private.rs,
token.rs, and amm.rs. Net result: -816 lines of boilerplate.
* Additional refactors
* refactor(integration_tests): apply shared helpers to remaining test files
Use account_balance, get_account, new_account, send, and sync_private
helpers in public.rs, pinata.rs, private_pda.rs, program_deployment.rs,
and token.rs to reduce boilerplate and improve consistency.
2026-07-01 12:13:51 -04:00
|
|
|
let post_state_account = get_account(&ctx, account_id).await?;
|
2025-12-31 04:02:25 +03:00
|
|
|
|
2026-06-18 01:01:40 +03:00
|
|
|
let expected_data: &[u8] = &[];
|
2026-06-09 16:02:56 +03:00
|
|
|
assert_eq!(post_state_account.program_owner, claimer.id());
|
2025-12-31 04:02:25 +03:00
|
|
|
assert_eq!(post_state_account.balance, 0);
|
2026-06-18 01:01:40 +03:00
|
|
|
assert_eq!(post_state_account.data.as_ref(), expected_data);
|
2026-03-27 21:43:28 +03:00
|
|
|
assert_eq!(post_state_account.nonce.0, 1);
|
2025-12-31 04:02:25 +03:00
|
|
|
|
|
|
|
|
info!("Successfully deployed and executed program");
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2026-07-01 19:06:52 +03:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
async fn deploy_invalid_program_fails() -> Result<()> {
|
|
|
|
|
// An invalid program bytecode is rejected by the sequencer during block production, so the
|
|
|
|
|
// deployment transaction is never included in a block. Shrink the wallet's polling window so
|
|
|
|
|
// the command gives up quickly instead of waiting for the full default timeout.
|
|
|
|
|
let mut ctx = TestContext::builder()
|
|
|
|
|
.with_wallet_config_overrides(WalletConfigOverrides {
|
|
|
|
|
seq_poll_timeout: Some(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)),
|
|
|
|
|
seq_tx_poll_max_blocks: Some(5),
|
|
|
|
|
seq_poll_max_retries: Some(2),
|
|
|
|
|
..WalletConfigOverrides::default()
|
|
|
|
|
})
|
|
|
|
|
.build()
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
let mut tempfile = tempfile::NamedTempFile::new()?;
|
|
|
|
|
tempfile.write_all(b"this is not a valid program binary")?;
|
|
|
|
|
|
|
|
|
|
let command = Command::DeployProgram {
|
|
|
|
|
binary_filepath: tempfile.path().to_owned(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let result = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await;
|
|
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
|
result.is_err(),
|
|
|
|
|
"Deploying an invalid program should fail, but got: {result:?}"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
info!("Deploying an invalid program failed as expected");
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|