Skip to content

Commit

Permalink
Multi transfer: Batch Transfer blackbox test
Browse files Browse the repository at this point in the history
  • Loading branch information
CostinCarabas committed Dec 29, 2023
1 parent a93762f commit d1767c5
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 77 deletions.
6 changes: 3 additions & 3 deletions bridged-tokens-wrapper/tests/dfp_big_uint_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use multiversx_sc_scenario::DebugApi;

#[test]
fn test_biguint() {
let _ = DebugApi::dummy();
DebugApi::dummy();
let raw = 123456u64;
let dfp = DFPBigUint::<DebugApi>::from_raw(raw.into(), 6);
let converted = dfp.clone().convert(9);
assert!(dfp.trunc() == converted.trunc());
assert!(converted.clone().convert(9).to_raw() == 123456000u64);
assert!(converted.clone().convert(1).to_raw() == 1u64);
assert!(converted.clone().convert(3).to_raw() == 123u64);
assert!(converted.clone().convert(5).to_raw() == 12345u64);
assert!(converted.convert(5).to_raw() == 12345u64);
}

#[test]
fn test_mandos_scenario_values() {
let _ = DebugApi::dummy();
DebugApi::dummy();
let raw = 300000000000000u64;
let dfp = DFPBigUint::<DebugApi>::from_raw(raw.into(), 18);
assert!(dfp.convert(6).to_raw() == 300u64);
Expand Down
10 changes: 6 additions & 4 deletions common/token-module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,6 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule {
);
if self.mint_burn_allowed(token_id).get() {
let accumulated_burned_tokens_mapper = self.accumulated_burned_tokens(token_id);
require!(
!accumulated_burned_tokens_mapper.is_empty(),
"Accumulated burned tokens storage is not initialized!"
);
accumulated_burned_tokens_mapper.update(|burned| {
require!(*burned >= *amount, "Not enough accumulated burned tokens!");
*burned -= amount;
Expand Down Expand Up @@ -156,6 +152,12 @@ pub trait TokenModule: fee_estimator_module::FeeEstimatorModule {
}
}

#[only_owner]
#[endpoint(setAccumulatedBurnedTokens)]
fn set_accumulated_burned_tokens(&self, token_id: &TokenIdentifier, value: BigUint) {
self.accumulated_burned_tokens(token_id).set_if_empty(value);
}

// storage

#[view(getAllKnownTokens)]
Expand Down
22 changes: 21 additions & 1 deletion esdt-safe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,27 @@ pub trait EsdtSafe:
}

#[upgrade]
fn upgrade(&self) {}
fn upgrade(&self, fee_estimator_contract_address: ManagedAddress, eth_tx_gas_limit: BigUint) {
self.fee_estimator_contract_address()
.set(&fee_estimator_contract_address);
self.eth_tx_gas_limit().set(&eth_tx_gas_limit);

self.max_tx_batch_size()
.set_if_empty(DEFAULT_MAX_TX_BATCH_SIZE);
self.max_tx_batch_block_duration()
.set_if_empty(DEFAULT_MAX_TX_BATCH_BLOCK_DURATION);

// batch ID 0 is considered invalid
self.first_batch_id().set_if_empty(1);
self.last_batch_id().set_if_empty(1);

// set ticker for "GWEI"
let gwei_token_id = TokenIdentifier::from(GWEI_STRING);
self.token_ticker(&gwei_token_id)
.set(gwei_token_id.as_managed_buffer());

self.set_paused(true);
}

/// Sets the statuses for the transactions, after they were executed on the Ethereum side.
///
Expand Down
15 changes: 10 additions & 5 deletions multi-transfer-esdt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ pub trait MultiTransferEsdt:
}

#[upgrade]
fn upgrade(&self) {}
fn upgrade(&self) {
self.max_tx_batch_size()
.set_if_empty(DEFAULT_MAX_TX_BATCH_SIZE);
self.max_tx_batch_block_duration()
.set_if_empty(DEFAULT_MAX_TX_BATCH_BLOCK_DURATION);
// batch ID 0 is considered invalid
self.first_batch_id().set_if_empty(1);
self.last_batch_id().set_if_empty(1);
}

#[only_owner]
#[endpoint(batchTransferEsdtToken)]
Expand All @@ -48,9 +56,6 @@ pub trait MultiTransferEsdt:
if eth_tx.to.is_zero() {
self.transfer_failed_invalid_destination(batch_id, eth_tx.tx_nonce);
must_refund = true;
} else if !self.is_local_role_set(&eth_tx.token_id, &EsdtLocalRole::Mint) {
self.transfer_failed_invalid_token(batch_id, eth_tx.tx_nonce);
must_refund = true;
} else if self.is_above_max_amount(&eth_tx.token_id, &eth_tx.amount) {
self.transfer_over_max_amount(batch_id, eth_tx.tx_nonce);
must_refund = true;
Expand All @@ -73,7 +78,7 @@ pub trait MultiTransferEsdt:
let minted_token = self
.get_esdt_safe_contract_proxy_instance()
.mint_token(&eth_tx.token_id, &eth_tx.amount)
.with_esdt_transfer((eth_tx.token_id.clone(), 0, eth_tx.amount.clone()))
// .with_esdt_transfer((eth_tx.token_id.clone(), 0, eth_tx.amount.clone()))
.execute_on_dest_context();

// emit event before the actual transfer so we don't have to save the tx_nonces as well
Expand Down
Loading

0 comments on commit d1767c5

Please sign in to comment.