Skip to content

Commit

Permalink
Fixes for all the version bumps (#6179)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfiedotwtf committed Sep 12, 2024
1 parent b3e22f5 commit 9791b81
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 67 deletions.
2 changes: 1 addition & 1 deletion forc-plugins/forc-client/src/util/pkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<toml_edit::Document>()?;
let mut manifest_toml = toml.parse::<toml_edit::DocumentMut>()?;
if manifest.proxy().is_some() {
manifest_toml["proxy"]["address"] = toml_edit::value(address);
let mut file = std::fs::OpenOptions::new()
Expand Down
6 changes: 3 additions & 3 deletions forc-plugins/forc-client/tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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::<Document>().unwrap();
let mut doc = toml_content.parse::<DocumentMut>().unwrap();
let new_std_path = get_workspace_root().join("sway-lib-std");

let mut std_dependency = InlineTable::new();
Expand All @@ -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::<Document>()?;
let mut doc = toml_content.parse::<DocumentMut>()?;

let proxy_table = doc.entry("proxy").or_insert(Item::Table(Table::new()));
let proxy_table = proxy_table.as_table_mut().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions forc/src/ops/forc_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<toml_edit::Document>()?;
let mut manifest_toml = toml.parse::<toml_edit::DocumentMut>()?;

let mut authors = Vec::new();
let forc_toml: toml::Value = toml::de::from_str(&toml)?;
Expand Down Expand Up @@ -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::<toml_edit::Document>()?;
let mut manifest_toml = toml.parse::<toml_edit::DocumentMut>()?;
manifest_toml["package"]["authors"] = toml_edit::value(updated_authors);
manifest_toml["package"]["name"] = toml_edit::value(project_name);

Expand Down
30 changes: 13 additions & 17 deletions sway-ir/sway-ir-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use {
quote::{format_ident, quote},
syn::{
parse_macro_input, Attribute, Data, DeriveInput, Fields, FieldsNamed, FieldsUnnamed, Ident,
Meta, NestedMeta, Variant,
Variant,
},
};

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<Ident> {
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)
}
20 changes: 9 additions & 11 deletions sway-lsp/src/core/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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::<toml_edit::Document>() {
if let Ok(mut manifest_toml) = toml.parse::<toml_edit::DocumentMut>() {
for (name, abs_path) in dependency_map {
manifest_toml["dependencies"][&name]["path"] =
toml_edit::value(abs_path.display().to_string());
Expand Down
2 changes: 1 addition & 1 deletion sway-lsp/src/utils/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions sway-utils/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
54 changes: 32 additions & 22 deletions test/src/e2e_vm_tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub(crate) async fn runs_on_node(

pub(crate) enum VMExecutionResult {
Fuel(ProgramState, Vec<Receipt>),
Evm(revm::ExecutionResult),
Evm(revm::primitives::result::ExecutionResult),
MidenVM(miden::ExecutionTrace),
}

Expand Down Expand Up @@ -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 => {
Expand Down
18 changes: 10 additions & 8 deletions test/src/e2e_vm_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 9791b81

Please sign in to comment.