diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index eff3a7d..30d014f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -14,5 +14,5 @@ - [ ] Rebased to the latest commit of the target branch (or merged it into my branch) - Once you make the PR reviewable, please avoid force-pushing - [ ] Updated the docs if needed -- [ ] Linked the [issues](https://github.com/0xSpaceShard/starknet-devnet-js/issues) resolvable by this PR - [linking info](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) +- [ ] Linked the [issues](https://github.com/starknet-io/starknet-devnet-js/issues) resolvable by this PR - [linking info](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword) - [ ] Updated the tests if needed; all passing - `npm test` diff --git a/.github/workflows/build-test-publish.yml b/.github/workflows/build-test-publish.yml index adadd14..8369da2 100644 --- a/.github/workflows/build-test-publish.yml +++ b/.github/workflows/build-test-publish.yml @@ -7,7 +7,7 @@ on: branches: ["*"] env: - DEVNET_VERSION: "0.8.1" + DEVNET_VERSION: "0.8.2" DEVNET_DIR: "/tmp/devnet-ci-storage" DEVNET_PATH: "/tmp/devnet-ci-storage/starknet-devnet" FORKED_DEVNET_PORT: 5051 @@ -64,7 +64,7 @@ jobs: - name: Download Devnet binary run: | mkdir -p ${DEVNET_DIR} - curl -sSfL https://github.com/0xSpaceShard/starknet-devnet/releases/download/v${DEVNET_VERSION}/starknet-devnet-x86_64-unknown-linux-gnu.tar.gz | tar -xvz -C ${DEVNET_DIR} + curl -sSfL https://github.com/starknet-io/starknet-devnet/releases/download/v${DEVNET_VERSION}/starknet-devnet-x86_64-unknown-linux-gnu.tar.gz | tar -xvz -C ${DEVNET_DIR} - name: Start Anvil container run: | diff --git a/README.md b/README.md index 31e4c22..09f2799 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Introduction -Using this JavaScript/TypeScript library, you can spawn [Starknet Devnet](https://github.com/0xSpaceShard/starknet-devnet/) without installing and running it in a separate terminal. You can interact with it via its specific [Devnet API](https://0xspaceshard.github.io/starknet-devnet/docs/api#devnet-api). To interact with any Starknet node or network (including Starknet Devnet) via the [Starknet JSON-RPC API](https://0xspaceshard.github.io/starknet-devnet/docs/api#starknet-api), see [starknet.js](https://www.starknetjs.com/). +Using this JavaScript/TypeScript library, you can spawn [Starknet Devnet](https://github.com/starknet-io/starknet-devnet/) without installing and running it in a separate terminal. You can interact with it via its specific [Devnet API](https://starknet-io.github.io/starknet-devnet/docs/api#devnet-api). To interact with any Starknet node or network (including Starknet Devnet) via the [Starknet JSON-RPC API](https://starknet-io.github.io/starknet-devnet/docs/api#starknet-api), see [starknet.js](https://www.starknetjs.com/). # Installation @@ -14,15 +14,15 @@ npm i starknet-devnet ## Devnet compatibility -This library version is compatible with Devnet `v0.8.1`. +This library version is compatible with Devnet `v0.8.2`. -[Devnet's balance checking functionality](https://0xspaceshard.github.io/starknet-devnet/docs/balance#check-balance) is not provided in this library because it is simply replaceable using starknet.js, as witnessed by the [getAccountBalance](./test/util.ts#L61) function. +[Devnet's balance checking functionality](https://starknet-io.github.io/starknet-devnet/docs/balance#check-balance) is not provided in this library because it is simply replaceable using starknet.js, as witnessed by the [getAccountBalance](./test/util.ts#L61) function. ## Environment compatibility This library is intended for use with Node.js, not in a browser environment. In browsers, you can only use [`DevnetProvider`](#connect-to-a-running-instance) for connecting to an already running Devnet instance, but you cannot [spawn a new Devnet](#spawn-a-new-devnet), because that relies on modules not present in the browser engine. -To enable the use of `DevnetProvider` in browser, you need to configure sources for modules otherwise reported as not found. See [this issue](https://github.com/0xSpaceShard/starknet-devnet-js/issues/26) and [this SO answer](https://stackoverflow.com/a/51669301) for more info, but generally, if using webpack, it should be enough to populate a config file with the desired polyfill implementations or with `false` values. +To enable the use of `DevnetProvider` in browser, you need to configure sources for modules otherwise reported as not found. See [this issue](https://github.com/starknet-io/starknet-devnet-js/issues/26) and [this SO answer](https://stackoverflow.com/a/51669301) for more info, but generally, if using webpack, it should be enough to populate a config file with the desired polyfill implementations or with `false` values. # Usage @@ -38,7 +38,7 @@ Assuming your machine has a supported OS (macOS or Linux) and supported architec import { Devnet } from "starknet-devnet"; async function main() { - // Specify anything from https://github.com/0xSpaceShard/starknet-devnet/releases + // Specify anything from https://github.com/starknet-io/starknet-devnet/releases // Be sure to include the 'v' if it's in the version name. const devnet = await Devnet.spawnVersion("v0.6.1"); console.log(await devnet.provider.isAlive()); // true @@ -129,7 +129,7 @@ In that case, you must take care of the spawned process after the program exits. ## Connect to a running instance -If there already is a running Devnet instance (e.g. in another terminal or in another JS/TS program), you can simply connect to it by importing `DevnetProvider`. [Read more](https://0xspaceshard.github.io/starknet-devnet/docs/category/running) about different ways of running Devnet. +If there already is a running Devnet instance (e.g. in another terminal or in another JS/TS program), you can simply connect to it by importing `DevnetProvider`. [Read more](https://starknet-io.github.io/starknet-devnet/docs/category/running) about different ways of running Devnet. ```typescript import { DevnetProvider } from "starknet-devnet"; @@ -139,7 +139,7 @@ console.log(await devnet.isAlive()); // true ## Enabling Starknet API support -Since this library only supports the [Devnet-specific API](https://0xspaceshard.github.io/starknet-devnet/docs/api#devnet-api), to interact via [Starknet JSON-RPC API](https://0xspaceshard.github.io/starknet-devnet/docs/api#starknet-api), use [starknet.js](https://www.starknetjs.com/). +Since this library only supports the [Devnet-specific API](https://starknet-io.github.io/starknet-devnet/docs/api#devnet-api), to interact via [Starknet JSON-RPC API](https://starknet-io.github.io/starknet-devnet/docs/api#starknet-api), use [starknet.js](https://www.starknetjs.com/). E.g. to get the latest block after spawning Devnet, you would need to do: @@ -155,11 +155,11 @@ const block = await starknetProvider.getBlock("latest"); ## L1-L2 communication -Assuming there is an L1 provider running (e.g. [anvil](https://github.com/foundry-rs/foundry/tree/master/crates/anvil)), use the `postman` property of `DevnetProvider` to achieve [L1-L2 communication](https://0xspaceshard.github.io/starknet-devnet/docs/postman). See [this example](https://github.com/0xSpaceShard/starknet-devnet-js/blob/master/test/l1-l2-postman.test.ts) for more info. +Assuming there is an L1 provider running (e.g. [anvil](https://github.com/foundry-rs/foundry/tree/master/crates/anvil)), use the `postman` property of `DevnetProvider` to achieve [L1-L2 communication](https://starknet-io.github.io/starknet-devnet/docs/postman). See [this example](https://github.com/starknet-io/starknet-devnet-js/blob/master/test/l1-l2-postman.test.ts) for more info. ## Transaction Proofs -Use the `proofs` property of `DevnetProvider` to prove INVOKE v3 transactions. This is useful for testing proof-aware flows in your application. See the [Devnet proofs documentation](https://0xspaceshard.github.io/starknet-devnet/docs/proofs) for more details on proof modes. +Use the `proofs` property of `DevnetProvider` to prove INVOKE v3 transactions. This is useful for testing proof-aware flows in your application. See the [Devnet proofs documentation](https://starknet-io.github.io/starknet-devnet/docs/proofs) for more details on proof modes. **Note:** Before calling `proveTransaction`, Devnet requires at least 10 blocks to exist. Start Devnet with `--proof-mode devnet` to enable this feature. @@ -199,7 +199,7 @@ console.log(proofResult.proof_facts); // Array of 9 hex strings console.log(proofResult.l2_to_l1_messages); // L2 to L1 messages from simulation ``` -See [this example](https://github.com/0xSpaceShard/starknet-devnet-js/blob/master/test/proofs.test.ts) for a complete test with transaction building and signing. +See [this example](https://github.com/starknet-io/starknet-devnet-js/blob/master/test/proofs.test.ts) for a complete test with transaction building and signing. ## Configuration modification and retrieval @@ -213,11 +213,11 @@ console.log(await devnet.provider.getConfig().l2_gas_price_fri); ## Examples -See the [`test` directory](https://github.com/0xSpaceShard/starknet-devnet-js/tree/master/test) for more usage examples. +See the [`test` directory](https://github.com/starknet-io/starknet-devnet-js/tree/master/test) for more usage examples. ## Contribute -If you spot a problem or room for improvement, check if an issue for it [already exists](https://github.com/0xSpaceShard/starknet-devnet-js/issues). If not, [create a new one](https://github.com/0xSpaceShard/starknet-devnet-js/issues/new). You are welcome to open a PR yourself to close the issue. Once you open a PR, you will see a template with a list of steps - please follow them. +If you spot a problem or room for improvement, check if an issue for it [already exists](https://github.com/starknet-io/starknet-devnet-js/issues). If not, [create a new one](https://github.com/starknet-io/starknet-devnet-js/issues/new). You are welcome to open a PR yourself to close the issue. Once you open a PR, you will see a template with a list of steps - please follow them. ### Test diff --git a/RELEASE.md b/RELEASE.md index cc79f7e..135066b 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,6 +1,6 @@ ## Adaptation to starknet-devnet -When adapting to a new [starknet-devnet](https://github.com/0xSpaceShard/starknet-devnet) version, be sure to have replaced all occurrences of the previous version with the new one. +When adapting to a new [starknet-devnet](https://github.com/starknet-io/starknet-devnet) version, be sure to have replaced all occurrences of the previous version with the new one. If possible, keep the semver of `starknet-devnet-js` the same as that of `starknet-devnet`. diff --git a/package-lock.json b/package-lock.json index c1a8e87..45fb3a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "starknet-devnet", - "version": "0.8.1", + "version": "0.8.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "starknet-devnet", - "version": "0.8.1", + "version": "0.8.2", "license": "MIT", "dependencies": { "axios": "^1.7.4", diff --git a/package.json b/package.json index 7ca0fee..84d58e0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "starknet-devnet", - "version": "0.8.1", + "version": "0.8.2", "description": "Starknet Devnet provider", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -21,7 +21,7 @@ "author": "SpaceShard", "repository": { "type": "git", - "url": "git+https://github.com/0xSpaceShard/starknet-devnet-js.git" + "url": "git+https://github.com/starknet-io/starknet-devnet-js.git" }, "keywords": [ "starknet", diff --git a/src/cheats.ts b/src/cheats.ts index 04a9b8d..fc01605 100644 --- a/src/cheats.ts +++ b/src/cheats.ts @@ -6,7 +6,7 @@ export class Cheats { /** * Deactivate using `stopImpersonateAccount`. * - * https://0xspaceshard.github.io/starknet-devnet/docs/account-impersonation + * https://starknet-io.github.io/starknet-devnet/docs/account-impersonation * @param address the address of a locally non-present account that you want to impersonate */ public async impersonateAccount(address: string): Promise { @@ -16,7 +16,7 @@ export class Cheats { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/account-impersonation + * https://starknet-io.github.io/starknet-devnet/docs/account-impersonation * @param address the address of a locally non-present account that you want to stop impersonating */ public async stopImpersonateAccount(address: string): Promise { @@ -28,14 +28,14 @@ export class Cheats { /** * Enables automatic account impersonation. Every account that does not exist in the local state will be impersonated. Deactivate using `stopAutoImpersonate`. * - * https://0xspaceshard.github.io/starknet-devnet/docs/account-impersonation + * https://starknet-io.github.io/starknet-devnet/docs/account-impersonation */ public async autoImpersonate(): Promise { await this.rpcProvider.sendRequest("devnet_autoImpersonate"); } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/account-impersonation + * https://starknet-io.github.io/starknet-devnet/docs/account-impersonation */ public async stopAutoImpersonate(): Promise { await this.rpcProvider.sendRequest("devnet_stopAutoImpersonate"); diff --git a/src/constants.ts b/src/constants.ts index 1bdaa44..ebcbf0e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -5,4 +5,4 @@ export const DEFAULT_DEVNET_HOST = "127.0.0.1"; export const DEFAULT_DEVNET_PORT = 5050; export const DEFAULT_DEVNET_URL = `http://${DEFAULT_DEVNET_HOST}:${DEFAULT_DEVNET_PORT}`; -export const LATEST_COMPATIBLE_DEVNET_VERSION = "v0.6.0"; +export const LATEST_COMPATIBLE_DEVNET_VERSION = "v0.8.2"; diff --git a/src/devnet-provider.ts b/src/devnet-provider.ts index aa877dc..b70ad79 100644 --- a/src/devnet-provider.ts +++ b/src/devnet-provider.ts @@ -80,7 +80,7 @@ export class DevnetProvider { /** * Restart the state of the underlying Devnet instance. You may opt to restart L1-L2 messaging. - * https://0xspaceshard.github.io/starknet-devnet/docs/dump-load-restart#restarting + * https://starknet-io.github.io/starknet-devnet/docs/dump-load-restart#restarting */ public async restart(params: { restartL1ToL2Messaging?: boolean } = {}): Promise { await this.rpcProvider.sendRequest("devnet_restart", { @@ -90,7 +90,7 @@ export class DevnetProvider { /** * Generate funds at the provided address. For return spec and more info, see - * https://0xspaceshard.github.io/starknet-devnet/docs/balance#mint-token---local-faucet + * https://starknet-io.github.io/starknet-devnet/docs/balance#mint-token---local-faucet * @param address the account address to receive funds * @param amount how much to mint * @param unit specifier of the currency unit; defaults to FRI @@ -115,7 +115,7 @@ export class DevnetProvider { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/predeployed#how-to-get-predeployment-info + * https://starknet-io.github.io/starknet-devnet/docs/predeployed#how-to-get-predeployment-info * @returns a list of containing information on predeployed accounts. Load an account using e.g. starknet.js. */ public async getPredeployedAccounts( @@ -127,7 +127,7 @@ export class DevnetProvider { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/blocks + * https://starknet-io.github.io/starknet-devnet/docs/blocks * @returns the block hash of the newly created block */ public async createBlock(): Promise { @@ -135,7 +135,7 @@ export class DevnetProvider { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/blocks + * https://starknet-io.github.io/starknet-devnet/docs/blocks * @param staringBlockId the block ID of the block after which (inclusive) all blocks * should be aborted. See docs {@link BlockId} for more info. * @returns hash values of aborted blocks @@ -147,7 +147,7 @@ export class DevnetProvider { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/next/starknet-time#set-time + * https://starknet-io.github.io/starknet-devnet/docs/next/starknet-time#set-time * @returns the new time in unix seconds and, if block creation requested, the hash of the created block */ public async setTime( @@ -162,7 +162,7 @@ export class DevnetProvider { /** * Increase the time by the provided `increment` seconds. - * https://0xspaceshard.github.io/starknet-devnet/docs/next/starknet-time#increase-time + * https://starknet-io.github.io/starknet-devnet/docs/next/starknet-time#increase-time * @returns the new time in unix seconds */ public async increaseTime(increment: number): Promise { @@ -172,7 +172,7 @@ export class DevnetProvider { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/dump-load-restart#dumping + * https://starknet-io.github.io/starknet-devnet/docs/dump-load-restart#dumping * @param path the path where your Devnet instance will be serialized; if not provided, defaults to the dump-path provided via CLI on Devnet startup. */ public async dump(path?: string): Promise { @@ -181,7 +181,7 @@ export class DevnetProvider { /** * After loading, this DevnetProvider instance will be connected to the loaded Devnet instance. - * https://0xspaceshard.github.io/starknet-devnet/docs/dump-load-restart#dumping + * https://starknet-io.github.io/starknet-devnet/docs/dump-load-restart#dumping * @param path the path from which a Devnet instance will be deserialized */ public async load(path: string): Promise { @@ -189,7 +189,7 @@ export class DevnetProvider { } /** - * Modify gas prices, according to https://0xspaceshard.github.io/starknet-devnet/docs/gas + * Modify gas prices, according to https://starknet-io.github.io/starknet-devnet/docs/gas * @param price new gas prices; any gas price can be ommitted * @param generateBlock if `true`, a new block is generated immediately, having new gas prices; * otherwise (by default) the price change takes effect with the usual next block generation @@ -221,7 +221,7 @@ export class DevnetProvider { } /** - * More info at: https://0xspaceshard.github.io/starknet-devnet/docs/api#config-api + * More info at: https://starknet-io.github.io/starknet-devnet/docs/api#config-api * @returns the configuration of the underlying Devnet instance. The returned object is marked * as `any` because it may change too often. */ diff --git a/src/devnet.ts b/src/devnet.ts index c15a866..373973f 100644 --- a/src/devnet.ts +++ b/src/devnet.ts @@ -137,7 +137,7 @@ The output location is configurable via the config object passed to the Devnet s * If you already have a local Devnet you would like to run, use {@link spawnCommand}. * @param version if set to `"latest"`, uses the latest Devnet version compatible with this library; * otherwise needs to be a semver string with a prepended "v" (e.g. "v1.2.3") and - * should be available in https://github.com/0xSpaceShard/starknet-devnet/releases + * should be available in https://github.com/starknet-io/starknet-devnet/releases * @param config configuration object * @returns a newly spawned Devnet instance */ diff --git a/src/postman.ts b/src/postman.ts index 79a6422..c24b469 100644 --- a/src/postman.ts +++ b/src/postman.ts @@ -55,13 +55,13 @@ export interface L2ToL1MockTxResponse { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/postman + * https://starknet-io.github.io/starknet-devnet/docs/postman */ export class Postman { public constructor(private rpcProvider: RpcProvider) {} /** - * https://0xspaceshard.github.io/starknet-devnet/docs/postman#flush + * https://starknet-io.github.io/starknet-devnet/docs/postman#flush */ public async flush(additionalArgs = { dryRun: false }): Promise { return this.rpcProvider.sendRequest("devnet_postmanFlush", { @@ -75,7 +75,7 @@ export class Postman { * account of the L1 network specified with `networkUrl`, assuming default mnemonic seed. * If this predeployed account assumption does not hold, you should specify the private key * of the account to be used in `deployerAccountPrivateKey`. - * More info in: https://0xspaceshard.github.io/starknet-devnet/docs/postman#load + * More info in: https://starknet-io.github.io/starknet-devnet/docs/postman#load */ public async loadL1MessagingContract( networkUrl: string, @@ -95,7 +95,7 @@ export class Postman { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/postman#mock-transactions + * https://starknet-io.github.io/starknet-devnet/docs/postman#mock-transactions */ public async sendMessageToL2( l2ContractAddress: string, @@ -116,7 +116,7 @@ export class Postman { } /** - * https://0xspaceshard.github.io/starknet-devnet/docs/postman#l2-l1 + * https://starknet-io.github.io/starknet-devnet/docs/postman#l2-l1 */ public async consumeMessageFromL2( fromAddress: string, diff --git a/src/proofs.ts b/src/proofs.ts index 99d821e..539c430 100644 --- a/src/proofs.ts +++ b/src/proofs.ts @@ -26,7 +26,7 @@ export type DataAvailabilityMode = "L1" | "L2"; /** * INVOKE v3 transaction payload. * Compatible with starknet.js RPC.INVOKE_TXN_V3 type. - * https://0xspaceshard.github.io/starknet-devnet/docs/proofs + * https://starknet-io.github.io/starknet-devnet/docs/proofs */ export interface InvokeV3Transaction { type: "INVOKE"; @@ -52,7 +52,7 @@ export interface ProofL2ToL1Message extends L2ToL1Message { /** * Response from `starknet_proveTransaction` - * https://0xspaceshard.github.io/starknet-devnet/docs/proofs + * https://starknet-io.github.io/starknet-devnet/docs/proofs */ export interface ProveTransactionResponse { /** Base64-encoded mock proof */ @@ -68,7 +68,7 @@ export interface ProveTransactionResponse { * * This covers `starknet_proveTransaction`, a Devnet extension for proving/validating * `INVOKE v3` transaction payloads. For configuration (proof modes), see: - * https://0xspaceshard.github.io/starknet-devnet/docs/proofs + * https://starknet-io.github.io/starknet-devnet/docs/proofs */ export class Proofs { constructor(private rpcProvider: RpcProvider) {} @@ -82,7 +82,7 @@ export class Proofs { * If the transaction simulation fails (e.g. execution reverts), an error is returned * instead of a proof. * - * https://0xspaceshard.github.io/starknet-devnet/docs/proofs + * https://starknet-io.github.io/starknet-devnet/docs/proofs * * @param blockId the block context for proving (e.g. "latest", block number, or block hash) * @param transaction the INVOKE v3 transaction payload to prove diff --git a/src/version-handler.ts b/src/version-handler.ts index 99a7f45..dd99e7d 100644 --- a/src/version-handler.ts +++ b/src/version-handler.ts @@ -26,7 +26,7 @@ export class VersionHandler { /** * Ensure that the command corresponding to the provided `version` exists. * @param version semver string with a prepended "v"; - * should be available in https://github.com/0xSpaceShard/starknet-devnet/releases + * should be available in https://github.com/starknet-io/starknet-devnet/releases * @returns the path to the executable corresponding to the version */ static async getExecutable(version: string): Promise { @@ -65,7 +65,7 @@ export class VersionHandler { } private static async getArchivedExecutableUrl(version: string): Promise { - const releasesUrl = "https://api.github.com/repos/0xSpaceShard/starknet-devnet/releases"; + const releasesUrl = "https://api.github.com/repos/starknet-io/starknet-devnet/releases"; const releasesResp = await this.httpProvider.get(releasesUrl); if (releasesResp.status !== axios.HttpStatusCode.Ok) { @@ -92,7 +92,7 @@ export class VersionHandler { const arch = this.getCompatibleArch(); const platform = this.getCompatiblePlatform(); - return `https://github.com/0xSpaceShard/starknet-devnet/releases/download/${version}/starknet-devnet-${arch}-${platform}.tar.gz`; + return `https://github.com/starknet-io/starknet-devnet/releases/download/${version}/starknet-devnet-${arch}-${platform}.tar.gz`; } /** @@ -101,7 +101,10 @@ export class VersionHandler { * @returns the path where the archive was stored */ private static async fetchArchivedExecutable(url: string, versionDir: string): Promise { - const resp = await this.httpProvider.get(url, { responseType: "stream" }); + const resp = await this.httpProvider.get(url, { + responseType: "stream", + timeout: 120_000, + }); if (resp.status === axios.HttpStatusCode.NotFound) { throw new GithubError(`Not found: ${url}`); } else if (resp.status !== axios.HttpStatusCode.Ok) { diff --git a/test/data/l1_l2.cairo b/test/data/l1_l2.cairo index 48c9c37..557718f 100644 --- a/test/data/l1_l2.cairo +++ b/test/data/l1_l2.cairo @@ -1,6 +1,6 @@ //! L1 L2 messaging demo contract. //! Rewrite in Cairo 1 of the contract from previous Devnet version: -//! https://github.com/0xSpaceShard/starknet-devnet/blob/e477aa1bbe2348ba92af2a69c32d2eef2579d863/test/contracts/cairo/l1l2.cairo +//! https://github.com/starknet-io/starknet-devnet/blob/e477aa1bbe2348ba92af2a69c32d2eef2579d863/test/contracts/cairo/l1l2.cairo //! //! This contract does not use interface to keep the code as simple as possible. //! diff --git a/test/devnet-persistence.test.ts b/test/devnet-persistence.test.ts index 4453d75..72ab01b 100644 --- a/test/devnet-persistence.test.ts +++ b/test/devnet-persistence.test.ts @@ -6,7 +6,8 @@ import { expect } from "chai"; describe("Devnet persistence", async function () { this.timeout(10_000); // ms - const WORKDIR = "."; + const WORKDIR = "/tmp"; + const DUMP_PREFIX = "persisted_devnet_"; const DUMP_EXTENSION = ".dump.json"; const DUMMY_ADDRESS = "0x1"; @@ -16,7 +17,7 @@ describe("Devnet persistence", async function () { function removeDumps() { for (const fileName of fs.readdirSync(WORKDIR)) { - if (fileName.endsWith(DUMP_EXTENSION)) { + if (fileName.startsWith(DUMP_PREFIX) && fileName.endsWith(DUMP_EXTENSION)) { const file = path.join(WORKDIR, fileName); fs.unlinkSync(file); } @@ -33,7 +34,7 @@ describe("Devnet persistence", async function () { }); function getRandomDumpPath() { - const name = `persisted_devnet_${Math.random().toString().slice(2)}${DUMP_EXTENSION}`; + const name = `${DUMP_PREFIX}${Math.random().toString().slice(2)}${DUMP_EXTENSION}`; return path.join(WORKDIR, name); } diff --git a/test/devnet-spawn.test.ts b/test/devnet-spawn.test.ts index fb7f462..1987f27 100644 --- a/test/devnet-spawn.test.ts +++ b/test/devnet-spawn.test.ts @@ -150,11 +150,13 @@ describe("Spawnable Devnet", function () { }); it("should spawn by version", async function () { + this.timeout(30_000); const devnet = await Devnet.spawnVersion(`v${devnetVersion}`); expect(await devnet.provider.isAlive()).to.be.true; }); it("should spawn if specifying 'latest'", async function () { + this.timeout(30_000); const devnet = await Devnet.spawnVersion("latest"); expect(await devnet.provider.isAlive()).to.be.true; }); diff --git a/test/util.ts b/test/util.ts index 6c2755b..e31baf3 100644 --- a/test/util.ts +++ b/test/util.ts @@ -61,20 +61,12 @@ export async function getAccountBalance( ): Promise { const tokenContractAddress = config.tokenContractAddress ?? ETH_TOKEN_CONTRACT_ADDRESS; const blockIdentifier = config.blockIdentifier ?? starknet.BlockTag.PRE_CONFIRMED; + const tokenClass = await provider.getClassAt(tokenContractAddress, blockIdentifier); + const tokenContract = new starknet.Contract({ + abi: tokenClass.abi, + address: tokenContractAddress, + providerOrAccount: provider, + }); - // Call balanceOf via low-level callContract instead of Contract + abi, because - // Devnet's predeployed token classes expose their abi as the literal string "null", - // which breaks starknet.Contract's abi parser. - const result = await provider.callContract( - { - contractAddress: tokenContractAddress, - entrypoint: "balance_of", - calldata: [accountAddress], - }, - blockIdentifier, - ); - const felts = Array.isArray(result) ? result : (result as { result: string[] }).result; - const low = BigInt(felts[0]); - const high = BigInt(felts[1]); - return low + (high << 128n); + return tokenContract.withOptions({ blockIdentifier }).balanceOf(accountAddress); }