sway
December 3, 2023, 10:10pm
1
Hi everyone,
I’m facing a perplexing issue:
My function’s return values different from what I log inside the function.
This odd behavior also occurred with my open_order
function, where the returned ID didn’t match its logged value.
Below is a test file showcasing the issue. Any insights or similar experiences would be greatly appreciated!
Test case
let max_abs_position_size = clearing_house
.get_max_abs_position_size(
bob_address,
btc.asset_id,
&[
&proxy.instance,
&perp_market.instance,
&pyth.instance,
&account_balance.instance,
&vault_bob.instance,
&clearing_house.instance,
],
)
.await
.unwrap();
let logs: Vec<(u64, u64)> = max_abs_position_size.decode_logs_with_type::<(u64, u64)>().unwrap();
println!("max_abs_position_size = {:?}", max_abs_position_size.value);
println!("logs = {:?}", logs);
output
max_abs_position_size = (0, 0)
logs= [(71428571, 71428571)]
function
fn get_max_abs_position_size(trader: Address, base_asset: AssetId) -> (u64, u64) { //(max_abs_short_size: u64, max_abs_long_size:u64)
//some code where I get valueson_size = max_position_value.mul_div(scale, mark_price).value;
let mut result =(0,0);
if current_position_size > I64::new(){
result = (2 * current_position_size.value + max_position_size, max_position_size);
} else{
result = (max_position_size, 2 * current_position_size.value + max_position_size);
}
log(result);
return result;
}
1 Like
sway
December 3, 2023, 10:13pm
2
installed toolchains
latest-aarch64-apple-darwin
beta-4-aarch64-apple-darwin (default)
latest-2023-11-15-aarch64-apple-darwin
active toolchain
beta-4-aarch64-apple-darwin (default)
forc : 0.46.1
- forc-client
- forc-deploy : 0.46.1
- forc-run : 0.46.1
- forc-doc : 0.46.1
- forc-explore : 0.28.1
- forc-fmt : 0.46.1
- forc-index : 0.23.0
- forc-lsp : 0.46.1
- forc-tx : 0.46.1
- forc-wallet : 0.3.0
fuel-core : 0.20.5
fuel-core-keygen : Error getting version string
fuel-indexer : 0.23.0
fuels versions
forc : 0.45
forc-wallet : 0.45
My toolchain
iqdecay
December 3, 2023, 10:58pm
3
It’s definitely not expected behavior.
Can you please check which version of fuels-rs
you are using?
Also, just to double-check, can you please tell me if by changing your function to:
let result = if current_position_size > I64::new() {
(2 * current_position_size.value + max_position_size, max_position_size)
} else{
(max_position_size, 2 * current_position_size.value + max_position_size)
}
log(result);
return result;
you still have the same issue? And also changing the condition of I64::new()
by 0i64
?
EDIT: just realized this is Sway not Rust, maybe my suggestion is not applicable.
Not sure if it is the same issue I faced some weeks ago, using fuels
0.49:
Please check if this a similar setup to yours:
Which was fixed here:
FuelLabs:master
← FuelLabs:hal3e/fix-gas-forwarded-bug
opened 01:11PM - 26 Oct 23 UTC
In [1122](https://github.com/FuelLabs/fuels-rs/pull/1122) I introduced a bug whe… re contract arguments are not put at the right location in the script data. We did not catch this because we did not have a test that has arguments and uses `gas_forwarded`. I have fixed the issue and added a test to cover this use-case.
### Checklist
- [x] I have added tests that prove my fix is effective or that my feature works.
- [x] I have added necessary labels.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
2 Likes
Hi there @sway
Is the fixed posted by @DefiCake working for you?
We’re having some problems reproducing this error.
Could you tell us the version of the Rust SDK you’re using?
Also, could you show us the raw receipts you’re getting back?
Is this code open source? If so, could you point us to it so we could try running it and investigate further?