diff --git a/crates/analyzer/tests/snapshots/analysis__module_level_events.snap b/crates/analyzer/tests/snapshots/analysis__module_level_events.snap index da0492dce3..81efce2740 100644 --- a/crates/analyzer/tests/snapshots/analysis__module_level_events.snap +++ b/crates/analyzer/tests/snapshots/analysis__module_level_events.snap @@ -6,33 +6,33 @@ expression: "build_snapshot(&files, module_id, &db)" note: ┌─ features/module_level_events.fe:2:5 │ -2 │ idx sum: u256 - │ ^^^^^^^^^^^^^ u256 +2 │ idx sender: address + │ ^^^^^^^^^^^^^^^^^^^ address +3 │ idx receiver: address + │ ^^^^^^^^^^^^^^^^^^^^^ address +4 │ value: u256 + │ ^^^^^^^^^^^ u256 note: - ┌─ features/module_level_events.fe:4:5 + ┌─ features/module_level_events.fe:6:5 │ -4 │ ╭ pub fn add(a: u256, b: u256) -> u256: -5 │ │ let sum: u256 = a + b -6 │ │ emit Added(sum=sum) -7 │ │ return a + b - │ ╰────────────────────^ attributes hash: 10094331793610550579 +6 │ ╭ fn transfer(to : address, value : u256): +7 │ │ emit Transfer(sender=msg.sender, receiver=to, value) + │ ╰────────────────────────────────────────────────────────────^ attributes hash: 5430479256040439660 │ = FunctionSignature { self_decl: None, params: [ FunctionParam { - name: "a", + name: "to", typ: Ok( Base( - Numeric( - U256, - ), + Address, ), ), }, FunctionParam { - name: "b", + name: "value", typ: Ok( Base( Numeric( @@ -44,56 +44,49 @@ note: ], return_type: Ok( Base( - Numeric( - U256, - ), + Unit, ), ), } note: - ┌─ features/module_level_events.fe:5:18 - │ -5 │ let sum: u256 = a + b - │ ^^^^ u256 - -note: - ┌─ features/module_level_events.fe:5:25 + ┌─ features/module_level_events.fe:7:30 │ -5 │ let sum: u256 = a + b - │ ^ ^ u256: Value - │ │ - │ u256: Value +7 │ emit Transfer(sender=msg.sender, receiver=to, value) + │ ^^^^^^^^^^ ^^ ^^^^^ u256: Value + │ │ │ + │ │ address: Value + │ address: Value note: - ┌─ features/module_level_events.fe:5:25 + ┌─ features/module_level_events.fe:7:9 │ -5 │ let sum: u256 = a + b - │ ^^^^^ u256: Value -6 │ emit Added(sum=sum) - │ ^^^ u256: Value -7 │ return a + b - │ ^ ^ u256: Value - │ │ - │ u256: Value - -note: - ┌─ features/module_level_events.fe:7:16 - │ -7 │ return a + b - │ ^^^^^ u256: Value - -note: - ┌─ features/module_level_events.fe:6:9 - │ -6 │ emit Added(sum=sum) - │ ^^^^^^^^^^^^^^^^^^^ attributes hash: 3277580564244611338 +7 │ emit Transfer(sender=msg.sender, receiver=to, value) + │ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attributes hash: 17986960071624595337 │ = Event { - name: "Added", + name: "Transfer", fields: [ EventField { - name: "sum", + name: "sender", + typ: Ok( + Base( + Address, + ), + ), + is_indexed: true, + }, + EventField { + name: "receiver", + typ: Ok( + Base( + Address, + ), + ), + is_indexed: true, + }, + EventField { + name: "value", typ: Ok( Base( Numeric( @@ -101,7 +94,7 @@ note: ), ), ), - is_indexed: true, + is_indexed: false, }, ], } diff --git a/crates/lowering/tests/snapshots/lowering__module_level_events.snap b/crates/lowering/tests/snapshots/lowering__module_level_events.snap index 1062c2a446..59749ccd66 100644 --- a/crates/lowering/tests/snapshots/lowering__module_level_events.snap +++ b/crates/lowering/tests/snapshots/lowering__module_level_events.snap @@ -3,11 +3,12 @@ source: crates/lowering/tests/lowering.rs expression: lowered_code --- -event Added: - idx sum: u256 +event Transfer: + idx sender: address + idx receiver: address + value: u256 -contract Adder: - pub fn add(a: u256, b: u256) -> u256: - let sum: u256 = a + b - emit Added(sum=sum) - return a + b +contract Foo: + fn transfer(to: address, value: u256) -> (): + emit Transfer(sender=msg.sender, receiver=to, value) + return () diff --git a/crates/parser/tests/cases/parse_ast.rs b/crates/parser/tests/cases/parse_ast.rs index 2fe574623a..461e10c6af 100644 --- a/crates/parser/tests/cases/parse_ast.rs +++ b/crates/parser/tests/cases/parse_ast.rs @@ -228,12 +228,12 @@ contract GuestBook: return self.guest_book[addr] "# } -test_parse! { module_level_event, module::parse_module, r#" -event Added: - idx sum: u256 -contract Adder: - pub fn add(a: u256, b: u256) -> u256: - let sum: u256 = a + b - emit Added(sum=sum) - return a + b +test_parse! { module_level_events, module::parse_module, r#" +event Transfer: + idx sender: address + idx receiver: address + value: u256 +contract Foo: + fn transfer(to : address, value : u256): + emit Transfer(sender=msg.sender, receiver=to, value) "# } diff --git a/crates/parser/tests/cases/snapshots/cases__parse_ast__module_level_event.snap b/crates/parser/tests/cases/snapshots/cases__parse_ast__module_level_event.snap deleted file mode 100644 index 717ccdd6c3..0000000000 --- a/crates/parser/tests/cases/snapshots/cases__parse_ast__module_level_event.snap +++ /dev/null @@ -1,293 +0,0 @@ ---- -source: crates/parser/tests/cases/parse_ast.rs -expression: "ast_string(stringify!(module_level_event), module::parse_module,\n r#\"\nevent Added:\n idx sum: u256\ncontract Adder:\n pub fn add(a: u256, b: u256) -> u256:\n let sum: u256 = a + b\n emit Added(sum=sum)\n return a + b\n\"#)" - ---- -Node( - kind: Module( - body: [ - Event(Node( - kind: Event( - name: Node( - kind: "Added", - span: Span( - start: 7, - end: 12, - ), - ), - fields: [ - Node( - kind: EventField( - is_idx: true, - name: Node( - kind: "sum", - span: Span( - start: 22, - end: 25, - ), - ), - typ: Node( - kind: Base( - base: "u256", - ), - span: Span( - start: 27, - end: 31, - ), - ), - ), - span: Span( - start: 18, - end: 31, - ), - ), - ], - pub_qual: None, - ), - span: Span( - start: 1, - end: 31, - ), - )), - Contract(Node( - kind: Contract( - name: Node( - kind: "Adder", - span: Span( - start: 41, - end: 46, - ), - ), - fields: [], - body: [ - Function(Node( - kind: Function( - pub_: Some(Span( - start: 52, - end: 55, - )), - unsafe_: None, - name: Node( - kind: "add", - span: Span( - start: 59, - end: 62, - ), - ), - args: [ - Node( - kind: Regular(RegularFunctionArg( - name: Node( - kind: "a", - span: Span( - start: 63, - end: 64, - ), - ), - typ: Node( - kind: Base( - base: "u256", - ), - span: Span( - start: 66, - end: 70, - ), - ), - )), - span: Span( - start: 63, - end: 70, - ), - ), - Node( - kind: Regular(RegularFunctionArg( - name: Node( - kind: "b", - span: Span( - start: 72, - end: 73, - ), - ), - typ: Node( - kind: Base( - base: "u256", - ), - span: Span( - start: 75, - end: 79, - ), - ), - )), - span: Span( - start: 72, - end: 79, - ), - ), - ], - return_type: Some(Node( - kind: Base( - base: "u256", - ), - span: Span( - start: 84, - end: 88, - ), - )), - body: [ - Node( - kind: VarDecl( - target: Node( - kind: Name("sum"), - span: Span( - start: 102, - end: 105, - ), - ), - typ: Node( - kind: Base( - base: "u256", - ), - span: Span( - start: 107, - end: 111, - ), - ), - value: Some(Node( - kind: BinOperation( - left: Node( - kind: Name("a"), - span: Span( - start: 114, - end: 115, - ), - ), - op: Node( - kind: Add, - span: Span( - start: 116, - end: 117, - ), - ), - right: Node( - kind: Name("b"), - span: Span( - start: 118, - end: 119, - ), - ), - ), - span: Span( - start: 114, - end: 119, - ), - )), - ), - span: Span( - start: 98, - end: 119, - ), - ), - Node( - kind: Emit( - name: Node( - kind: "Added", - span: Span( - start: 133, - end: 138, - ), - ), - args: Node( - kind: [ - Node( - kind: CallArg( - label: Some(Node( - kind: "sum", - span: Span( - start: 139, - end: 142, - ), - )), - value: Node( - kind: Name("sum"), - span: Span( - start: 143, - end: 146, - ), - ), - ), - span: Span( - start: 139, - end: 146, - ), - ), - ], - span: Span( - start: 138, - end: 147, - ), - ), - ), - span: Span( - start: 128, - end: 147, - ), - ), - Node( - kind: Return( - value: Some(Node( - kind: BinOperation( - left: Node( - kind: Name("a"), - span: Span( - start: 163, - end: 164, - ), - ), - op: Node( - kind: Add, - span: Span( - start: 165, - end: 166, - ), - ), - right: Node( - kind: Name("b"), - span: Span( - start: 167, - end: 168, - ), - ), - ), - span: Span( - start: 163, - end: 168, - ), - )), - ), - span: Span( - start: 156, - end: 168, - ), - ), - ], - ), - span: Span( - start: 52, - end: 168, - ), - )), - ], - pub_qual: None, - ), - span: Span( - start: 32, - end: 168, - ), - )), - ], - ), - span: Span( - start: 0, - end: 168, - ), -) diff --git a/crates/parser/tests/cases/snapshots/cases__parse_ast__module_level_events.snap b/crates/parser/tests/cases/snapshots/cases__parse_ast__module_level_events.snap new file mode 100644 index 0000000000..210a37df1e --- /dev/null +++ b/crates/parser/tests/cases/snapshots/cases__parse_ast__module_level_events.snap @@ -0,0 +1,295 @@ +--- +source: crates/parser/tests/cases/parse_ast.rs +expression: "ast_string(stringify!(module_level_events), module::parse_module,\n r#\"\nevent Transfer:\n idx sender: address\n idx receiver: address\n value: u256\ncontract Foo:\n fn transfer(to : address, value : u256):\n emit Transfer(sender=msg.sender, receiver=to, value)\n\"#)" + +--- +Node( + kind: Module( + body: [ + Event(Node( + kind: Event( + name: Node( + kind: "Transfer", + span: Span( + start: 7, + end: 15, + ), + ), + fields: [ + Node( + kind: EventField( + is_idx: true, + name: Node( + kind: "sender", + span: Span( + start: 25, + end: 31, + ), + ), + typ: Node( + kind: Base( + base: "address", + ), + span: Span( + start: 33, + end: 40, + ), + ), + ), + span: Span( + start: 21, + end: 40, + ), + ), + Node( + kind: EventField( + is_idx: true, + name: Node( + kind: "receiver", + span: Span( + start: 49, + end: 57, + ), + ), + typ: Node( + kind: Base( + base: "address", + ), + span: Span( + start: 59, + end: 66, + ), + ), + ), + span: Span( + start: 45, + end: 66, + ), + ), + Node( + kind: EventField( + is_idx: false, + name: Node( + kind: "value", + span: Span( + start: 71, + end: 76, + ), + ), + typ: Node( + kind: Base( + base: "u256", + ), + span: Span( + start: 78, + end: 82, + ), + ), + ), + span: Span( + start: 71, + end: 82, + ), + ), + ], + pub_qual: None, + ), + span: Span( + start: 1, + end: 82, + ), + )), + Contract(Node( + kind: Contract( + name: Node( + kind: "Foo", + span: Span( + start: 92, + end: 95, + ), + ), + fields: [], + body: [ + Function(Node( + kind: Function( + pub_: None, + unsafe_: None, + name: Node( + kind: "transfer", + span: Span( + start: 104, + end: 112, + ), + ), + args: [ + Node( + kind: Regular(RegularFunctionArg( + name: Node( + kind: "to", + span: Span( + start: 113, + end: 115, + ), + ), + typ: Node( + kind: Base( + base: "address", + ), + span: Span( + start: 118, + end: 125, + ), + ), + )), + span: Span( + start: 113, + end: 125, + ), + ), + Node( + kind: Regular(RegularFunctionArg( + name: Node( + kind: "value", + span: Span( + start: 127, + end: 132, + ), + ), + typ: Node( + kind: Base( + base: "u256", + ), + span: Span( + start: 135, + end: 139, + ), + ), + )), + span: Span( + start: 127, + end: 139, + ), + ), + ], + return_type: None, + body: [ + Node( + kind: Emit( + name: Node( + kind: "Transfer", + span: Span( + start: 155, + end: 163, + ), + ), + args: Node( + kind: [ + Node( + kind: CallArg( + label: Some(Node( + kind: "sender", + span: Span( + start: 164, + end: 170, + ), + )), + value: Node( + kind: Attribute( + value: Node( + kind: Name("msg"), + span: Span( + start: 171, + end: 174, + ), + ), + attr: Node( + kind: "sender", + span: Span( + start: 175, + end: 181, + ), + ), + ), + span: Span( + start: 171, + end: 181, + ), + ), + ), + span: Span( + start: 164, + end: 181, + ), + ), + Node( + kind: CallArg( + label: Some(Node( + kind: "receiver", + span: Span( + start: 183, + end: 191, + ), + )), + value: Node( + kind: Name("to"), + span: Span( + start: 192, + end: 194, + ), + ), + ), + span: Span( + start: 183, + end: 194, + ), + ), + Node( + kind: CallArg( + label: None, + value: Node( + kind: Name("value"), + span: Span( + start: 196, + end: 201, + ), + ), + ), + span: Span( + start: 196, + end: 201, + ), + ), + ], + span: Span( + start: 163, + end: 202, + ), + ), + ), + span: Span( + start: 150, + end: 202, + ), + ), + ], + ), + span: Span( + start: 101, + end: 202, + ), + )), + ], + pub_qual: None, + ), + span: Span( + start: 83, + end: 202, + ), + )), + ], + ), + span: Span( + start: 0, + end: 202, + ), +) diff --git a/crates/test-files/fixtures/features/module_level_events.fe b/crates/test-files/fixtures/features/module_level_events.fe index 031bc6455e..e4375738dd 100644 --- a/crates/test-files/fixtures/features/module_level_events.fe +++ b/crates/test-files/fixtures/features/module_level_events.fe @@ -1,7 +1,7 @@ -event Added: - idx sum: u256 -contract Adder: - pub fn add(a: u256, b: u256) -> u256: - let sum: u256 = a + b - emit Added(sum=sum) - return a + b +event Transfer: + idx sender: address + idx receiver: address + value: u256 +contract Foo: + fn transfer(to : address, value : u256): + emit Transfer(sender=msg.sender, receiver=to, value) \ No newline at end of file diff --git a/crates/test-files/fixtures/lowering/module_level_events.fe b/crates/test-files/fixtures/lowering/module_level_events.fe index 031bc6455e..e4375738dd 100644 --- a/crates/test-files/fixtures/lowering/module_level_events.fe +++ b/crates/test-files/fixtures/lowering/module_level_events.fe @@ -1,7 +1,7 @@ -event Added: - idx sum: u256 -contract Adder: - pub fn add(a: u256, b: u256) -> u256: - let sum: u256 = a + b - emit Added(sum=sum) - return a + b +event Transfer: + idx sender: address + idx receiver: address + value: u256 +contract Foo: + fn transfer(to : address, value : u256): + emit Transfer(sender=msg.sender, receiver=to, value) \ No newline at end of file