Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions forc-plugins/forc-client/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ async fn test_simple_deploy() {
node.kill().unwrap();
let expected = vec![DeployedPackage::Contract(DeployedContract {
id: ContractId::from_str(
"b9443b8e389d42e551b80bb7e94adb4dd37c6985088401940035e36489c90af8",
"d54d140236c92deb6b10fb5926d0362f86654111cd8e24bb9b416a84c5eba9a5",
)
.unwrap(),
proxy: None,
Expand Down Expand Up @@ -421,7 +421,7 @@ async fn test_deploy_submit_only() {
node.kill().unwrap();
let expected = vec![DeployedPackage::Contract(DeployedContract {
id: ContractId::from_str(
"b9443b8e389d42e551b80bb7e94adb4dd37c6985088401940035e36489c90af8",
"d54d140236c92deb6b10fb5926d0362f86654111cd8e24bb9b416a84c5eba9a5",
)
.unwrap(),
proxy: None,
Expand Down Expand Up @@ -468,12 +468,12 @@ async fn test_deploy_fresh_proxy() {
node.kill().unwrap();
let impl_contract = DeployedPackage::Contract(DeployedContract {
id: ContractId::from_str(
"b9443b8e389d42e551b80bb7e94adb4dd37c6985088401940035e36489c90af8",
"d54d140236c92deb6b10fb5926d0362f86654111cd8e24bb9b416a84c5eba9a5",
)
.unwrap(),
proxy: Some(
ContractId::from_str(
"e597d0ef3dc3375402f32bcaa7fc66940f92c31a916e87e7eebb32fcd147d752",
"3806de177541f8e9e970640c1455bc9740a2b0248ee959a634ffe4ab6df558e2",
)
.unwrap(),
),
Expand Down
8 changes: 4 additions & 4 deletions forc/tests/cli_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ fn test_forc_test_raw_logs() -> Result<(), rexpect::error::Error> {
// Assert that the output is correct
process.exp_string(" test test_log_4")?;
process.exp_string("raw logs:")?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12408,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12044,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(" test test_log_2")?;
process.exp_string("raw logs:")?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12408,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12044,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;

process.process.exit()?;
Ok(())
Expand All @@ -77,12 +77,12 @@ fn test_forc_test_both_logs() -> Result<(), rexpect::error::Error> {
process.exp_string("decoded log values:")?;
process.exp_string("4, log rb: 1515152261580153489")?;
process.exp_string("raw logs:")?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12408,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12044,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(" test test_log_2")?;
process.exp_string("decoded log values:")?;
process.exp_string("2, log rb: 1515152261580153489")?;
process.exp_string("raw logs:")?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12408,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12044,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?;
process.process.exit()?;
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
},
Engines, TypeInfo, TypeParameter,
};
use itertools::Itertools;
use std::collections::BTreeMap;
use sway_error::{
error::CompileError,
Expand Down Expand Up @@ -312,15 +313,16 @@ where
fallback_fn: Option<DeclId<TyFunctionDecl>>,
handler: &Handler,
) -> Result<TyAstNode, ErrorEmitted> {
let mut code = String::new();

let mut reads = false;
let mut writes = false;

// used to check for name collisions
let mut contract_methods: BTreeMap<String, Vec<Span>> = <_>::default();

let mut arm_by_size = BTreeMap::<usize, String>::default();

// generate code
let mut method_names = String::new();
for r in contract_fns {
let decl = engines.de().get(r);

Expand Down Expand Up @@ -382,8 +384,20 @@ where
};

let method_name = decl.name.as_str();
let offset = if let Some(offset) = method_names.find(method_name) {
offset
} else {
let offset = method_names.len();
method_names.push_str(method_name);
offset
};

let method_name_len = method_name.len();
let code = arm_by_size.entry(method_name.len()).or_default();

code.push_str(&format!("if _method_name == \"{method_name}\" {{\n"));
code.push_str(&format!("
let is_this_method = asm(r, ptr: _method_name_ptr, name: _method_names_ptr, len: {method_name_len}) {{ addi r name i{offset}; meq r ptr r len; r: bool }};
if is_this_method {{\n"));

if args_types == "()" {
code.push_str(&format!(
Expand Down Expand Up @@ -454,10 +468,19 @@ where
(false, false) => "",
};

let code = arm_by_size
.iter()
.map(|(len, code)| format!("if _method_len == {len} {{ {code} }}"))
.join("");
let code = format!(
"{att} pub fn __entry() {{
let _method_names = \"{method_names}\";
let mut _buffer = BufferReader::from_second_parameter();
let _method_name = decode_first_param::<str>();

let mut _first_param_buffer = BufferReader::from_first_parameter();
let _method_len = _first_param_buffer.read::<u64>();
let _method_name_ptr = _first_param_buffer.ptr();
let _method_names_ptr = _method_names.as_ptr();
{code}
{fallback}
}}"
Expand Down
Loading
Loading