Skip to content

Commit

Permalink
Curly brace block syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig committed May 25, 2022
1 parent 95e4a38 commit 141c9e4
Show file tree
Hide file tree
Showing 671 changed files with 14,522 additions and 13,154 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,25 @@ Run `fe --help` to explore further options.

The following is a simple contract implemented in Fe.

```python
```rust
use std::context::Context

contract GuestBook:
contract GuestBook {
messages: Map<address, String<100>>

event Signed:
event Signed {
book_msg: String<100>
}

pub fn sign(self, ctx: Context, book_msg: String<100>):
pub fn sign(self, ctx: Context, book_msg: String<100>) {
self.messages[ctx.msg_sender()] = book_msg
emit Signed(ctx, book_msg: book_msg)
}

pub fn get_msg(self, addr: address) -> String<100>:
pub fn get_msg(self, addr: address) -> String<100> {
return self.messages[addr].to_mem()
}
}
```

A lot more working examples can be found in our [test fixtures directory](https://github.com/ethereum/fe/tree/master/crates/test-files/fixtures/demos).
Expand Down
22 changes: 13 additions & 9 deletions crates/abi/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,23 @@ mod tests {
#[test]
fn build_contract_abi() {
let contract = r#"
pub fn add(_ x: u256, _ y: u256) -> u256:
pub fn add(_ x: u256, _ y: u256) -> u256 {
return x + y
contract Foo:
event Food:
}
contract Foo {
event Food {
idx barge: u256
pub fn __init__(x: address):
pass
fn baz(_ x: address) -> u256:
}
pub fn __init__(x: address) {
}
fn baz(_ x: address) -> u256 {
add(10, 20)
revert
pub fn bar(_ x: u256) -> Array<u256, 10>:
revert"#;
}
pub fn bar(_ x: u256) -> Array<u256, 10> {
revert
}
}"#;

let mut db = TestDb::default();
let module = ModuleId::new_standalone(&mut db, "test_module", contract);
Expand Down
1 change: 0 additions & 1 deletion crates/analyzer/src/traversal/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fn func_stmt(scope: &mut BlockScope, stmt: &Node<fe::FuncStmt>) -> Result<(), Fa
Unsafe { .. } => unsafe_block(scope, stmt),
Assert { .. } => assert(scope, stmt),
Expr { value } => expressions::expr(scope, value, None).map(|_| ()),
Pass => Ok(()),
Revert { .. } => revert(scope, stmt),
Break | Continue => {
loop_flow_statement(scope, stmt);
Expand Down
35 changes: 7 additions & 28 deletions crates/analyzer/tests/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,7 @@ macro_rules! test_stmt {
#[wasm_bindgen_test]
fn $name() {
let src = format!(
"contract C:\n pub fn f(self):\n {}",
$stmt.replace('\n', "\n ")
);
if cfg!(target_arch = "wasm32") {
fe_common::assert_snapshot_wasm!(
concat!("snapshots/errors__", stringify!($name), ".snap"),
error_string("[snippet]", &src)
);
} else {
assert_snapshot!(error_string("[snippet]", &src));
}
}
};
}

macro_rules! test_stmt_unsafe {
($name:ident, $stmt:expr) => {
#[test]
#[wasm_bindgen_test]
fn $name() {
let src = format!(
"contract C:\n pub fn f(self):\n unsafe:\n {}",
"contract C {{\n pub fn f(self) {{\n {}\n }}\n}}",
$stmt.replace('\n', "\n ")
);
if cfg!(target_arch = "wasm32") {
Expand Down Expand Up @@ -136,7 +115,7 @@ test_stmt! { binary_op_boolean_mismatch3, "1 or 2" }
test_stmt! { bool_constructor, "bool(true)" }
test_stmt! { bool_cast, "bool(0)" }
test_stmt! { break_without_loop, "break" }
test_stmt! { break_without_loop_2, "if true:\n break" }
test_stmt! { break_without_loop_2, "if true { break }" }
test_stmt! { call_undefined_function_on_contract, "self.doesnt_exist()" }
test_stmt! { call_address_with_wrong_type, "address(true)" }
test_stmt! { call_keccak_without_parameter, "keccak256()" }
Expand All @@ -145,13 +124,13 @@ test_stmt! { call_keccak_with_2_args, "keccak256(1, 2)" }
test_stmt! { call_keccak_with_generic_args, "keccak256<10>(1)" }
test_stmt! { cast_address_to_u64, "u64(address(0))" }

test_stmt_unsafe! { call_balance_of_without_parameter, "std::evm::balance_of()" }
test_stmt_unsafe! { call_balance_of_with_wrong_type, "std::evm::balance_of(true)" }
test_stmt_unsafe! { call_balance_of_with_2_args, "std::evm::balance_of(address(0), 2)" }
test_stmt_unsafe! { call_balance_with_arg, "std::evm::balance(address(0))" }
test_stmt! { call_balance_of_without_parameter, "unsafe { std::evm::balance_of() }" }
test_stmt! { call_balance_of_with_wrong_type, "unsafe { std::evm::balance_of(true) }" }
test_stmt! { call_balance_of_with_2_args, "unsafe { std::evm::balance_of(address(0), 2) }" }
test_stmt! { call_balance_with_arg, "unsafe { std::evm::balance(address(0)) }" }
test_stmt! { clone_arg_count, "let x: Array<u256, 2> = [5, 6]\nlet y: Array<u256, 2> = x.clone(y)" }
test_stmt! { continue_without_loop, "continue" }
test_stmt! { continue_without_loop_2, "if true:\n continue" }
test_stmt! { continue_without_loop_2, "if true { continue }" }
test_stmt! { emit_undefined_event, "emit MyEvent()" }
test_stmt! { emit_type_name, "emit u8()" }
test_stmt! { emit_variable, "let x: u8 = 10\nemit x()" }
Expand Down
Loading

0 comments on commit 141c9e4

Please sign in to comment.