Skip to content

Commit

Permalink
Validate the value of the arguments before sending the transaction (#840
Browse files Browse the repository at this point in the history
)
  • Loading branch information
osipov-mit authored Jul 18, 2022
1 parent cd7d836 commit 56d556b
Show file tree
Hide file tree
Showing 39 changed files with 1,303 additions and 934 deletions.
44 changes: 44 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"root": true,
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"indent": [
"warn",
2,
{
"SwitchCase": 1,
"flatTernaryExpressions": false
}
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"warn",
"single"
],
"semi": [
"error",
"always"
],
"@typescript-eslint/no-empty-function": 0,
"no-case-declarations": 0
}
}
14 changes: 8 additions & 6 deletions .github/workflows/CI-CD-gear-js-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ jobs:
- name: Prepare
run: |
wget -O ./gear-node https://github.com/gear-tech/gear/releases/download/build/gear-node
mkdir api/test/wasm/examples
wget -O api/test/wasm/examples/examples.tar.gz https://github.com/gear-tech/gear/releases/download/build/examples.tar.gz
chmod +x gear-node
./gear-node --dev --tmp --pruning archive & sleep 10
- name: Unpack gear-examples
working-directory: api/test/wasm/examples
run: tar -xvf examples.tar.gz
- name: Download gear examples
working-directory: api/test/wasm
run: |
mkdir examples
cd examples
wget -O ./examples.tar.gz https://github.com/gear-tech/gear/releases/download/build/examples.tar.gz
tar -xvf examples.tar.gz
- name: Run tests
working-directory: api
Expand All @@ -51,7 +53,7 @@ jobs:
if: ${{ contains(github.event.*.labels.*.name, 'api') }}
working-directory: api/examples
run: |
npm install
npm install --no-package-lock
npm run build
publish-to-npm:
Expand Down
22 changes: 22 additions & 0 deletions api/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": ["warn", 2, { "SwitchCase": 1, "flatTernaryExpressions": false }],
"linebreak-style": ["error", "unix"],
"quotes": ["warn", "single"],
"semi": ["error", "always"],
"@typescript-eslint/no-empty-function": 0,
"no-case-declarations": 0
}
}
22 changes: 0 additions & 22 deletions api/.eslintrc.cjs

This file was deleted.

15 changes: 15 additions & 0 deletions api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## 0.23.4

_07/18/2022_

https://github.com/gear-tech/gear-js/pull/840

### Changes

- Rename `api.program.is` method to `api.program.exists`
- Add validation of gasLimit, value and codeId before sending transactions
- `api.code.submit` method is now async
- Add get some runtime constants (`existentialDeposit`, `blockGasLimit`, `mailboxTreshold`, `waitlistCost`)
- Add eslint config

---
## 0.23.3

_07/12/2022_
Expand Down
6 changes: 2 additions & 4 deletions api/examples/package-lock.json

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

6 changes: 3 additions & 3 deletions api/examples/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "examples",
"version": "1.0.0",
"description": "To run examples run",
"description": "Examples of using @gear-js/api library",
"main": "meta.js",
"scripts": {
"build": "tsc",
Expand All @@ -13,12 +13,12 @@
"code:submit": "ts-node src/program/submitCode.ts"
},
"author": "",
"license": "ISC",
"license": "GPL-3.0",
"dependencies": {
"@gear-js/api": "file:../",
"@polkadot/api": "8.9.1",
"dotenv": "^16.0.0",
"rxjs": "^7.5.5",
"ts-node": "^10.4.0"
}
}
}
2 changes: 1 addition & 1 deletion api/examples/src/message/claimValue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GearApi, GearKeyring } from '@gear-js/api';
import { GearApi, GearKeyring } from '../../../lib';

const main = async () => {
const api = await GearApi.create();
Expand Down
2 changes: 1 addition & 1 deletion api/examples/src/message/readMailbox.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GearApi, GearKeyring } from '@gear-js/api';
import { GearApi, GearKeyring } from '../../../lib';

const main = async () => {
const api = await GearApi.create();
Expand Down
2 changes: 1 addition & 1 deletion api/examples/src/message/sendMessage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GearApi, GearKeyring, getWasmMetadata, MessageEnqueued, Hex } from '@gear-js/api';
import { GearApi, GearKeyring, getWasmMetadata, MessageEnqueued, Hex } from '../../../lib';
import { readFileSync } from 'fs';
import { PATH_TO_META } from '../config';
import { waitForReply } from './waitForReply';
Expand Down
2 changes: 1 addition & 1 deletion api/examples/src/message/waitForReply.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GearApi, UserMessageSent } from '@gear-js/api';
import { GearApi, UserMessageSent } from '../../../lib';

export function waitForReply(api: GearApi, programId: string): (messageId: string) => Promise<UserMessageSent> {
const messages = {};
Expand Down
4 changes: 2 additions & 2 deletions api/examples/src/program/submitCode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GearApi, GearKeyring } from '@gear-js/api';
import { GearApi, GearKeyring } from '../../../lib';
import { readFileSync } from 'fs';
import { PATH_TO_OPT } from '../config';

Expand All @@ -9,7 +9,7 @@ const main = async () => {

const code = readFileSync(PATH_TO_OPT);

const { codeHash } = api.code.submit(code);
const { codeHash } = await api.code.submit(code);

console.log(`CodeHash: ${codeHash}\n`);

Expand Down
2 changes: 1 addition & 1 deletion api/examples/src/program/uploadProgram.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GearApi, GearKeyring, getWasmMetadata } from '@gear-js/api';
import { GearApi, GearKeyring, getWasmMetadata } from '../../../lib';
import { readFileSync } from 'fs';
import { PATH_TO_META, PATH_TO_OPT } from '../config';
import { waitForInit } from './waitForInit';
Expand Down
2 changes: 1 addition & 1 deletion api/examples/src/program/waitForInit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GearApi, Hex, MessageEnqueued, ProgramChanged, UserMessageSent } from '@gear-js/api';
import { GearApi, Hex, MessageEnqueued, ProgramChanged, UserMessageSent } from '../../../lib';
import { UnsubscribePromise } from '@polkadot/api/types';

export function waitForInit(api: GearApi, programId: string): Promise<UnsubscribePromise> {
Expand Down
2 changes: 1 addition & 1 deletion api/examples/src/state/readState.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GearApi, Hex } from '@gear-js/api';
import { GearApi, Hex } from '../../../lib';
import { readFileSync } from 'fs';
import { PATH_TO_META } from '../config';

Expand Down
Loading

0 comments on commit 56d556b

Please sign in to comment.