Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
noot committed Mar 26, 2024
1 parent 43cf8b1 commit 1a55c1a
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion crates/astria-sequencer/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,55 @@ mod test {
};

let signed_tx = tx.into_signed(&alice_signing_key);
check_balance_mempool(&signed_tx, &state_tx).await.unwrap();
check_balance_mempool(&signed_tx, &state_tx)
.await
.expect("sufficient balance for all actions");
}

#[tokio::test]
async fn check_balance_mempool_insuffient_other_asset_balance() {
let storage = cnidarium::TempStorage::new().await.unwrap();
let snapshot = storage.latest_snapshot();
let mut state_tx = StateDelta::new(snapshot);

crate::asset::initialize_native_asset(DEFAULT_NATIVE_ASSET_DENOM);
let native_asset = crate::asset::get_native_asset().id();
let other_asset = Denom::from_base_denom("other").id();

let (alice_signing_key, alice_address) = get_alice_signing_key_and_address();
let amount = 100;
let data = [0; 32].to_vec();
state_tx
.increase_balance(
alice_address,
native_asset,
TRANSFER_FEE + crate::sequence::calculate_fee(&data).unwrap(),
)
.await
.unwrap();

let actions = vec![
Action::Transfer(TransferAction {
asset_id: other_asset,
amount,
fee_asset_id: native_asset,
to: [0; ADDRESS_LEN].into(),
}),
Action::Sequence(SequenceAction {
rollup_id: RollupId::from_unhashed_bytes([0; 32]),
data,
fee_asset_id: native_asset,
}),
];

let tx = UnsignedTransaction {
nonce: 0,
actions,
};

let signed_tx = tx.into_signed(&alice_signing_key);
check_balance_mempool(&signed_tx, &state_tx)
.await
.expect_err("insuffient funds for `other` asset");
}
}

0 comments on commit 1a55c1a

Please sign in to comment.