Skip to content

Commit 9800cfb

Browse files
committed
fix generic test spending more tokens than available
1 parent 454a059 commit 9800cfb

1 file changed

Lines changed: 19 additions & 5 deletions

File tree

wallet/src/signer/tests/generic_tests.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,16 @@ pub async fn test_sign_transaction_generic<MkS1, MkS2, S1, S2>(
387387
coin_input_amounts.iter().fold(Amount::ZERO, |acc, a| acc.add(*a).unwrap());
388388

389389
let decommissioned_pool_id = PoolId::new(H256::random_using(rng));
390-
let decommissioned_pool_balance = Amount::from_atoms(rng.gen_range(100..200));
390+
let decommissioned_pool_balance = Amount::from_atoms(
391+
rng.gen_range(100..200)
392+
+ chain_config.fungible_token_issuance_fee().into_atoms()
393+
+ chain_config.nft_issuance_fee(tx_block_height).into_atoms() * 2
394+
+ chain_config.token_supply_change_fee(tx_block_height).into_atoms() * 3
395+
+ chain_config.token_freeze_fee(tx_block_height).into_atoms() * 2
396+
+ chain_config.token_change_authority_fee(tx_block_height).into_atoms()
397+
+ chain_config.data_deposit_fee(tx_block_height).into_atoms(),
398+
);
399+
391400
let decommissioned_pool_data = PoolData {
392401
utxo_outpoint: UtxoOutPoint::new(Id::<Transaction>::random_using(rng).into(), 1),
393402
creation_block: BlockInfo {
@@ -645,14 +654,17 @@ pub async fn test_sign_transaction_generic<MkS1, MkS2, S1, S2>(
645654
]);
646655
}
647656

657+
let token_max_fill = std::cmp::min(
658+
filled_order2_info.initially_asked.amount(),
659+
token_mint_amount,
660+
);
661+
let token_amount_to_fill = rng.gen_range(1..token_max_fill.into_atoms());
648662
acc_inputs.extend([
649663
TxInput::OrderAccountCommand(OrderAccountCommand::ConcludeOrder(concluded_order2_id)),
650664
TxInput::OrderAccountCommand(OrderAccountCommand::FreezeOrder(frozen_order_id)),
651665
TxInput::OrderAccountCommand(OrderAccountCommand::FillOrder(
652666
filled_order2_id,
653-
Amount::from_atoms(
654-
rng.gen_range(1..filled_order2_info.initially_asked.amount().into_atoms()),
655-
),
667+
Amount::from_atoms(token_amount_to_fill),
656668
)),
657669
]);
658670

@@ -726,7 +738,9 @@ pub async fn test_sign_transaction_generic<MkS1, MkS2, S1, S2>(
726738
TxOutput::Transfer(
727739
OutputValue::TokenV1(
728740
token_id,
729-
Amount::from_atoms(rng.gen_range(1..=token_mint_amount.into_atoms())),
741+
Amount::from_atoms(
742+
rng.gen_range(1..=(token_mint_amount.into_atoms() - token_amount_to_fill)),
743+
),
730744
),
731745
Destination::PublicKey(dest_pub.clone()),
732746
),

0 commit comments

Comments
 (0)