From f6b8019567c4ddd4c8fdec1ea6f967fd7846c0e1 Mon Sep 17 00:00:00 2001 From: FabijanC Date: Fri, 29 Sep 2023 09:29:08 +0200 Subject: [PATCH] Prepare release of 0.8.0 alpha.5 (#410) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [skip ci] - new release commit follows right away * Update docs (Cairo 0 compilation) * Update scarb to 0.7.0 * Update devnet to 0.6.3 * Update cairo compiler to 2.2.0 * Remove migrate --------- Co-authored-by: Petar Penović --- config.json | 6 +-- scripts/test-setup.sh | 1 + src/index.ts | 6 --- src/starknet-wrappers.ts | 19 -------- src/starknet_cli_wrapper.py | 10 ---- src/task-actions.ts | 22 --------- test/general-tests/cairo-migrate/check.ts | 21 -------- .../cairo-migrate/hardhat.config.ts | 12 ----- test/general-tests/cairo-migrate/network.json | 4 -- .../cairo-migrate/old_contract.cairo | 21 -------- test/utils/cli-functions.ts | 4 -- www/docs/intro.md | 48 +++++-------------- 12 files changed, 15 insertions(+), 159 deletions(-) delete mode 100644 test/general-tests/cairo-migrate/check.ts delete mode 100644 test/general-tests/cairo-migrate/hardhat.config.ts delete mode 100644 test/general-tests/cairo-migrate/network.json delete mode 100644 test/general-tests/cairo-migrate/old_contract.cairo diff --git a/config.json b/config.json index cbc6acff..92fdc643 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "CAIRO_LANG": "0.11.2", - "STARKNET_DEVNET": "0.6.0", - "CAIRO_COMPILER": "2.1.0", - "SCARB_VERSION": "0.4.0" + "STARKNET_DEVNET": "0.6.3", + "CAIRO_COMPILER": "2.2.0", + "SCARB_VERSION": "0.7.0" } diff --git a/scripts/test-setup.sh b/scripts/test-setup.sh index 7e3dd3ee..dc6b0770 100755 --- a/scripts/test-setup.sh +++ b/scripts/test-setup.sh @@ -14,6 +14,7 @@ trap 'for killable in $(jobs -p); do kill -9 $killable; done' EXIT rm -rf starknet-hardhat-example EXAMPLE_REPO_BRANCH="plugin" if [[ "$CIRCLE_BRANCH" == "master" ]] && [[ "$EXAMPLE_REPO_BRANCH" != "plugin" ]]; then + # prevents using starknet-hardhat-example branch other than "plugin" when starknet-hardhat-plugin PRs are merged echo "Invalid example repo branch: $EXAMPLE_REPO_BRANCH" exit 1 fi diff --git a/src/index.ts b/src/index.ts index 5d017669..15afeccf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -47,7 +47,6 @@ import { starknetTestAction, starknetRunAction, starknetPluginVersionAction, - starknetMigrateAction, starknetCompileCairo1Action, starknetBuildAction } from "./task-actions"; @@ -353,11 +352,6 @@ task("starknet-plugin-version", "Prints the version of the starknet plugin.").se starknetPluginVersionAction ); -task("migrate", "Migrates a cairo contract to syntax of cairo-lang v0.10.0.") - .addOptionalVariadicPositionalParam("paths", "The name of the contract to migrate") - .addFlag("inplace", "Applies changes to the files in place.") - .setAction(starknetMigrateAction); - task("amarna", "Runs Amarna, the static-analyzer and linter for Cairo.") .addFlag("script", "Run ./amarna.sh file to use Amarna with custom args.") .setAction(amarnaAction); diff --git a/src/starknet-wrappers.ts b/src/starknet-wrappers.ts index 87a8dbd0..bec4e6ac 100644 --- a/src/starknet-wrappers.ts +++ b/src/starknet-wrappers.ts @@ -71,11 +71,6 @@ interface NonceQueryWrapperOptions { blockNumber?: BlockNumber; } -interface MigrateContractWrapperOptions { - files: string[]; - inplace: boolean; -} - export abstract class StarknetWrapper { constructor( protected externalServer: ExternalServer, @@ -108,7 +103,6 @@ export abstract class StarknetWrapper { command: | "starknet-compile-deprecated" | "get_class_hash" - | "cairo-migrate" | "get_contract_class" | "get_contract_class_hash" | "get_compiled_class_hash", @@ -281,19 +275,6 @@ export abstract class StarknetWrapper { return executed.stdout.toString().trim(); } - public async migrateContract(options: MigrateContractWrapperOptions): Promise { - const commandArr = [...options.files]; - - if (options.inplace) { - commandArr.push("-i"); - } - const executed = await this.execute("cairo-migrate", commandArr); - if (executed.statusCode) { - throw new StarknetPluginError(executed.stderr.toString()); - } - return executed; - } - public async estimateMessageFee( functionName: string, fromAddress: string, diff --git a/src/starknet_cli_wrapper.py b/src/starknet_cli_wrapper.py index fbd1df24..2f5051e2 100644 --- a/src/starknet_cli_wrapper.py +++ b/src/starknet_cli_wrapper.py @@ -13,7 +13,6 @@ from starkware.starknet.compiler.compile import main as starknet_compile_main from starkware.starknet.core.os.contract_class.deprecated_class_hash import compute_deprecated_class_hash from starkware.starknet.services.api.contract_class.contract_class import DeprecatedCompiledClass - from starkware.cairo.lang.migrators.migrator import main as cairo_migrate_main from starkware.starknet.services.api.contract_class.contract_class import CompiledClass from starkware.starknet.services.api.contract_class.contract_class_utils import load_sierra from starkware.starknet.core.os.contract_class.class_hash import compute_class_hash @@ -68,21 +67,12 @@ async def get_contract_class_hash(args): print(hex(compute_class_hash(contract_class))) return 0 -async def cairo_migrate_main_wrapper(args): - sys.argv = [sys.argv[0], *args] - try: - return cairo_migrate_main() - except Exception as err: - print(err, file=sys.stderr) - return 1 - MAIN_MAP = { "starknet": starknet_main_wrapper, "starknet-compile-deprecated": starknet_compile_main_wrapper, "get_class_hash": get_class_hash, "get_contract_class_hash": get_contract_class_hash, "get_compiled_class_hash": get_compiled_class_hash, - "cairo-migrate": cairo_migrate_main_wrapper } class MyRequestHandler(BaseHTTPRequestHandler): diff --git a/src/task-actions.ts b/src/task-actions.ts index 0b80fbdd..3057b5c9 100644 --- a/src/task-actions.ts +++ b/src/task-actions.ts @@ -620,25 +620,3 @@ Use the "network" property of the "starknet" object in your hardhat config file. export async function starknetPluginVersionAction() { console.log(`Version: ${version}`); } - -export async function starknetMigrateAction(args: TaskArguments, hre: HardhatRuntimeEnvironment) { - if (!args.paths || args.paths.length < 1) { - throw new StarknetPluginError("Expected at least one file to migrate"); - } - - const root = hre.config.paths.root; - const defaultSourcesPath = hre.config.paths.starknetSources; - const files: string[] = args.paths || [defaultSourcesPath]; - const cairoFiles: string[] = []; - for (let file of files) { - file = adaptPath(root, file); - cairoFiles.push(file); - } - - const result = await hre.starknetWrapper.migrateContract({ - files: cairoFiles, - inplace: args.inplace - }); - - processExecuted(result, true); -} diff --git a/test/general-tests/cairo-migrate/check.ts b/test/general-tests/cairo-migrate/check.ts deleted file mode 100644 index dc5e2d6f..00000000 --- a/test/general-tests/cairo-migrate/check.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { copyFileSync, readFileSync } from "fs"; -import path from "path"; -import { hardhatStarknetMigrate } from "../../utils/cli-functions"; -import { assertContains } from "../../utils/utils"; - -const contractName = "old_contract.cairo"; -const contractPath = path.join("contracts", contractName); -const newComment = "// Declare this file as a Starknet contract."; - -copyFileSync(path.join(__dirname, contractName), contractPath); - -console.log("Testing migration of old cairo contract to a new one"); -// Migrate contract to new version. -const execution = hardhatStarknetMigrate([contractPath]); -assertContains(execution.stdout, newComment); - -// Migrate contract to new version with change content in place option. -hardhatStarknetMigrate(`${contractPath} --inplace`.split(" ")); -assertContains(readFileSync(contractPath).toString(), newComment); - -console.log("Success"); diff --git a/test/general-tests/cairo-migrate/hardhat.config.ts b/test/general-tests/cairo-migrate/hardhat.config.ts deleted file mode 100644 index f568acd8..00000000 --- a/test/general-tests/cairo-migrate/hardhat.config.ts +++ /dev/null @@ -1,12 +0,0 @@ -import "@shardlabs/starknet-hardhat-plugin"; - -module.exports = { - starknet: { - network: process.env.NETWORK - }, - networks: { - devnet: { - url: "http://127.0.0.1:5050" - } - } -}; diff --git a/test/general-tests/cairo-migrate/network.json b/test/general-tests/cairo-migrate/network.json deleted file mode 100644 index f1977760..00000000 --- a/test/general-tests/cairo-migrate/network.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "../../network.schema", - "devnet": true -} diff --git a/test/general-tests/cairo-migrate/old_contract.cairo b/test/general-tests/cairo-migrate/old_contract.cairo deleted file mode 100644 index bb8b6fbd..00000000 --- a/test/general-tests/cairo-migrate/old_contract.cairo +++ /dev/null @@ -1,21 +0,0 @@ -# Declare this file as a Starknet contract. -%lang starknet - -from starkware.cairo.common.cairo_builtins import HashBuiltin - -# Define a storage variable. -@storage_var -func balance() -> (res : felt): -end - -# Increases the balance by the given amount. -@external -func increase_balance{ - syscall_ptr : felt*, - pedersen_ptr : HashBuiltin*, - range_check_ptr, -}(amount : felt): - let (res) = balance.read() - balance.write(res + amount) - return () -end diff --git a/test/utils/cli-functions.ts b/test/utils/cli-functions.ts index 67acef44..1241d0af 100644 --- a/test/utils/cli-functions.ts +++ b/test/utils/cli-functions.ts @@ -33,10 +33,6 @@ export const hardhatStarknetVerify = (args: Array, expectFailure = false return exec(`npx hardhat starknet-verify ${args.join(" ")}`, expectFailure); }; -export const hardhatStarknetMigrate = (args: Array, expectFailure = false) => { - return exec(`npx hardhat migrate ${args.join(" ")}`, expectFailure); -}; - export const hardhatStarknetPluginVersion = () => { return exec("npx hardhat starknet-plugin-version"); }; diff --git a/www/docs/intro.md b/www/docs/intro.md index b6006c12..d5dba777 100644 --- a/www/docs/intro.md +++ b/www/docs/intro.md @@ -46,7 +46,7 @@ This plugin was tested with: - Node.js v14.17.3 - npm/npx v7.19.1 - Docker v20.10.8 (optional): - - Since plugin version 0.3.4, Docker is no longer necessary if you opt for a Python environment (more info in [Config](#cairo-version)). + - Since plugin version 0.3.4, Docker is no longer necessary if you opt for a Python environment (more info in [Config](#cairo-0-compilation)). - If you opt for the containerized version, make sure you have a running Docker daemon. - If you're experiencing Docker access issues, check [this](https://stackoverflow.com/questions/52364905/after-executing-following-code-of-dockerode-npm-getting-error-connect-eacces-v). - Linux / macOS: @@ -125,7 +125,7 @@ starknet.getContractFactory("MyPackage_FooContract"); The name of the file where the contract was defined doesn't play a role. -The plugin doesn't have a default Scarb command yet (a dockerized wrapper will be supported soon). You need to provide a `scarbCommand` (either an exact command or the path to it) under `starknet` in your hardhat config file, or you can override that via `--scarb-command `. +The plugin doesn't have a default Scarb command yet. You need to provide a `scarbCommand` (either an exact command or the path to it) under `starknet` in your hardhat config file, or you can override that via `--scarb-command `. ### `starknet-verify` @@ -151,20 +151,6 @@ $ npx hardhat starknet-plugin-version Prints the version of the plugin. -### `migrate` - -``` -$ npx hardhat migrate [PATH...] [--inplace] -``` - -**NOT APPLICABLE TO CAIRO 1** - -Converts old syntax to Cairo 0.10 syntax. The `--inplace` flag will change the contract file in place. - -``` -$ npx hardhat migrate --inplace contract/contract.cairo -``` - ### `run` Using `--starknet-network` with `hardhat run` currently does not have effect. Use the `network` property of the `starknet` object in your hardhat config file. @@ -515,42 +501,28 @@ If you want to have your debug lines printed in the same terminal as your hardha Specify custom configuration by editing your project's `hardhat.config.ts` (or `hardhat.config.js`). -### Cairo version +### Cairo 0 compilation -Use this configuration option to select the `cairo-lang`/`starknet` version used by the underlying Docker container. - -A Docker image tailored to the machine will be pulled. The `-arm` suffix will be applied to the version name, if it's not applied on `hardhat.config.ts`, if the device's architecture is `arm64`. (e.g. `dockerizedVersion: "0.8.1-arm"` and `dockerizedVersion: "0.8.1"` both will work). - -If you specify neither `dockerizedVersion` nor [venv](#existing-virtual-environment), the latest dockerized version is used. - -A list of available dockerized versions can be found [here](https://hub.docker.com/r/shardlabs/cairo-cli/tags). +Cairo 0 compilation is by default done using the latest stable Dockerized compiler. If you want to use an older Cairo 0 compiler, specify the full semver string ([available versions](https://hub.docker.com/r/shardlabs/cairo-cli/tags)): ```javascript module.exports = { starknet: { - dockerizedVersion: "0.8.1" + // Docker image tailored to the machine is pulled. If not applied, the `-arm` suffix is applied to the version name if on an arm64 machine. + dockerizedVersion: "0.11.2" } ... }; ``` -### Existing virtual environment - -If you want to use an existing Python virtual environment (pyenv, poetry, conda, miniconda), specify it by using `starknet["venv"]`. - -To use the currently activated environment (or if you have the starknet commands globally installed), set `venv` to `"active"`. - -In any case, the specified environment is expected to contain the `python3` command. - -If you are on a Mac, you may experience Docker-related issues, so this may be the only way to run the plugin. - -If you specify neither [dockerizedVersion](#cairo-version) nor `venv`, the latest dockerized version is used. +If you cannot use Docker (e.g. on Mac), you'll need to have the `cairo-lang` Python package installed locally and `python3` command runnable. Use one of the following: ```typescript module.exports = { starknet: { - // venv: "active" <- for the active virtual environment + // venv: "active" <- for the active virtual environment or global environment // venv: "path/to/my-venv" <- for env created with e.g. `python -m venv path/to/my-venv` + // Python virtual environment can be created with: pyenv, poetry, conda, miniconda, ... venv: "" } }; @@ -769,6 +741,8 @@ const contractFactory = await starknet.getContractFactory( Recompilation is performed when contracts are updated or when artifacts are missing. A file will be created with the name `cairo-files-cache.json` to handle caching. Recompilation is handled before the following [CLI commands](#cli-commands) are executed. +This feature is **only** guaranteed to work with Cairo 0 contracts. + - `npx hardhat run` - `npx hardhat test`