Hello team,
I have a following scenario:
fn push_bytes(ref mut a: Bytes, b: Bytes) {
let mut i = 0;
while i < b.len() {
a.push(b.get(i).unwrap());
i = i + 1;
}
}
pub fn concat_str_with_num(s: String, num: u64) -> String {
let mut result = Bytes::new();
push_bytes(result, s.as_bytes());
push_bytes(result, String::from_ascii_str("$").as_bytes()); // an arbitrary delimeter
push_bytes(result, num.to_le_bytes()); // [link to the lib](https://github.com/FuelLabs/sway/blob/master/sway-lib-std/src/bytes_conversions/u64.sw)
String::from_ascii(result)
}
The problem is: when I try to create a Unit test like the following:
#[test]
fn test_concat_str_with_num() {
log(concat_str_with_num(String::from_ascii_str("test"), 1));
assert(concat_str_with_num(String::from_ascii_str("test"), 1) == String::from_ascii_str("test$1"));
}
tests fail all the time regardless of what endian type I use in the conversion → to_be_bytes() also leads to the same failure of the test.
Could you please tell me if there is a way to concatenate strings like that or where I might be mistaken.
Also I have a follow-up question to this (might create another topic for that): is there any way of how one can display a pointer-based data type in the logs? Currently for any pointer type the response looks like this:
{
"LogData": {
"data": "0000000003ffffd20000000000000010000000000000000f",
"digest": "f0bc62614581cb6b44520055e084416ca3359a15efd3ee394fd83e6f3edb7d92",
"id": "0000000000000000000000000000000000000000000000000000000000000000",
"is": 10336,
"len": 24,
"pc": 299280,
"ptr": 308016,
"ra": 0,
"rb": 18
}
}
Thank you!