ts: Check if execution context stack is empty in event parser (#524)
This commit is contained in:
parent
a65665f476
commit
ab49478259
|
@ -44,6 +44,7 @@ jobs:
|
||||||
- cargo fmt -- --check
|
- cargo fmt -- --check
|
||||||
- cargo clippy --all-targets -- -D warnings
|
- cargo clippy --all-targets -- -D warnings
|
||||||
- cargo test
|
- cargo test
|
||||||
|
- pushd ts && yarn && yarn test && popd
|
||||||
- <<: *examples
|
- <<: *examples
|
||||||
name: Runs the examples 1
|
name: Runs the examples 1
|
||||||
script:
|
script:
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
"lint:fix": "prettier src/** -w",
|
"lint:fix": "prettier src/** -w",
|
||||||
"watch": "tsc -p tsconfig.cjs.json --watch",
|
"watch": "tsc -p tsconfig.cjs.json --watch",
|
||||||
"prepublishOnly": "yarn build",
|
"prepublishOnly": "yarn build",
|
||||||
"docs": "typedoc --excludePrivate --includeVersion --out ../docs/src/.vuepress/dist/ts/ --readme none src/index.ts"
|
"docs": "typedoc --excludePrivate --includeVersion --out ../docs/src/.vuepress/dist/ts/ --readme none src/index.ts",
|
||||||
|
"test": "jest tests --detectOpenHandles"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@project-serum/borsh": "^0.2.2",
|
"@project-serum/borsh": "^0.2.2",
|
||||||
|
|
|
@ -58,7 +58,7 @@ export class EventParser {
|
||||||
log: string
|
log: string
|
||||||
): [Event | null, string | null, boolean] {
|
): [Event | null, string | null, boolean] {
|
||||||
// Executing program is this program.
|
// Executing program is this program.
|
||||||
if (execution.program() === this.programId.toString()) {
|
if (execution.stack.length > 0 && execution.program() === this.programId.toString()) {
|
||||||
return this.handleProgramLog(log);
|
return this.handleProgramLog(log);
|
||||||
}
|
}
|
||||||
// Executing program is not this program.
|
// Executing program is not this program.
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
import { PublicKey } from "@solana/web3.js";
|
||||||
|
import { EventParser } from "../src/program/event";
|
||||||
|
import { Coder } from "../src";
|
||||||
|
|
||||||
|
describe("Events", () => {
|
||||||
|
it("Parses multiple instructions", async () => {
|
||||||
|
const logs = [
|
||||||
|
"Program 11111111111111111111111111111111 invoke [1]",
|
||||||
|
"Program 11111111111111111111111111111111 success",
|
||||||
|
"Program J2XMGdW2qQLx7rAdwWtSZpTXDgAQ988BLP9QTgUZvm54 invoke [1]",
|
||||||
|
"Program J2XMGdW2qQLx7rAdwWtSZpTXDgAQ988BLP9QTgUZvm54 consumed 17867 of 200000 compute units",
|
||||||
|
"Program J2XMGdW2qQLx7rAdwWtSZpTXDgAQ988BLP9QTgUZvm54 success",
|
||||||
|
];
|
||||||
|
const idl = {
|
||||||
|
version: "0.0.0",
|
||||||
|
name: "basic_0",
|
||||||
|
instructions: [
|
||||||
|
{
|
||||||
|
name: "initialize",
|
||||||
|
accounts: [],
|
||||||
|
args: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const coder = new Coder(idl);
|
||||||
|
const programId = PublicKey.default;
|
||||||
|
const eventParser = new EventParser(coder, programId);
|
||||||
|
|
||||||
|
eventParser.parseLogs(logs, () => {
|
||||||
|
throw new Error("Should never find logs");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue