Skip to content

Commit

Permalink
Merge pull request #1816 from mintlayer/fix/no_freeze_tokens_in_orders
Browse files Browse the repository at this point in the history
No frozen tokens in orders
  • Loading branch information
azarovh authored Sep 20, 2024
2 parents b5d6d58 + b140bd1 commit 43b3bfb
Show file tree
Hide file tree
Showing 15 changed files with 475 additions and 83 deletions.
35 changes: 21 additions & 14 deletions chainstate/test-framework/src/random_tx_maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,13 @@ fn get_random_token<'a>(
.iter()
.choose(rng)
.and_then(|(token_id, _)| {
tip_view.get_token_data(token_id).unwrap().is_some().then_some(*token_id)
tip_view
.get_token_data(token_id)
.unwrap()
.is_some_and(|data| match data {
tokens_accounting::TokenData::FungibleToken(data) => !data.is_frozen(),
})
.then_some(*token_id)
})
.map(|token_id| {
(
Expand Down Expand Up @@ -257,6 +263,20 @@ impl<'a> RandomTxMaker<'a> {
let orders_db = OrdersAccountingDB::new(self.orders_store);
let mut orders_cache = OrdersAccountingCache::new(&orders_db);

// Select random number of accounts to spend from
let account_inputs = self.select_accounts(rng);

// Spend from accounts first then from utxo because account commands affect the state (like freezing tokens)
let (account_inputs, account_outputs) = self.create_account_spending(
rng,
&mut tokens_cache,
&pos_db,
&mut pos_delta,
&mut orders_cache,
&account_inputs,
key_manager,
);

// Select random number of utxos to spend
let inputs_with_utxos = {
let mut inputs_with_utxos = self.select_utxos(rng);
Expand Down Expand Up @@ -298,19 +318,6 @@ impl<'a> RandomTxMaker<'a> {
inputs_with_utxos,
);

// Select random number of accounts to spend from
let account_inputs = self.select_accounts(rng);

let (account_inputs, account_outputs) = self.create_account_spending(
rng,
&mut tokens_cache,
&pos_db,
&mut pos_delta,
&mut orders_cache,
&account_inputs,
key_manager,
);

let mut inputs: Vec<_> = inputs.into_iter().chain(account_inputs).collect();

outputs.extend(account_outputs);
Expand Down
8 changes: 6 additions & 2 deletions chainstate/test-suite/src/tests/chainstate_storage_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use common::{
output_value::OutputValue,
tokens::{make_token_id, NftIssuance, TokenAuxiliaryData, TokenIssuanceV0},
ChainstateUpgrade, ChangeTokenMetadataUriActivated, DataDepositFeeVersion, Destination,
HtlcActivated, NetUpgrades, OrdersActivated, OutPointSourceId, RewardDistributionVersion,
TokenIssuanceVersion, TokensFeeVersion, Transaction, TxInput, TxOutput, UtxoOutPoint,
FrozenTokensValidationVersion, HtlcActivated, NetUpgrades, OrdersActivated,
OutPointSourceId, RewardDistributionVersion, TokenIssuanceVersion, TokensFeeVersion,
Transaction, TxInput, TxOutput, UtxoOutPoint,
},
primitives::{Amount, Id, Idable},
};
Expand Down Expand Up @@ -121,6 +122,7 @@ fn store_fungible_token_v0(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -203,6 +205,7 @@ fn store_nft_v0(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -516,6 +519,7 @@ fn store_aux_data_from_issue_nft(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
6 changes: 5 additions & 1 deletion chainstate/test-suite/src/tests/fungible_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use chainstate::{
};
use chainstate_test_framework::{get_output_value, TestFramework, TransactionBuilder};
use common::chain::tokens::{Metadata, NftIssuanceV0, TokenIssuanceV0, TokenTransfer};
use common::chain::{RewardDistributionVersion, UtxoOutPoint};
use common::chain::{FrozenTokensValidationVersion, RewardDistributionVersion, UtxoOutPoint};
use common::primitives::{id, BlockHeight, Id};
use common::{
chain::{
Expand Down Expand Up @@ -59,6 +59,7 @@ fn make_test_framework_with_v0(rng: &mut (impl Rng + CryptoRng)) -> TestFramewor
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -966,6 +967,7 @@ fn no_v0_issuance_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down Expand Up @@ -1032,6 +1034,7 @@ fn no_v0_transfer_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand All @@ -1044,6 +1047,7 @@ fn no_v0_transfer_after_v1(#[case] seed: Seed) {
TokensFeeVersion::V1,
DataDepositFeeVersion::V1,
ChangeTokenMetadataUriActivated::Yes,
FrozenTokensValidationVersion::V1,
HtlcActivated::Yes,
OrdersActivated::Yes,
),
Expand Down
Loading

0 comments on commit 43b3bfb

Please sign in to comment.