From 72826045b98ea24cc520e26cb2dba4e7d95b0247 Mon Sep 17 00:00:00 2001 From: Heorhii Azarov Date: Mon, 24 Jun 2024 17:19:07 +0300 Subject: [PATCH] Fix api simulation test --- Cargo.lock | 1 + .../scanner-lib/src/sync/tests/simulation.rs | 15 +++++++++------ orders-accounting/src/cache.rs | 2 +- tokens-accounting/Cargo.toml | 1 + tokens-accounting/src/cache.rs | 12 ++++++++++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7ea1670661..a0c6a83eba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7558,6 +7558,7 @@ dependencies = [ "chainstate-types", "common", "crypto", + "logging", "parity-scale-codec", "randomness", "rstest", diff --git a/api-server/scanner-lib/src/sync/tests/simulation.rs b/api-server/scanner-lib/src/sync/tests/simulation.rs index d00744e6fb..61dbb115d9 100644 --- a/api-server/scanner-lib/src/sync/tests/simulation.rs +++ b/api-server/scanner-lib/src/sync/tests/simulation.rs @@ -406,7 +406,7 @@ async fn simulation( | TxOutput::LockThenTransfer(_, _, _) | TxOutput::ProduceBlockFromStake(_, _) | TxOutput::Htlc(_, _) => {} - TxOutput::AnyoneCanTake(_) => todo!(), + TxOutput::AnyoneCanTake(_) => unimplemented!(), // TODO: support orders }); tx.inputs().iter().for_each(|inp| match inp { @@ -427,7 +427,9 @@ async fn simulation( statistics .entry(CoinOrTokenStatistic::CirculatingSupply) .or_default() - .insert(CoinOrTokenId::TokenId(*token_id), *to_mint); + .entry(CoinOrTokenId::TokenId(*token_id)) + .and_modify(|amount| *amount = (*amount + *to_mint).unwrap()) + .or_insert(*to_mint); let token_supply_change_fee = chain_config.token_supply_change_fee(block_height); burn_coins(&mut statistics, token_supply_change_fee); @@ -451,8 +453,9 @@ async fn simulation( chain_config.token_change_authority_fee(block_height); burn_coins(&mut statistics, token_change_authority_fee); } - AccountCommand::CancelOrder(_) => todo!(), - AccountCommand::FillOrder(_, _, _) => todo!(), + AccountCommand::CancelOrder(_) | AccountCommand::FillOrder(_, _, _) => { + unimplemented!() // TODO: support orders + } }, }); } @@ -471,6 +474,8 @@ async fn simulation( .and_modify(|amount| *amount = (*amount + block_subsidy).unwrap()) .or_insert(block_subsidy); + let pos_store = PoSAccountingAdapterToCheckFees::new(tf.chainstate.as_ref()); + let mut total_fees = AccumulatedFee::new(); for tx in block.transactions().iter() { let inputs_utxos: Vec<_> = tx @@ -484,8 +489,6 @@ async fn simulation( }) .collect(); - let pos_store = PoSAccountingAdapterToCheckFees::new(tf.chainstate.as_ref()); - let inputs_accumulator = ConstrainedValueAccumulator::from_inputs( &chain_config, block_height, diff --git a/orders-accounting/src/cache.rs b/orders-accounting/src/cache.rs index 64314aa266..23d45d4305 100644 --- a/orders-accounting/src/cache.rs +++ b/orders-accounting/src/cache.rs @@ -287,7 +287,7 @@ impl OrdersAccountingOperations for OrdersAccountingCac } fn undo(&mut self, undo_data: OrdersAccountingUndo) -> Result<()> { - log::debug!("Uno an order: {:?}", undo_data); + log::debug!("Undo an order: {:?}", undo_data); match undo_data { OrdersAccountingUndo::CreateOrder(undo) => self.undo_create_order(undo), OrdersAccountingUndo::CancelOrder(undo) => self.undo_cancel_order(undo), diff --git a/tokens-accounting/Cargo.toml b/tokens-accounting/Cargo.toml index 4b6d39e6ae..e55f989956 100644 --- a/tokens-accounting/Cargo.toml +++ b/tokens-accounting/Cargo.toml @@ -12,6 +12,7 @@ accounting = { path = "../accounting" } chainstate-types = { path = "../chainstate/types" } common = { path = "../common" } crypto = { path = "../crypto" } +logging = { path = "../logging" } randomness = { path = "../randomness" } serialization = { path = "../serialization" } utils = { path = "../utils" } diff --git a/tokens-accounting/src/cache.rs b/tokens-accounting/src/cache.rs index 057962acba..f0d32ac3f9 100644 --- a/tokens-accounting/src/cache.rs +++ b/tokens-accounting/src/cache.rs @@ -21,6 +21,7 @@ use common::{ }, primitives::Amount, }; +use logging::log; use crate::{ data::{TokenData, TokensAccountingDeltaData}, @@ -101,6 +102,8 @@ impl

FlushableTokensAccountingView for TokensAccountingCache

{ impl TokensAccountingOperations for TokensAccountingCache

{ fn issue_token(&mut self, id: TokenId, data: TokenData) -> Result { + log::debug!("Issuing a token: {:?} {:?}", id, data); + if self.get_token_data(&id)?.is_some() { return Err(Error::TokenAlreadyExists(id)); } @@ -125,6 +128,8 @@ impl TokensAccountingOperations for TokensAccountingCac id: TokenId, amount_to_add: Amount, ) -> Result { + log::debug!("Minting tokens: {:?} {:?}", id, amount_to_add); + let token_data = self.get_token_data(&id)?.ok_or(Error::TokenDataNotFound(id))?; let circulating_supply = self.get_circulating_supply(&id)?.unwrap_or(Amount::ZERO); @@ -165,6 +170,8 @@ impl TokensAccountingOperations for TokensAccountingCac id: TokenId, amount_to_burn: Amount, ) -> Result { + log::debug!("Unminting tokens: {:?} {:?}", id, amount_to_burn); + let token_data = self.get_token_data(&id)?.ok_or(Error::TokenDataNotFound(id))?; let circulating_supply = self.get_circulating_supply(&id)?.ok_or(Error::CirculatingSupplyNotFound(id))?; @@ -199,6 +206,7 @@ impl TokensAccountingOperations for TokensAccountingCac &mut self, id: TokenId, ) -> crate::error::Result { + log::debug!("Locking token supply: {:?}", id); let token_data = self.get_token_data(&id)?.ok_or(Error::TokenDataNotFound(id))?; let undo_data = match token_data { @@ -231,6 +239,7 @@ impl TokensAccountingOperations for TokensAccountingCac id: TokenId, is_unfreezable: IsTokenUnfreezable, ) -> Result { + log::debug!("Freezing token: {:?} {:?}", id, is_unfreezable); let token_data = self.get_token_data(&id)?.ok_or(Error::TokenDataNotFound(id))?; let undo_data = match token_data { @@ -258,6 +267,7 @@ impl TokensAccountingOperations for TokensAccountingCac } fn unfreeze_token(&mut self, id: TokenId) -> Result { + log::debug!("Unfreezing token supply: {:?}", id); let token_data = self.get_token_data(&id)?.ok_or(Error::TokenDataNotFound(id))?; let undo_data = match token_data { @@ -289,6 +299,7 @@ impl TokensAccountingOperations for TokensAccountingCac id: TokenId, new_authority: Destination, ) -> Result { + log::debug!("Changing token authority: {:?}", id); let token_data = self.get_token_data(&id)?.ok_or(Error::TokenDataNotFound(id))?; let undo_data = match token_data { @@ -313,6 +324,7 @@ impl TokensAccountingOperations for TokensAccountingCac } fn undo(&mut self, undo_data: TokenAccountingUndo) -> Result<(), Error> { + log::debug!("Undo in tokens: {:?}", undo_data); match undo_data { TokenAccountingUndo::IssueToken(undo) => { let _ = self