mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-06-30 19:09:36 +00:00
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.
This commit is contained in:
parent
906cf80009
commit
456a2fe159
@ -169,9 +169,6 @@ pub fn assert_public_account_restored(ctx: &TestContext, account_id: AccountId,
|
||||
.unwrap_or_else(|| panic!("{label} should be restored"));
|
||||
}
|
||||
|
||||
/// Maximum time to wait for the indexer to catch up to the sequencer.
|
||||
pub const L2_TO_L1_TIMEOUT: Duration = Duration::from_mins(7);
|
||||
|
||||
/// Poll the indexer until its last finalized block id reaches the sequencer's
|
||||
/// current last block id or until [`L2_TO_L1_TIMEOUT`] elapses.
|
||||
/// Returns the last indexer block id observed.
|
||||
|
||||
@ -6,7 +6,7 @@ use integration_tests::{
|
||||
TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, account_balance, get_account, new_account,
|
||||
public_mention, send,
|
||||
};
|
||||
use lee::{program::Program, public_transaction, system_faucet_account_id};
|
||||
use lee::public_transaction;
|
||||
use log::info;
|
||||
use sequencer_service_rpc::RpcClient as _;
|
||||
use tokio::test;
|
||||
@ -21,19 +21,23 @@ use wallet::{
|
||||
#[test]
|
||||
async fn successful_transfer_to_existing_account() -> Result<()> {
|
||||
let mut ctx = TestContext::new().await?;
|
||||
let (acc0, acc1) = (
|
||||
ctx.existing_public_accounts()[0],
|
||||
ctx.existing_public_accounts()[1],
|
||||
);
|
||||
|
||||
send(&mut ctx, public_mention(acc0), public_mention(acc1), 100).await?;
|
||||
let sender = ctx.existing_public_accounts()[0];
|
||||
let receiver = ctx.existing_public_accounts()[1];
|
||||
send(
|
||||
&mut ctx,
|
||||
public_mention(sender),
|
||||
public_mention(receiver),
|
||||
100,
|
||||
)
|
||||
.await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move");
|
||||
let acc_1_balance = account_balance(&ctx, ctx.existing_public_accounts()[0]).await?;
|
||||
let acc_2_balance = account_balance(&ctx, ctx.existing_public_accounts()[1]).await?;
|
||||
let acc_1_balance = account_balance(&ctx, sender).await?;
|
||||
let acc_2_balance = account_balance(&ctx, receiver).await?;
|
||||
|
||||
info!("Balance of sender: {acc_1_balance:#?}");
|
||||
info!("Balance of receiver: {acc_2_balance:#?}");
|
||||
@ -49,11 +53,11 @@ pub async fn successful_transfer_to_new_account() -> Result<()> {
|
||||
let mut ctx = TestContext::new().await?;
|
||||
|
||||
let new_persistent_account_id = new_account(&mut ctx, false, None).await?;
|
||||
let acc0 = ctx.existing_public_accounts()[0];
|
||||
|
||||
let sender = ctx.existing_public_accounts()[0];
|
||||
send(
|
||||
&mut ctx,
|
||||
public_mention(acc0),
|
||||
public_mention(sender),
|
||||
public_mention(new_persistent_account_id),
|
||||
100,
|
||||
)
|
||||
@ -63,7 +67,7 @@ pub async fn successful_transfer_to_new_account() -> Result<()> {
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move");
|
||||
let acc_1_balance = account_balance(&ctx, ctx.existing_public_accounts()[0]).await?;
|
||||
let acc_1_balance = account_balance(&ctx, sender).await?;
|
||||
let acc_2_balance = account_balance(&ctx, new_persistent_account_id).await?;
|
||||
|
||||
info!("Balance of sender: {acc_1_balance:#?}");
|
||||
@ -111,20 +115,25 @@ async fn failed_transfer_with_insufficient_balance() -> Result<()> {
|
||||
#[test]
|
||||
async fn two_consecutive_successful_transfers() -> Result<()> {
|
||||
let mut ctx = TestContext::new().await?;
|
||||
let (acc0, acc1) = (
|
||||
ctx.existing_public_accounts()[0],
|
||||
ctx.existing_public_accounts()[1],
|
||||
);
|
||||
|
||||
let sender = ctx.existing_public_accounts()[0];
|
||||
let receiver = ctx.existing_public_accounts()[1];
|
||||
|
||||
// First transfer
|
||||
send(&mut ctx, public_mention(acc0), public_mention(acc1), 100).await?;
|
||||
send(
|
||||
&mut ctx,
|
||||
public_mention(sender),
|
||||
public_mention(receiver),
|
||||
100,
|
||||
)
|
||||
.await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move after first transfer");
|
||||
let acc_1_balance = account_balance(&ctx, ctx.existing_public_accounts()[0]).await?;
|
||||
let acc_2_balance = account_balance(&ctx, ctx.existing_public_accounts()[1]).await?;
|
||||
let acc_1_balance = account_balance(&ctx, sender).await?;
|
||||
let acc_2_balance = account_balance(&ctx, receiver).await?;
|
||||
|
||||
info!("Balance of sender: {acc_1_balance:#?}");
|
||||
info!("Balance of receiver: {acc_2_balance:#?}");
|
||||
@ -135,14 +144,20 @@ async fn two_consecutive_successful_transfers() -> Result<()> {
|
||||
info!("First TX Success!");
|
||||
|
||||
// Second transfer
|
||||
send(&mut ctx, public_mention(acc0), public_mention(acc1), 100).await?;
|
||||
send(
|
||||
&mut ctx,
|
||||
public_mention(sender),
|
||||
public_mention(receiver),
|
||||
100,
|
||||
)
|
||||
.await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move after second transfer");
|
||||
let acc_1_balance = account_balance(&ctx, ctx.existing_public_accounts()[0]).await?;
|
||||
let acc_2_balance = account_balance(&ctx, ctx.existing_public_accounts()[1]).await?;
|
||||
let acc_1_balance = account_balance(&ctx, sender).await?;
|
||||
let acc_2_balance = account_balance(&ctx, receiver).await?;
|
||||
|
||||
info!("Balance of sender: {acc_1_balance:#?}");
|
||||
info!("Balance of receiver: {acc_2_balance:#?}");
|
||||
@ -195,11 +210,12 @@ async fn successful_transfer_using_from_label() -> Result<()> {
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
|
||||
// Send using the label instead of account ID
|
||||
let acc1 = ctx.existing_public_accounts()[1];
|
||||
let sender = ctx.existing_public_accounts()[0];
|
||||
let receiver = ctx.existing_public_accounts()[1];
|
||||
send(
|
||||
&mut ctx,
|
||||
CliAccountMention::Label(label),
|
||||
public_mention(acc1),
|
||||
public_mention(receiver),
|
||||
100,
|
||||
)
|
||||
.await?;
|
||||
@ -208,8 +224,8 @@ async fn successful_transfer_using_from_label() -> Result<()> {
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move");
|
||||
let acc_1_balance = account_balance(&ctx, ctx.existing_public_accounts()[0]).await?;
|
||||
let acc_2_balance = account_balance(&ctx, ctx.existing_public_accounts()[1]).await?;
|
||||
let acc_1_balance = account_balance(&ctx, sender).await?;
|
||||
let acc_2_balance = account_balance(&ctx, receiver).await?;
|
||||
|
||||
assert_eq!(acc_1_balance, 9900);
|
||||
assert_eq!(acc_2_balance, 20100);
|
||||
@ -232,10 +248,11 @@ async fn successful_transfer_using_to_label() -> Result<()> {
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
|
||||
// Send using the label for the recipient
|
||||
let acc0 = ctx.existing_public_accounts()[0];
|
||||
let sender = ctx.existing_public_accounts()[0];
|
||||
let receiver = ctx.existing_public_accounts()[1];
|
||||
send(
|
||||
&mut ctx,
|
||||
public_mention(acc0),
|
||||
public_mention(sender),
|
||||
CliAccountMention::Label(label),
|
||||
100,
|
||||
)
|
||||
@ -245,8 +262,8 @@ async fn successful_transfer_using_to_label() -> Result<()> {
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move");
|
||||
let acc_1_balance = account_balance(&ctx, ctx.existing_public_accounts()[0]).await?;
|
||||
let acc_2_balance = account_balance(&ctx, ctx.existing_public_accounts()[1]).await?;
|
||||
let acc_1_balance = account_balance(&ctx, sender).await?;
|
||||
let acc_2_balance = account_balance(&ctx, receiver).await?;
|
||||
|
||||
assert_eq!(acc_1_balance, 9900);
|
||||
assert_eq!(acc_2_balance, 20100);
|
||||
|
||||
@ -6,17 +6,15 @@
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use common::PINATA_BASE58;
|
||||
use anyhow::{Context as _, Result};
|
||||
use integration_tests::{
|
||||
TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, account_balance,
|
||||
assert_private_commitment_in_state, private_mention, public_mention, sync_private,
|
||||
TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, account_balance, new_account, private_mention,
|
||||
public_mention, sync_private, verify_commitment_is_in_state,
|
||||
};
|
||||
use log::info;
|
||||
use tokio::test;
|
||||
use wallet::cli::{
|
||||
Command, SubcommandReturnValue,
|
||||
account::{AccountSubcommand, NewSubcommand},
|
||||
programs::{
|
||||
native_token_transfer::AuthTransferSubcommand, pinata::PinataProgramAgnosticSubcommand,
|
||||
},
|
||||
@ -26,22 +24,9 @@ use wallet::cli::{
|
||||
async fn claim_pinata_to_uninitialized_public_account_fails_fast() -> Result<()> {
|
||||
let mut ctx = TestContext::new().await?;
|
||||
|
||||
let result = wallet::cli::execute_subcommand(
|
||||
ctx.wallet_mut(),
|
||||
Command::Account(AccountSubcommand::New(NewSubcommand::Public {
|
||||
cci: None,
|
||||
label: None,
|
||||
})),
|
||||
)
|
||||
.await?;
|
||||
let SubcommandReturnValue::RegisterAccount {
|
||||
account_id: winner_account_id,
|
||||
} = result
|
||||
else {
|
||||
anyhow::bail!("Expected RegisterAccount return value");
|
||||
};
|
||||
let winner_account_id = new_account(&mut ctx, false, None).await?;
|
||||
|
||||
let pinata_balance_pre = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_pre = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
let claim_result = wallet::cli::execute_subcommand(
|
||||
ctx.wallet_mut(),
|
||||
@ -61,7 +46,7 @@ async fn claim_pinata_to_uninitialized_public_account_fails_fast() -> Result<()>
|
||||
"Expected init guidance, got: {err}",
|
||||
);
|
||||
|
||||
let pinata_balance_post = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_post = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
assert_eq!(pinata_balance_post, pinata_balance_pre);
|
||||
|
||||
@ -72,22 +57,9 @@ async fn claim_pinata_to_uninitialized_public_account_fails_fast() -> Result<()>
|
||||
async fn claim_pinata_to_uninitialized_private_account_fails_fast() -> Result<()> {
|
||||
let mut ctx = TestContext::new().await?;
|
||||
|
||||
let result = wallet::cli::execute_subcommand(
|
||||
ctx.wallet_mut(),
|
||||
Command::Account(AccountSubcommand::New(NewSubcommand::Private {
|
||||
cci: None,
|
||||
label: None,
|
||||
})),
|
||||
)
|
||||
.await?;
|
||||
let SubcommandReturnValue::RegisterAccount {
|
||||
account_id: winner_account_id,
|
||||
} = result
|
||||
else {
|
||||
anyhow::bail!("Expected RegisterAccount return value");
|
||||
};
|
||||
let winner_account_id = new_account(&mut ctx, true, None).await?;
|
||||
|
||||
let pinata_balance_pre = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_pre = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
let claim_result = wallet::cli::execute_subcommand(
|
||||
ctx.wallet_mut(),
|
||||
@ -107,7 +79,7 @@ async fn claim_pinata_to_uninitialized_private_account_fails_fast() -> Result<()
|
||||
"Expected init guidance, got: {err}",
|
||||
);
|
||||
|
||||
let pinata_balance_post = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_post = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
assert_eq!(pinata_balance_post, pinata_balance_pre);
|
||||
|
||||
@ -123,7 +95,7 @@ async fn claim_pinata_to_existing_public_account() -> Result<()> {
|
||||
to: public_mention(ctx.existing_public_accounts()[0]),
|
||||
});
|
||||
|
||||
let pinata_balance_pre = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_pre = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
|
||||
@ -131,7 +103,7 @@ async fn claim_pinata_to_existing_public_account() -> Result<()> {
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
info!("Checking correct balance move");
|
||||
let pinata_balance_post = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_post = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
let winner_balance_post = account_balance(&ctx, ctx.existing_public_accounts()[0]).await?;
|
||||
|
||||
@ -152,7 +124,7 @@ async fn claim_pinata_to_existing_private_account() -> Result<()> {
|
||||
to: private_mention(ctx.existing_private_accounts()[0]),
|
||||
});
|
||||
|
||||
let pinata_balance_pre = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_pre = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
let result = wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
let SubcommandReturnValue::PrivacyPreservingTransfer { tx_hash: _ } = result else {
|
||||
@ -165,9 +137,13 @@ async fn claim_pinata_to_existing_private_account() -> Result<()> {
|
||||
info!("Syncing private accounts");
|
||||
sync_private(&mut ctx).await?;
|
||||
|
||||
assert_private_commitment_in_state(&ctx, ctx.existing_private_accounts()[0], "account").await?;
|
||||
let new_commitment = ctx
|
||||
.wallet()
|
||||
.get_private_account_commitment(ctx.existing_private_accounts()[0])
|
||||
.context("Failed to get private account commitment")?;
|
||||
assert!(verify_commitment_is_in_state(new_commitment, ctx.sequencer_client()).await);
|
||||
|
||||
let pinata_balance_post = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_post = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
assert_eq!(pinata_balance_post, pinata_balance_pre - pinata_prize);
|
||||
|
||||
@ -183,20 +159,7 @@ async fn claim_pinata_to_new_private_account() -> Result<()> {
|
||||
let pinata_prize = 150;
|
||||
|
||||
// Create new private account
|
||||
let result = wallet::cli::execute_subcommand(
|
||||
ctx.wallet_mut(),
|
||||
Command::Account(AccountSubcommand::New(NewSubcommand::Private {
|
||||
cci: None,
|
||||
label: None,
|
||||
})),
|
||||
)
|
||||
.await?;
|
||||
let SubcommandReturnValue::RegisterAccount {
|
||||
account_id: winner_account_id,
|
||||
} = result
|
||||
else {
|
||||
anyhow::bail!("Expected RegisterAccount return value");
|
||||
};
|
||||
let winner_account_id = new_account(&mut ctx, true, None).await?;
|
||||
|
||||
// Initialize account under auth transfer program
|
||||
let command = Command::AuthTransfer(AuthTransferSubcommand::Init {
|
||||
@ -207,23 +170,31 @@ async fn claim_pinata_to_new_private_account() -> Result<()> {
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
assert_private_commitment_in_state(&ctx, winner_account_id, "account").await?;
|
||||
let new_commitment = ctx
|
||||
.wallet()
|
||||
.get_private_account_commitment(winner_account_id)
|
||||
.context("Failed to get private account commitment")?;
|
||||
assert!(verify_commitment_is_in_state(new_commitment, ctx.sequencer_client()).await);
|
||||
|
||||
// Claim pinata to the new private account
|
||||
let command = Command::Pinata(PinataProgramAgnosticSubcommand::Claim {
|
||||
to: private_mention(winner_account_id),
|
||||
});
|
||||
|
||||
let pinata_balance_pre = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_pre = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
assert_private_commitment_in_state(&ctx, winner_account_id, "account").await?;
|
||||
let new_commitment = ctx
|
||||
.wallet()
|
||||
.get_private_account_commitment(winner_account_id)
|
||||
.context("Failed to get private account commitment")?;
|
||||
assert!(verify_commitment_is_in_state(new_commitment, ctx.sequencer_client()).await);
|
||||
|
||||
let pinata_balance_post = account_balance(&ctx, PINATA_BASE58.parse().unwrap()).await?;
|
||||
let pinata_balance_post = account_balance(&ctx, system_accounts::pinata_account_id()).await?;
|
||||
|
||||
assert_eq!(pinata_balance_post, pinata_balance_pre - pinata_prize);
|
||||
|
||||
|
||||
@ -9,8 +9,7 @@ use anyhow::{Context as _, Result};
|
||||
use authenticated_transfer_core::Instruction as AuthTransferInstruction;
|
||||
use common::transaction::LeeTransaction;
|
||||
use integration_tests::{
|
||||
LEE_PROGRAM_FOR_TEST_PDA_SPEND_PROXY, TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext,
|
||||
assert_private_commitment_in_state, sync_private, verify_commitment_is_in_state,
|
||||
TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, sync_private, verify_commitment_is_in_state,
|
||||
};
|
||||
use key_protocol::key_management::ephemeral_key_holder::EphemeralKeyHolder;
|
||||
use lee::{
|
||||
@ -310,8 +309,23 @@ async fn private_pda_family_members_receive_and_spend() -> Result<()> {
|
||||
assert_eq!(pda_1_spent.balance, amount - amount_spend_1);
|
||||
|
||||
// Post-spend commitments must be in state.
|
||||
assert_private_commitment_in_state(&ctx, alice_pda_0_id, "alice_pda_0").await?;
|
||||
assert_private_commitment_in_state(&ctx, alice_pda_1_id, "alice_pda_1").await?;
|
||||
let post_spend_commitment_0 = ctx
|
||||
.wallet()
|
||||
.get_private_account_commitment(alice_pda_0_id)
|
||||
.context("post-spend commitment for alice_pda_0 missing")?;
|
||||
assert!(
|
||||
verify_commitment_is_in_state(post_spend_commitment_0, ctx.sequencer_client()).await,
|
||||
"alice_pda_0 post-spend commitment not in state"
|
||||
);
|
||||
|
||||
let post_spend_commitment_1 = ctx
|
||||
.wallet()
|
||||
.get_private_account_commitment(alice_pda_1_id)
|
||||
.context("post-spend commitment for alice_pda_1 missing")?;
|
||||
assert!(
|
||||
verify_commitment_is_in_state(post_spend_commitment_1, ctx.sequencer_client()).await,
|
||||
"alice_pda_1 post-spend commitment not in state"
|
||||
);
|
||||
|
||||
info!("Private PDA family member receive-and-spend test passed");
|
||||
Ok(())
|
||||
|
||||
@ -7,17 +7,11 @@ use std::{io::Write as _, time::Duration};
|
||||
|
||||
use anyhow::Result;
|
||||
use common::transaction::LeeTransaction;
|
||||
use integration_tests::{
|
||||
LEE_PROGRAM_FOR_TEST_DATA_CHANGER, TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, get_account,
|
||||
};
|
||||
use lee::program::Program;
|
||||
use integration_tests::{TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, get_account, new_account};
|
||||
use log::info;
|
||||
use sequencer_service_rpc::RpcClient as _;
|
||||
use tokio::test;
|
||||
use wallet::cli::{
|
||||
Command, SubcommandReturnValue,
|
||||
account::{AccountSubcommand, NewSubcommand},
|
||||
};
|
||||
use wallet::cli::Command;
|
||||
|
||||
#[test]
|
||||
async fn deploy_and_execute_program() -> Result<()> {
|
||||
@ -38,17 +32,7 @@ async fn deploy_and_execute_program() -> Result<()> {
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
let SubcommandReturnValue::RegisterAccount { account_id } = wallet::cli::execute_subcommand(
|
||||
ctx.wallet_mut(),
|
||||
Command::Account(AccountSubcommand::New(NewSubcommand::Public {
|
||||
cci: None,
|
||||
label: None,
|
||||
})),
|
||||
)
|
||||
.await?
|
||||
else {
|
||||
panic!("Expected RegisterAccount return value");
|
||||
};
|
||||
let account_id = new_account(&mut ctx, false, None).await?;
|
||||
|
||||
let nonces = ctx.wallet().get_accounts_nonces(vec![account_id]).await?;
|
||||
let private_key = ctx
|
||||
|
||||
@ -8,8 +8,8 @@ use std::time::Duration;
|
||||
|
||||
use anyhow::{Context as _, Result};
|
||||
use integration_tests::{
|
||||
TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, create_token, get_account, new_account,
|
||||
private_mention, public_mention, token_send, verify_commitment_is_in_state,
|
||||
TIME_TO_WAIT_FOR_BLOCK_SECONDS, TestContext, get_account, new_account, private_mention,
|
||||
public_mention, sync_private, verify_commitment_is_in_state,
|
||||
};
|
||||
use key_protocol::key_management::key_tree::chain_index::ChainIndex;
|
||||
use log::info;
|
||||
@ -40,14 +40,16 @@ async fn create_and_transfer_public_token() -> Result<()> {
|
||||
// Create new token
|
||||
let name = "A NAME".to_owned();
|
||||
let total_supply = 37;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
public_mention(definition_account_id),
|
||||
public_mention(supply_account_id),
|
||||
name.clone(),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: public_mention(definition_account_id),
|
||||
supply_account_id: public_mention(supply_account_id),
|
||||
name: name.clone(),
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Check the status of the token definition account
|
||||
let definition_acc = get_account(&ctx, definition_account_id).await?;
|
||||
@ -79,17 +81,24 @@ async fn create_and_transfer_public_token() -> Result<()> {
|
||||
|
||||
// Transfer 7 tokens from supply_acc to recipient_account_id
|
||||
let transfer_amount = 7;
|
||||
token_send(
|
||||
&mut ctx,
|
||||
public_mention(supply_account_id),
|
||||
public_mention(recipient_account_id),
|
||||
transfer_amount,
|
||||
)
|
||||
.await?;
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: public_mention(supply_account_id),
|
||||
to: Some(public_mention(recipient_account_id)),
|
||||
to_npk: None,
|
||||
to_vpk: None,
|
||||
to_keys: None,
|
||||
to_identifier: Some(0),
|
||||
amount: transfer_amount,
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Check the status of the supply account after transfer
|
||||
let supply_acc = get_account(&ctx, supply_account_id).await?;
|
||||
assert_eq!(supply_acc.program_owner, Program::token().id());
|
||||
assert_eq!(supply_acc.program_owner, programs::token().id());
|
||||
let token_holding = TokenHolding::try_from(&supply_acc.data)?;
|
||||
assert_eq!(
|
||||
token_holding,
|
||||
@ -101,7 +110,7 @@ async fn create_and_transfer_public_token() -> Result<()> {
|
||||
|
||||
// Check the status of the recipient account after transfer
|
||||
let recipient_acc = get_account(&ctx, recipient_account_id).await?;
|
||||
assert_eq!(recipient_acc.program_owner, Program::token().id());
|
||||
assert_eq!(recipient_acc.program_owner, programs::token().id());
|
||||
let token_holding = TokenHolding::try_from(&recipient_acc.data)?;
|
||||
assert_eq!(
|
||||
token_holding,
|
||||
@ -212,14 +221,17 @@ async fn create_and_transfer_token_with_private_supply() -> Result<()> {
|
||||
// Create new token
|
||||
let name = "A NAME".to_owned();
|
||||
let total_supply = 37;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
public_mention(definition_account_id),
|
||||
private_mention(supply_account_id),
|
||||
name.clone(),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: public_mention(definition_account_id),
|
||||
supply_account_id: private_mention(supply_account_id),
|
||||
name: name.clone(),
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Check the status of the token definition account
|
||||
let definition_acc = get_account(&ctx, definition_account_id).await?;
|
||||
@ -243,13 +255,20 @@ async fn create_and_transfer_token_with_private_supply() -> Result<()> {
|
||||
|
||||
// Transfer 7 tokens from supply_acc to recipient_account_id
|
||||
let transfer_amount = 7;
|
||||
token_send(
|
||||
&mut ctx,
|
||||
private_mention(supply_account_id),
|
||||
private_mention(recipient_account_id),
|
||||
transfer_amount,
|
||||
)
|
||||
.await?;
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: private_mention(supply_account_id),
|
||||
to: Some(private_mention(recipient_account_id)),
|
||||
to_npk: None,
|
||||
to_vpk: None,
|
||||
to_keys: None,
|
||||
to_identifier: Some(0),
|
||||
amount: transfer_amount,
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
let new_commitment1 = ctx
|
||||
.wallet()
|
||||
@ -328,14 +347,17 @@ async fn create_token_with_private_definition() -> Result<()> {
|
||||
// Create token with private definition
|
||||
let name = "A NAME".to_owned();
|
||||
let total_supply = 37;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
private_mention(definition_account_id),
|
||||
public_mention(supply_account_id),
|
||||
name.clone(),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: private_mention(definition_account_id),
|
||||
supply_account_id: public_mention(supply_account_id),
|
||||
name: name.clone(),
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Verify private definition commitment
|
||||
let new_commitment = ctx
|
||||
@ -465,14 +487,17 @@ async fn create_token_with_private_definition_and_supply() -> Result<()> {
|
||||
// Create token with both private definition and supply
|
||||
let name = "A NAME".to_owned();
|
||||
let total_supply = 37;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
private_mention(definition_account_id),
|
||||
private_mention(supply_account_id),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: private_mention(definition_account_id),
|
||||
supply_account_id: private_mention(supply_account_id),
|
||||
name,
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Verify definition commitment
|
||||
let definition_commitment = ctx
|
||||
@ -508,13 +533,20 @@ async fn create_token_with_private_definition_and_supply() -> Result<()> {
|
||||
|
||||
// Transfer tokens
|
||||
let transfer_amount = 7;
|
||||
token_send(
|
||||
&mut ctx,
|
||||
private_mention(supply_account_id),
|
||||
private_mention(recipient_account_id),
|
||||
transfer_amount,
|
||||
)
|
||||
.await?;
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: private_mention(supply_account_id),
|
||||
to: Some(private_mention(recipient_account_id)),
|
||||
to_npk: None,
|
||||
to_vpk: None,
|
||||
to_keys: None,
|
||||
to_identifier: Some(0),
|
||||
amount: transfer_amount,
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Verify both commitments updated
|
||||
let supply_commitment = ctx
|
||||
@ -577,24 +609,34 @@ async fn shielded_token_transfer() -> Result<()> {
|
||||
// Create token
|
||||
let name = "A NAME".to_owned();
|
||||
let total_supply = 37;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
public_mention(definition_account_id),
|
||||
public_mention(supply_account_id),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: public_mention(definition_account_id),
|
||||
supply_account_id: public_mention(supply_account_id),
|
||||
name,
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Perform shielded transfer: public supply -> private recipient
|
||||
let transfer_amount = 7;
|
||||
token_send(
|
||||
&mut ctx,
|
||||
public_mention(supply_account_id),
|
||||
private_mention(recipient_account_id),
|
||||
transfer_amount,
|
||||
)
|
||||
.await?;
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: public_mention(supply_account_id),
|
||||
to: Some(private_mention(recipient_account_id)),
|
||||
to_npk: None,
|
||||
to_vpk: None,
|
||||
to_keys: None,
|
||||
to_identifier: Some(0),
|
||||
amount: transfer_amount,
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Verify supply account balance
|
||||
let supply_acc = get_account(&ctx, supply_account_id).await?;
|
||||
@ -649,24 +691,34 @@ async fn deshielded_token_transfer() -> Result<()> {
|
||||
// Create token with private supply
|
||||
let name = "A NAME".to_owned();
|
||||
let total_supply = 37;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
public_mention(definition_account_id),
|
||||
private_mention(supply_account_id),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: public_mention(definition_account_id),
|
||||
supply_account_id: private_mention(supply_account_id),
|
||||
name,
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Perform deshielded transfer: private supply -> public recipient
|
||||
let transfer_amount = 7;
|
||||
token_send(
|
||||
&mut ctx,
|
||||
private_mention(supply_account_id),
|
||||
public_mention(recipient_account_id),
|
||||
transfer_amount,
|
||||
)
|
||||
.await?;
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: private_mention(supply_account_id),
|
||||
to: Some(public_mention(recipient_account_id)),
|
||||
to_npk: None,
|
||||
to_vpk: None,
|
||||
to_keys: None,
|
||||
to_identifier: Some(0),
|
||||
amount: transfer_amount,
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Verify supply account commitment exists
|
||||
let new_commitment = ctx
|
||||
@ -718,14 +770,17 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> {
|
||||
// Create token
|
||||
let name = "A NAME".to_owned();
|
||||
let total_supply = 37;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
private_mention(definition_account_id),
|
||||
private_mention(supply_account_id),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: private_mention(definition_account_id),
|
||||
supply_account_id: private_mention(supply_account_id),
|
||||
name,
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Create new private account for claiming path
|
||||
let recipient_account_id = new_account(&mut ctx, true, None).await?;
|
||||
@ -759,8 +814,7 @@ async fn token_claiming_path_with_private_accounts() -> Result<()> {
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Sync to claim the account
|
||||
let command = Command::Account(AccountSubcommand::SyncPrivate {});
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), command).await?;
|
||||
sync_private(&mut ctx).await?;
|
||||
|
||||
// Verify commitment exists
|
||||
let recipient_commitment = ctx
|
||||
@ -829,14 +883,16 @@ async fn create_token_using_labels() -> Result<()> {
|
||||
// Create token using account labels instead of IDs
|
||||
let name = "LABELED TOKEN".to_owned();
|
||||
let total_supply = 100;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
def_label.into(),
|
||||
supply_label.into(),
|
||||
name.clone(),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: def_label.into(),
|
||||
supply_account_id: supply_label.into(),
|
||||
name: name.clone(),
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
let definition_acc = get_account(&ctx, definition_account_id).await?;
|
||||
let token_definition = TokenDefinition::try_from(&definition_acc.data)?;
|
||||
@ -895,24 +951,32 @@ async fn transfer_token_using_from_label() -> Result<()> {
|
||||
|
||||
// Create token
|
||||
let total_supply = 50;
|
||||
create_token(
|
||||
&mut ctx,
|
||||
public_mention(definition_account_id),
|
||||
public_mention(supply_account_id),
|
||||
"LABEL TEST TOKEN".to_owned(),
|
||||
let subcommand = TokenProgramAgnosticSubcommand::New {
|
||||
definition_account_id: public_mention(definition_account_id),
|
||||
supply_account_id: public_mention(supply_account_id),
|
||||
name: "LABEL TEST TOKEN".to_owned(),
|
||||
total_supply,
|
||||
)
|
||||
.await?;
|
||||
};
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
// Transfer token using from_label instead of from
|
||||
let transfer_amount = 20;
|
||||
token_send(
|
||||
&mut ctx,
|
||||
supply_label.into(),
|
||||
public_mention(recipient_account_id),
|
||||
transfer_amount,
|
||||
)
|
||||
.await?;
|
||||
let subcommand = TokenProgramAgnosticSubcommand::Send {
|
||||
from: supply_label.into(),
|
||||
to: Some(public_mention(recipient_account_id)),
|
||||
to_npk: None,
|
||||
to_vpk: None,
|
||||
to_keys: None,
|
||||
to_identifier: Some(0),
|
||||
amount: transfer_amount,
|
||||
};
|
||||
wallet::cli::execute_subcommand(ctx.wallet_mut(), Command::Token(subcommand)).await?;
|
||||
|
||||
info!("Waiting for next block creation");
|
||||
tokio::time::sleep(Duration::from_secs(TIME_TO_WAIT_FOR_BLOCK_SECONDS)).await;
|
||||
|
||||
let recipient_acc = get_account(&ctx, recipient_account_id).await?;
|
||||
let token_holding = TokenHolding::try_from(&recipient_acc.data)?;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user