Skip to content

Commit

Permalink
adjust regex for function and event names
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyTM committed Jun 4, 2024
1 parent 5a6187c commit c04f678
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core/src/internal/utils/identifier-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const solidityIdentifierRegex = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/;
/**
* A regex capturing the solidity identifier rule but extended to support
* the `myfun(uint256,bool)` parameter syntax
*
* This *could* be even stricter, but it works for now and covers obvious mistakes
*/
const functionNameRegex = /^[a-zA-Z$_][a-zA-Z0-9$_,()]*$/;
const functionNameRegex = /^[a-zA-Z$_]*(\([a-zA-Z0-9$_,\[\]]*\))?$/;

/**
* Does the identifier match Ignition's rules for ids. Specifically that they
Expand Down
21 changes: 21 additions & 0 deletions packages/core/test/validations/identifier-validators.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { assert } from "chai";

import { isValidFunctionOrEventName } from "../../src/internal/utils/identifier-validators";

describe("isValidFunctionOrEventName", () => {
it("should return true for valid solidity function names", () => {
assert.isTrue(isValidFunctionOrEventName("myFunction"));
assert.isTrue(isValidFunctionOrEventName("myFunction()"));
assert.isTrue(isValidFunctionOrEventName("myFunction(uint256)"));
assert.isTrue(isValidFunctionOrEventName("myFunction(uint256)"));
assert.isTrue(isValidFunctionOrEventName("myFunction(uint256,bool)"));
assert.isTrue(isValidFunctionOrEventName("myFunction(uint256[],bool)"));
});

it("should return false for invalid solidity function names", () => {
assert.isFalse(isValidFunctionOrEventName("myFunction("));
assert.isFalse(isValidFunctionOrEventName("myFunction(uint)256"));
assert.isFalse(isValidFunctionOrEventName("myFunction(uint256"));
assert.isFalse(isValidFunctionOrEventName("myFunctionuint256)"));
});
});

0 comments on commit c04f678

Please sign in to comment.