-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from sygmaprotocol/nmlinaric/generate-func-si…
…gnatures feat: add function for generating function signatures
- Loading branch information
Showing
5 changed files
with
76 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,13 +26,20 @@ jobs: | |
node-version: ${{ matrix.node-version }} | ||
- name: Install dependencies | ||
run: make install-deps | ||
- name: Compile contracts | ||
run: make compile | ||
- name: Store contract artifacts | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: contracts-artifacts | ||
path: build | ||
- name: Ganache Tests | ||
run: | | ||
SILENT=true make start-ganache | ||
make test | ||
coverage: | ||
needs: Test | ||
needs: test | ||
name: Coverage | ||
runs-on: ubuntu-latest | ||
strategy: | ||
|
@@ -45,6 +52,11 @@ jobs: | |
uses: actions/[email protected] | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Download contracts artifacts | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: contracts-artifacts | ||
path: build | ||
- name: Yarn install | ||
run: yarn install --frozen-lockfile | ||
- name: Run coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* Copyright 2020 ChainSafe Systems | ||
* SPDX-License-Identifier: LGPL-3.0-only | ||
*/ | ||
|
||
const fs = require("fs"); | ||
const {utils} = require("ethers"); | ||
const {resolve} = require("path"); | ||
|
||
|
||
const BRIDGE_CONTRACT_PATH = resolve(__dirname, "../contracts/Bridge.sol"); | ||
const ARTIFACTS_PATH = resolve(__dirname, "../build/contracts/Bridge.json"); | ||
|
||
function generateAccessControlFuncSignatures() { | ||
const bridgeAbiJson = JSON.parse(fs.readFileSync(ARTIFACTS_PATH)); | ||
const bridgeContractMethods = bridgeAbiJson.userdoc.methods | ||
const bridgeContract = fs.readFileSync(BRIDGE_CONTRACT_PATH); | ||
|
||
// regex that will match all functions that have "onlyAllowed" modifier | ||
const regex = RegExp("function\\s+(?:(?!_onlyAllowed|function).)+onlyAllowed", "gs"); | ||
|
||
let a; | ||
const b = []; | ||
// fetch all functions that have "onlyAllowed" modifier from "Bridge.sol" | ||
while ((a = regex.exec(bridgeContract)) !== null) { | ||
// filter out only function name from matching (onlyAllowed) functions | ||
b.push(a[0].split(/[\s()]+/)[1]); | ||
} | ||
|
||
let accessControlFuncSignatures = [] | ||
// filter out from Bridge ABI functions signatures with "onlyAllowed" modifier | ||
accessControlFuncSignatures = Object.keys(bridgeContractMethods).filter( | ||
el1 => b.some( | ||
el2 => el1.includes(el2))).map( | ||
func => ({ | ||
function: func, | ||
hash: utils.keccak256(Buffer.from(func)).substring(0,10) | ||
}) | ||
); | ||
|
||
console.table(accessControlFuncSignatures); | ||
|
||
return accessControlFuncSignatures; | ||
} | ||
|
||
module.exports = { | ||
generateAccessControlFuncSignatures | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters