Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi-transfer: max_tx_batch_block_duration #265

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion multi-transfer-esdt/scenarios/setup_accounts.scen.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
"str:firstBatchId": "1",
"str:lastBatchId": "1",
"str:maxTxBatchSize": "10",
"str:maxTxBatchBlockDuration": "0xffffffffffffffff"
"str:maxTxBatchBlockDuration": "100_000_000"
}
},
"sc:bridge-proxy": {
Expand Down
2 changes: 1 addition & 1 deletion multi-transfer-esdt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use sc_proxies::{bridge_proxy_contract_proxy, bridged_tokens_wrapper_proxy, esdt
use transaction::{EthTransaction, PaymentsVec, Transaction, TxNonce};

const DEFAULT_MAX_TX_BATCH_SIZE: usize = 10;
const DEFAULT_MAX_TX_BATCH_BLOCK_DURATION: u64 = u64::MAX;
const DEFAULT_MAX_TX_BATCH_BLOCK_DURATION: u64 = 100_000_000u64;
const CHAIN_SPECIFIC_TO_UNIVERSAL_TOKEN_MAPPING: &[u8] = b"chainSpecificToUniversalMapping";

#[multiversx_sc::contract]
Expand Down
164 changes: 164 additions & 0 deletions multi-transfer-esdt/tests/multi_transfer_blackbox_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const MAX_AMOUNT: u64 = 100_000_000_000_000u64;
const BALANCE: &str = "2,000,000";
const ERROR: u64 = 4;
const MINTED_AMOUNT: u64 = 100_000_000_000;
const DEFAULT_MAX_TX_BATCH_BLOCK_DURATION: u64 = 100_000_000u64;

fn world() -> ScenarioWorld {
let mut blockchain = ScenarioWorld::new();
Expand Down Expand Up @@ -1371,3 +1372,166 @@ fn batch_transfer_esdt_token_to_address_zero() {
.batch_transfer_esdt_token(1u32, transfers)
.run();
}

#[test]
fn multi_transfer_reduce_max_tx_batch_size_test() {
let mut state: MultiTransferTestState = MultiTransferTestState::new();

state.multisig_deploy();
state.multi_transfer_deploy();
state.bridge_proxy_deploy();
state.safe_deploy_real_contract();
state.bridged_tokens_wrapper_deploy();
state.config_multi_transfer();

state.world.set_esdt_balance(
MULTISIG_ADDRESS,
b"TOKEN-WITH",
BigUint::from(10_000_000u64),
);

let eth_tx = EthTransaction {
from: EthAddress::zero(),
to: ManagedAddress::zero(),
token_id: TokenIdentifier::from(TOKEN_TICKER),
amount: BigUint::from(MAX_AMOUNT),
tx_nonce: 1u64,
call_data: ManagedOption::none(),
};

let mut transfers: MultiValueEncoded<StaticApi, EthTransaction<StaticApi>> =
MultiValueEncoded::new();
transfers.push(eth_tx.clone());

// Batch size is default 10
state
.world
.tx()
.from(MULTISIG_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.batch_transfer_esdt_token(1u32, transfers.clone())
.run();

state
.world
.tx()
.from(MULTISIG_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.batch_transfer_esdt_token(1u32, transfers.clone())
.run();

state
.world
.tx()
.from(MULTISIG_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.batch_transfer_esdt_token(1u32, transfers.clone())
.run();

state
.world
.tx()
.from(MULTISIG_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.batch_transfer_esdt_token(1u32, transfers.clone())
.run();

let batch_status = state
.world
.tx()
.from(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.get_batch_status(1u64)
.returns(ReturnsResult)
.run();

assert_eq!(
batch_status,
BatchStatus::PartiallyFull {
end_block_nonce: DEFAULT_MAX_TX_BATCH_BLOCK_DURATION,
tx_ids: ManagedVec::from(vec![1u64, 1u64, 1u64, 1u64])
},
"Incorrect batch status"
);

let new_max_batch_status = 2usize;
state
.world
.tx()
.from(MULTISIG_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.set_max_tx_batch_size(new_max_batch_status)
.run();

//get_batch_status
let batch_id = 1u64;
let batch_status = state
.world
.tx()
.from(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.get_batch_status(batch_id)
.returns(ReturnsResult)
.run();

assert_eq!(
batch_status,
BatchStatus::WaitingForSignatures,
"Incorrect batch status"
);

state
.world
.tx()
.from(MULTISIG_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.batch_transfer_esdt_token(batch_id, transfers)
.run();

//First batch should be full
let batch_id = 1u64;
let batch_status = state
.world
.tx()
.from(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.get_batch_status(batch_id)
.returns(ReturnsResult)
.run();

assert_eq!(
batch_status,
BatchStatus::WaitingForSignatures,
"Incorrect batch status"
);

//A new batch should be created
let batch_id = 2u64;
let batch_status = state
.world
.tx()
.from(BRIDGED_TOKENS_WRAPPER_ADDRESS)
.to(MULTI_TRANSFER_ADDRESS)
.typed(multi_transfer_esdt_proxy::MultiTransferEsdtProxy)
.get_batch_status(batch_id)
.returns(ReturnsResult)
.run();

assert_eq!(
batch_status,
BatchStatus::PartiallyFull {
end_block_nonce: DEFAULT_MAX_TX_BATCH_BLOCK_DURATION,
tx_ids: ManagedVec::from(vec![1u64])
},
"Incorrect batch status"
);
}
Loading