@sovereign-sdk/test 0.1.3 → 0.1.5
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/dist/soak/index.d.mts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { BaseTypeSpec, Rollup } from '@sovereign-sdk/web3';
|
|
2
|
-
import SovereignSDK from '@sovereign-sdk/client';
|
|
1
|
+
import { SovereignClient, BaseTypeSpec, Rollup } from '@sovereign-sdk/web3';
|
|
3
2
|
import { Signer } from '@sovereign-sdk/signers';
|
|
4
3
|
|
|
5
4
|
/** Response data type from a transaction submission */
|
|
6
|
-
type TxResult = SovereignSDK.Sequencer.TxCreateResponse.Data;
|
|
5
|
+
type TxResult = SovereignClient.SovereignSDK.Sequencer.TxCreateResponse.Data;
|
|
7
6
|
/**
|
|
8
7
|
* Possible outcomes for a generated transaction.
|
|
9
8
|
* Used to control whether the transaction should succeed or fail.
|
package/dist/soak/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { BaseTypeSpec, Rollup } from '@sovereign-sdk/web3';
|
|
2
|
-
import SovereignSDK from '@sovereign-sdk/client';
|
|
1
|
+
import { SovereignClient, BaseTypeSpec, Rollup } from '@sovereign-sdk/web3';
|
|
3
2
|
import { Signer } from '@sovereign-sdk/signers';
|
|
4
3
|
|
|
5
4
|
/** Response data type from a transaction submission */
|
|
6
|
-
type TxResult = SovereignSDK.Sequencer.TxCreateResponse.Data;
|
|
5
|
+
type TxResult = SovereignClient.SovereignSDK.Sequencer.TxCreateResponse.Data;
|
|
7
6
|
/**
|
|
8
7
|
* Possible outcomes for a generated transaction.
|
|
9
8
|
* Used to control whether the transaction should succeed or fail.
|
package/dist/soak/index.js.map
CHANGED
|
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,qBAAmB;AAsCZ,IAAM,aAAN,MAAyC;AAAA;AAAA;AAAA;AAAA;AAAA,EAY9C,YAAY,EAAE,QAAQ,WAAW,YAAY,GAAmB;AAC9D,SAAK,aAAa,IAAI,gBAAgB;AACtC,SAAK,cAAc,oCAAe;AAClC,SAAK,QAAQ,IAAI,eAAAA,QAAO,EAAE,aAAa,KAAK,YAAY,CAAC;AACzD,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQM,MAAqB;AAAA;AACzB,YAAM,KAAK,mBAAmB;AAC9B,WAAK,YAA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ACOO,IAAK,UAAL,kBAAKC,aAAL;AAEL,EAAAA,kBAAA,aAAU,KAAV;AAEA,EAAAA,kBAAA,aAAU,KAAV;AAJU,SAAAA;AAAA,GAAA;AA4DL,IAAe,uBAAf,MAA4D;AAAA;AAAA;AAAA;AAAA;AAAA,EAKjE,aAAyC;AACvC,UAAM,IAAI,oBAAoB,iCAAiC;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAsC;AACpC,UAAM,IAAI,oBAAoB,8BAA8B;AAAA,EAC9D;AACF;AA8BO,IAAM,yBAAN,MAEP;AAAA;AAAA;AAAA;AAAA;AAAA,EAOE,YAAY,WAAoC;AAC9C,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASM,SAAS,QAAoD;AAAA;AACjE,YAAM,WAAW,CAAC;AAElB,eAAS,IAAI,GAAG,KAAK,QAAQ,KAAK,GAAG;AACnC,iBAAS,KAAK,KAAK,UAAU,WAAW,CAAC;AAAA,MAC3C;AAEA,YAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;AACzC,aAAO,OAAO,IAAI,CAAC,WAAW;AAAA,QAC5B;AAAA,QACA,iBAAiB;AAAA,MACnB,EAAE;AAAA,IACJ;AAAA;AACF;","names":["PQueue","Outcome"]}
|
|
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 { Signer } from \"@sovereign-sdk/signers\";\nimport type { BaseTypeSpec, SovereignClient } from \"@sovereign-sdk/web3\";\nimport { NotImplementedError } from \"./errors\";\n\n/** Response data type from a transaction submission */\nexport type TxResult =\n SovereignClient.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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,qBAAmB;AAsCZ,IAAM,aAAN,MAAyC;AAAA;AAAA;AAAA;AAAA;AAAA,EAY9C,YAAY,EAAE,QAAQ,WAAW,YAAY,GAAmB;AAC9D,SAAK,aAAa,IAAI,gBAAgB;AACtC,SAAK,cAAc,oCAAe;AAClC,SAAK,QAAQ,IAAI,eAAAA,QAAO,EAAE,aAAa,KAAK,YAAY,CAAC;AACzD,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQM,MAAqB;AAAA;AACzB,YAAM,KAAK,mBAAmB;AAC9B,WAAK,YAAY;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMM,OAAsB;AAAA;AAC1B,WAAK,WAAW,MAAM;AAAA,IACxB;AAAA;AAAA,EAEc,cAA6B;AAAA;AACzC,UAAI,KAAK,WAAW,OAAO,QAAS;AAIpC,YAAM,aAAa,IAAI,gBAAgB;AACvC,YAAM,SAAS,WAAW;AAC1B,WAAK,WAAW,OAAO,iBAAiB,SAAS,WAAW,OAAO;AAAA,QACjE,MAAM;AAAA,MACR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BAA8B;AAAA,EAC9D;AACF;AA8BO,IAAM,yBAAN,MAEP;AAAA;AAAA;AAAA;AAAA;AAAA,EAOE,YAAY,WAAoC;AAC9C,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASM,SAAS,QAAoD;AAAA;AACjE,YAAM,WAAW,CAAC;AAElB,eAAS,IAAI,GAAG,KAAK,QAAQ,KAAK,GAAG;AACnC,iBAAS,KAAK,KAAK,UAAU,WAAW,CAAC;AAAA,MAC3C;AAEA,YAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;AACzC,aAAO,OAAO,IAAI,CAAC,WAAW;AAAA,QAC5B;AAAA,QACA,iBAAiB;AAAA,MACnB,EAAE;AAAA,IACJ;AAAA;AACF;","names":["PQueue","Outcome"]}
|
package/dist/soak/index.mjs.map
CHANGED
|
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,YAAY;AAsCZ,IAAM,aAAN,MAAyC;AAAA;AAAA;AAAA;AAAA;AAAA,EAY9C,YAAY,EAAE,QAAQ,WAAW,YAAY,GAAmB;AAC9D,SAAK,aAAa,IAAI,gBAAgB;AACtC,SAAK,cAAc,oCAAe;AAClC,SAAK,QAAQ,IAAI,OAAO,EAAE,aAAa,KAAK,YAAY,CAAC;AACzD,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQM,MAAqB;AAAA;AACzB,YAAM,KAAK,mBAAmB;AAC9B,WAAK,YAAY;AAAA,IACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMM,OAAsB;AAAA;AAC1B,WAAK,WAAW,MAAM;AAAA,IACxB;AAAA;AAAA,EAEc,cAA6B;AAAA;AACzC,UAAI,KAAK,WAAW,OAAO,QAAS;AAIpC,YAAM,aAAa,IAAI,gBAAgB;AACvC,YAAM,SAAS,WAAW;AAC1B,WAAK,WAAW,OAAO,iBAAiB,SAAS,WAAW,OAAO;AAAA,QACjE,MAAM;AAAA,MACR,CAAC;AAED,YAAM,SAAS,MAAM,KAAK,UAAU,SAAS,GAAG;AAEhD,YAAM,YAAY,OAAO,IAAI,CAAC,EAAE,MAAM,MAAM;AAC1C,eAAO,MAAY;AACjB,cAAI,OAAO,QAAS;AAEpB,gBAAM,EAAE,QAAQ,qBAAqB,YAAY,IAAI;AAErD,gBAAM,EAAE,SAAS,IAAI,MAAM,KAAK,OAAO;AAAA,YACrC;AAAA,YACA,EAAE,OAAO;AAAA,YACT,EAAE,OAAO;AAAA,UACX;AAEA,cAAI,aAAa;AAEf,kBAAM,YAAY,SAAS,IAAI;AAAA,UACjC;AAAA,QACF;AAAA,MACF,CAA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AC,WAAW;AAAA,QAC5B;AAAA,QACA,iBAAiB;AAAA,MACnB,EAAE;AAAA,IACJ;AAAA;AACF;","names":["Outcome"]}
|
|
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 { Signer } from \"@sovereign-sdk/signers\";\nimport type { BaseTypeSpec, SovereignClient } from \"@sovereign-sdk/web3\";\nimport { NotImplementedError } from \"./errors\";\n\n/** Response data type from a transaction submission */\nexport type TxResult =\n SovereignClient.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":";;;;;;;;;;;;;;;;;;;;;;AACA,OAAO,YAAY;AAsCZ,IAAM,aAAN,MAAyC;AAAA;AAAA;AAAA;AAAA;AAAA,EAY9C,YAAY,EAAE,QAAQ,WAAW,YAAY,GAAmB;AAC9D,SAAK,aAAa,IAAI,gBAAgB;AACtC,SAAK,cAAc,oCAAe;AAClC,SAAK,QAAQ,IAAI,OAAO,EAAE,aAAa,KAAK,YAAY,CAAC;AACzD,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQM,MAAqB;AAAA;AAC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AE;AAClC,SAAK,OAAO;AAAA,EACd;AACF;;;ACOO,IAAK,UAAL,kBAAKA,aAAL;AAEL,EAAAA,kBAAA,aAAU,KAAV;AAEA,EAAAA,kBAAA,aAAU,KAAV;AAJU,SAAAA;AAAA,GAAA;AA4DL,IAAe,uBAAf,MAA4D;AAAA;AAAA;AAAA;AAAA;AAAA,EAKjE,aAAyC;AACvC,UAAM,IAAI,oBAAoB,iCAAiC;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,UAAsC;AACpC,UAAM,IAAI,oBAAoB,8BAA8B;AAAA,EAC9D;AACF;AA8BO,IAAM,yBAAN,MAEP;AAAA;AAAA;AAAA;AAAA;AAAA,EAOE,YAAY,WAAoC;AAC9C,SAAK,YAAY;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASM,SAAS,QAAoD;AAAA;AACjE,YAAM,WAAW,CAAC;AAElB,eAAS,IAAI,GAAG,KAAK,QAAQ,KAAK,GAAG;AACnC,iBAAS,KAAK,KAAK,UAAU,WAAW,CAAC;AAAA,MAC3C;AAEA,YAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;AACzC,aAAO,OAAO,IAAI,CAAC,WAAW;AAAA,QAC5B;AAAA,QACA,iBAAiB;AAAA,MACnB,EAAE;AAAA,IACJ;AAAA;AACF;","names":["Outcome"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sovereign-sdk/test",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": "github:Sovereign-Labs/sovereign-sdk-web3-js",
|
|
6
6
|
"files": [
|
|
@@ -15,10 +15,9 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@sovereign-sdk/client": "0.1.0-alpha.32",
|
|
19
18
|
"p-queue": "^8.1.0",
|
|
20
|
-
"@sovereign-sdk/signers": "^0.0
|
|
21
|
-
"@sovereign-sdk/web3": "^0.
|
|
19
|
+
"@sovereign-sdk/signers": "^0.1.0",
|
|
20
|
+
"@sovereign-sdk/web3": "^0.6.0"
|
|
22
21
|
},
|
|
23
22
|
"publishConfig": {
|
|
24
23
|
"access": "public"
|