Skip to content

Commit c428344

Browse files
ts: Remove usage of assert (otter-sec#2535)
1 parent 1dd3c00 commit c428344

16 files changed

Lines changed: 15 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ The minor version will be incremented upon a breaking change and the patch versi
1414

1515
### Fixes
1616

17+
- ts: Packages no longer depend on `assert` ([#2535](https://github.com/coral-xyz/anchor/pull/2535)).
18+
1719
### Breaking
1820

1921
## [0.28.0] - 2023-06-09

ts/packages/anchor/rollup.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import nodeResolve from "@rollup/plugin-node-resolve";
22
import typescript from "@rollup/plugin-typescript";
33
import replace from "@rollup/plugin-replace";
44
import commonjs from "@rollup/plugin-commonjs";
5-
import { terser } from "rollup-plugin-terser";
65

76
const env = process.env.NODE_ENV;
87

@@ -34,7 +33,6 @@ export default {
3433
external: [
3534
"@coral-xyz/borsh",
3635
"@solana/web3.js",
37-
"assert",
3836
"base64-js",
3937
"bn.js",
4038
"bs58",

ts/packages/anchor/src/program/event.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { PublicKey } from "@solana/web3.js";
2-
import * as assert from "assert";
32
import { IdlEvent, IdlEventField } from "../idl.js";
43
import { Coder } from "../coder/index.js";
54
import { DecodeType } from "./namespace/types.js";
@@ -144,8 +143,13 @@ export class EventManager {
144143
}
145144

146145
// Kill the websocket connection if all listeners have been removed.
147-
if (this._eventCallbacks.size == 0) {
148-
assert.ok(this._eventListeners.size === 0);
146+
if (this._eventCallbacks.size === 0) {
147+
if (this._eventListeners.size !== 0) {
148+
throw new Error(
149+
`Expected event listeners size to be 0 but got ${this._eventListeners.size}`
150+
);
151+
}
152+
149153
if (this._onLogsSubscriptionId !== undefined) {
150154
await this._provider!.connection.removeOnLogsListener(
151155
this._onLogsSubscriptionId
@@ -273,7 +277,9 @@ class ExecutionContext {
273277
stack: string[] = [];
274278

275279
program(): string {
276-
assert.ok(this.stack.length > 0);
280+
if (!this.stack.length) {
281+
throw new Error("Expected the stack to have elements");
282+
}
277283
return this.stack[this.stack.length - 1];
278284
}
279285

@@ -282,7 +288,9 @@ class ExecutionContext {
282288
}
283289

284290
pop() {
285-
assert.ok(this.stack.length > 0);
291+
if (!this.stack.length) {
292+
throw new Error("Expected the stack to have elements");
293+
}
286294
this.stack.pop();
287295
}
288296
}

ts/packages/spl-associated-token-account/rollup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default {
3535
external: [
3636
"@coral-xyz/borsh",
3737
"@solana/web3.js",
38-
"assert",
3938
"base64-js",
4039
"bn.js",
4140
"bs58",

ts/packages/spl-binary-option/rollup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default {
3535
external: [
3636
"@coral-xyz/borsh",
3737
"@solana/web3.js",
38-
"assert",
3938
"base64-js",
4039
"bn.js",
4140
"bs58",

ts/packages/spl-binary-oracle-pair/rollup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default {
3535
external: [
3636
"@coral-xyz/borsh",
3737
"@solana/web3.js",
38-
"assert",
3938
"base64-js",
4039
"bn.js",
4140
"bs58",

ts/packages/spl-feature-proposal/rollup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default {
3535
external: [
3636
"@coral-xyz/borsh",
3737
"@solana/web3.js",
38-
"assert",
3938
"base64-js",
4039
"bn.js",
4140
"bs58",

ts/packages/spl-governance/rollup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default {
3535
external: [
3636
"@coral-xyz/borsh",
3737
"@solana/web3.js",
38-
"assert",
3938
"base64-js",
4039
"bn.js",
4140
"bs58",

ts/packages/spl-memo/rollup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default {
3535
external: [
3636
"@coral-xyz/borsh",
3737
"@solana/web3.js",
38-
"assert",
3938
"base64-js",
4039
"bn.js",
4140
"bs58",

ts/packages/spl-name-service/rollup.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default {
3535
external: [
3636
"@coral-xyz/borsh",
3737
"@solana/web3.js",
38-
"assert",
3938
"base64-js",
4039
"bn.js",
4140
"bs58",

0 commit comments

Comments
 (0)