Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

braces #707

Merged
merged 1 commit into from
May 30, 2022
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
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