@sovereign-sdk/test 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,188 @@
1
+ import { BaseTypeSpec, Rollup } from '@sovereign-sdk/web3';
2
+ import SovereignSDK from '@sovereign-sdk/client';
3
+ import { Signer } from '@sovereign-sdk/signers';
4
+
5
+ /** Response data type from a transaction submission */
6
+ type TxResult = SovereignSDK.Sequencer.TxCreateResponse.Data;
7
+ /**
8
+ * Possible outcomes for a generated transaction.
9
+ * Used to control whether the transaction should succeed or fail.
10
+ */
11
+ declare enum Outcome {
12
+ /** Transaction should be generated to succeed */
13
+ Success = 0,
14
+ /** Transaction should be generated to fail */
15
+ Failure = 1
16
+ }
17
+ /**
18
+ * Represents a generated transaction input with its associated metadata.
19
+ * @template S - The type specification for the rollup being tested
20
+ */
21
+ type GeneratedInput<S extends BaseTypeSpec> = {
22
+ /** The unsigned transaction to be submitted */
23
+ unsignedTransaction: S["UnsignedTransaction"];
24
+ /** The signer to use for signing the transaction */
25
+ signer: Signer;
26
+ /**
27
+ * Optional callback to be executed after the transaction is onSubmitted
28
+ * This function is passed the transaction receipt along with events and
29
+ * other result related data - it can be used to assert the output of the provided
30
+ * input.
31
+ */
32
+ onSubmitted?: (result: TxResult) => Promise<void>;
33
+ };
34
+ /**
35
+ * Represents a generated transaction with its expected outcome.
36
+ * This is returned by generator strategies to indicate both the transaction
37
+ * and whether it should succeed or fail.
38
+ */
39
+ type InputWithExpectation<S extends BaseTypeSpec> = {
40
+ /** The generated transaction input */
41
+ input: GeneratedInput<S>;
42
+ /** The expected outcome of the transaction */
43
+ expectedOutcome: Outcome;
44
+ };
45
+ /**
46
+ * Interface for generating individual test transactions.
47
+ * Implementations should create transactions that can either succeed or fail
48
+ * based on the provided outcome.
49
+ *
50
+ * @template S - The type specification for the rollup being tested
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * class CustomGenerator implements TransactionGenerator<YourTypeSpec> {
55
+ * async successful(): Promise<GeneratedInput<YourTypeSpec>> {
56
+ * // Generate transaction based on outcome
57
+ * return {
58
+ * unsignedTransaction: {},
59
+ * signer: {},
60
+ * onSubmitted: async (result) => {
61
+ * // Handle submission result
62
+ * }
63
+ * };
64
+ * }
65
+ * }
66
+ * ```
67
+ */
68
+ declare abstract class TransactionGenerator<S extends BaseTypeSpec> {
69
+ /**
70
+ * Generate a single test transaction that should succeed.
71
+ * @returns A promise that resolves to the generated transaction input
72
+ */
73
+ successful(): Promise<GeneratedInput<S>>;
74
+ /**
75
+ * Generate a single test transaction that should fail.
76
+ * @returns A promise that resolves to the generated transaction input
77
+ */
78
+ failure(): Promise<GeneratedInput<S>>;
79
+ }
80
+ /**
81
+ * Interface for generating batches of test transactions.
82
+ * Implementations should create multiple transactions according to the specified amount.
83
+ *
84
+ * @template S - The type specification for the rollup being tested
85
+ */
86
+ interface GeneratorStrategy<S extends BaseTypeSpec> {
87
+ /**
88
+ * Generates a batch of test transactions.
89
+ * @param amount - The number of transactions to generate
90
+ * @returns A promise that resolves to an array of generated transactions with their expected outcomes
91
+ */
92
+ generate(amount: number): Promise<InputWithExpectation<S>[]>;
93
+ }
94
+ /**
95
+ * A basic implementation of GeneratorStrategy that generates a fixed number of
96
+ * transactions that always succeed using a singular TransactionGenerator.
97
+ *
98
+ * @template S - The type specification for the rollup being tested
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const generator = new YourTransactionGenerator();
103
+ * const strategy = new BasicGeneratorStrategy(generator);
104
+ * const transactions = await strategy.generate(100);
105
+ * ```
106
+ */
107
+ declare class BasicGeneratorStrategy<S extends BaseTypeSpec> implements GeneratorStrategy<S> {
108
+ private readonly generator;
109
+ /**
110
+ * Creates a new BasicGeneratorStrategy instance.
111
+ * @param generator - The transaction generator to use for creating individual transactions
112
+ */
113
+ constructor(generator: TransactionGenerator<S>);
114
+ /**
115
+ * Generates a batch of test transactions using the configured generator.
116
+ * All transactions are generated with Outcome.Success.
117
+ *
118
+ * @param amount - The number of transactions to generate
119
+ * @returns A promise that resolves to an array of generated transactions with their expected outcomes
120
+ */
121
+ generate(amount: number): Promise<InputWithExpectation<S>[]>;
122
+ }
123
+
124
+ /**
125
+ * Configuration options for creating a new TestRunner instance.
126
+ * @template S - The type specification for the rollup being tested
127
+ */
128
+ interface TestOptions<S extends BaseTypeSpec> {
129
+ /** Maximum number of concurrent transactions to run (default: 30) */
130
+ concurrency?: number;
131
+ /** Strategy for generating test transactions */
132
+ generator: GeneratorStrategy<S>;
133
+ /** The rollup instance to test against */
134
+ rollup: Rollup<S, any>;
135
+ }
136
+ /**
137
+ * A class for running soak tests against a Sovereign rollup.
138
+ * Manages concurrent transaction execution and provides control over test execution.
139
+ *
140
+ * @template S - The type specification for the rollup being tested
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const runner = new TestRunner({
145
+ * rollup: new YourRollup(),
146
+ * generator: new YourGeneratorStrategy(),
147
+ * concurrency: 30
148
+ * });
149
+ *
150
+ * // Start the test
151
+ * await runner.run();
152
+ *
153
+ * // Stop the test when needed
154
+ * await runner.stop();
155
+ * ```
156
+ */
157
+ declare class TestRunner<S extends BaseTypeSpec> {
158
+ private controller;
159
+ private readonly concurrency;
160
+ private readonly queue;
161
+ private readonly rollup;
162
+ private readonly generator;
163
+ /**
164
+ * Creates a new TestRunner instance.
165
+ * @param options - Configuration options for the test runner
166
+ */
167
+ constructor({ rollup, generator, concurrency }: TestOptions<S>);
168
+ /**
169
+ * Starts the soak test. This will begin generating and submitting transactions
170
+ * according to the configured generator strategy and concurrency settings.
171
+ *
172
+ * The test will continue running until explicitly stopped using the stop() method.
173
+ */
174
+ run(): Promise<void>;
175
+ /**
176
+ * Stops the soak test. This will abort any pending transactions and prevent
177
+ * new transactions from being generated.
178
+ */
179
+ stop(): Promise<void>;
180
+ private doExecution;
181
+ private silenceNodeWarning;
182
+ }
183
+
184
+ declare class NotImplementedError extends Error {
185
+ constructor(symbol: string);
186
+ }
187
+
188
+ export { BasicGeneratorStrategy, type GeneratedInput, type GeneratorStrategy, type InputWithExpectation, NotImplementedError, Outcome, type TestOptions, TestRunner, TransactionGenerator, type TxResult };
@@ -0,0 +1,188 @@
1
+ import { BaseTypeSpec, Rollup } from '@sovereign-sdk/web3';
2
+ import SovereignSDK from '@sovereign-sdk/client';
3
+ import { Signer } from '@sovereign-sdk/signers';
4
+
5
+ /** Response data type from a transaction submission */
6
+ type TxResult = SovereignSDK.Sequencer.TxCreateResponse.Data;
7
+ /**
8
+ * Possible outcomes for a generated transaction.
9
+ * Used to control whether the transaction should succeed or fail.
10
+ */
11
+ declare enum Outcome {
12
+ /** Transaction should be generated to succeed */
13
+ Success = 0,
14
+ /** Transaction should be generated to fail */
15
+ Failure = 1
16
+ }
17
+ /**
18
+ * Represents a generated transaction input with its associated metadata.
19
+ * @template S - The type specification for the rollup being tested
20
+ */
21
+ type GeneratedInput<S extends BaseTypeSpec> = {
22
+ /** The unsigned transaction to be submitted */
23
+ unsignedTransaction: S["UnsignedTransaction"];
24
+ /** The signer to use for signing the transaction */
25
+ signer: Signer;
26
+ /**
27
+ * Optional callback to be executed after the transaction is onSubmitted
28
+ * This function is passed the transaction receipt along with events and
29
+ * other result related data - it can be used to assert the output of the provided
30
+ * input.
31
+ */
32
+ onSubmitted?: (result: TxResult) => Promise<void>;
33
+ };
34
+ /**
35
+ * Represents a generated transaction with its expected outcome.
36
+ * This is returned by generator strategies to indicate both the transaction
37
+ * and whether it should succeed or fail.
38
+ */
39
+ type InputWithExpectation<S extends BaseTypeSpec> = {
40
+ /** The generated transaction input */
41
+ input: GeneratedInput<S>;
42
+ /** The expected outcome of the transaction */
43
+ expectedOutcome: Outcome;
44
+ };
45
+ /**
46
+ * Interface for generating individual test transactions.
47
+ * Implementations should create transactions that can either succeed or fail
48
+ * based on the provided outcome.
49
+ *
50
+ * @template S - The type specification for the rollup being tested
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * class CustomGenerator implements TransactionGenerator<YourTypeSpec> {
55
+ * async successful(): Promise<GeneratedInput<YourTypeSpec>> {
56
+ * // Generate transaction based on outcome
57
+ * return {
58
+ * unsignedTransaction: {},
59
+ * signer: {},
60
+ * onSubmitted: async (result) => {
61
+ * // Handle submission result
62
+ * }
63
+ * };
64
+ * }
65
+ * }
66
+ * ```
67
+ */
68
+ declare abstract class TransactionGenerator<S extends BaseTypeSpec> {
69
+ /**
70
+ * Generate a single test transaction that should succeed.
71
+ * @returns A promise that resolves to the generated transaction input
72
+ */
73
+ successful(): Promise<GeneratedInput<S>>;
74
+ /**
75
+ * Generate a single test transaction that should fail.
76
+ * @returns A promise that resolves to the generated transaction input
77
+ */
78
+ failure(): Promise<GeneratedInput<S>>;
79
+ }
80
+ /**
81
+ * Interface for generating batches of test transactions.
82
+ * Implementations should create multiple transactions according to the specified amount.
83
+ *
84
+ * @template S - The type specification for the rollup being tested
85
+ */
86
+ interface GeneratorStrategy<S extends BaseTypeSpec> {
87
+ /**
88
+ * Generates a batch of test transactions.
89
+ * @param amount - The number of transactions to generate
90
+ * @returns A promise that resolves to an array of generated transactions with their expected outcomes
91
+ */
92
+ generate(amount: number): Promise<InputWithExpectation<S>[]>;
93
+ }
94
+ /**
95
+ * A basic implementation of GeneratorStrategy that generates a fixed number of
96
+ * transactions that always succeed using a singular TransactionGenerator.
97
+ *
98
+ * @template S - The type specification for the rollup being tested
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const generator = new YourTransactionGenerator();
103
+ * const strategy = new BasicGeneratorStrategy(generator);
104
+ * const transactions = await strategy.generate(100);
105
+ * ```
106
+ */
107
+ declare class BasicGeneratorStrategy<S extends BaseTypeSpec> implements GeneratorStrategy<S> {
108
+ private readonly generator;
109
+ /**
110
+ * Creates a new BasicGeneratorStrategy instance.
111
+ * @param generator - The transaction generator to use for creating individual transactions
112
+ */
113
+ constructor(generator: TransactionGenerator<S>);
114
+ /**
115
+ * Generates a batch of test transactions using the configured generator.
116
+ * All transactions are generated with Outcome.Success.
117
+ *
118
+ * @param amount - The number of transactions to generate
119
+ * @returns A promise that resolves to an array of generated transactions with their expected outcomes
120
+ */
121
+ generate(amount: number): Promise<InputWithExpectation<S>[]>;
122
+ }
123
+
124
+ /**
125
+ * Configuration options for creating a new TestRunner instance.
126
+ * @template S - The type specification for the rollup being tested
127
+ */
128
+ interface TestOptions<S extends BaseTypeSpec> {
129
+ /** Maximum number of concurrent transactions to run (default: 30) */
130
+ concurrency?: number;
131
+ /** Strategy for generating test transactions */
132
+ generator: GeneratorStrategy<S>;
133
+ /** The rollup instance to test against */
134
+ rollup: Rollup<S, any>;
135
+ }
136
+ /**
137
+ * A class for running soak tests against a Sovereign rollup.
138
+ * Manages concurrent transaction execution and provides control over test execution.
139
+ *
140
+ * @template S - The type specification for the rollup being tested
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const runner = new TestRunner({
145
+ * rollup: new YourRollup(),
146
+ * generator: new YourGeneratorStrategy(),
147
+ * concurrency: 30
148
+ * });
149
+ *
150
+ * // Start the test
151
+ * await runner.run();
152
+ *
153
+ * // Stop the test when needed
154
+ * await runner.stop();
155
+ * ```
156
+ */
157
+ declare class TestRunner<S extends BaseTypeSpec> {
158
+ private controller;
159
+ private readonly concurrency;
160
+ private readonly queue;
161
+ private readonly rollup;
162
+ private readonly generator;
163
+ /**
164
+ * Creates a new TestRunner instance.
165
+ * @param options - Configuration options for the test runner
166
+ */
167
+ constructor({ rollup, generator, concurrency }: TestOptions<S>);
168
+ /**
169
+ * Starts the soak test. This will begin generating and submitting transactions
170
+ * according to the configured generator strategy and concurrency settings.
171
+ *
172
+ * The test will continue running until explicitly stopped using the stop() method.
173
+ */
174
+ run(): Promise<void>;
175
+ /**
176
+ * Stops the soak test. This will abort any pending transactions and prevent
177
+ * new transactions from being generated.
178
+ */
179
+ stop(): Promise<void>;
180
+ private doExecution;
181
+ private silenceNodeWarning;
182
+ }
183
+
184
+ declare class NotImplementedError extends Error {
185
+ constructor(symbol: string);
186
+ }
187
+
188
+ export { BasicGeneratorStrategy, type GeneratedInput, type GeneratorStrategy, type InputWithExpectation, NotImplementedError, Outcome, type TestOptions, TestRunner, TransactionGenerator, type TxResult };
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
49
+
50
+ // src/soak/index.ts
51
+ var soak_exports = {};
52
+ __export(soak_exports, {
53
+ BasicGeneratorStrategy: () => BasicGeneratorStrategy,
54
+ NotImplementedError: () => NotImplementedError,
55
+ Outcome: () => Outcome,
56
+ TestRunner: () => TestRunner,
57
+ TransactionGenerator: () => TransactionGenerator
58
+ });
59
+ module.exports = __toCommonJS(soak_exports);
60
+
61
+ // src/soak/runner.ts
62
+ var import_p_queue = __toESM(require("p-queue"));
63
+ var TestRunner = class {
64
+ /**
65
+ * Creates a new TestRunner instance.
66
+ * @param options - Configuration options for the test runner
67
+ */
68
+ constructor({ rollup, generator, concurrency }) {
69
+ this.controller = new AbortController();
70
+ this.concurrency = concurrency != null ? concurrency : 30;
71
+ this.queue = new import_p_queue.default({ concurrency: this.concurrency });
72
+ this.rollup = rollup;
73
+ this.generator = generator;
74
+ }
75
+ /**
76
+ * Starts the soak test. This will begin generating and submitting transactions
77
+ * according to the configured generator strategy and concurrency settings.
78
+ *
79
+ * The test will continue running until explicitly stopped using the stop() method.
80
+ */
81
+ run() {
82
+ return __async(this, null, function* () {
83
+ yield this.silenceNodeWarning();
84
+ this.doExecution();
85
+ });
86
+ }
87
+ /**
88
+ * Stops the soak test. This will abort any pending transactions and prevent
89
+ * new transactions from being generated.
90
+ */
91
+ stop() {
92
+ return __async(this, null, function* () {
93
+ this.controller.abort();
94
+ });
95
+ }
96
+ doExecution() {
97
+ return __async(this, null, function* () {
98
+ if (this.controller.signal.aborted) return;
99
+ const controller = new AbortController();
100
+ const signal = controller.signal;
101
+ this.controller.signal.addEventListener("abort", controller.abort, {
102
+ once: true
103
+ });
104
+ const inputs = yield this.generator.generate(100);
105
+ const execution = inputs.map(({ input }) => {
106
+ return () => __async(this, null, function* () {
107
+ if (signal.aborted) return;
108
+ const { signer, unsignedTransaction, onSubmitted } = input;
109
+ const { response } = yield this.rollup.signAndSubmitTransaction(
110
+ unsignedTransaction,
111
+ { signer },
112
+ { signal }
113
+ );
114
+ if (onSubmitted) {
115
+ yield onSubmitted(response.data);
116
+ }
117
+ });
118
+ });
119
+ this.queue.addAll(execution);
120
+ yield this.queue.onSizeLessThan(this.concurrency);
121
+ this.controller.signal.removeEventListener("abort", controller.abort);
122
+ setTimeout(() => this.doExecution(), 100);
123
+ });
124
+ }
125
+ // Node emits a warning if there's more than 10 listeners by default
126
+ // to try detect listener leaks. This is nodejs specific, we're OK to ignore it.
127
+ silenceNodeWarning() {
128
+ return __async(this, null, function* () {
129
+ var _a;
130
+ if ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node) {
131
+ const events = yield import("events");
132
+ events.setMaxListeners(200);
133
+ }
134
+ });
135
+ }
136
+ };
137
+
138
+ // src/soak/errors.ts
139
+ var NotImplementedError = class extends Error {
140
+ constructor(symbol) {
141
+ super(`Not implemented: ${symbol}`);
142
+ this.name = "NotImplementedError";
143
+ }
144
+ };
145
+
146
+ // src/soak/generation.ts
147
+ var Outcome = /* @__PURE__ */ ((Outcome2) => {
148
+ Outcome2[Outcome2["Success"] = 0] = "Success";
149
+ Outcome2[Outcome2["Failure"] = 1] = "Failure";
150
+ return Outcome2;
151
+ })(Outcome || {});
152
+ var TransactionGenerator = class {
153
+ /**
154
+ * Generate a single test transaction that should succeed.
155
+ * @returns A promise that resolves to the generated transaction input
156
+ */
157
+ successful() {
158
+ throw new NotImplementedError("TransactionGenerator.successful");
159
+ }
160
+ /**
161
+ * Generate a single test transaction that should fail.
162
+ * @returns A promise that resolves to the generated transaction input
163
+ */
164
+ failure() {
165
+ throw new NotImplementedError("TransactionGenerator.failure");
166
+ }
167
+ };
168
+ var BasicGeneratorStrategy = class {
169
+ /**
170
+ * Creates a new BasicGeneratorStrategy instance.
171
+ * @param generator - The transaction generator to use for creating individual transactions
172
+ */
173
+ constructor(generator) {
174
+ this.generator = generator;
175
+ }
176
+ /**
177
+ * Generates a batch of test transactions using the configured generator.
178
+ * All transactions are generated with Outcome.Success.
179
+ *
180
+ * @param amount - The number of transactions to generate
181
+ * @returns A promise that resolves to an array of generated transactions with their expected outcomes
182
+ */
183
+ generate(amount) {
184
+ return __async(this, null, function* () {
185
+ const promises = [];
186
+ for (let i = 0; i <= amount; i += 1) {
187
+ promises.push(this.generator.successful());
188
+ }
189
+ const inputs = yield Promise.all(promises);
190
+ return inputs.map((input) => ({
191
+ input,
192
+ expectedOutcome: 0 /* Success */
193
+ }));
194
+ });
195
+ }
196
+ };
197
+ // Annotate the CommonJS export names for ESM import in node:
198
+ 0 && (module.exports = {
199
+ BasicGeneratorStrategy,
200
+ NotImplementedError,
201
+ Outcome,
202
+ TestRunner,
203
+ TransactionGenerator
204
+ });
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/soak/index.ts","../../src/soak/runner.ts","../../src/soak/errors.ts","../../src/soak/generation.ts"],"sourcesContent":["export * from \"./runner\";\nexport * from \"./generation\";\nexport * from \"./errors\";\n","import type { BaseTypeSpec, Rollup } from \"@sovereign-sdk/web3\";\nimport PQueue from \"p-queue\";\nimport type { GeneratorStrategy } from \"./generation\";\n\n/**\n * Configuration options for creating a new TestRunner instance.\n * @template S - The type specification for the rollup being tested\n */\nexport interface TestOptions<S extends BaseTypeSpec> {\n /** Maximum number of concurrent transactions to run (default: 30) */\n concurrency?: number;\n /** Strategy for generating test transactions */\n generator: GeneratorStrategy<S>;\n /** The rollup instance to test against */\n // biome-ignore lint/suspicious/noExplicitAny: generic not need\n rollup: Rollup<S, any>;\n}\n\n/**\n * A class for running soak tests against a Sovereign rollup.\n * Manages concurrent transaction execution and provides control over test execution.\n *\n * @template S - The type specification for the rollup being tested\n *\n * @example\n * ```typescript\n * const runner = new TestRunner({\n * rollup: new YourRollup(),\n * generator: new YourGeneratorStrategy(),\n * concurrency: 30\n * });\n *\n * // Start the test\n * await runner.run();\n *\n * // Stop the test when needed\n * await runner.stop();\n * ```\n */\nexport class TestRunner<S extends BaseTypeSpec> {\n private controller: AbortController;\n private readonly concurrency: number;\n private readonly queue: PQueue;\n // biome-ignore lint/suspicious/noExplicitAny: generic not need\n private readonly rollup: Rollup<S, any>;\n private readonly generator: GeneratorStrategy<S>;\n\n /**\n * Creates a new TestRunner instance.\n * @param options - Configuration options for the test runner\n */\n constructor({ rollup, generator, concurrency }: TestOptions<S>) {\n this.controller = new AbortController();\n this.concurrency = concurrency ?? 30;\n this.queue = new PQueue({ concurrency: this.concurrency });\n this.rollup = rollup;\n this.generator = generator;\n }\n\n /**\n * Starts the soak test. This will begin generating and submitting transactions\n * according to the configured generator strategy and concurrency settings.\n *\n * The test will continue running until explicitly stopped using the stop() method.\n */\n async run(): Promise<void> {\n await this.silenceNodeWarning();\n this.doExecution();\n }\n\n /**\n * Stops the soak test. This will abort any pending transactions and prevent\n * new transactions from being generated.\n */\n async stop(): Promise<void> {\n this.controller.abort();\n }\n\n private async doExecution(): Promise<void> {\n if (this.controller.signal.aborted) return;\n\n // create a child abort signal per batch because there's no way\n // to clean up abort listeners, this prevents them building up and leaking\n const controller = new AbortController();\n const signal = controller.signal;\n this.controller.signal.addEventListener(\"abort\", controller.abort, {\n once: true,\n });\n\n const inputs = await this.generator.generate(100);\n // TODO: check expectedOutcome with what the rollup actually returns\n const execution = inputs.map(({ input }) => {\n return async () => {\n if (signal.aborted) return;\n\n const { signer, unsignedTransaction, onSubmitted } = input;\n // TODO: handle abort error\n const { response } = await this.rollup.signAndSubmitTransaction(\n unsignedTransaction,\n { signer },\n { signal },\n );\n\n if (onSubmitted) {\n // TODO: handle errors\n await onSubmitted(response.data);\n }\n };\n });\n\n this.queue.addAll(execution);\n await this.queue.onSizeLessThan(this.concurrency);\n\n // clean-up listener to prevent listener leak on top-level abort controller\n this.controller.signal.removeEventListener(\"abort\", controller.abort);\n\n setTimeout(() => this.doExecution(), 100);\n }\n\n // Node emits a warning if there's more than 10 listeners by default\n // to try detect listener leaks. This is nodejs specific, we're OK to ignore it.\n private async silenceNodeWarning(): Promise<void> {\n if (process?.versions?.node) {\n const events = await import(\"node:events\");\n // biome-ignore lint/suspicious/noExplicitAny: node specific\n (events as any).setMaxListeners(200);\n }\n }\n}\n","export class NotImplementedError extends Error {\n constructor(symbol: string) {\n super(`Not implemented: ${symbol}`);\n this.name = \"NotImplementedError\";\n }\n}\n","import type SovereignSDK from \"@sovereign-sdk/client\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport type { BaseTypeSpec } from \"@sovereign-sdk/web3\";\nimport { NotImplementedError } from \"./errors\";\n\n/** Response data type from a transaction submission */\nexport type TxResult = SovereignSDK.Sequencer.TxCreateResponse.Data;\n\n/**\n * Possible outcomes for a generated transaction.\n * Used to control whether the transaction should succeed or fail.\n */\nexport enum Outcome {\n /** Transaction should be generated to succeed */\n Success = 0,\n /** Transaction should be generated to fail */\n Failure = 1,\n}\n\n/**\n * Represents a generated transaction input with its associated metadata.\n * @template S - The type specification for the rollup being tested\n */\nexport type GeneratedInput<S extends BaseTypeSpec> = {\n /** The unsigned transaction to be submitted */\n unsignedTransaction: S[\"UnsignedTransaction\"];\n /** The signer to use for signing the transaction */\n signer: Signer;\n /**\n * Optional callback to be executed after the transaction is onSubmitted\n * This function is passed the transaction receipt along with events and\n * other result related data - it can be used to assert the output of the provided\n * input.\n */\n onSubmitted?: (result: TxResult) => Promise<void>;\n};\n\n/**\n * Represents a generated transaction with its expected outcome.\n * This is returned by generator strategies to indicate both the transaction\n * and whether it should succeed or fail.\n */\nexport type InputWithExpectation<S extends BaseTypeSpec> = {\n /** The generated transaction input */\n input: GeneratedInput<S>;\n /** The expected outcome of the transaction */\n expectedOutcome: Outcome;\n};\n\n/**\n * Interface for generating individual test transactions.\n * Implementations should create transactions that can either succeed or fail\n * based on the provided outcome.\n *\n * @template S - The type specification for the rollup being tested\n *\n * @example\n * ```typescript\n * class CustomGenerator implements TransactionGenerator<YourTypeSpec> {\n * async successful(): Promise<GeneratedInput<YourTypeSpec>> {\n * // Generate transaction based on outcome\n * return {\n * unsignedTransaction: {},\n * signer: {},\n * onSubmitted: async (result) => {\n * // Handle submission result\n * }\n * };\n * }\n * }\n * ```\n */\nexport abstract class TransactionGenerator<S extends BaseTypeSpec> {\n /**\n * Generate a single test transaction that should succeed.\n * @returns A promise that resolves to the generated transaction input\n */\n successful(): Promise<GeneratedInput<S>> {\n throw new NotImplementedError(\"TransactionGenerator.successful\");\n }\n\n /**\n * Generate a single test transaction that should fail.\n * @returns A promise that resolves to the generated transaction input\n */\n failure(): Promise<GeneratedInput<S>> {\n throw new NotImplementedError(\"TransactionGenerator.failure\");\n }\n}\n\n/**\n * Interface for generating batches of test transactions.\n * Implementations should create multiple transactions according to the specified amount.\n *\n * @template S - The type specification for the rollup being tested\n */\nexport interface GeneratorStrategy<S extends BaseTypeSpec> {\n /**\n * Generates a batch of test transactions.\n * @param amount - The number of transactions to generate\n * @returns A promise that resolves to an array of generated transactions with their expected outcomes\n */\n generate(amount: number): Promise<InputWithExpectation<S>[]>;\n}\n\n/**\n * A basic implementation of GeneratorStrategy that generates a fixed number of\n * transactions that always succeed using a singular TransactionGenerator.\n *\n * @template S - The type specification for the rollup being tested\n *\n * @example\n * ```typescript\n * const generator = new YourTransactionGenerator();\n * const strategy = new BasicGeneratorStrategy(generator);\n * const transactions = await strategy.generate(100);\n * ```\n */\nexport class BasicGeneratorStrategy<S extends BaseTypeSpec>\n implements GeneratorStrategy<S>\n{\n private readonly generator: TransactionGenerator<S>;\n\n /**\n * Creates a new BasicGeneratorStrategy instance.\n * @param generator - The transaction generator to use for creating individual transactions\n */\n constructor(generator: TransactionGenerator<S>) {\n this.generator = generator;\n }\n\n /**\n * Generates a batch of test transactions using the configured generator.\n * All transactions are generated with Outcome.Success.\n *\n * @param amount - The number of transactions to generate\n * @returns A promise that resolves to an array of generated transactions with their expected outcomes\n */\n async generate(amount: number): Promise<InputWithExpectation<S>[]> {\n const promises = [];\n\n for (let i = 0; i <= amount; i += 1) {\n promises.push(this.generator.successful());\n }\n\n const inputs = await Promise.all(promises);\n return inputs.map((input) => ({\n input,\n expectedOutcome: Outcome.Success,\n }));\n }\n}\n"],"mappings":"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","names":["PQueue","Outcome"]}
@@ -0,0 +1,165 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+
22
+ // src/soak/runner.ts
23
+ import PQueue from "p-queue";
24
+ var TestRunner = class {
25
+ /**
26
+ * Creates a new TestRunner instance.
27
+ * @param options - Configuration options for the test runner
28
+ */
29
+ constructor({ rollup, generator, concurrency }) {
30
+ this.controller = new AbortController();
31
+ this.concurrency = concurrency != null ? concurrency : 30;
32
+ this.queue = new PQueue({ concurrency: this.concurrency });
33
+ this.rollup = rollup;
34
+ this.generator = generator;
35
+ }
36
+ /**
37
+ * Starts the soak test. This will begin generating and submitting transactions
38
+ * according to the configured generator strategy and concurrency settings.
39
+ *
40
+ * The test will continue running until explicitly stopped using the stop() method.
41
+ */
42
+ run() {
43
+ return __async(this, null, function* () {
44
+ yield this.silenceNodeWarning();
45
+ this.doExecution();
46
+ });
47
+ }
48
+ /**
49
+ * Stops the soak test. This will abort any pending transactions and prevent
50
+ * new transactions from being generated.
51
+ */
52
+ stop() {
53
+ return __async(this, null, function* () {
54
+ this.controller.abort();
55
+ });
56
+ }
57
+ doExecution() {
58
+ return __async(this, null, function* () {
59
+ if (this.controller.signal.aborted) return;
60
+ const controller = new AbortController();
61
+ const signal = controller.signal;
62
+ this.controller.signal.addEventListener("abort", controller.abort, {
63
+ once: true
64
+ });
65
+ const inputs = yield this.generator.generate(100);
66
+ const execution = inputs.map(({ input }) => {
67
+ return () => __async(this, null, function* () {
68
+ if (signal.aborted) return;
69
+ const { signer, unsignedTransaction, onSubmitted } = input;
70
+ const { response } = yield this.rollup.signAndSubmitTransaction(
71
+ unsignedTransaction,
72
+ { signer },
73
+ { signal }
74
+ );
75
+ if (onSubmitted) {
76
+ yield onSubmitted(response.data);
77
+ }
78
+ });
79
+ });
80
+ this.queue.addAll(execution);
81
+ yield this.queue.onSizeLessThan(this.concurrency);
82
+ this.controller.signal.removeEventListener("abort", controller.abort);
83
+ setTimeout(() => this.doExecution(), 100);
84
+ });
85
+ }
86
+ // Node emits a warning if there's more than 10 listeners by default
87
+ // to try detect listener leaks. This is nodejs specific, we're OK to ignore it.
88
+ silenceNodeWarning() {
89
+ return __async(this, null, function* () {
90
+ var _a;
91
+ if ((_a = process == null ? void 0 : process.versions) == null ? void 0 : _a.node) {
92
+ const events = yield import("node:events");
93
+ events.setMaxListeners(200);
94
+ }
95
+ });
96
+ }
97
+ };
98
+
99
+ // src/soak/errors.ts
100
+ var NotImplementedError = class extends Error {
101
+ constructor(symbol) {
102
+ super(`Not implemented: ${symbol}`);
103
+ this.name = "NotImplementedError";
104
+ }
105
+ };
106
+
107
+ // src/soak/generation.ts
108
+ var Outcome = /* @__PURE__ */ ((Outcome2) => {
109
+ Outcome2[Outcome2["Success"] = 0] = "Success";
110
+ Outcome2[Outcome2["Failure"] = 1] = "Failure";
111
+ return Outcome2;
112
+ })(Outcome || {});
113
+ var TransactionGenerator = class {
114
+ /**
115
+ * Generate a single test transaction that should succeed.
116
+ * @returns A promise that resolves to the generated transaction input
117
+ */
118
+ successful() {
119
+ throw new NotImplementedError("TransactionGenerator.successful");
120
+ }
121
+ /**
122
+ * Generate a single test transaction that should fail.
123
+ * @returns A promise that resolves to the generated transaction input
124
+ */
125
+ failure() {
126
+ throw new NotImplementedError("TransactionGenerator.failure");
127
+ }
128
+ };
129
+ var BasicGeneratorStrategy = class {
130
+ /**
131
+ * Creates a new BasicGeneratorStrategy instance.
132
+ * @param generator - The transaction generator to use for creating individual transactions
133
+ */
134
+ constructor(generator) {
135
+ this.generator = generator;
136
+ }
137
+ /**
138
+ * Generates a batch of test transactions using the configured generator.
139
+ * All transactions are generated with Outcome.Success.
140
+ *
141
+ * @param amount - The number of transactions to generate
142
+ * @returns A promise that resolves to an array of generated transactions with their expected outcomes
143
+ */
144
+ generate(amount) {
145
+ return __async(this, null, function* () {
146
+ const promises = [];
147
+ for (let i = 0; i <= amount; i += 1) {
148
+ promises.push(this.generator.successful());
149
+ }
150
+ const inputs = yield Promise.all(promises);
151
+ return inputs.map((input) => ({
152
+ input,
153
+ expectedOutcome: 0 /* Success */
154
+ }));
155
+ });
156
+ }
157
+ };
158
+ export {
159
+ BasicGeneratorStrategy,
160
+ NotImplementedError,
161
+ Outcome,
162
+ TestRunner,
163
+ TransactionGenerator
164
+ };
165
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/soak/runner.ts","../../src/soak/errors.ts","../../src/soak/generation.ts"],"sourcesContent":["import type { BaseTypeSpec, Rollup } from \"@sovereign-sdk/web3\";\nimport PQueue from \"p-queue\";\nimport type { GeneratorStrategy } from \"./generation\";\n\n/**\n * Configuration options for creating a new TestRunner instance.\n * @template S - The type specification for the rollup being tested\n */\nexport interface TestOptions<S extends BaseTypeSpec> {\n /** Maximum number of concurrent transactions to run (default: 30) */\n concurrency?: number;\n /** Strategy for generating test transactions */\n generator: GeneratorStrategy<S>;\n /** The rollup instance to test against */\n // biome-ignore lint/suspicious/noExplicitAny: generic not need\n rollup: Rollup<S, any>;\n}\n\n/**\n * A class for running soak tests against a Sovereign rollup.\n * Manages concurrent transaction execution and provides control over test execution.\n *\n * @template S - The type specification for the rollup being tested\n *\n * @example\n * ```typescript\n * const runner = new TestRunner({\n * rollup: new YourRollup(),\n * generator: new YourGeneratorStrategy(),\n * concurrency: 30\n * });\n *\n * // Start the test\n * await runner.run();\n *\n * // Stop the test when needed\n * await runner.stop();\n * ```\n */\nexport class TestRunner<S extends BaseTypeSpec> {\n private controller: AbortController;\n private readonly concurrency: number;\n private readonly queue: PQueue;\n // biome-ignore lint/suspicious/noExplicitAny: generic not need\n private readonly rollup: Rollup<S, any>;\n private readonly generator: GeneratorStrategy<S>;\n\n /**\n * Creates a new TestRunner instance.\n * @param options - Configuration options for the test runner\n */\n constructor({ rollup, generator, concurrency }: TestOptions<S>) {\n this.controller = new AbortController();\n this.concurrency = concurrency ?? 30;\n this.queue = new PQueue({ concurrency: this.concurrency });\n this.rollup = rollup;\n this.generator = generator;\n }\n\n /**\n * Starts the soak test. This will begin generating and submitting transactions\n * according to the configured generator strategy and concurrency settings.\n *\n * The test will continue running until explicitly stopped using the stop() method.\n */\n async run(): Promise<void> {\n await this.silenceNodeWarning();\n this.doExecution();\n }\n\n /**\n * Stops the soak test. This will abort any pending transactions and prevent\n * new transactions from being generated.\n */\n async stop(): Promise<void> {\n this.controller.abort();\n }\n\n private async doExecution(): Promise<void> {\n if (this.controller.signal.aborted) return;\n\n // create a child abort signal per batch because there's no way\n // to clean up abort listeners, this prevents them building up and leaking\n const controller = new AbortController();\n const signal = controller.signal;\n this.controller.signal.addEventListener(\"abort\", controller.abort, {\n once: true,\n });\n\n const inputs = await this.generator.generate(100);\n // TODO: check expectedOutcome with what the rollup actually returns\n const execution = inputs.map(({ input }) => {\n return async () => {\n if (signal.aborted) return;\n\n const { signer, unsignedTransaction, onSubmitted } = input;\n // TODO: handle abort error\n const { response } = await this.rollup.signAndSubmitTransaction(\n unsignedTransaction,\n { signer },\n { signal },\n );\n\n if (onSubmitted) {\n // TODO: handle errors\n await onSubmitted(response.data);\n }\n };\n });\n\n this.queue.addAll(execution);\n await this.queue.onSizeLessThan(this.concurrency);\n\n // clean-up listener to prevent listener leak on top-level abort controller\n this.controller.signal.removeEventListener(\"abort\", controller.abort);\n\n setTimeout(() => this.doExecution(), 100);\n }\n\n // Node emits a warning if there's more than 10 listeners by default\n // to try detect listener leaks. This is nodejs specific, we're OK to ignore it.\n private async silenceNodeWarning(): Promise<void> {\n if (process?.versions?.node) {\n const events = await import(\"node:events\");\n // biome-ignore lint/suspicious/noExplicitAny: node specific\n (events as any).setMaxListeners(200);\n }\n }\n}\n","export class NotImplementedError extends Error {\n constructor(symbol: string) {\n super(`Not implemented: ${symbol}`);\n this.name = \"NotImplementedError\";\n }\n}\n","import type SovereignSDK from \"@sovereign-sdk/client\";\nimport type { Signer } from \"@sovereign-sdk/signers\";\nimport type { BaseTypeSpec } from \"@sovereign-sdk/web3\";\nimport { NotImplementedError } from \"./errors\";\n\n/** Response data type from a transaction submission */\nexport type TxResult = SovereignSDK.Sequencer.TxCreateResponse.Data;\n\n/**\n * Possible outcomes for a generated transaction.\n * Used to control whether the transaction should succeed or fail.\n */\nexport enum Outcome {\n /** Transaction should be generated to succeed */\n Success = 0,\n /** Transaction should be generated to fail */\n Failure = 1,\n}\n\n/**\n * Represents a generated transaction input with its associated metadata.\n * @template S - The type specification for the rollup being tested\n */\nexport type GeneratedInput<S extends BaseTypeSpec> = {\n /** The unsigned transaction to be submitted */\n unsignedTransaction: S[\"UnsignedTransaction\"];\n /** The signer to use for signing the transaction */\n signer: Signer;\n /**\n * Optional callback to be executed after the transaction is onSubmitted\n * This function is passed the transaction receipt along with events and\n * other result related data - it can be used to assert the output of the provided\n * input.\n */\n onSubmitted?: (result: TxResult) => Promise<void>;\n};\n\n/**\n * Represents a generated transaction with its expected outcome.\n * This is returned by generator strategies to indicate both the transaction\n * and whether it should succeed or fail.\n */\nexport type InputWithExpectation<S extends BaseTypeSpec> = {\n /** The generated transaction input */\n input: GeneratedInput<S>;\n /** The expected outcome of the transaction */\n expectedOutcome: Outcome;\n};\n\n/**\n * Interface for generating individual test transactions.\n * Implementations should create transactions that can either succeed or fail\n * based on the provided outcome.\n *\n * @template S - The type specification for the rollup being tested\n *\n * @example\n * ```typescript\n * class CustomGenerator implements TransactionGenerator<YourTypeSpec> {\n * async successful(): Promise<GeneratedInput<YourTypeSpec>> {\n * // Generate transaction based on outcome\n * return {\n * unsignedTransaction: {},\n * signer: {},\n * onSubmitted: async (result) => {\n * // Handle submission result\n * }\n * };\n * }\n * }\n * ```\n */\nexport abstract class TransactionGenerator<S extends BaseTypeSpec> {\n /**\n * Generate a single test transaction that should succeed.\n * @returns A promise that resolves to the generated transaction input\n */\n successful(): Promise<GeneratedInput<S>> {\n throw new NotImplementedError(\"TransactionGenerator.successful\");\n }\n\n /**\n * Generate a single test transaction that should fail.\n * @returns A promise that resolves to the generated transaction input\n */\n failure(): Promise<GeneratedInput<S>> {\n throw new NotImplementedError(\"TransactionGenerator.failure\");\n }\n}\n\n/**\n * Interface for generating batches of test transactions.\n * Implementations should create multiple transactions according to the specified amount.\n *\n * @template S - The type specification for the rollup being tested\n */\nexport interface GeneratorStrategy<S extends BaseTypeSpec> {\n /**\n * Generates a batch of test transactions.\n * @param amount - The number of transactions to generate\n * @returns A promise that resolves to an array of generated transactions with their expected outcomes\n */\n generate(amount: number): Promise<InputWithExpectation<S>[]>;\n}\n\n/**\n * A basic implementation of GeneratorStrategy that generates a fixed number of\n * transactions that always succeed using a singular TransactionGenerator.\n *\n * @template S - The type specification for the rollup being tested\n *\n * @example\n * ```typescript\n * const generator = new YourTransactionGenerator();\n * const strategy = new BasicGeneratorStrategy(generator);\n * const transactions = await strategy.generate(100);\n * ```\n */\nexport class BasicGeneratorStrategy<S extends BaseTypeSpec>\n implements GeneratorStrategy<S>\n{\n private readonly generator: TransactionGenerator<S>;\n\n /**\n * Creates a new BasicGeneratorStrategy instance.\n * @param generator - The transaction generator to use for creating individual transactions\n */\n constructor(generator: TransactionGenerator<S>) {\n this.generator = generator;\n }\n\n /**\n * Generates a batch of test transactions using the configured generator.\n * All transactions are generated with Outcome.Success.\n *\n * @param amount - The number of transactions to generate\n * @returns A promise that resolves to an array of generated transactions with their expected outcomes\n */\n async generate(amount: number): Promise<InputWithExpectation<S>[]> {\n const promises = [];\n\n for (let i = 0; i <= amount; i += 1) {\n promises.push(this.generator.successful());\n }\n\n const inputs = await Promise.all(promises);\n return inputs.map((input) => ({\n input,\n expectedOutcome: Outcome.Success,\n }));\n }\n}\n"],"mappings":"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","names":["Outcome"]}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@sovereign-sdk/test",
3
+ "version": "0.1.1",
4
+ "description": "",
5
+ "repository": "github:Sovereign-Labs/sovereign-sdk-web3-js",
6
+ "files": [
7
+ "dist",
8
+ "package.json"
9
+ ],
10
+ "exports": {
11
+ "./soak": {
12
+ "types": "./dist/soak/index.d.ts",
13
+ "require": "./dist/soak/index.js",
14
+ "import": "./dist/soak/index.mjs"
15
+ }
16
+ },
17
+ "dependencies": {
18
+ "@sovereign-sdk/client": "0.1.0-alpha.32",
19
+ "p-queue": "^8.1.0",
20
+ "@sovereign-sdk/signers": "^0.0.4",
21
+ "@sovereign-sdk/web3": "^0.4.1"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "devDependencies": {
27
+ "tsup": "^8.3.0",
28
+ "vitest": "^3.0.5"
29
+ },
30
+ "scripts": {
31
+ "build": "pnpm typecheck && tsup",
32
+ "ci": "biome ci",
33
+ "fix": "biome check --write",
34
+ "lint": "biome lint",
35
+ "typecheck": "tsc --noEmit"
36
+ }
37
+ }