From 4d373b529ba6bd3963b197c80b9e660890870c45 Mon Sep 17 00:00:00 2001 From: clemlak Date: Mon, 21 Oct 2024 10:34:22 +0400 Subject: [PATCH 1/5] feat: add sol_raw_event_primitive_type --- crates/ast/src/parser.rs | 46 +++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/crates/ast/src/parser.rs b/crates/ast/src/parser.rs index 308a75e..5e4dcdc 100644 --- a/crates/ast/src/parser.rs +++ b/crates/ast/src/parser.rs @@ -331,6 +331,10 @@ fn sol_type<'tokens, 'src: 'tokens>() -> impl Parser<'tokens, 'src, Spanned() -> impl Parser<'tokens, 'src, Spanned Date: Mon, 21 Oct 2024 10:35:35 +0400 Subject: [PATCH 2/5] test: add parse_sol_event_indexed --- crates/ast/src/parser.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/crates/ast/src/parser.rs b/crates/ast/src/parser.rs index 5e4dcdc..eb2be17 100644 --- a/crates/ast/src/parser.rs +++ b/crates/ast/src/parser.rs @@ -815,6 +815,34 @@ mod tests { ); } + #[test] + fn parse_sol_event_indexed() { + let span: Span = SimpleSpan::new(0, 0); + assert_ok!( + sol_event(), + vec![ + Ident("event"), + Ident("Transfer"), + Punct('('), + Ident("address"), + Ident("indexed"), + Punct(','), + Ident("address"), + Punct(','), + Ident("uint256"), + Punct(')') + ], + ast::Definition::SolEvent(ast::SolEvent { + name: ("Transfer", span), + args: Box::new([ + (DynSolType::parse("address").unwrap(), span), + (DynSolType::parse("address").unwrap(), span), + (DynSolType::parse("uint256").unwrap(), span), + ]), + }) + ); + } + #[test] fn parse_sol_error() { let span: Span = SimpleSpan::new(0, 0); From 07199cf41120517527460c5f2d5ed00c4033d714 Mon Sep 17 00:00:00 2001 From: clemlak Date: Mon, 21 Oct 2024 10:58:29 +0400 Subject: [PATCH 3/5] fix: error due to solving previous conflicts --- crates/ast/src/parser.rs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/crates/ast/src/parser.rs b/crates/ast/src/parser.rs index 1fe429e..e55eecf 100644 --- a/crates/ast/src/parser.rs +++ b/crates/ast/src/parser.rs @@ -341,8 +341,8 @@ fn sol_type<'tokens, 'src: 'tokens>() -> impl Parser<'tokens, 'src, Spanned() -> impl Parser<'tokens, 'src, Spanned Date: Mon, 21 Oct 2024 14:52:16 +0400 Subject: [PATCH 4/5] test: merge parse_sol_event tests --- crates/ast/src/parser.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/crates/ast/src/parser.rs b/crates/ast/src/parser.rs index e55eecf..36a99c7 100644 --- a/crates/ast/src/parser.rs +++ b/crates/ast/src/parser.rs @@ -847,11 +847,6 @@ mod tests { ]), }) ); - } - - #[test] - fn parse_sol_event_indexed() { - let span: Span = SimpleSpan::new(0, 0); assert_ok!( sol_event(), vec![ From 16b06d0f518fff11641173c27ac3bf7a318d772e Mon Sep 17 00:00:00 2001 From: lmittmann Date: Mon, 21 Oct 2024 16:23:08 +0200 Subject: [PATCH 5/5] added more tests --- crates/ast/src/parser.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/ast/src/parser.rs b/crates/ast/src/parser.rs index 36a99c7..e6e7700 100644 --- a/crates/ast/src/parser.rs +++ b/crates/ast/src/parser.rs @@ -820,6 +820,22 @@ mod tests { rets: Box::new([(DynSolType::parse("uint256").unwrap(), span)]), }) ); + assert_err!( + sol_function(), + vec![ + Ident("function"), + Ident("balanceOf"), + Punct('('), + Ident("address"), + Ident("indexed"), + Punct(')'), + Ident("returns"), + Punct('('), + Ident("uint256"), + Punct(')') + ], + "word overflows" + ); } #[test] @@ -855,10 +871,14 @@ mod tests { Punct('('), Ident("address"), Ident("indexed"), + Ident("sender"), Punct(','), Ident("address"), + Ident("indexed"), + Ident("recipient"), Punct(','), Ident("uint256"), + Ident("amount"), Punct(')') ], ast::Definition::SolEvent(ast::SolEvent {