Skip to content

Commit f354d08

Browse files
committed
gnd: Test reserved/unnamed param accessors against codegen
Regression guard for the LHS/RHS escaping mismatch: codegen a contract with a reserved-word param (`new`) and an unnamed param, then assert the mapping's event.params accessor matches the getter the bindings actually expose (new_, param1).
1 parent 928e7a4 commit f354d08

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

gnd/tests/cli_commands.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,63 @@ fn test_init_tuple_event_unrolls() {
745745
);
746746
}
747747

748+
#[test]
749+
fn test_init_reserved_and_unnamed_params_codegen() {
750+
let temp_dir = TempDir::new().unwrap();
751+
let subgraph_dir = temp_dir.path().join("rw-sub");
752+
753+
// A reserved-word param (`new`) and an unnamed param.
754+
let abi = temp_dir.path().join("RW.json");
755+
fs::write(
756+
&abi,
757+
r#"[
758+
{"type":"event","name":"Act","inputs":[
759+
{"name":"new","type":"uint256","indexed":false},
760+
{"name":"","type":"address","indexed":false}
761+
]}
762+
]"#,
763+
)
764+
.unwrap();
765+
766+
run_gnd_success(
767+
&[
768+
"init",
769+
"--from-contract",
770+
"0x1111111111111111111111111111111111111111",
771+
"--abi",
772+
abi.to_str().unwrap(),
773+
"--network",
774+
"mainnet",
775+
"--contract-name",
776+
"RW",
777+
"--index-events",
778+
"--skip-install",
779+
"--skip-git",
780+
"rw-sub",
781+
],
782+
temp_dir.path(),
783+
);
784+
run_gnd_success(&["codegen"], &subgraph_dir);
785+
786+
// The mapping's event.params accessor must match the getter the codegen
787+
// actually generates: `new` is escaped to `new_`, the unnamed param is
788+
// `param1`. (Regression guard for the LHS/RHS escaping mismatch.)
789+
let mapping = fs::read_to_string(subgraph_dir.join("src").join("rw.ts")).unwrap();
790+
let bindings =
791+
fs::read_to_string(subgraph_dir.join("generated").join("RW").join("RW.ts")).unwrap();
792+
793+
assert!(
794+
bindings.contains("get new_(") && mapping.contains("event.params.new_"),
795+
"reserved getter and accessor should both be new_\nmapping:\n{}",
796+
mapping
797+
);
798+
assert!(
799+
bindings.contains("get param1(") && mapping.contains("event.params.param1"),
800+
"unnamed getter and accessor should both be param1\nmapping:\n{}",
801+
mapping
802+
);
803+
}
804+
748805
#[test]
749806
fn test_add_duplicate_name_errors() {
750807
let temp_dir = TempDir::new().unwrap();

0 commit comments

Comments
 (0)