Skip to content

Commit

Permalink
Remove huff-examples submodule (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
cakevm authored Jan 12, 2025
1 parent 6efddf9 commit 6cced17
Show file tree
Hide file tree
Showing 23 changed files with 643 additions and 81 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
ref: ${{ github.event.pull_request.head.sha || github.ref }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
default-members = ["bin/hnc"]
exclude = ["assets", "hnc-up", "huff-examples"]
exclude = [".github", "assets", "hnc-up"]
members = ["bin/hnc", "crates/codegen", "crates/core", "crates/js", "crates/lexer", "crates/parser", "crates/test-runner", "crates/utils"]
resolver = "2"

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ These are the projects that are maintained for Huff Neo:
| [huff-neo-tests-action](https://github.com/cakevm/huff-neo-tests-action) | GitHub Action (Tests) ||
| [huff-neo-project-template](https://github.com/cakevm/huff-neo-project-template) | Project Template ||
| [huffmate-neo](https://github.com/cakevm/huffmate-neo) | Example Contracts ||
| [huff-examples](https://github.com/cakevm/huff-examples) | Example Contracts ||

Supported IDEs:

Expand Down
18 changes: 8 additions & 10 deletions bin/hnc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,42 @@ Error: Invalid File Directory ./contracts
```

#### Examples using [`huff-examples`](https://github.com/huff-language/huff-examples)
#### Usage

The [huff-examples](https://github.com/huff-language/huff-examples) github repository is added as a submodule to this repo for testing.
To run `hnc` against one of the resource test files, the path may simply be passed to `hnc`.

To run `hnc` against one of the examples, the path may simply be passed to `hnc`.

For example, to compile huff-example's [ERC20.huff](../../huff-examples/erc20/contracts/ERC20.huff) contract, run:
For example, to compile huff-example's [ERC20.huff](../../resources/erc20/ERC20.huff) contract, run:

```bash
hnc --bytecode ./huff-examples/erc20/contracts/ERC20.huff
hnc --bytecode ./resources/erc20/ERC20.huff
```

_NOTE: The `--bytecode` flag will output the full deploy bytecode._

`hnc` also supports tracing using the [`tracing`](https://docs.rs/tracing/0.1.29/tracing/) crate. To produce a verbose output using tracing, append the `--verbose` or `-v` flag like so:

```bash
hnc --verbose --bytecode ./huff-examples/erc20/contracts/ERC20.huff
hnc --verbose --bytecode ./resources/erc20/ERC20.huff
```

#### Specifying Artifact Outputs

**By default**, `hnc` will export json build artifacts to a `./artifacts` directory. This can be overidden using the `--output-directory` flag or shorthand `-d` flag and specifying a string following. For example:

```bash
hnc -d ./output ./huff-examples/erc20/contracts/ERC20.huff
hnc -d ./output ./resources/erc20/ERC20.huff
```

_NOTE: The huff cli will gracefully remove double and single quotes, so the following will also compile:_

```bash
hnc -d "./output" './huff-examples/erc20/contracts/ERC20.huff'
hnc -d "./output" './resources/erc20/ERC20.huff'
```

If a specific contract is specified for compiling (ie not a directory), a single `json` file may be specified as an output location for the contract artifact like so:

```bash
hnc -o ./artifact.json ./huff-examples/erc20/contracts/ERC20.huff
hnc -o ./artifact.json ./resources/erc20/ERC20.huff
```

**NOTE**: The following will _not_ compile since multiple artifacts cannot be output to the same artifact json file.
Expand Down
4 changes: 2 additions & 2 deletions crates/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Once you instantiate a [Compiler](struct.Compiler.html) (WLOG, `compiler`) with
let artifacts: Result<Vec<Artifact>, CompilerError> = compiler.execute();
```

Below we demonstrate taking a source file `../../huff-examples/erc20/contracts/ERC20.huff`, and generating the copmiled artifacts.
Below we demonstrate taking a source file `../../resources/erc20/ERC20.huff`, and generating the compiled artifacts.

```rust
use huff_neo_core::Compiler;
Expand All @@ -25,7 +25,7 @@ use std::rc::Rc;

// Instantiate the Compiler Instance with a targeted evm version.
let evm_version = &EVMVersion::default();
let mut compiler = Compiler::new(evm_version, Arc::new(vec!["../../huff-examples/erc20/contracts/ERC20.huff".to_string()]), None, None, None, None, None, false, false);
let mut compiler = Compiler::new(evm_version, Arc::new(vec!["../../resources/erc20/ERC20.huff".to_string()]), None, None, None, None, None, false, false);

// Execute the compiler
let res: Result<Vec<Arc<Artifact>>, Arc<CompilerError>> = compiler.execute();
Expand Down
18 changes: 9 additions & 9 deletions crates/core/benches/huff_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{path::PathBuf, sync::Arc};
fn lex_erc20_from_source_benchmark(c: &mut Criterion) {
let file_provider = Arc::new(FileSystemFileProvider::new());
let file_sources: Vec<Arc<FileSource>> =
Compiler::fetch_sources(vec![PathBuf::from("../../huff-examples/erc20/contracts/ERC20.huff".to_string())], file_provider.clone())
Compiler::fetch_sources(vec![PathBuf::from("../../resources/erc20/ERC20.huff".to_string())], file_provider.clone())
.into_iter()
.map(|p| p.unwrap())
.collect();
Expand All @@ -38,7 +38,7 @@ fn lex_erc20_from_source_benchmark(c: &mut Criterion) {
fn parse_erc20_benchmark(c: &mut Criterion) {
let file_provider = Arc::new(FileSystemFileProvider::new());
let file_sources: Vec<Arc<FileSource>> =
Compiler::fetch_sources(vec![PathBuf::from("../../huff-examples/erc20/contracts/ERC20.huff".to_string())], file_provider.clone())
Compiler::fetch_sources(vec![PathBuf::from("../../resources/erc20/ERC20.huff".to_string())], file_provider.clone())
.into_iter()
.map(|p| p.unwrap())
.collect();
Expand All @@ -56,7 +56,7 @@ fn parse_erc20_benchmark(c: &mut Criterion) {
// Isolate parsing to benchmark
c.bench_function("Parser: ERC-20", |b| {
b.iter(|| {
let mut parser = Parser::new(*tokens.clone(), Some("../../huff-examples/erc20/contracts".to_string()));
let mut parser = Parser::new(*tokens.clone(), Some("../../resources/erc20".to_string()));
let mut contract = parser.parse().unwrap();
contract.derive_storage_pointers();
})
Expand All @@ -66,7 +66,7 @@ fn parse_erc20_benchmark(c: &mut Criterion) {
fn codegen_erc20_benchmark(c: &mut Criterion) {
let file_provider = Arc::new(FileSystemFileProvider::new());
let file_sources: Vec<Arc<FileSource>> =
Compiler::fetch_sources(vec![PathBuf::from("../../huff-examples/erc20/contracts/ERC20.huff".to_string())], file_provider.clone())
Compiler::fetch_sources(vec![PathBuf::from("../../resources/erc20/ERC20.huff".to_string())], file_provider.clone())
.into_iter()
.map(|p| p.unwrap())
.collect();
Expand All @@ -81,7 +81,7 @@ fn codegen_erc20_benchmark(c: &mut Criterion) {
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();

let mut parser = Parser::new(tokens, Some("../../huff-examples/erc20/contracts".to_string()));
let mut parser = Parser::new(tokens, Some("../../resources/erc20".to_string()));
let mut contract = parser.parse().unwrap();
contract.derive_storage_pointers();

Expand Down Expand Up @@ -109,7 +109,7 @@ fn erc20_compilation_benchmark(c: &mut Criterion) {
c.bench_function("Full ERC-20 compilation", |b| b.iter(|| {
let file_provider = Arc::new(FileSystemFileProvider::new());
let file_sources: Vec<Arc<FileSource>> = Compiler::fetch_sources(vec![PathBuf::from(
"../../huff-examples/erc20/contracts/ERC20.huff".to_string(),
"../../resources/erc20/ERC20.huff".to_string(),
)], file_provider.clone())
.into_iter()
.map(|p| p.unwrap())
Expand All @@ -131,7 +131,7 @@ fn erc20_compilation_benchmark(c: &mut Criterion) {
};
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("../../huff-examples/erc20/contracts".to_string()));
let mut parser = Parser::new(tokens, Some("../../resources/erc20".to_string()));
let mut contract = parser.parse().unwrap();
contract.derive_storage_pointers();

Expand All @@ -157,7 +157,7 @@ fn erc721_compilation_benchmark(c: &mut Criterion) {
c.bench_function("Full ERC-721 compilation", |b| b.iter(|| {
let file_provider = Arc::new(FileSystemFileProvider::new());
let file_sources: Vec<Arc<FileSource>> = Compiler::fetch_sources(vec![PathBuf::from(
"../../huff-examples/erc721/contracts/ERC721.huff".to_string(),
"../../resources/erc721/ERC721.huff".to_string(),
)], file_provider.clone())
.into_iter()
.map(|p| p.unwrap())
Expand All @@ -179,7 +179,7 @@ fn erc721_compilation_benchmark(c: &mut Criterion) {
};
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("../../huff-examples/erc20/contracts".to_string()));
let mut parser = Parser::new(tokens, Some("../../resources/erc20".to_string()));
let mut contract = parser.parse().unwrap();
contract.derive_storage_pointers();

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(crate) mod cache;
///
/// let compiler = Compiler::new(
/// &EVMVersion::default(),
/// Arc::new(vec!["../../huff-examples/erc20/contracts/ERC20.huff".to_string()]),
/// Arc::new(vec!["../../resources/erc20/ERC20.huff".to_string()]),
/// Some("./artifacts".to_string()),
/// None,
/// None,
Expand Down
6 changes: 3 additions & 3 deletions crates/core/tests/aliased_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ fn test_parses_foundry_aliased_imports() {
// Create a remapper at the root level
let remapper = Remapper::new("./");

// Use an aliased import defined in foundry.toml for "huff-examples" -> "examples"
let mut import_bufs = vec![std::path::PathBuf::from_str("examples/erc20/contracts/ERC20.huff").unwrap()];
// Use an aliased import defined in foundry.toml for "resources" -> "examples"
let mut import_bufs = vec![std::path::PathBuf::from_str("examples/erc20/ERC20.huff").unwrap()];

// Remap import bufs with `remapper`. Panic on failure.
import_bufs = import_bufs.into_iter().map(|p| std::path::PathBuf::from(remapper.remap(p.to_str().unwrap()).unwrap())).collect();
Expand All @@ -27,7 +27,7 @@ fn test_parses_foundry_aliased_imports() {
#[test]
#[should_panic]
fn test_invalid_imports_break() {
let import_bufs = vec![std::path::PathBuf::from_str("unaliased/erc20/contracts/ERC20.huff").unwrap()];
let import_bufs = vec![std::path::PathBuf::from_str("unaliased/erc20/ERC20.huff").unwrap()];
let file_provider = FileSystemFileProvider {};

// Try to fetch sources
Expand Down
4 changes: 2 additions & 2 deletions crates/core/tests/erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{path::PathBuf, sync::Arc};
fn test_erc20_compile() {
let file_provider = Arc::new(FileSystemFileProvider {});
let file_sources: Vec<Arc<FileSource>> =
Compiler::fetch_sources(vec![PathBuf::from("../../huff-examples/erc20/contracts/ERC20.huff".to_string())], file_provider.clone())
Compiler::fetch_sources(vec![PathBuf::from("../../resources/erc20/ERC20.huff".to_string())], file_provider.clone())
.iter()
.map(|p| p.clone().unwrap())
.collect();
Expand All @@ -27,7 +27,7 @@ fn test_erc20_compile() {
let full_source = FullFileSource { source: &flattened.0, file: Some(Arc::clone(file_source)), spans: flattened.1 };
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("../../huff-examples/erc20/contracts".to_string()));
let mut parser = Parser::new(tokens, Some("../../resources/erc20/contracts".to_string()));
let mut contract = parser.parse().unwrap();
contract.derive_storage_pointers();

Expand Down
4 changes: 2 additions & 2 deletions crates/core/tests/erc721.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{path::PathBuf, sync::Arc};
fn test_erc721_compile() {
let file_provider = Arc::new(FileSystemFileProvider {});
let file_sources: Vec<Arc<FileSource>> =
Compiler::fetch_sources(vec![PathBuf::from("../../huff-examples/erc721/contracts/ERC721.huff".to_string())], file_provider.clone())
Compiler::fetch_sources(vec![PathBuf::from("../../resources/erc721/ERC721.huff".to_string())], file_provider.clone())
.iter()
.map(|p| p.clone().unwrap())
.collect();
Expand All @@ -27,7 +27,7 @@ fn test_erc721_compile() {
let full_source = FullFileSource { source: &flattened.0, file: Some(Arc::clone(file_source)), spans: flattened.1 };
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("../../huff-examples/erc20/contracts".to_string()));
let mut parser = Parser::new(tokens, Some("../../resources/erc20".to_string()));
let mut contract = parser.parse().unwrap();
contract.derive_storage_pointers();

Expand Down
16 changes: 6 additions & 10 deletions crates/core/tests/file_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@ fn test_get_outputs_with_output() {
#[test]
fn test_transform_paths() {
let file_provider = FileSystemFileProvider {};
let path_bufs: Result<Vec<PathBuf>, CompilerError> = file_provider.transform_paths(&[
"../../huff-examples/erc20/contracts/ERC20.huff".to_string(),
"../../huff-examples/erc20/contracts/utils/".to_string(),
]);
let path_bufs: Result<Vec<PathBuf>, CompilerError> =
file_provider.transform_paths(&["../../resources/erc20/ERC20.huff".to_string(), "../../resources/utils/".to_string()]);
assert!(path_bufs.is_ok());
match path_bufs {
Ok(bufs) => {
assert_eq!(bufs.len(), 5);
assert!(bufs.contains(&PathBuf::from("../../huff-examples/erc20/contracts/ERC20.huff".to_string())));
assert!(bufs.contains(&PathBuf::from("../../huff-examples/erc20/contracts/utils/Address.huff".to_string())));
assert!(bufs.contains(&PathBuf::from("../../huff-examples/erc20/contracts/utils/HashMap.huff".to_string())));
assert!(bufs.contains(&PathBuf::from("../../huff-examples/erc20/contracts/utils/Ownable.huff".to_string())));
assert!(bufs.contains(&PathBuf::from("../../huff-examples/erc20/contracts/utils/Utils.huff".to_string())));
assert_eq!(bufs.len(), 3);
assert!(bufs.contains(&PathBuf::from("../../resources/erc20/ERC20.huff".to_string())));
assert!(bufs.contains(&PathBuf::from("../../resources/utils/HashMap.huff".to_string())));
assert!(bufs.contains(&PathBuf::from("../../resources/utils/Ownable.huff".to_string())));
}
Err(_) => {
panic!("moose")
Expand Down
8 changes: 4 additions & 4 deletions crates/core/tests/recurse_deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use std::{path::PathBuf, sync::Arc};
fn test_recursing_fs_dependencies() {
let file_provider = Arc::new(FileSystemFileProvider {});
let file_sources: Vec<Arc<file_source::FileSource>> =
Compiler::fetch_sources(vec![PathBuf::from("../../huff-examples/erc20/contracts/ERC20.huff".to_string())], file_provider.clone())
Compiler::fetch_sources(vec![PathBuf::from("../../resources/erc20/ERC20.huff".to_string())], file_provider.clone())
.iter()
.map(|p| p.clone().unwrap())
.collect();
assert_eq!(file_sources.len(), 1);
let erc20_file_source = file_sources[0].clone();
let res = Compiler::recurse_deps(Arc::clone(&erc20_file_source), &remapper::Remapper::new("./"), file_provider, HashSet::new());
let full_erc20_file_source = res.unwrap();
assert_eq!(full_erc20_file_source.dependencies.len(), 4);
assert_eq!(full_erc20_file_source.dependencies.len(), 2);
for dep in full_erc20_file_source.dependencies.iter() {
assert!(dep.source.is_some());
assert_eq!(dep.dependencies.len(), 0);
Expand All @@ -27,7 +27,7 @@ fn test_recursing_fs_dependencies() {
fn test_recursing_external_dependencies() {
let file_provider = Arc::new(FileSystemFileProvider {});
let file_sources: Vec<Arc<file_source::FileSource>> =
Compiler::fetch_sources(vec![PathBuf::from("../../huff-examples/erc20/contracts/ERC20.huff".to_string())], file_provider.clone())
Compiler::fetch_sources(vec![PathBuf::from("../../resources/erc20/ERC20.huff".to_string())], file_provider.clone())
.iter()
.map(|p| p.clone().unwrap())
.collect();
Expand All @@ -36,7 +36,7 @@ fn test_recursing_external_dependencies() {
let res = Compiler::recurse_deps(Arc::clone(&erc20_file_source), &remapper::Remapper::new("./"), file_provider, HashSet::new());
let full_erc20_file_source = res.unwrap();

assert_eq!(full_erc20_file_source.dependencies.len(), 4);
assert_eq!(full_erc20_file_source.dependencies.len(), 2);
for dep in full_erc20_file_source.dependencies.iter() {
assert!(dep.source.is_some());
assert_eq!(dep.dependencies.len(), 0);
Expand Down
22 changes: 11 additions & 11 deletions crates/core/tests/sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ fn test_fetch_sources() {
let file_provider = Arc::new(FileSystemFileProvider {});
let file_sources: Vec<Arc<FileSource>> = Compiler::fetch_sources(
vec![
PathBuf::from("../../huff-examples/erc20/contracts/ERC20.huff".to_string()),
PathBuf::from("../../huff-examples/erc20/contracts/utils/Address.huff".to_string()),
PathBuf::from("../../huff-examples/erc20/contracts/utils/HashMap.huff".to_string()),
PathBuf::from("../../resources/erc20/ERC20.huff".to_string()),
PathBuf::from("../../resources/utils/HashMap.huff".to_string()),
PathBuf::from("../../resources/utils/Ownable.huff".to_string()),
],
file_provider,
)
.iter()
.map(|p| p.clone().unwrap())
.collect();
assert_eq!(file_sources.len(), 3);
assert_eq!(file_sources[0].path, "../../huff-examples/erc20/contracts/ERC20.huff".to_string());
assert_eq!(file_sources[1].path, "../../huff-examples/erc20/contracts/utils/Address.huff".to_string());
assert_eq!(file_sources[2].path, "../../huff-examples/erc20/contracts/utils/HashMap.huff".to_string());
assert_eq!(file_sources[0].path, "../../resources/erc20/ERC20.huff".to_string());
assert_eq!(file_sources[1].path, "../../resources/utils/HashMap.huff".to_string());
assert_eq!(file_sources[2].path, "../../resources/utils/Ownable.huff".to_string());
}

#[test]
fn test_fetch_invalid_sources() {
let paths = vec![
PathBuf::from("../../huff-examples/erc20/contracts/non_existant.huff".to_string()),
PathBuf::from("../../huff-examples/erc20/contracts/non_huff.txt".to_string()),
PathBuf::from("../../huff-examples/erc20/contracts/random/Address.huff".to_string()),
PathBuf::from("../../huff-examples/erc20/contracts/random/".to_string()),
PathBuf::from("../../huff-examples/erc20/contracts/utils/".to_string()),
PathBuf::from("../../resources/erc20/non_existant.huff".to_string()),
PathBuf::from("../../resources/erc20/non_huff.txt".to_string()),
PathBuf::from("../../resources/erc20/random/Address.huff".to_string()),
PathBuf::from("../../resources/erc20/random/".to_string()),
PathBuf::from("../../resources/erc20/utils/".to_string()),
];
let file_provider = FileSystemFileProvider {};
let file_sources: Vec<Result<Arc<FileSource>, CompilerError>> = Compiler::fetch_sources(paths.clone(), Arc::new(file_provider));
Expand Down
Loading

0 comments on commit 6cced17

Please sign in to comment.