Skip to content

Commit

Permalink
Merge branch 'master' into chore/use-fuel-asm-instead-vm
Browse files Browse the repository at this point in the history
  • Loading branch information
hal3e authored Jul 12, 2023
2 parents 0711159 + ea4687d commit 2a3cf49
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub(crate) fn contract_bindings(
fn id(&self) -> ::fuels::types::bech32::Bech32ContractId {
self.contract_id.clone()
}

fn log_decoder(&self) -> ::fuels::programs::logs::LogDecoder {
self.log_decoder.clone()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub(crate) fn script_bindings(
self
}

pub fn log_decoder(&self) -> ::fuels::programs::logs::LogDecoder {
self.log_decoder.clone()
}

#main_function
}

Expand Down
63 changes: 63 additions & 0 deletions packages/fuels-code-gen/src/program_bindings/resolved_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,69 @@ mod tests {
)
}

#[test]
fn test_resolve_bytes() -> Result<()> {
test_resolve_first_type(
":: fuels :: types :: Bytes",
&[
TypeDeclaration {
type_id: 0,
type_field: "struct String".to_string(),
components: Some(vec![TypeApplication {
name: "bytes".to_string(),
type_id: 1,
..Default::default()
}]),
..Default::default()
},
TypeDeclaration {
type_id: 0,
type_field: "struct std::bytes::Bytes".to_string(),
components: Some(vec![
TypeApplication {
name: "buf".to_string(),
type_id: 1,
..Default::default()
},
TypeApplication {
name: "len".to_string(),
type_id: 3,
..Default::default()
},
]),
..Default::default()
},
TypeDeclaration {
type_id: 1,
type_field: "struct std::bytes::RawBytes".to_string(),
components: Some(vec![
TypeApplication {
name: "ptr".to_string(),
type_id: 2,
..Default::default()
},
TypeApplication {
name: "cap".to_string(),
type_id: 3,
..Default::default()
},
]),
..Default::default()
},
TypeDeclaration {
type_id: 2,
type_field: "raw untyped ptr".to_string(),
..Default::default()
},
TypeDeclaration {
type_id: 3,
type_field: "u64".to_string(),
..Default::default()
},
],
)
}

#[test]
fn test_resolve_string() -> Result<()> {
test_resolve_primitive_type("str[3]", ":: fuels :: types :: SizedAsciiString < 3usize >")
Expand Down
11 changes: 11 additions & 0 deletions packages/fuels-core/src/codec/abi_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,17 @@ mod tests {
Ok(())
}

#[test]
fn decode_bytes() -> Result<()> {
let data = [0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05];
let decoded = ABIDecoder::decode_single(&ParamType::Bytes, &data)?;

let expected = Token::Bytes(data.to_vec());

assert_eq!(decoded, expected);
Ok(())
}

#[test]
fn decode_enum() -> Result<()> {
// enum MyEnum {
Expand Down
9 changes: 9 additions & 0 deletions packages/fuels-core/src/codec/function_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ mod tests {
assert_eq!(selector, "some_fun(s<u32>(s<u32>(rawptr,u64),u64))")
}

#[test]
fn handles_bytes() {
let inputs = [ParamType::Bytes];

let selector = resolve_fn_signature("some_fun", &inputs);

assert_eq!(selector, "some_fun(s(s(rawptr,u64),u64))")
}

#[test]
fn handles_enums() {
let types = vec![ParamType::U64, ParamType::U32];
Expand Down
6 changes: 3 additions & 3 deletions packages/fuels-core/src/types/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ pub enum Error {
revert_id: u64,
receipts: Vec<Receipt>,
},
#[error("Transaction is using predicates. Provide consensus parameters by using .set_consensus_parameters().")]
TransactionBuildError,
#[error("Transaction build error: {0}")]
TransactionBuildError(String),
}

pub type Result<T> = std::result::Result<T, Error>;

/// This macro can only be used for `Error` variants that have a `String` field.
/// Those are: `InvalidData`, `InvalidType`, `InfrastructureError`,
/// `InstantiationError`, `WalletError`, `ProviderError`
/// `InstantiationError`, `WalletError`, `ProviderError`, `TransactionBuildError`
#[macro_export]
macro_rules! error {
($err_variant:ident, $fmt_str: literal $(,$arg: expr)*) => {
Expand Down
10 changes: 6 additions & 4 deletions packages/fuels-core/src/types/transaction_builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
types::{
coin::Coin,
coin_type::CoinType,
errors::{Error, Result},
errors::{error, Error, Result},
input::Input,
message::Message,
transaction::{CreateTransaction, ScriptTransaction, Transaction, TxParameters},
Expand Down Expand Up @@ -57,7 +57,9 @@ macro_rules! impl_tx_trait {
let base_offset = if self.is_using_predicates() {
let params = self
.consensus_parameters
.ok_or(Error::TransactionBuildError)?;
.ok_or(error!(
TransactionBuildError,
"predicate inputs require consensus parameters. Use `.set_consensus_parameters()`."))?;
self.base_offset(&params)
} else {
0
Expand All @@ -67,7 +69,7 @@ macro_rules! impl_tx_trait {
}

fn fee_checked_from_tx(&self, params: &ConsensusParameters) -> Option<TransactionFee> {
let tx = &self.clone().build().expect("Error in build").tx;
let tx = &self.clone().build().expect("error in build").tx;
TransactionFee::checked_from_tx(params, tx)
}

Expand All @@ -79,7 +81,7 @@ macro_rules! impl_tx_trait {
Ok(self
.clone()
.build()
.expect("Error in build")
.expect("error in build")
.tx
.check_without_signatures(block_height.into(), parameters)?)
}
Expand Down

0 comments on commit 2a3cf49

Please sign in to comment.