From 9791b81e59941322a27d7632be16959cb38e7402 Mon Sep 17 00:00:00 2001 From: Alfie John Date: Thu, 12 Sep 2024 06:22:00 +0000 Subject: [PATCH] Fixes for all the version bumps (#6179) --- forc-plugins/forc-client/src/util/pkg.rs | 2 +- forc-plugins/forc-client/tests/deploy.rs | 6 +-- forc/src/ops/forc_template.rs | 4 +- sway-ir/sway-ir-macros/src/lib.rs | 30 ++++++------- sway-lsp/src/core/sync.rs | 20 ++++----- sway-lsp/src/utils/keyword_docs.rs | 2 +- sway-utils/src/performance.rs | 4 +- test/src/e2e_vm_tests/harness.rs | 54 ++++++++++++++---------- test/src/e2e_vm_tests/mod.rs | 18 ++++---- 9 files changed, 73 insertions(+), 67 deletions(-) diff --git a/forc-plugins/forc-client/src/util/pkg.rs b/forc-plugins/forc-client/src/util/pkg.rs index 3aa8f6b2236..c93df24bacc 100644 --- a/forc-plugins/forc-client/src/util/pkg.rs +++ b/forc-plugins/forc-client/src/util/pkg.rs @@ -26,7 +26,7 @@ pub(crate) fn update_proxy_address_in_manifest( let mut toml = String::new(); let mut file = File::open(manifest.path())?; file.read_to_string(&mut toml)?; - let mut manifest_toml = toml.parse::()?; + let mut manifest_toml = toml.parse::()?; if manifest.proxy().is_some() { manifest_toml["proxy"]["address"] = toml_edit::value(address); let mut file = std::fs::OpenOptions::new() diff --git a/forc-plugins/forc-client/tests/deploy.rs b/forc-plugins/forc-client/tests/deploy.rs index fa2941325b5..a86d8eef75f 100644 --- a/forc-plugins/forc-client/tests/deploy.rs +++ b/forc-plugins/forc-client/tests/deploy.rs @@ -23,7 +23,7 @@ use std::{ str::FromStr, }; use tempfile::tempdir; -use toml_edit::{value, Document, InlineTable, Item, Table, Value}; +use toml_edit::{value, DocumentMut, InlineTable, Item, Table, Value}; fn get_workspace_root() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")) @@ -75,7 +75,7 @@ fn patch_manifest_file_with_path_std(manifest_dir: &Path) -> anyhow::Result<()> let toml_path = manifest_dir.join(sway_utils::constants::MANIFEST_FILE_NAME); let toml_content = fs::read_to_string(&toml_path).unwrap(); - let mut doc = toml_content.parse::().unwrap(); + let mut doc = toml_content.parse::().unwrap(); let new_std_path = get_workspace_root().join("sway-lib-std"); let mut std_dependency = InlineTable::new(); @@ -89,7 +89,7 @@ fn patch_manifest_file_with_path_std(manifest_dir: &Path) -> anyhow::Result<()> fn patch_manifest_file_with_proxy_table(manifest_dir: &Path, proxy: Proxy) -> anyhow::Result<()> { let toml_path = manifest_dir.join(sway_utils::constants::MANIFEST_FILE_NAME); let toml_content = fs::read_to_string(&toml_path)?; - let mut doc = toml_content.parse::()?; + let mut doc = toml_content.parse::()?; let proxy_table = doc.entry("proxy").or_insert(Item::Table(Table::new())); let proxy_table = proxy_table.as_table_mut().unwrap(); diff --git a/forc/src/ops/forc_template.rs b/forc/src/ops/forc_template.rs index 23703ea575e..0304a9d298a 100644 --- a/forc/src/ops/forc_template.rs +++ b/forc/src/ops/forc_template.rs @@ -84,7 +84,7 @@ fn edit_forc_toml(out_dir: &Path, project_name: &str, real_name: &str) -> Result let mut file = File::open(out_dir.join(constants::MANIFEST_FILE_NAME))?; let mut toml = String::new(); file.read_to_string(&mut toml)?; - let mut manifest_toml = toml.parse::()?; + let mut manifest_toml = toml.parse::()?; let mut authors = Vec::new(); let forc_toml: toml::Value = toml::de::from_str(&toml)?; @@ -144,7 +144,7 @@ fn edit_cargo_toml(out_dir: &Path, project_name: &str, real_name: &str) -> Resul } updated_authors.push(real_name); - let mut manifest_toml = toml.parse::()?; + let mut manifest_toml = toml.parse::()?; manifest_toml["package"]["authors"] = toml_edit::value(updated_authors); manifest_toml["package"]["name"] = toml_edit::value(project_name); diff --git a/sway-ir/sway-ir-macros/src/lib.rs b/sway-ir/sway-ir-macros/src/lib.rs index d6bcd7a7fc5..514a3986a75 100644 --- a/sway-ir/sway-ir-macros/src/lib.rs +++ b/sway-ir/sway-ir-macros/src/lib.rs @@ -4,7 +4,7 @@ use { quote::{format_ident, quote}, syn::{ parse_macro_input, Attribute, Data, DeriveInput, Fields, FieldsNamed, FieldsUnnamed, Ident, - Meta, NestedMeta, Variant, + Variant, }, }; @@ -170,7 +170,7 @@ fn pass_through_context(field_name: &Ident, attrs: &[Attribute]) -> proc_macro2: attrs .iter() .filter_map(|attr| { - let attr_name = attr.path.get_ident()?; + let attr_name = attr.path().get_ident()?; if attr_name != "in_context" { return None; } @@ -199,20 +199,16 @@ fn pass_through_context(field_name: &Ident, attrs: &[Attribute]) -> proc_macro2: } fn try_parse_context_field_from_attr(attr: &Attribute) -> Option { - let meta = attr.parse_meta().ok()?; - let Meta::List(meta_list) = meta else { - return None; - }; - if meta_list.nested.len() != 1 { - return None; + let mut context_fields = Vec::new(); + + let _ = attr.parse_nested_meta(|nested_meta| { + context_fields.push(nested_meta.path.get_ident().unwrap().clone()); + Ok(()) + }); + + if context_fields.len() != 1 { + None + } else { + context_fields.pop() } - let nested_meta = meta_list.nested.first()?; - let NestedMeta::Meta(inner_meta) = nested_meta else { - return None; - }; - let Meta::Path(path) = inner_meta else { - return None; - }; - let context_field_name = path.get_ident()?.clone(); - Some(context_field_name) } diff --git a/sway-lsp/src/core/sync.rs b/sway-lsp/src/core/sync.rs index f00189880fe..6fec9f0dec0 100644 --- a/sway-lsp/src/core/sync.rs +++ b/sway-lsp/src/core/sync.rs @@ -7,8 +7,7 @@ use forc_pkg::manifest::GenericManifestFile; use forc_pkg::{manifest::Dependency, PackageManifestFile}; use indexmap::IndexMap; use lsp_types::Url; -use notify::RecursiveMode; -use notify_debouncer_mini::new_debouncer; +use notify_debouncer_mini::{new_debouncer, notify::RecursiveMode}; use parking_lot::RwLock; use std::{ fs::{self, File}, @@ -193,14 +192,13 @@ impl SyncWorkspace { let handle = tokio::spawn(async move { let (tx, mut rx) = tokio::sync::mpsc::channel(10); - // Setup debouncer. No specific tickrate, max debounce time 2 seconds - let mut debouncer = - new_debouncer(Duration::from_secs(1), None, move |event| { - if let Ok(e) = event { - let _ = tx.blocking_send(e); - } - }) - .unwrap(); + // Setup debouncer, max debounce time 2 seconds + let mut debouncer = new_debouncer(Duration::from_secs(1), move |event| { + if let Ok(e) = event { + let _ = tx.blocking_send(e); + } + }) + .unwrap(); debouncer .watcher() @@ -286,7 +284,7 @@ pub(crate) fn edit_manifest_dependency_paths( if let Ok(mut file) = File::open(manifest.path()) { let mut toml = String::new(); let _ = file.read_to_string(&mut toml); - if let Ok(mut manifest_toml) = toml.parse::() { + if let Ok(mut manifest_toml) = toml.parse::() { for (name, abs_path) in dependency_map { manifest_toml["dependencies"][&name]["path"] = toml_edit::value(abs_path.display().to_string()); diff --git a/sway-lsp/src/utils/keyword_docs.rs b/sway-lsp/src/utils/keyword_docs.rs index f26d48a3b37..9582f75b5f1 100644 --- a/sway-lsp/src/utils/keyword_docs.rs +++ b/sway-lsp/src/utils/keyword_docs.rs @@ -802,7 +802,7 @@ impl KeywordDocs { let name = ident.trim_end_matches("_keyword").to_owned(); let mut documentation = String::new(); keyword.attrs.iter().for_each(|attr| { - let tokens = attr.tokens.to_token_stream(); + let tokens = attr.to_token_stream(); let lit = extract_lit(tokens); writeln!(documentation, "{lit}").unwrap(); }); diff --git a/sway-utils/src/performance.rs b/sway-utils/src/performance.rs index cbf53cc5510..b8a31f60cce 100644 --- a/sway-utils/src/performance.rs +++ b/sway-utils/src/performance.rs @@ -29,9 +29,9 @@ macro_rules! time_expr { if cfg.metrics_outfile.is_some() { #[cfg(not(target_os = "macos"))] let memory_usage = { - use sysinfo::{System, SystemExt}; + use sysinfo::{MemoryRefreshKind, System}; let mut sys = System::new(); - sys.refresh_system(); + sys.refresh_memory_specifics(MemoryRefreshKind::new().with_ram()); Some(sys.used_memory()) }; #[cfg(target_os = "macos")] diff --git a/test/src/e2e_vm_tests/harness.rs b/test/src/e2e_vm_tests/harness.rs index a77a01acd84..de822e38a7d 100644 --- a/test/src/e2e_vm_tests/harness.rs +++ b/test/src/e2e_vm_tests/harness.rs @@ -140,7 +140,7 @@ pub(crate) async fn runs_on_node( pub(crate) enum VMExecutionResult { Fuel(ProgramState, Vec), - Evm(revm::ExecutionResult), + Evm(revm::primitives::result::ExecutionResult), MidenVM(miden::ExecutionTrace), } @@ -214,31 +214,41 @@ pub(crate) fn runs_in_vm( )) } BuildTarget::EVM => { - let mut evm = revm::new(); - evm.database(revm::InMemoryDB::default()); - evm.env = revm::Env::default(); + let mut evm = revm::EvmBuilder::default() + .with_db(revm::InMemoryDB::default()) + .with_clear_env() + .build(); // Transaction to create the smart contract - evm.env.tx.transact_to = revm::TransactTo::create(); - evm.env.tx.data = bytes::Bytes::from(script.bytecode.bytes.into_boxed_slice()); - let result = evm.transact_commit(); - - match result.out { - revm::TransactOut::None => Err(anyhow!("Could not create smart contract")), - revm::TransactOut::Call(_) => todo!(), - revm::TransactOut::Create(ref _bytes, account_opt) => { - match account_opt { - Some(account) => { - evm.env.tx.transact_to = revm::TransactTo::Call(account); - - // Now issue a call. - //evm.env.tx. = bytes::Bytes::from(script.bytecode.into_boxed_slice()); - let result = evm.transact_commit(); - Ok(VMExecutionResult::Evm(result)) + evm.tx_mut().transact_to = revm::interpreter::primitives::TransactTo::Create; + evm.tx_mut().data = script.clone().bytecode.bytes.into(); + + let result = evm + .transact_commit() + .map_err(|e| anyhow::anyhow!("Could not create smart contract on EVM: {e:?}"))?; + + match result { + revm::primitives::ExecutionResult::Revert { .. } + | revm::primitives::ExecutionResult::Halt { .. } => todo!(), + revm::primitives::ExecutionResult::Success { ref output, .. } => match output { + revm::primitives::result::Output::Call(_) => todo!(), + revm::primitives::result::Output::Create(_bytes, address_opt) => { + match address_opt { + None => todo!(), + Some(address) => { + evm.tx_mut().data = script.bytecode.bytes.into(); + evm.tx_mut().transact_to = + revm::interpreter::primitives::TransactTo::Call(*address); + + let result = evm + .transact_commit() + .map_err(|e| anyhow::anyhow!("Failed call on EVM: {e:?}"))?; + + Ok(VMExecutionResult::Evm(result)) + } } - None => todo!(), } - } + }, } } BuildTarget::MidenVM => { diff --git a/test/src/e2e_vm_tests/mod.rs b/test/src/e2e_vm_tests/mod.rs index 947ad9b20cc..ca7550d3940 100644 --- a/test/src/e2e_vm_tests/mod.rs +++ b/test/src/e2e_vm_tests/mod.rs @@ -414,14 +414,16 @@ impl TestContext { } } } - harness::VMExecutionResult::Evm(state) => match state.exit_reason { - revm::Return::Continue => todo!(), - revm::Return::Stop => TestResult::Result(0), - revm::Return::Return => todo!(), - revm::Return::SelfDestruct => todo!(), - revm::Return::Revert => TestResult::Revert(0), - _ => { - panic!("EVM exited with unhandled reason: {:?}", state.exit_reason); + harness::VMExecutionResult::Evm(state) => match state { + revm::primitives::ExecutionResult::Success { reason, .. } => match reason { + revm::primitives::SuccessReason::Stop => TestResult::Result(0), + revm::primitives::SuccessReason::Return => todo!(), + revm::primitives::SuccessReason::SelfDestruct => todo!(), + revm::primitives::SuccessReason::EofReturnContract => todo!(), + }, + revm::primitives::ExecutionResult::Revert { .. } => TestResult::Result(0), + revm::primitives::ExecutionResult::Halt { reason, .. } => { + panic!("EVM exited with unhandled reason: {:?}", reason); } }, harness::VMExecutionResult::MidenVM(trace) => {