Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dorin-iancu committed Feb 27, 2024
1 parent e46f95f commit 72918a5
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 26 deletions.
4 changes: 4 additions & 0 deletions common/transaction/src/call_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ impl<M: ManagedTypeApi> NestedDecode for CallData<M> {
args.push(arg);
}

if !input.is_depleted() {
return core::result::Result::Err(DecodeError::from("Input too long"));
}

core::result::Result::Ok(Self {
endpoint: endpoint_name,
gas_limit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"function": "batchTransferEsdtToken",
"arguments": [
"1",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|0x01|nested:str:data|u64:10000000|u32:0",
"0x0102030405060708091011121314151617181920|address:user2|nested:str:WRAPPED-123456|biguint:500|u64:2|0x01|nested:str:data|u64:10000000|u32:0"
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1|0x01|u8:4|str:data|u32:10000000|u8:0",
"0x0102030405060708091011121314151617181920|address:user2|nested:str:WRAPPED-123456|biguint:500|u64:2|0x01|u8:4|str:data|u32:10000000|u8:0"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"arguments": [
"1",
"0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x0",
"0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:WRAPPED-123456|biguint:100,500|u64:2||0x01|nested:str:data|u64:90|u32:0"
"0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:WRAPPED-123456|biguint:100,500|u64:2||0x01|u8:4|str:data|u32:90|u8:0"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
Expand All @@ -40,14 +40,12 @@
"expect": {
"out": [
"1",

"0",
"1",
"0x0102030405060708091011121314151617181920",
"sc:multi_transfer_esdt",
"str:BRIDGE-123456",
"100,200",

"0",
"2",
"0x0102030405060708091011121314151617181920",
Expand All @@ -74,14 +72,12 @@
"message": "",
"out": [
"1",

"0",
"1",
"0x0102030405060708091011121314151617181920",
"sc:multi_transfer_esdt",
"str:BRIDGE-123456",
"100,200",

"0",
"2",
"0x0102030405060708091011121314151617181920",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"function": "batchTransferEsdtToken",
"arguments": [
"1",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|u8:4|str:data|u32:10000000|u8:0",
"0x0102030405060708091011121314151617181920|sc:multi_transfer_esdt|nested:str:WRAPPED-123456|biguint:500|u64:2||0x0"
],
"gasLimit": "50,000,000",
Expand Down Expand Up @@ -64,4 +64,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"function": "batchTransferEsdtToken",
"arguments": [
"1",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0",
"0x0102030405060708091011121314151617181920|address:frozen_user|nested:str:BRIDGE-123456|biguint:500|u64:2||0x01|nested:str:data|u64:10000000|u32:0"
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|u8:4|str:data|u32:10000000|u8:0",
"0x0102030405060708091011121314151617181920|address:frozen_user|nested:str:BRIDGE-123456|biguint:500|u64:2||0x01|u8:4|str:data|u32:10000000|u8:0"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
Expand Down Expand Up @@ -84,4 +84,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@
"function": "batchTransferEsdtToken",
"arguments": [
"1",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0",
"0x0102030405060708091011121314151617181920|address:user2|nested:str:USDC-aaaaaa|biguint:500,000,000,000,000|u64:2||0x01|nested:str:data|u64:10000000|u32:0",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:USDC-cccccc|biguint:1,000,000,000,000,000|u64:3||0x01|nested:str:data|u64:10000000|u32:0"
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|u8:4|str:data|u32:10000000|u8:0",
"0x0102030405060708091011121314151617181920|address:user2|nested:str:USDC-aaaaaa|biguint:500,000,000,000,000|u64:2||0x01|u8:4|str:data|u32:10000000|u8:0",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:USDC-cccccc|biguint:1,000,000,000,000,000|u64:3||0x01|u8:4|str:data|u32:10000000|u8:0"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
Expand Down Expand Up @@ -346,4 +346,4 @@
}
}
]
}
}
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 @@ -330,4 +330,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"function": "batchTransferEsdtToken",
"arguments": [
"1",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0"
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|u8:4|str:data|u32:10000000|u8:0"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
Expand All @@ -62,4 +62,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion multi-transfer-esdt/scenarios/transfer_ok.scen.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"function": "batchTransferEsdtToken",
"arguments": [
"1",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0"
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|u8:4|str:data|u32:10000000|u8:0"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"function": "batchTransferEsdtToken",
"arguments": [
"1",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|nested:str:data|u64:10000000|u32:0",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:2||0x01|nested:str:data|u64:10000000|u32:0"
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:1||0x01|u8:4|str:data|u32:10000000|u8:0",
"0x0102030405060708091011121314151617181920|address:user1|nested:str:BRIDGE-123456|biguint:100,200|u64:2||0x01|u8:4|str:data|u32:10000000|u8:0"
],
"gasLimit": "50,000,000",
"gasPrice": "0"
Expand Down
17 changes: 13 additions & 4 deletions multi-transfer-esdt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use transaction::{
const DEFAULT_MAX_TX_BATCH_SIZE: usize = 10;
const DEFAULT_MAX_TX_BATCH_BLOCK_DURATION: u64 = u64::MAX;
const MIN_GAS_LIMIT_FOR_SC_CALL: u64 = 10_000_000;
const MAX_GAS_LIMIT_FOR_SC_CALL: u64 = 600_000_000;

#[multiversx_sc::contract]
pub trait MultiTransferEsdt:
Expand Down Expand Up @@ -53,6 +54,7 @@ pub trait MultiTransferEsdt:

for eth_tx in transfers {
let mut must_refund = false;
let is_dest_sc = self.blockchain().is_smart_contract(&eth_tx.to);

if eth_tx.to.is_zero() {
self.transfer_failed_invalid_destination(batch_id, eth_tx.tx_nonce);
Expand All @@ -63,16 +65,23 @@ pub trait MultiTransferEsdt:
} else if self.is_account_same_shard_frozen(sc_shard, &eth_tx.to, &eth_tx.token_id) {
self.transfer_failed_frozen_destination_account(batch_id, eth_tx.tx_nonce);
must_refund = true;
} else if self.blockchain().is_smart_contract(&eth_tx.to)
{
} else if is_dest_sc {
match &eth_tx.call_data {
Some(call_data) => {
if call_data.gas_limit < MIN_GAS_LIMIT_FOR_SC_CALL {
if call_data.gas_limit < MIN_GAS_LIMIT_FOR_SC_CALL
|| call_data.gas_limit > MAX_GAS_LIMIT_FOR_SC_CALL
{

Check warning on line 73 in multi-transfer-esdt/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] multi-transfer-esdt/src/lib.rs#L73

warning: this `if` has identical blocks --> multi-transfer-esdt/src/lib.rs:73:25 | 73 | / { 74 | | must_refund = true; 75 | | } else if call_data.endpoint.len() > u8::MAX as usize { | |_________________________^ | note: same as this --> multi-transfer-esdt/src/lib.rs:75:79 | 75 | } else if call_data.endpoint.len() > u8::MAX as usize { | _______________________________________________________________________________^ 76 | | must_refund = true; 77 | | } else if call_data.args.len() > u8::MAX as usize { | |_________________________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else = note: `#[warn(clippy::if_same_then_else)]` on by default
Raw output
multi-transfer-esdt/src/lib.rs:73:25:w:warning: this `if` has identical blocks
  --> multi-transfer-esdt/src/lib.rs:73:25
   |
73 | /                         {
74 | |                             must_refund = true;
75 | |                         } else if call_data.endpoint.len() > u8::MAX as usize {
   | |_________________________^
   |
note: same as this
  --> multi-transfer-esdt/src/lib.rs:75:79
   |
75 |                           } else if call_data.endpoint.len() > u8::MAX as usize {
   |  _______________________________________________________________________________^
76 | |                             must_refund = true;
77 | |                         } else if call_data.args.len() > u8::MAX as usize {
   | |_________________________^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
   = note: `#[warn(clippy::if_same_then_else)]` on by default


__END__

Check warning on line 73 in multi-transfer-esdt/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] multi-transfer-esdt/src/lib.rs#L73

warning: this `if` has identical blocks --> multi-transfer-esdt/src/lib.rs:73:25 | 73 | / { 74 | | must_refund = true; 75 | | } else if call_data.endpoint.len() > u8::MAX as usize { | |_________________________^ | note: same as this --> multi-transfer-esdt/src/lib.rs:75:79 | 75 | } else if call_data.endpoint.len() > u8::MAX as usize { | _______________________________________________________________________________^ 76 | | must_refund = true; 77 | | } else if call_data.args.len() > u8::MAX as usize { | |_________________________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else = note: `#[warn(clippy::if_same_then_else)]` on by default
Raw output
multi-transfer-esdt/src/lib.rs:73:25:w:warning: this `if` has identical blocks
  --> multi-transfer-esdt/src/lib.rs:73:25
   |
73 | /                         {
74 | |                             must_refund = true;
75 | |                         } else if call_data.endpoint.len() > u8::MAX as usize {
   | |_________________________^
   |
note: same as this
  --> multi-transfer-esdt/src/lib.rs:75:79
   |
75 |                           } else if call_data.endpoint.len() > u8::MAX as usize {
   |  _______________________________________________________________________________^
76 | |                             must_refund = true;
77 | |                         } else if call_data.args.len() > u8::MAX as usize {
   | |_________________________^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
   = note: `#[warn(clippy::if_same_then_else)]` on by default


__END__
must_refund = true;
} else if call_data.endpoint.len() > u8::MAX as usize {

Check warning on line 75 in multi-transfer-esdt/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] multi-transfer-esdt/src/lib.rs#L75

warning: this `if` has identical blocks --> multi-transfer-esdt/src/lib.rs:75:79 | 75 | } else if call_data.endpoint.len() > u8::MAX as usize { | _______________________________________________________________________________^ 76 | | must_refund = true; 77 | | } else if call_data.args.len() > u8::MAX as usize { | |_________________________^ | note: same as this --> multi-transfer-esdt/src/lib.rs:77:75 | 77 | } else if call_data.args.len() > u8::MAX as usize { | ___________________________________________________________________________^ 78 | | must_refund = true; 79 | | } | |_________________________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
Raw output
multi-transfer-esdt/src/lib.rs:75:79:w:warning: this `if` has identical blocks
  --> multi-transfer-esdt/src/lib.rs:75:79
   |
75 |                           } else if call_data.endpoint.len() > u8::MAX as usize {
   |  _______________________________________________________________________________^
76 | |                             must_refund = true;
77 | |                         } else if call_data.args.len() > u8::MAX as usize {
   | |_________________________^
   |
note: same as this
  --> multi-transfer-esdt/src/lib.rs:77:75
   |
77 |                           } else if call_data.args.len() > u8::MAX as usize {
   |  ___________________________________________________________________________^
78 | |                             must_refund = true;
79 | |                         }
   | |_________________________^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else


__END__

Check warning on line 75 in multi-transfer-esdt/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

[clippy] multi-transfer-esdt/src/lib.rs#L75

warning: this `if` has identical blocks --> multi-transfer-esdt/src/lib.rs:75:79 | 75 | } else if call_data.endpoint.len() > u8::MAX as usize { | _______________________________________________________________________________^ 76 | | must_refund = true; 77 | | } else if call_data.args.len() > u8::MAX as usize { | |_________________________^ | note: same as this --> multi-transfer-esdt/src/lib.rs:77:75 | 77 | } else if call_data.args.len() > u8::MAX as usize { | ___________________________________________________________________________^ 78 | | must_refund = true; 79 | | } | |_________________________^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
Raw output
multi-transfer-esdt/src/lib.rs:75:79:w:warning: this `if` has identical blocks
  --> multi-transfer-esdt/src/lib.rs:75:79
   |
75 |                           } else if call_data.endpoint.len() > u8::MAX as usize {
   |  _______________________________________________________________________________^
76 | |                             must_refund = true;
77 | |                         } else if call_data.args.len() > u8::MAX as usize {
   | |_________________________^
   |
note: same as this
  --> multi-transfer-esdt/src/lib.rs:77:75
   |
77 |                           } else if call_data.args.len() > u8::MAX as usize {
   |  ___________________________________________________________________________^
78 | |                             must_refund = true;
79 | |                         }
   | |_________________________^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else


__END__
must_refund = true;
} else if call_data.args.len() > u8::MAX as usize {
must_refund = true;
}
}
None => must_refund = true,
}
} else if is_dest_sc && eth_tx.call_data.is_some() {
must_refund = true;
}

if must_refund {
Expand All @@ -87,7 +96,7 @@ pub trait MultiTransferEsdt:
.mint_token(&eth_tx.token_id, &eth_tx.amount)
.execute_on_dest_context();

if minted_token.amount == BigUint::zero() {
if minted_token.amount == 0 {
let refund_tx = self.convert_to_refund_tx(eth_tx);
refund_tx_list.push(refund_tx);

Expand Down

0 comments on commit 72918a5

Please sign in to comment.