@sovereign-sdk/test 0.1.1 → 0.1.3
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/README.md +184 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# @sovereign-sdk/test
|
|
2
|
+
|
|
3
|
+
Testing utilities for Sovereign SDK rollups, including soak testing and transaction generation.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sovereign-sdk/test
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
The package provides utilities for testing Sovereign SDK rollups, with a focus on soak testing and transaction generation. Soak testing helps verify the stability and performance of your rollup under sustained load by continuously submitting transactions.
|
|
14
|
+
|
|
15
|
+
> **Note:** Currently, soak tests require a pre-started rollup node to run against. In a future version, we plan to add functionality to manage the rollup process lifecycle (starting, stopping, and monitoring the node) as part of the test framework.
|
|
16
|
+
|
|
17
|
+
### Transaction Generators
|
|
18
|
+
|
|
19
|
+
Transaction generators are responsible for creating individual test transactions. They implement the `TransactionGenerator` interface:
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { TransactionGenerator } from "@sovereign-sdk/test/soak";
|
|
23
|
+
|
|
24
|
+
class MyTransactionGenerator implements TransactionGenerator<YourTypeSpec> {
|
|
25
|
+
async successful(): Promise<GeneratedInput<YourTypeSpec>> {
|
|
26
|
+
// Create a transaction that should succeed
|
|
27
|
+
const unsignedTransaction = {
|
|
28
|
+
// Your transaction details
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const signer = await getSigner();
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
unsignedTransaction,
|
|
35
|
+
signer,
|
|
36
|
+
onSubmitted: async (result) => {
|
|
37
|
+
// Verify transaction results
|
|
38
|
+
// Check events
|
|
39
|
+
// Validate state changes
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async failure(): Promise<GeneratedInput<YourTypeSpec>> {
|
|
45
|
+
// Create a transaction that should fail
|
|
46
|
+
const unsignedTransaction = {
|
|
47
|
+
// Your invalid transaction details
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const signer = await getSigner();
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
unsignedTransaction,
|
|
54
|
+
signer,
|
|
55
|
+
onSubmitted: async (result) => {
|
|
56
|
+
// Verify the transaction failed as expected
|
|
57
|
+
// Check error messages
|
|
58
|
+
// Validate state remains unchanged
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Generator Strategies
|
|
66
|
+
|
|
67
|
+
Generator strategies determine how multiple transactions are generated and executed. The package provides a `BasicGeneratorStrategy` that generates a fixed number of successful transactions:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { BasicGeneratorStrategy } from "@sovereign-sdk/test/soak";
|
|
71
|
+
|
|
72
|
+
const generator = new MyTransactionGenerator();
|
|
73
|
+
const strategy = new BasicGeneratorStrategy(generator);
|
|
74
|
+
|
|
75
|
+
// Generate 100 transactions
|
|
76
|
+
const transactions = await strategy.generate(100);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
You can also create custom strategies by implementing the `GeneratorStrategy` interface:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { GeneratorStrategy, Outcome } from "@sovereign-sdk/test/soak";
|
|
83
|
+
|
|
84
|
+
class CustomStrategy implements GeneratorStrategy<YourTypeSpec> {
|
|
85
|
+
private readonly generators: TransactionGenerator<YourTypeSpec>[];
|
|
86
|
+
|
|
87
|
+
constructor(generators: TransactionGenerator<YourTypeSpec>[]) {
|
|
88
|
+
this.generators = generators;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async generate(amount: number): Promise<InputWithExpectation<YourTypeSpec>[]> {
|
|
92
|
+
const transactions = [];
|
|
93
|
+
|
|
94
|
+
for (let i = 0; i < amount; i++) {
|
|
95
|
+
// Choose a generator based on your strategy
|
|
96
|
+
const generator = this.selectGenerator();
|
|
97
|
+
const transaction = await generator.successful();
|
|
98
|
+
transactions.push({
|
|
99
|
+
input: transaction,
|
|
100
|
+
expectedOutcome: Outcome.Success
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return transactions;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private selectGenerator(): TransactionGenerator<YourTypeSpec> {
|
|
108
|
+
// Implement your selection logic
|
|
109
|
+
return this.generators[Math.floor(Math.random() * this.generators.length)];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Running Soak Tests
|
|
115
|
+
|
|
116
|
+
To run a soak test, create a test runner with your strategy:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { TestRunner } from "@sovereign-sdk/test/soak";
|
|
120
|
+
|
|
121
|
+
const rollup = await createStandardRollup<YourTypeSpec>({
|
|
122
|
+
context: { defaultTxDetails },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const strategy = new YourStrategy();
|
|
126
|
+
const runner = new TestRunner<S>({
|
|
127
|
+
rollup,
|
|
128
|
+
generator: strategy,
|
|
129
|
+
concurrency: 30, // Adjust based on your needs
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
// Start the test
|
|
133
|
+
await runner.run();
|
|
134
|
+
|
|
135
|
+
// Stop when needed
|
|
136
|
+
await runner.stop();
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
> **Note:** The current API requires manual management of the test runner lifecycle (start/stop). In a future version, we plan to simplify this by handling the lifecycle internally, so users won't need to manage these operations in their code.
|
|
140
|
+
|
|
141
|
+
## Example
|
|
142
|
+
|
|
143
|
+
See the [soak-testing example](../../examples/soak-testing) for a complete implementation of a bank transfer soak test.
|
|
144
|
+
|
|
145
|
+
## API Reference
|
|
146
|
+
|
|
147
|
+
### TransactionGenerator
|
|
148
|
+
|
|
149
|
+
Interface for generating individual test transactions.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
abstract class TransactionGenerator<S extends BaseTypeSpec> {
|
|
153
|
+
abstract successful(): Promise<GeneratedInput<S>>;
|
|
154
|
+
abstract failure(): Promise<GeneratedInput<S>>;
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### GeneratorStrategy
|
|
159
|
+
|
|
160
|
+
Interface for generating batches of test transactions.
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
interface GeneratorStrategy<S extends BaseTypeSpec> {
|
|
164
|
+
generate(amount: number): Promise<InputWithExpectation<S>[]>;
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### TestRunner
|
|
169
|
+
|
|
170
|
+
Class for running soak tests.
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
class TestRunner<S extends BaseTypeSpec> {
|
|
174
|
+
constructor(options: {
|
|
175
|
+
rollup: StandardRollup<S>;
|
|
176
|
+
generator: GeneratorStrategy<S>;
|
|
177
|
+
concurrency: number;
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
run(): Promise<void>;
|
|
181
|
+
stop(): Promise<void>;
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sovereign-sdk/test",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": "github:Sovereign-Labs/sovereign-sdk-web3-js",
|
|
6
6
|
"files": [
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@sovereign-sdk/client": "0.1.0-alpha.32",
|
|
19
19
|
"p-queue": "^8.1.0",
|
|
20
20
|
"@sovereign-sdk/signers": "^0.0.4",
|
|
21
|
-
"@sovereign-sdk/web3": "^0.
|
|
21
|
+
"@sovereign-sdk/web3": "^0.5.0"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|