fuel_core_e2e_client/tests/
transfers.rsuse crate::test_context::{
TestContext,
BASE_AMOUNT,
};
use libtest_mimic::Failed;
use tokio::time::timeout;
pub async fn basic_transfer(ctx: &TestContext) -> Result<(), Failed> {
let result = ctx
.alice
.transfer(ctx.bob.address, 4 * BASE_AMOUNT, None)
.await?;
if !result.success {
return Err("transfer failed".into())
}
timeout(
ctx.config.sync_timeout(),
ctx.bob.client.await_transaction_commit(&result.tx_id),
)
.await??;
println!("\nThe tx id of the transfer: {}", result.tx_id);
let received_transfer = ctx.bob.owns_coin(result.transferred_utxo).await?;
if !received_transfer {
return Err("Bob failed to receive transfer".into())
}
Ok(())
}
pub async fn transfer_back(ctx: &TestContext) -> Result<(), Failed> {
basic_transfer(ctx).await?;
let result = ctx
.bob
.transfer(ctx.alice.address, 3 * BASE_AMOUNT, None)
.await?;
if !result.success {
return Err("transfer failed".into())
}
timeout(
ctx.config.sync_timeout(),
ctx.alice.client.await_transaction_commit(&result.tx_id),
)
.await??;
let received_transfer = ctx.alice.owns_coin(result.transferred_utxo).await?;
if !received_transfer {
return Err("Alice failed to receive transfer".into())
}
Ok(())
}