Skip to content

Commit

Permalink
Fix api simulation test
Browse files Browse the repository at this point in the history
  • Loading branch information
azarovh committed Jun 25, 2024
1 parent 03da404 commit 7282604
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions api-server/scanner-lib/src/sync/tests/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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
}
},
});
}
Expand All @@ -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
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion orders-accounting/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<P: OrdersAccountingView> 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),
Expand Down
1 change: 1 addition & 0 deletions tokens-accounting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
12 changes: 12 additions & 0 deletions tokens-accounting/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use common::{
},
primitives::Amount,
};
use logging::log;

use crate::{
data::{TokenData, TokensAccountingDeltaData},
Expand Down Expand Up @@ -101,6 +102,8 @@ impl<P> FlushableTokensAccountingView for TokensAccountingCache<P> {

impl<P: TokensAccountingView> TokensAccountingOperations for TokensAccountingCache<P> {
fn issue_token(&mut self, id: TokenId, data: TokenData) -> Result<TokenAccountingUndo, Error> {
log::debug!("Issuing a token: {:?} {:?}", id, data);

if self.get_token_data(&id)?.is_some() {
return Err(Error::TokenAlreadyExists(id));
}
Expand All @@ -125,6 +128,8 @@ impl<P: TokensAccountingView> TokensAccountingOperations for TokensAccountingCac
id: TokenId,
amount_to_add: Amount,
) -> Result<TokenAccountingUndo, Error> {
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);

Expand Down Expand Up @@ -165,6 +170,8 @@ impl<P: TokensAccountingView> TokensAccountingOperations for TokensAccountingCac
id: TokenId,
amount_to_burn: Amount,
) -> Result<TokenAccountingUndo, Error> {
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))?;
Expand Down Expand Up @@ -199,6 +206,7 @@ impl<P: TokensAccountingView> TokensAccountingOperations for TokensAccountingCac
&mut self,
id: TokenId,
) -> crate::error::Result<TokenAccountingUndo> {
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 {
Expand Down Expand Up @@ -231,6 +239,7 @@ impl<P: TokensAccountingView> TokensAccountingOperations for TokensAccountingCac
id: TokenId,
is_unfreezable: IsTokenUnfreezable,
) -> Result<TokenAccountingUndo, Error> {
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 {
Expand Down Expand Up @@ -258,6 +267,7 @@ impl<P: TokensAccountingView> TokensAccountingOperations for TokensAccountingCac
}

fn unfreeze_token(&mut self, id: TokenId) -> Result<TokenAccountingUndo, Error> {
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 {
Expand Down Expand Up @@ -289,6 +299,7 @@ impl<P: TokensAccountingView> TokensAccountingOperations for TokensAccountingCac
id: TokenId,
new_authority: Destination,
) -> Result<TokenAccountingUndo, Error> {
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 {
Expand All @@ -313,6 +324,7 @@ impl<P: TokensAccountingView> 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
Expand Down

0 comments on commit 7282604

Please sign in to comment.