Skip to content

Commit 9bb2b0c

Browse files
committed
Merge branch 'master' of github.com:FuelLabs/sway into vaivaswatha/ir2_pr3
2 parents 89eaad3 + 134916d commit 9bb2b0c

File tree

27 files changed

+1404
-309
lines changed

27 files changed

+1404
-309
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

forc-plugins/forc-client/src/op/call/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use fuels::{
3131
use fuels_core::types::{transaction::TxPolicies, AssetId, ContractId};
3232
use serde::{Deserialize, Serialize};
3333
use std::{collections::HashMap, str::FromStr};
34-
use sway_core;
3534

3635
/// Response returned from a contract call operation
3736
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
@@ -264,17 +263,18 @@ pub(crate) fn process_transaction_output(
264263
data: Some(data),
265264
..
266265
} => {
266+
let default_program_abi = ProgramABI::default();
267267
let program_abi = abis
268268
.get(contract_id)
269-
.map(|abi| {
270-
sway_core::asm_generation::ProgramABI::Fuel(abi.program.clone())
271-
})
272-
.unwrap_or(sway_core::asm_generation::ProgramABI::Fuel(
273-
ProgramABI::default(),
274-
));
275-
forc_util::tx_utils::decode_log_data(&rb.to_string(), data, &program_abi)
276-
.ok()
277-
.map(|decoded| decoded.value)
269+
.map(|abi| &abi.program)
270+
.unwrap_or(&default_program_abi);
271+
forc_util::tx_utils::decode_fuel_vm_log_data(
272+
&rb.to_string(),
273+
data,
274+
program_abi,
275+
)
276+
.ok()
277+
.map(|decoded| decoded.value)
278278
}
279279
_ => None,
280280
})

forc-plugins/forc-client/src/op/call/transaction_trace.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,14 @@ impl Node<'_> {
263263
Some(data) => {
264264
let hex_str = format!("0x{}", hex::encode(data));
265265
match self.abis.get(id) {
266-
Some(abi) => {
267-
let program_abi = sway_core::asm_generation::ProgramABI::Fuel(
268-
abi.program.clone(),
269-
);
270-
forc_util::tx_utils::decode_log_data(
271-
&rb.to_string(),
272-
data,
273-
&program_abi,
274-
)
275-
.ok()
276-
.map(|decoded| decoded.value)
277-
.unwrap_or(hex_str)
278-
}
266+
Some(abi) => forc_util::tx_utils::decode_fuel_vm_log_data(
267+
&rb.to_string(),
268+
data,
269+
&abi.program,
270+
)
271+
.ok()
272+
.map(|decoded| decoded.value)
273+
.unwrap_or(hex_str),
279274
None => hex_str,
280275
}
281276
}

forc-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ repository.workspace = true
1111
[dependencies]
1212
anyhow.workspace = true
1313
forc-pkg.workspace = true
14+
forc-util.workspace = true
1415
fuel-abi-types.workspace = true
1516
fuel-tx = { workspace = true, features = ["test-helpers"] }
1617
fuel-vm = { workspace = true, features = ["random", "test-helpers"] }

forc-test/src/ecal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ impl Syscall {
2525
let mut f = unsafe { std::fs::File::from_raw_fd(*fd as i32) };
2626
write!(&mut f, "{}", s).unwrap();
2727

28-
// Dont close the fd
28+
// Don't close the fd
2929
std::mem::forget(f);
3030
}
3131
Syscall::Fflush { fd } => {
3232
let mut f = unsafe { std::fs::File::from_raw_fd(*fd as i32) };
3333
let _ = f.flush();
3434

35-
// Dont close the fd
35+
// Don't close the fd
3636
std::mem::forget(f);
3737
}
3838
Syscall::Unknown { ra, rb, rc, rd } => {

forc-test/src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use crate::setup::{
88
};
99
use ecal::EcalSyscallHandler;
1010
use forc_pkg::{self as pkg, BuildOpts};
11-
use fuel_abi_types::error_codes::ErrorSignal;
11+
use forc_util::tx_utils::RevertInfo;
12+
use fuel_abi_types::abi::program::ProgramABI;
1213
use fuel_tx as tx;
1314
use fuel_vm::checked_transaction::builder::TransactionBuilderExt;
1415
use fuel_vm::{self as vm};
@@ -516,12 +517,13 @@ impl TestResult {
516517
}
517518
}
518519

519-
/// Return an [ErrorSignal] for this [TestResult] if the test is failed to pass.
520-
pub fn error_signal(&self) -> anyhow::Result<ErrorSignal> {
521-
let revert_code = self.revert_code().ok_or_else(|| {
522-
anyhow::anyhow!("there is no revert code to convert to `ErrorSignal`")
523-
})?;
524-
ErrorSignal::try_from_revert_code(revert_code).map_err(|e| anyhow::anyhow!(e))
520+
pub fn revert_info(
521+
&self,
522+
program_abi: Option<&ProgramABI>,
523+
logs: &[fuel_tx::Receipt],
524+
) -> Option<RevertInfo> {
525+
self.revert_code()
526+
.map(|revert_code| RevertInfo::new(revert_code, program_abi, logs))
525527
}
526528

527529
/// Return [TestDetails] from the span of the function declaring this test.

forc-util/src/lib.rs

Lines changed: 2 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use sway_utils::constants;
2626
pub mod bytecode;
2727
pub mod fs_locking;
2828
pub mod restricted;
29+
#[cfg(feature = "tx")]
30+
pub mod tx_utils;
2931

3032
#[macro_use]
3133
pub mod cli;
@@ -141,111 +143,6 @@ macro_rules! forc_result_bail {
141143
};
142144
}
143145

144-
#[cfg(feature = "tx")]
145-
pub mod tx_utils {
146-
147-
use anyhow::Result;
148-
use clap::Args;
149-
use fuels_core::{codec::ABIDecoder, types::param_types::ParamType};
150-
use serde::{Deserialize, Serialize};
151-
use std::collections::HashMap;
152-
use sway_core::{asm_generation::ProgramABI, fuel_prelude::fuel_tx};
153-
154-
/// Added salt used to derive the contract ID.
155-
#[derive(Debug, Args, Default, Deserialize, Serialize)]
156-
pub struct Salt {
157-
/// Added salt used to derive the contract ID.
158-
///
159-
/// By default, this is
160-
/// `0x0000000000000000000000000000000000000000000000000000000000000000`.
161-
#[clap(long = "salt")]
162-
pub salt: Option<fuel_tx::Salt>,
163-
}
164-
165-
/// Format `Log` and `LogData` receipts.
166-
pub fn format_log_receipts(
167-
receipts: &[fuel_tx::Receipt],
168-
pretty_print: bool,
169-
) -> Result<String> {
170-
let mut receipt_to_json_array = serde_json::to_value(receipts)?;
171-
for (rec_index, receipt) in receipts.iter().enumerate() {
172-
let rec_value = receipt_to_json_array.get_mut(rec_index).ok_or_else(|| {
173-
anyhow::anyhow!(
174-
"Serialized receipts does not contain {} th index",
175-
rec_index
176-
)
177-
})?;
178-
match receipt {
179-
fuel_tx::Receipt::LogData {
180-
data: Some(data), ..
181-
} => {
182-
if let Some(v) = rec_value.pointer_mut("/LogData/data") {
183-
*v = hex::encode(data).into();
184-
}
185-
}
186-
fuel_tx::Receipt::ReturnData {
187-
data: Some(data), ..
188-
} => {
189-
if let Some(v) = rec_value.pointer_mut("/ReturnData/data") {
190-
*v = hex::encode(data).into();
191-
}
192-
}
193-
_ => {}
194-
}
195-
}
196-
if pretty_print {
197-
Ok(serde_json::to_string_pretty(&receipt_to_json_array)?)
198-
} else {
199-
Ok(serde_json::to_string(&receipt_to_json_array)?)
200-
}
201-
}
202-
203-
/// A `LogData` decoded into a human readable format with its type information.
204-
pub struct DecodedLog {
205-
pub value: String,
206-
}
207-
208-
pub fn decode_log_data(
209-
log_id: &str,
210-
log_data: &[u8],
211-
program_abi: &ProgramABI,
212-
) -> anyhow::Result<DecodedLog> {
213-
let program_abi = match program_abi {
214-
ProgramABI::Fuel(fuel_abi) => Some(
215-
fuel_abi_types::abi::unified_program::UnifiedProgramABI::from_counterpart(
216-
fuel_abi,
217-
)?,
218-
),
219-
_ => None,
220-
}
221-
.ok_or_else(|| anyhow::anyhow!("only fuelvm is supported for log decoding"))?;
222-
// Create type lookup (id, TypeDeclaration)
223-
let type_lookup = program_abi
224-
.types
225-
.iter()
226-
.map(|decl| (decl.type_id, decl.clone()))
227-
.collect::<HashMap<_, _>>();
228-
229-
let logged_type_lookup: HashMap<_, _> = program_abi
230-
.logged_types
231-
.iter()
232-
.flatten()
233-
.map(|logged_type| (logged_type.log_id.as_str(), logged_type.application.clone()))
234-
.collect();
235-
236-
let type_application = logged_type_lookup
237-
.get(&log_id)
238-
.ok_or_else(|| anyhow::anyhow!("log id is missing"))?;
239-
240-
let abi_decoder = ABIDecoder::default();
241-
let param_type = ParamType::try_from_type_application(type_application, &type_lookup)?;
242-
let decoded_str = abi_decoder.decode_as_debug_str(&param_type, log_data)?;
243-
let decoded_log = DecodedLog { value: decoded_str };
244-
245-
Ok(decoded_log)
246-
}
247-
}
248-
249146
pub fn find_file_name<'sc>(manifest_dir: &Path, entry_path: &'sc Path) -> Result<&'sc Path> {
250147
let mut file_path = manifest_dir.to_path_buf();
251148
file_path.pop();

0 commit comments

Comments
 (0)