Skip to content

Commit a292e8b

Browse files
committed
Add new tests proving that 1) signatures on FillOrder inputs are not enforced by chainstate; 2) submitting 2 txs with identical FillOrder inputs is handled gracefully by mempool
1 parent 85ef3a5 commit a292e8b

File tree

21 files changed

+776
-138
lines changed

21 files changed

+776
-138
lines changed

chainstate/test-framework/src/framework.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use common::{
4949
use crypto::{key::PrivateKey, vrf::VRFPrivateKey};
5050
use randomness::{CryptoRng, Rng};
5151
use utils::atomics::SeqCstAtomicU64;
52+
use utxo::Utxo;
5253

5354
/// The `Chainstate` wrapper that simplifies operations and checks in the tests.
5455
#[must_use]
@@ -590,11 +591,12 @@ impl TestFramework {
590591
self.best_block_height().next_height()
591592
}
592593

594+
pub fn utxo(&self, outpoint: &UtxoOutPoint) -> Utxo {
595+
self.chainstate.utxo(outpoint).unwrap().unwrap()
596+
}
597+
593598
pub fn coin_amount_from_utxo(&self, outpoint: &UtxoOutPoint) -> Amount {
594-
get_output_value(self.chainstate.utxo(outpoint).unwrap().unwrap().output())
595-
.unwrap()
596-
.coin_amount()
597-
.unwrap()
599+
get_output_value(self.utxo(outpoint).output()).unwrap().coin_amount().unwrap()
598600
}
599601
}
600602

chainstate/test-suite/src/tests/helpers/mod.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ use common::{
2424
signature::inputsig::InputWitness,
2525
timelock::OutputTimeLock,
2626
tokens::{TokenId, TokenIssuance},
27-
AccountCommand, AccountNonce, AccountType, Block, Destination, GenBlock, Transaction,
28-
TxInput, TxOutput, UtxoOutPoint,
27+
AccountCommand, AccountNonce, AccountType, Block, Destination, GenBlock, OrderId,
28+
OrdersVersion, Transaction, TxInput, TxOutput, UtxoOutPoint,
2929
},
3030
primitives::{Amount, BlockDistance, BlockHeight, Id, Idable},
3131
};
3232
use crypto::key::{KeyKind, PrivateKey};
33+
use orders_accounting::OrdersAccountingDB;
3334
use randomness::{CryptoRng, Rng};
3435

3536
pub mod block_creation_helpers;
@@ -185,3 +186,21 @@ pub fn mint_tokens_in_block(
185186

186187
(block_id, tx_id)
187188
}
189+
190+
/// Given the fill amount in the "ask" currency, return the filled amount in the "give" currency.
191+
pub fn calculate_fill_order(
192+
tf: &TestFramework,
193+
order_id: &OrderId,
194+
fill_amount_in_ask_currency: Amount,
195+
orders_version: OrdersVersion,
196+
) -> Amount {
197+
let db_tx = tf.storage.transaction_ro().unwrap();
198+
let orders_db = OrdersAccountingDB::new(&db_tx);
199+
orders_accounting::calculate_fill_order(
200+
&orders_db,
201+
*order_id,
202+
fill_amount_in_ask_currency,
203+
orders_version,
204+
)
205+
.unwrap()
206+
}

0 commit comments

Comments
 (0)