Skip to content

Commit

Permalink
Merge pull request #805 from onflow/staging
Browse files Browse the repository at this point in the history
fix for #804
  • Loading branch information
nialexsan authored Sep 18, 2024
2 parents 6f25d0c + c7f8fa0 commit 2ded248
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "webpack-dev-server -d source-map --config webpack.config.js",
"build": "webpack --mode=production",
"graphql:codegen": "npx graphql-codegen --config codegen.yml",
"test": "echo Tests command not implemented.",
"test": "jest",
"format:app": "prettier --write 'src'",
"format:check:app": "prettier --check 'src/**/*.{js,jsx,ts,tsx,css}' ",
"lint": "eslint --ext .js,.jsx,.ts,.tsx src",
Expand Down Expand Up @@ -85,6 +85,7 @@
"@sentry/types": "^7.44.0",
"@types/file-saver": "^2.0.5",
"@types/isomorphic-fetch": "0.0.36",
"@types/jest": "^29.5.13",
"@types/mixpanel-browser": "^2.38.0",
"@types/reach__router": "^1.3.10",
"@types/react": "^17.0.39",
Expand Down
2 changes: 1 addition & 1 deletion src/providers/Project/projectDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function createLocalProject(
const accountEntities: Account[] = accounts.map((_account) => {
return {
__typename: 'Account',
address: _account.padStart(16, "0"),
address: _account.padStart(16, '0'),
deployedContracts: [],
state: DEFAULT_ACCOUNT_STATE,
};
Expand Down
24 changes: 24 additions & 0 deletions src/util/parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { extractSigners } from './parser';

const oneSigner = `
transaction {
prepare(acct: auth(LoadValue, SaveValue) &Account) {}
}`;

const twoSigners = `
transaction {
prepare(authorizer1: auth(Capabilities,SomethingElse) &Account, authorizer2: auth(Storage,Vaults) &Account) { }
}`;

describe('parser tests', () => {
it('should extract one code signer', () => {
const signers = extractSigners(oneSigner);

expect(signers).toHaveLength(1);
});
it('should extract two code signer', () => {
const signers = extractSigners(twoSigners);

expect(signers).toHaveLength(2);
});
});
12 changes: 10 additions & 2 deletions src/util/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ export const collapseSpaces = (input: string) => input.replace(/\s+/g, ' ');
export const stripNewLines = (input: string) =>
input.replace(/\r\n|\n|\r/g, ' ');

const COMMA_PLACEHOLDER = '<COMMA>';

export const generateSchema = (argsDefinition: string) =>
argsDefinition
.replace(/\(([^()]+)\)/g, (match) => {
// Replace commas with placeholder inside the parentheses content
return match.replace(/,/g, COMMA_PLACEHOLDER);
})
.split(',')
.map((item) => item.replace(/\s*/g, ''))
.map((item) =>
item.replace(/\s*/g, '').replace(new RegExp(COMMA_PLACEHOLDER, 'g'), ','),
)
.filter((item) => item !== '');

export const stripComments = (code: string) => {
Expand All @@ -32,5 +40,5 @@ export const extract = (code: string, keyWord: string) => {
};

export const extractSigners = (code: string) => {
return extract(code, `(?:prepare\\s*\\(\\s*)([^\\)]*)(?:\\))`);
return extract(code, `(?:prepare\\s*\\(\\s*)([^{}]*)(?:\\))`);
};
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compileOnSave": false,
"compilerOptions": {
"types": ["node"],
"types": ["node", "jest"],
"target": "es6",
"module": "esnext",
"jsx": "react",
Expand Down

0 comments on commit 2ded248

Please sign in to comment.