Skip to content

Commit

Permalink
Fix missing await before callMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
learnforpractice committed Nov 29, 2022
1 parent 369acf9 commit fd774eb
Show file tree
Hide file tree
Showing 5 changed files with 672 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pr-any.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: PR
on:
pull_request:
push:
branches: [ master ]
branches: [ master, debugging ]
tags:
- "v*.*.*"

Expand Down Expand Up @@ -41,6 +41,8 @@ jobs:
run: |
yarn install --immutable | grep -v 'YN0013'
PYTHON_SHARED_LIB_PATH=${{ env.pythonLocation }}/lib/libpython3.9.so yarn ${{ matrix.step }}
- name: Setup upterm session
uses: lhotari/action-upterm@v1
- name: publish chaintester & as-contract & as-chain
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu-20.04' }}
run:
Expand Down
11 changes: 5 additions & 6 deletions ts-packages/chaintester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ it('test hello', async () => {
let tester = new ChainTester();
await tester.init();
try {
let ret = await tester.deployContract("hello", "./assembly/target/counter.wasm", "./assembly/target/counter.abi");
expect(ret.except).toBeUndefined();
await tester.deployContract("hello", "./assembly/target/counter.wasm", "./assembly/target/counter.abi");

ret = await tester.pushAction("hello", "inc", {}, {"hello": "active"});
expect(ret.except).toBeUndefined();
await tester.pushAction("hello", "inc", {}, {"hello": "active"});
await tester.produceBlock();

await tester.pushAction("hello", "inc", {}, {"hello": "active"});
await tester.produceBlock();
ret = await tester.pushAction("hello", "inc", {}, {"hello": "active"});
expect(ret.except).toBeUndefined();
} finally {
await tester.free();
}
Expand Down
4 changes: 2 additions & 2 deletions ts-packages/chaintester/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"devDependencies": {
"@types/jest": "^28.1.6",
"@types/node": "^18.7.1",
"jest": "^28.1.3",
"ts-jest": "^28.0.7",
"jest": "^29.3.1",
"ts-jest": "^29.0.3",
"typescript": "^4.7.4"
}
}
22 changes: 15 additions & 7 deletions ts-packages/chaintester/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ interface PushTransactionReturn {
elapsed: number;
}

class ChainException extends Error {
json: object;
constructor(ret: object) {
super(JSON.stringify(ret, null, 2));
this.json = ret
}
}

export class ChainTester {
id: number;
initialize: Promise<number>;
Expand Down Expand Up @@ -103,7 +111,7 @@ export class ChainTester {
}

async createAccount(creator: string, account: string, owner_key: string, active_key: string, ram_bytes: number = 5 * 1024 * 1024, stake_net: number = 0, stake_cpu: number = 0) {
let ret = this.callMethod('create_account', {
let ret = await this.callMethod('create_account', {
id: this.id,
creator,
account,
Expand All @@ -117,7 +125,7 @@ export class ChainTester {

let except = ret['except'];
if (except) {
throw new Error(except);
throw new ChainException(ret);
}

return new Promise((resolve) => {
Expand All @@ -137,7 +145,7 @@ export class ChainTester {
});
let except = ret['except'];
if (except) {
throw new Error(JSON.stringify(except, null, 2));
throw new ChainException(ret);
}

return new Promise((resolve) => {
Expand All @@ -146,7 +154,7 @@ export class ChainTester {
}

async pushAction(account: string, action: string, args: object, permissions: object): Promise<PushTransactionReturn> {
let ret = this.callMethod('push_action', {
let ret = await this.callMethod('push_action', {
id: this.id,
account: account,
action: action,
Expand All @@ -156,7 +164,7 @@ export class ChainTester {

let except = ret['except'];
if (except) {
throw new Error(except);
throw new ChainException(ret);
}

return new Promise((resolve) => {
Expand All @@ -165,14 +173,14 @@ export class ChainTester {
}

async pushActions(actions: Action[]): Promise<PushTransactionReturn>{
let ret = this.callMethod('push_actions', {
let ret = await this.callMethod('push_actions', {
id: this.id,
actions: JSON.stringify(actions),
});

let except = ret['except'];
if (except) {
throw new Error(except);
throw new ChainException(ret);
}

return new Promise((resolve) => {
Expand Down
Loading

0 comments on commit fd774eb

Please sign in to comment.