diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6286e81b6..760e09edc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,6 @@ jobs: with: node-version: 16 cache: npm - - name: npm latest - run: npm i -g npm@8 && npm i -g npm@latest - name: Install run: npm install - name: Build @@ -37,8 +35,6 @@ jobs: with: node-version: 16 cache: npm - - name: npm latest - run: npm i -g npm - name: Install run: npm install - name: Build @@ -53,15 +49,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [16, 18, 20] + node: [16, 18, 20.5] steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: ${{ matrix.node }} cache: npm - - name: npm latest - run: npm i -g npm - name: Install run: npm install - name: Build @@ -80,8 +74,6 @@ jobs: with: node-version: 16 cache: npm - - name: npm latest - run: npm i -g npm - name: Install run: npm install - name: Build diff --git a/README.md b/README.md index c6baa835d..e28e5463d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![npm](https://img.shields.io/npm/v/@ignored/hardhat-ignition.svg)](https://www.npmjs.com/package/@ignored/hardhat-ignition) [![hardhat](https://hardhat.org/buidler-plugin-badge.svg?1)](https://hardhat.org) +[![npm](https://img.shields.io/npm/v/@nomicfoundation/hardhat-ignition.svg)](https://www.npmjs.com/package/@nomicfoundation/hardhat-ignition) [![hardhat](https://hardhat.org/buidler-plugin-badge.svg?1)](https://hardhat.org) # Ignition @@ -13,19 +13,19 @@ Join our [Hardhat Support Discord server](https://hardhat.org/discord) to stay u ## Installation ```bash -npm install --save-dev @ignored/hardhat-ignition +npm install --save-dev @nomicfoundation/hardhat-ignition ``` And add the following statement to your `hardhat.config.js`: ```js -require("@ignored/hardhat-ignition"); +require("@nomicfoundation/hardhat-ignition"); ``` Or, if you are using TypeScript, add this to your `hardhat.config.ts`: ```js -import "@ignored/hardhat-ignition"; +import "@nomicfoundation/hardhat-ignition"; ``` ## Getting Started @@ -44,7 +44,7 @@ See our [Getting started guide](./docs/getting-started-guide.md) for a worked ex - [Switching based on the _Network Chain ID_](./docs/creating-modules-for-deployment.md#switching-based-on-the-network-chain-id) - [Using Ignition in _Hardhat_ tests](./docs/using-ignition-in-hardhat-tests.md) - [Running a deployment](./docs/running-a-deployment.md) - - [Visualizing your deployment with the `plan` task](./docs/running-a-deployment.md#visualizing-your-deployment-with-the-plan-task) + - [Visualizing your deployment with the `visualize` task](./docs/running-a-deployment.md#visualizing-your-deployment-with-the-visualize-task) - [Executing the deployment](./docs/running-a-deployment.md#executing-the-deployment) ### Examples diff --git a/docs/creating-modules-for-deployment.md b/docs/creating-modules-for-deployment.md index 59a823ed2..a0c1dda98 100644 --- a/docs/creating-modules-for-deployment.md +++ b/docs/creating-modules-for-deployment.md @@ -29,7 +29,7 @@ An **Ignition** deployment is composed of modules. A module is a special javascr For example, this is a minimal module `MyModule` that deploys an instance of a `Token` contract and exposes it to any consumer of `MyModule`: ```javascript -const { buildModule } = require("@ignored/hardhat-ignition"); +const { buildModule } = require("@nomicfoundation/hardhat-ignition"); module.exports = buildModule("MyModule", (m) => { const token = m.contract("Token"); @@ -92,13 +92,13 @@ const b = m.contract("B", [], { ### Deploying from an artifact -To allow you to use your own mechanism for getting the contract artifact, `contractFromArtifact` supports passing an `Artifact` as the second parameter: +To allow you to use your own mechanism for getting the contract artifact, `contract` supports passing an `Artifact` as the second parameter: ```javascript const artifact = hre.artifacts.readArtifactSync("Foo"); const userModule = buildModule("MyModule", (m) => { - m.contractFromArtifact("Foo", artifact, [0]); + m.contract("Foo", artifact, [0]); }); ``` @@ -107,7 +107,7 @@ const userModule = buildModule("MyModule", (m) => { A user might need to execute a method in a contract that wasn't deployed by Ignition. An existing contract can be leveraged by passing an address and artifact: ```tsx -const uniswap = m.contractAtFromArtifact("UniswapRouter", "0x0...", artifact); +const uniswap = m.contractAt("UniswapRouter", "0x0...", artifact); m.call(uniswap, "swap", [ /*...*/ diff --git a/docs/getting-started-guide.md b/docs/getting-started-guide.md index 328fb81b8..56d15a88d 100644 --- a/docs/getting-started-guide.md +++ b/docs/getting-started-guide.md @@ -40,7 +40,7 @@ $ npx hardhat Add **Ignition** to your **Hardhat** project by installing the plugin: ```bash -npm install --save-dev @ignored/hardhat-ignition +npm install --save-dev @nomicfoundation/hardhat-ignition ``` Modify your `hardhat.config.js` file, to include **Ignition**: @@ -48,7 +48,7 @@ Modify your `hardhat.config.js` file, to include **Ignition**: ```javascript require("@nomicfoundation/hardhat-toolbox"); // ... -require("@ignored/hardhat-ignition"); +require("@nomicfoundation/hardhat-ignition"); ``` Create an `./ignition` folder in your project root to contain your deployment modules. @@ -63,7 +63,7 @@ Add a deployment module under the `./ignition` folder for the example `Lock.sol` ```js // ./ignition/LockModule.js -const { buildModule } = require("@ignored/hardhat-ignition"); +const { buildModule } = require("@nomicfoundation/hardhat-ignition"); const currentTimestampInSeconds = Math.round(new Date(2023, 0, 1) / 1000); const TEN_YEAR_IN_SECS = 10 * 365 * 24 * 60 * 60; diff --git a/docs/images/plan-1.png b/docs/images/visualize-1.png similarity index 100% rename from docs/images/plan-1.png rename to docs/images/visualize-1.png diff --git a/docs/images/plan-2.png b/docs/images/visualize-2.png similarity index 100% rename from docs/images/plan-2.png rename to docs/images/visualize-2.png diff --git a/docs/publish.md b/docs/publish.md index 965126f8a..e7814f35e 100644 --- a/docs/publish.md +++ b/docs/publish.md @@ -30,5 +30,5 @@ yyyy-mm-dd` release. 13. On a successful check, `rebase merge` the release branch into `main` 14. Switch to main branch and pull the latest changes 15. Git tag the version, `g tag -a v0.x.x -m "v0.x.x"` and push the tag `git push --follow-tags` -16. Publish `@ignored/ignition-core`, `@ignored/ignition-ui` and `@ignored/hardhat-ignition` : `npm publish -w @ignored/ignition-core -w @ignored/ignition-ui -w @ignored/hardhat-ignition` +16. Publish `@nomicfoundation/ignition-core`, `@nomicfoundation/ignition-ui` and `@nomicfoundation/hardhat-ignition` : `npm publish -w @nomicfoundation/ignition-core -w @nomicfoundation/ignition-ui -w @nomicfoundation/hardhat-ignition` 17. Create a release on github off of the pushed tag diff --git a/docs/running-a-deployment.md b/docs/running-a-deployment.md index 14b12762d..5cc484a02 100644 --- a/docs/running-a-deployment.md +++ b/docs/running-a-deployment.md @@ -4,34 +4,34 @@ ### Table of Contents -- [Visualizing your deployment with the `plan` task](./running-a-deployment.md#visualizing-your-deployment-with-the-plan-task) +- [Visualizing your deployment with the `visualize` task](./running-a-deployment.md#visualizing-your-deployment-with-the-visualize-task) - [Executing the deployment](./running-a-deployment.md#executing-the-deployment) - [Configuration options](./running-a-deployment.md#configuration-options) - + --- Once you have built and tested your deployment module, it is time to deploy it! Start by making sure you understand exactly what will be executed on chain. -## Visualizing your deployment with the `plan` task +## Visualizing your deployment with the `visualize` task -**Ignition** adds a `plan` task to the cli, that will generate a HTML report showing a _dry run_ of the deployment - the contract deploys and contract calls. +**Ignition** adds a `visualize` task to the cli, that will generate a HTML report showing a _dry run_ of the deployment - the contract deploys and contract calls. -The `plan` task takes one argument, the module to visualize. For example, using the `ENS.js` module from our [ENS example project](../examples/ens/README.md): +The `visualize` task takes one argument, the module to visualize. For example, using the `ENS.js` module from our [ENS example project](../examples/ens/README.md): ```bash -npx hardhat plan ENS +npx hardhat visualize ENS ``` -Running `plan` will generate the report based on the given module (in this case `ENS.js`), it will then open the report in your system's default browser: +Running `visualize` will generate the report based on the given module (in this case `ENS.js`), it will then open the report in your system's default browser: -![Main plan output](images/plan-1.png) +![Main visualize output](images/visualize-1.png) The report summarises the contract that will be deployed and the contract calls that will be made. It shows the dependency graph as it will be executed by Ignition (where a dependency will not be run until all its dependents have successfully completed). -If something in your deployment isn't behaving the way you expected, the `plan` task can be an extremely helpful tool for debugging and verifying that your and **Ignition**'s understanding of the deployment are the same. +If something in your deployment isn't behaving the way you expected, the `visualize` task can be an extremely helpful tool for debugging and verifying that your and **Ignition**'s understanding of the deployment are the same. ## Executing the deployment diff --git a/examples/complete/hardhat.config.js b/examples/complete/hardhat.config.js index 25f05d06a..13d2a0f3f 100644 --- a/examples/complete/hardhat.config.js +++ b/examples/complete/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomicfoundation/hardhat-toolbox"); -require("@ignored/hardhat-ignition"); +require("@nomicfoundation/hardhat-ignition"); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { diff --git a/examples/complete/ignition/CompleteModule.js b/examples/complete/ignition/CompleteModule.js index 20568a2d1..3c6a3b669 100644 --- a/examples/complete/ignition/CompleteModule.js +++ b/examples/complete/ignition/CompleteModule.js @@ -1,5 +1,5 @@ // ./ignition/CompleteModule.js -const { buildModule } = require("@ignored/hardhat-ignition"); +const { buildModule } = require("@nomicfoundation/hardhat-ignition"); const withLibArtifact = require("../libArtifacts/ContractWithLibrary.json"); const libArtifact = require("../libArtifacts/BasicLibrary.json"); @@ -7,17 +7,12 @@ const libArtifact = require("../libArtifacts/BasicLibrary.json"); module.exports = buildModule("CompleteModule", (m) => { const basic = m.contract("BasicContract"); const library = m.library("BasicLibrary"); - const libFromArtifact = m.libraryFromArtifact("BasicLibrary", libArtifact, { + const libFromArtifact = m.library("BasicLibrary", libArtifact, { id: "BasicLibrary2", }); - const withLib = m.contractFromArtifact( - "ContractWithLibrary", - withLibArtifact, - [], - { - libraries: { BasicLibrary: library }, - } - ); + const withLib = m.contract("ContractWithLibrary", withLibArtifact, [], { + libraries: { BasicLibrary: library }, + }); const call = m.call(basic, "basicFunction", [40]); const eventArg = m.readEventArgument(call, "BasicEvent", "eventArg"); @@ -26,14 +21,14 @@ module.exports = buildModule("CompleteModule", (m) => { const duplicate = m.contractAt("BasicContract", basic, { id: "BasicContract2", }); - const duplicateWithLib = m.contractAtFromArtifact( + const duplicateWithLib = m.contractAt( "ContractWithLibrary", withLib, withLibArtifact, { id: "ContractWithLibrary2" } ); - m.send("test-send", duplicate, 123n); + m.send("test_send", duplicate, 123n); return { basic, diff --git a/examples/complete/package.json b/examples/complete/package.json index 6b11a4ead..f33290ecb 100644 --- a/examples/complete/package.json +++ b/examples/complete/package.json @@ -1,7 +1,7 @@ { "name": "@nomicfoundation/ignition-complete-example", "private": true, - "version": "0.3.0", + "version": "0.4.0", "scripts": { "test": "hardhat test", "lint": "npm run prettier -- --check && npm run eslint", @@ -10,7 +10,7 @@ "prettier": "prettier \"*.{js,md,json}\" \"ignition/*.{js,md,json}\" \"test/*.{js,md,json}\" \"contracts/**/*.sol\"" }, "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" diff --git a/examples/ens/hardhat.config.js b/examples/ens/hardhat.config.js index 0e8d9661a..35757a331 100644 --- a/examples/ens/hardhat.config.js +++ b/examples/ens/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomicfoundation/hardhat-toolbox"); -require("@ignored/hardhat-ignition"); +require("@nomicfoundation/hardhat-ignition"); /** * @type import('hardhat/config').HardhatUserConfig diff --git a/examples/ens/ignition/ENS.js b/examples/ens/ignition/ENS.js index 335ae8e1e..3d817ab9a 100644 --- a/examples/ens/ignition/ENS.js +++ b/examples/ens/ignition/ENS.js @@ -1,4 +1,4 @@ -const { buildModule } = require("@ignored/hardhat-ignition"); +const { buildModule } = require("@nomicfoundation/hardhat-ignition"); const namehash = require("eth-ens-namehash"); const ethers = hre.ethers; @@ -30,7 +30,7 @@ const resolverModule = buildModule("RESOLVER", (m) => { const resolver = m.contract("PublicResolver", [ens, ZERO_ADDRESS]); m.call(ens, "setSubnodeOwner", [ZERO_HASH, resolverLabel, account], { - id: "set-subnode-owner-for-resolver", + id: "set_subnode_owner_for_resolver", }); m.call(ens, "setResolver", [resolverNode, resolver]); @@ -50,7 +50,7 @@ const reverseRegistrarModule = buildModule("REVERSEREGISTRAR", (m) => { const reverseRegistrar = m.contract("ReverseRegistrar", [ens, resolver]); m.call(ens, "setSubnodeOwner", [ZERO_HASH, reverseLabel, account], { - id: "set-subnode-owner-reverse", + id: "set_subnode_owner_reverse", }); m.call( @@ -58,7 +58,7 @@ const reverseRegistrarModule = buildModule("REVERSEREGISTRAR", (m) => { "setSubnodeOwner", [reverseTldHash, addrLabel, reverseRegistrar], { - id: "set-subnode-addr-label", + id: "set_subnode_addr_label", } ); diff --git a/examples/ens/ignition/test-registrar.js b/examples/ens/ignition/test-registrar.js index e1e65070a..30d036824 100644 --- a/examples/ens/ignition/test-registrar.js +++ b/examples/ens/ignition/test-registrar.js @@ -1,4 +1,4 @@ -const { buildModule } = require("@ignored/hardhat-ignition"); +const { buildModule } = require("@nomicfoundation/hardhat-ignition"); const namehash = require("eth-ens-namehash"); const setupENSRegistry = require("./ENS"); @@ -11,7 +11,7 @@ const ZERO_HASH = const ACCOUNT_0 = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; -module.exports = buildModule("TEST registrar", (m) => { +module.exports = buildModule("TEST_registrar", (m) => { const tld = "test"; const tldHash = namehash.hash(tld); const tldLabel = labelhash(tld); @@ -22,7 +22,7 @@ module.exports = buildModule("TEST registrar", (m) => { const registrar = m.contract("FIFSRegistrar", [ens, tldHash]); m.call(ens, "setSubnodeOwner", [ZERO_HASH, tldLabel, ACCOUNT_0], { - id: "set-subnode-owner-for-registrar", + id: "set_subnode_owner_for_registrar", }); return { ens, resolver, registrar, reverseRegistrar }; diff --git a/examples/ens/package.json b/examples/ens/package.json index c01795cb0..3c21a7f26 100644 --- a/examples/ens/package.json +++ b/examples/ens/package.json @@ -1,7 +1,7 @@ { "name": "@nomicfoundation/ignition-ens-example", "private": true, - "version": "0.3.0", + "version": "0.4.0", "scripts": { "test": "hardhat test", "lint": "npm run prettier -- --check && npm run eslint", @@ -10,7 +10,7 @@ "prettier": "prettier \"*.{js,md,json}\" \"ignition/*.{js,md,json}\" \"test/*.{js,md,json}\" \"contracts/**/*.sol\"" }, "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" diff --git a/examples/sample/hardhat.config.js b/examples/sample/hardhat.config.js index b58214d62..e2073ce58 100644 --- a/examples/sample/hardhat.config.js +++ b/examples/sample/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomicfoundation/hardhat-toolbox"); -require("@ignored/hardhat-ignition"); +require("@nomicfoundation/hardhat-ignition"); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { diff --git a/examples/sample/ignition/LockModule.js b/examples/sample/ignition/LockModule.js index b92a97215..b2f59882b 100644 --- a/examples/sample/ignition/LockModule.js +++ b/examples/sample/ignition/LockModule.js @@ -1,5 +1,5 @@ // ./ignition/LockModule.js -const { buildModule } = require("@ignored/hardhat-ignition"); +const { buildModule } = require("@nomicfoundation/hardhat-ignition"); const currentTimestampInSeconds = Math.round(new Date(2023, 0, 1) / 1000); const TEN_YEAR_IN_SECS = 10 * 365 * 24 * 60 * 60; diff --git a/examples/sample/package.json b/examples/sample/package.json index 66ef176f0..22d64492c 100644 --- a/examples/sample/package.json +++ b/examples/sample/package.json @@ -1,7 +1,7 @@ { "name": "@nomicfoundation/ignition-sample-example", "private": true, - "version": "0.3.0", + "version": "0.4.0", "scripts": { "test": "hardhat test", "lint": "npm run prettier -- --check && npm run eslint", @@ -10,7 +10,7 @@ "prettier": "prettier \"*.{js,md,json}\" \"ignition/*.{js,md,json}\" \"test/*.{js,md,json}\" \"contracts/**/*.sol\"" }, "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" diff --git a/examples/ts-sample/hardhat.config.ts b/examples/ts-sample/hardhat.config.ts index 032fa8e67..007372f69 100644 --- a/examples/ts-sample/hardhat.config.ts +++ b/examples/ts-sample/hardhat.config.ts @@ -1,7 +1,7 @@ import type { HardhatUserConfig } from "hardhat/config"; +import "@nomicfoundation/hardhat-ignition"; import "@nomicfoundation/hardhat-toolbox"; -import "@ignored/hardhat-ignition"; const config: HardhatUserConfig = { solidity: "0.8.17", diff --git a/examples/ts-sample/ignition/LockModule.ts b/examples/ts-sample/ignition/LockModule.ts index e196458c5..cc64bd5d8 100644 --- a/examples/ts-sample/ignition/LockModule.ts +++ b/examples/ts-sample/ignition/LockModule.ts @@ -1,4 +1,4 @@ -import { buildModule } from "@ignored/hardhat-ignition"; +import { buildModule } from "@nomicfoundation/hardhat-ignition"; import hre from "hardhat"; const currentTimestampInSeconds = Math.round( diff --git a/examples/ts-sample/package.json b/examples/ts-sample/package.json index f37b4e158..417c3ac75 100644 --- a/examples/ts-sample/package.json +++ b/examples/ts-sample/package.json @@ -1,7 +1,7 @@ { "name": "@nomicfoundation/ignition-ts-sample-example", "private": true, - "version": "0.3.0", + "version": "0.4.0", "scripts": { "test": "hardhat test", "lint": "npm run prettier -- --check && npm run eslint", @@ -10,7 +10,7 @@ "prettier": "prettier \"*.{js,ts,md,json}\" \"ignition/*.{js,ts,md,json}\" \"test/*.{js,ts,md,json}\" \"contracts/**/*.sol\"" }, "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" diff --git a/examples/uniswap/.gitignore b/examples/uniswap/.gitignore index 36077f288..72d98e146 100644 --- a/examples/uniswap/.gitignore +++ b/examples/uniswap/.gitignore @@ -7,3 +7,4 @@ typechain #Hardhat files cache artifacts +ignition/deployments diff --git a/examples/uniswap/hardhat.config.js b/examples/uniswap/hardhat.config.js index 08c4c1b02..7c6679302 100644 --- a/examples/uniswap/hardhat.config.js +++ b/examples/uniswap/hardhat.config.js @@ -1,5 +1,5 @@ require("@nomicfoundation/hardhat-toolbox"); -require("@ignored/hardhat-ignition"); +require("@nomicfoundation/hardhat-ignition"); /** * @type import('hardhat/config').HardhatUserConfig diff --git a/examples/uniswap/ignition/Uniswap.js b/examples/uniswap/ignition/Uniswap.js index 04b35f8e2..d753af1a1 100644 --- a/examples/uniswap/ignition/Uniswap.js +++ b/examples/uniswap/ignition/Uniswap.js @@ -1,4 +1,4 @@ -const { buildModule } = require("@ignored/hardhat-ignition"); +const { buildModule } = require("@nomicfoundation/hardhat-ignition"); const UniswapV3Factory = require("@uniswap/v3-core/artifacts/contracts/UniswapV3Factory.sol/UniswapV3Factory.json"); const UniswapInterfaceMulticall = require("@uniswap/v3-periphery/artifacts/contracts/lens/UniswapInterfaceMulticall.sol/UniswapInterfaceMulticall.json"); @@ -49,10 +49,7 @@ module.exports = buildModule("Uniswap", (m) => { const weth9 = m.contract("WETH9"); // DEPLOY_V3_CORE_FACTORY - const uniswapV3Factory = m.contractFromArtifact( - "UniswapV3Factory", - UniswapV3Factory - ); + const uniswapV3Factory = m.contract("UniswapV3Factory", UniswapV3Factory); // 1 - add-1bp-fee-tier m.call(uniswapV3Factory, "enableFeeAmount", [ @@ -61,22 +58,19 @@ module.exports = buildModule("Uniswap", (m) => { ]); // 2 - deploy-multicall2 - const multicall2Address = m.contractFromArtifact( - "Multicall2", - UniswapInterfaceMulticall - ); + const multicall2Address = m.contract("Multicall2", UniswapInterfaceMulticall); // DEPLOY_PROXY_ADMIN - const proxyAdmin = m.contractFromArtifact("ProxyAdmin", ProxyAdmin); + const proxyAdmin = m.contract("ProxyAdmin", ProxyAdmin); // DEPLOY_TICK_LENS - const tickLens = m.contractFromArtifact("TickLens", TickLens); + const tickLens = m.contract("TickLens", TickLens); // DEPLOY_NFT_DESCRIPTOR_LIBRARY_V1_3_0 - const nftDescriptor = m.contractFromArtifact("NFTDescriptor", NFTDescriptor); + const nftDescriptor = m.contract("NFTDescriptor", NFTDescriptor); // DEPLOY_NFT_POSITION_DESCRIPTOR_V1_3_0 - const nonfungibleTokenPositionDescriptor = m.contractFromArtifact( + const nonfungibleTokenPositionDescriptor = m.contract( "nonfungibleTokenPositionDescriptorAddressV1_3_0", NonfungibleTokenPositionDescriptor, [weth9, asciiStringToBytes32(NATIVE_CURRENCY_LABEL)], @@ -88,21 +82,21 @@ module.exports = buildModule("Uniswap", (m) => { ); // DEPLOY_TRANSPARENT_PROXY_DESCRIPTOR - const descriptorProxy = m.contractFromArtifact( + const descriptorProxy = m.contract( "TransparentUpgradeableProxy", TransparentUpgradeableProxy, [nonfungibleTokenPositionDescriptor, proxyAdmin, "0x"] ); // DEPLOY_NONFUNGIBLE_POSITION_MANAGER - const nonfungibleTokenPositionManager = m.contractFromArtifact( + const nonfungibleTokenPositionManager = m.contract( "NonfungibleTokenPositionManager", NonfungiblePositionManager, [uniswapV3Factory, weth9, descriptorProxy] ); // DEPLOY_V3_MIGRATOR - const v3Migrator = m.contractFromArtifact("V3Migrator", V3Migrator, [ + const v3Migrator = m.contract("V3Migrator", V3Migrator, [ uniswapV3Factory, weth9, nonfungibleTokenPositionManager, @@ -114,7 +108,7 @@ module.exports = buildModule("Uniswap", (m) => { }); // DEPLOY_V3_STAKER - const v3Staker = m.contractFromArtifact("UniswapV3Staker", UniswapV3Staker, [ + const v3Staker = m.contract("UniswapV3Staker", UniswapV3Staker, [ uniswapV3Factory, nonfungibleTokenPositionManager, MAX_INCENTIVE_START_LEAD_TIME, @@ -122,13 +116,10 @@ module.exports = buildModule("Uniswap", (m) => { ]); // DEPLOY_QUOTER_V2 - const quoterV2 = m.contractFromArtifact("QuoterV2", QuoterV2, [ - uniswapV3Factory, - weth9, - ]); + const quoterV2 = m.contract("QuoterV2", QuoterV2, [uniswapV3Factory, weth9]); // DEPLOY_V3_SWAP_ROUTER_02 - const swapRouter02 = m.contractFromArtifact("SwapRouter02", SwapRouter02, [ + const swapRouter02 = m.contract("SwapRouter02", SwapRouter02, [ v2CoreFactoryAddress, uniswapV3Factory, nonfungibleTokenPositionManager, diff --git a/examples/uniswap/package.json b/examples/uniswap/package.json index e56b8e9ac..cbadd0a13 100644 --- a/examples/uniswap/package.json +++ b/examples/uniswap/package.json @@ -1,7 +1,7 @@ { "name": "@nomicfoundation/ignition-uniswap-example", "private": true, - "version": "0.3.0", + "version": "0.4.0", "scripts": { "test": "hardhat test", "lint": "npm run prettier -- --check && npm run eslint", @@ -10,7 +10,7 @@ "prettier": "prettier \"*.{js,md,json}\" \"ignition/*.{js,md,json}\" \"test/*.{js,md,json}\" \"contracts/**/*.sol\"" }, "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" diff --git a/package-lock.json b/package-lock.json index 9f7cf30a2..a2f1745b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,9 +30,9 @@ }, "examples/complete": { "name": "@nomicfoundation/ignition-complete-example", - "version": "0.3.0", + "version": "0.4.0", "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" @@ -246,12 +246,12 @@ }, "examples/ens": { "name": "@nomicfoundation/ignition-ens-example", - "version": "0.3.0", + "version": "0.4.0", "dependencies": { "@ensdomains/ens-contracts": "0.0.11" }, "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" @@ -465,9 +465,9 @@ }, "examples/sample": { "name": "@nomicfoundation/ignition-sample-example", - "version": "0.3.0", + "version": "0.4.0", "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" @@ -667,9 +667,9 @@ }, "examples/ts-sample": { "name": "@nomicfoundation/ignition-ts-sample-example", - "version": "0.3.0", + "version": "0.4.0", "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" @@ -869,7 +869,7 @@ }, "examples/uniswap": { "name": "@nomicfoundation/ignition-uniswap-example", - "version": "0.3.0", + "version": "0.4.0", "dependencies": { "@openzeppelin/contracts": "npm:@openzeppelin/contracts@3.4.2-solc-0.7", "@uniswap/swap-router-contracts": "1.1.0", @@ -881,7 +881,7 @@ "v3-periphery-1_3_0": "npm:@uniswap/v3-periphery@1.3.0" }, "devDependencies": { - "@ignored/hardhat-ignition": "^0.3.0", + "@nomicfoundation/hardhat-ignition": "^0.4.0", "@nomicfoundation/hardhat-toolbox": "3.0.0", "hardhat": "^2.14.0", "prettier-plugin-solidity": "1.1.3" @@ -3311,18 +3311,6 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "dev": true }, - "node_modules/@ignored/hardhat-ignition": { - "resolved": "packages/hardhat-plugin", - "link": true - }, - "node_modules/@ignored/ignition-core": { - "resolved": "packages/core", - "link": true - }, - "node_modules/@ignored/ignition-ui": { - "resolved": "packages/ui", - "link": true - }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -4034,6 +4022,10 @@ "setimmediate": "^1.0.5" } }, + "node_modules/@nomicfoundation/hardhat-ignition": { + "resolved": "packages/hardhat-plugin", + "link": true + }, "node_modules/@nomicfoundation/hardhat-network-helpers": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@nomicfoundation/hardhat-network-helpers/-/hardhat-network-helpers-1.0.8.tgz", @@ -4123,6 +4115,10 @@ "resolved": "examples/complete", "link": true }, + "node_modules/@nomicfoundation/ignition-core": { + "resolved": "packages/core", + "link": true + }, "node_modules/@nomicfoundation/ignition-ens-example": { "resolved": "examples/ens", "link": true @@ -4135,6 +4131,10 @@ "resolved": "examples/ts-sample", "link": true }, + "node_modules/@nomicfoundation/ignition-ui": { + "resolved": "packages/ui", + "link": true + }, "node_modules/@nomicfoundation/ignition-uniswap-example": { "resolved": "examples/uniswap", "link": true @@ -5464,6 +5464,15 @@ "integrity": "sha512-kb9/98N6X8gyME9Cf7YaqIMvYGnBSWqEci6tiettE6iJWH1XdJz/PO8LB0GtLCG7x8dU3KWhZT+lA1a35127tA==", "dev": true }, + "node_modules/@types/lodash.flattendeep": { + "version": "4.4.7", + "resolved": "https://registry.npmjs.org/@types/lodash.flattendeep/-/lodash.flattendeep-4.4.7.tgz", + "integrity": "sha512-1h6GW/AeZw/Wej6uxrqgmdTDZX1yFS39lRsXYkg+3kWvOWWrlGCI6H7lXxlUHOzxDT4QeYGmgPpQ3BX9XevzOg==", + "dev": true, + "dependencies": { + "@types/lodash": "*" + } + }, "node_modules/@types/lru-cache": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/@types/lru-cache/-/lru-cache-5.1.1.tgz", @@ -14215,8 +14224,7 @@ "node_modules/lodash.flattendeep": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz", - "integrity": "sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ==", - "dev": true + "integrity": "sha512-uHaJFihxmJcEX3kT4I23ABqKKalJ/zDrDg0lsFtc1h+3uw49SIJ5beyhx5ExVRti3AvKoOJngIj7xz3oylPdWQ==" }, "node_modules/lodash.get": { "version": "4.4.2", @@ -21716,8 +21724,8 @@ } }, "packages/core": { - "name": "@ignored/ignition-core", - "version": "0.3.0", + "name": "@nomicfoundation/ignition-core", + "version": "0.4.0", "license": "MIT", "dependencies": { "@ethersproject/address": "5.6.1", @@ -21851,8 +21859,8 @@ } }, "packages/hardhat-plugin": { - "name": "@ignored/hardhat-ignition", - "version": "0.3.0", + "name": "@nomicfoundation/hardhat-ignition", + "version": "0.4.0", "license": "MIT", "dependencies": { "debug": "^4.3.2", @@ -21860,16 +21868,17 @@ "fs-extra": "^10.0.0", "ink": "3.2.0", "ink-spinner": "4.0.3", + "lodash.flattendeep": "^4.4.0", "ndjson": "2.0.0", "prompts": "^2.4.2", "react": "18.2.0", "serialize-error": "8.1.0" }, "devDependencies": { - "@ignored/ignition-core": "^0.3.0", - "@ignored/ignition-ui": "^0.3.0", "@istanbuljs/nyc-config-typescript": "1.0.2", "@nomicfoundation/hardhat-ethers": "^3.0.4", + "@nomicfoundation/ignition-core": "^0.4.0", + "@nomicfoundation/ignition-ui": "^0.4.0", "@types/chai": "^4.2.22", "@types/chai-as-promised": "^7.1.4", "@types/d3": "7.4.0", @@ -21877,6 +21886,7 @@ "@types/dompurify": "2.4.0", "@types/fs-extra": "^9.0.13", "@types/lodash": "4.14.189", + "@types/lodash.flattendeep": "^4.4.7", "@types/mermaid": "^9.1.0", "@types/mocha": "^9.0.0", "@types/ndjson": "2.0.1", @@ -21906,9 +21916,9 @@ "typescript": "^4.7.4" }, "peerDependencies": { - "@ignored/ignition-core": "^0.3.0", - "@ignored/ignition-ui": "^0.3.0", "@nomicfoundation/hardhat-ethers": "^3.0.4", + "@nomicfoundation/ignition-core": "^0.4.0", + "@nomicfoundation/ignition-ui": "^0.4.0", "hardhat": "^2.14.0" } }, @@ -22143,10 +22153,10 @@ } }, "packages/ui": { - "name": "@ignored/ignition-ui", - "version": "0.3.0", + "name": "@nomicfoundation/ignition-ui", + "version": "0.4.0", "dependencies": { - "@ignored/ignition-core": "^0.3.0", + "@nomicfoundation/ignition-core": "^0.4.0", "mermaid": "10.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 7c4ae555c..a9ee9b9ed 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## 0.4.0 - 2023-09-15 + +### Added + +- Store artifact debug files as part of deployment directory ([#473](https://github.com/NomicFoundation/ignition/pull/473)) + +### Changed + +- Changed npm package name to `@nomicfoundation/ignition-core` +- Constrain module ids and action ids to better support storing deployments on windows ([#466](https://github.com/NomicFoundation/ignition/pull/466)) + +### Fixed + +- Fix batch completion on non-automining chains ([#467](https://github.com/NomicFoundation/ignition/pull/467)) + ## 0.3.0 - 2023-08-30 ### Added diff --git a/packages/core/package.json b/packages/core/package.json index fb7588a3d..5a1f86150 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { - "name": "@ignored/ignition-core", - "version": "0.3.0", + "name": "@nomicfoundation/ignition-core", + "version": "0.4.0", "license": "MIT", "author": "Nomic Foundation", "homepage": "https://hardhat.org", diff --git a/packages/core/src/new-api/build-module.ts b/packages/core/src/build-module.ts similarity index 80% rename from packages/core/src/new-api/build-module.ts rename to packages/core/src/build-module.ts index 867cf4fb8..7f3c9ef9c 100644 --- a/packages/core/src/new-api/build-module.ts +++ b/packages/core/src/build-module.ts @@ -1,6 +1,6 @@ -import { IgnitionError } from "../errors"; - +import { IgnitionError } from "./errors"; import { ModuleConstructor } from "./internal/module-builder"; +import { isValidIgnitionIdentifier } from "./internal/utils/identifier-validators"; import { IgnitionModule, IgnitionModuleResult } from "./types/module"; import { IgnitionModuleBuilder } from "./types/module-builder"; @@ -26,6 +26,12 @@ export function buildModule< throw new IgnitionError(`\`moduleId\` must be a string`); } + if (!isValidIgnitionIdentifier(moduleId)) { + throw new IgnitionError( + `The moduleId "${moduleId}" contains banned characters, ids can only contain alphanumerics or underscores` + ); + } + if (typeof moduleDefintionFunction !== "function") { throw new IgnitionError(`\`moduleDefintionFunction\` must be a function`); } diff --git a/packages/core/src/new-api/deploy.ts b/packages/core/src/deploy.ts similarity index 68% rename from packages/core/src/new-api/deploy.ts rename to packages/core/src/deploy.ts index db81a5957..da4509e26 100644 --- a/packages/core/src/new-api/deploy.ts +++ b/packages/core/src/deploy.ts @@ -1,5 +1,4 @@ -import { IgnitionValidationError } from "../errors"; - +import { IgnitionValidationError } from "./errors"; import { DEFAULT_AUTOMINE_REQUIRED_CONFIRMATIONS, defaultConfig, @@ -7,9 +6,9 @@ import { import { Deployer } from "./internal/deployer"; import { EphemeralDeploymentLoader } from "./internal/deployment-loader/ephemeral-deployment-loader"; import { FileDeploymentLoader } from "./internal/deployment-loader/file-deployment-loader"; -import { BasicExecutionStrategy } from "./internal/new-execution/basic-execution-strategy"; -import { EIP1193JsonRpcClient } from "./internal/new-execution/jsonrpc-client"; -import { getDefaultSender } from "./internal/new-execution/utils/get-default-sender"; +import { BasicExecutionStrategy } from "./internal/execution/basic-execution-strategy"; +import { EIP1193JsonRpcClient } from "./internal/execution/jsonrpc-client"; +import { getDefaultSender } from "./internal/execution/utils/get-default-sender"; import { checkAutominedNetwork } from "./internal/utils/check-automined-network"; import { validateStageOne } from "./internal/validation/validateStageOne"; import { ArtifactResolver } from "./types/artifact"; @@ -18,6 +17,10 @@ import { DeploymentParameters, DeploymentResult, } from "./types/deploy"; +import { + ExecutionEventListener, + ExecutionEventType, +} from "./types/execution-events"; import { IgnitionModule, IgnitionModuleResult } from "./types/module"; import { EIP1193Provider } from "./types/provider"; @@ -34,16 +37,17 @@ export async function deploy< config = {}, artifactResolver, provider, + executionEventListener, deploymentDir, ignitionModule, deploymentParameters, accounts, - verbose, defaultSender, }: { config?: Partial; artifactResolver: ArtifactResolver; provider: EIP1193Provider; + executionEventListener?: ExecutionEventListener; deploymentDir?: string; ignitionModule: IgnitionModule< ModuleIdT, @@ -52,10 +56,30 @@ export async function deploy< >; deploymentParameters: DeploymentParameters; accounts: string[]; - verbose: boolean; defaultSender?: string; }): Promise> { - await validateStageOne(ignitionModule, artifactResolver); + if (executionEventListener !== undefined) { + executionEventListener.setModuleId({ + type: ExecutionEventType.SET_MODULE_ID, + moduleName: ignitionModule.id, + }); + } + + const validationResult = await validateStageOne( + ignitionModule, + artifactResolver + ); + + if (validationResult !== null) { + if (executionEventListener !== undefined) { + executionEventListener.deploymentComplete({ + type: ExecutionEventType.DEPLOYMENT_COMPLETE, + result: validationResult, + }); + } + + return validationResult; + } if (defaultSender !== undefined) { if (!accounts.includes(defaultSender)) { @@ -69,8 +93,8 @@ export async function deploy< const deploymentLoader = deploymentDir === undefined - ? new EphemeralDeploymentLoader(artifactResolver, verbose) - : new FileDeploymentLoader(deploymentDir, verbose); + ? new EphemeralDeploymentLoader(artifactResolver, executionEventListener) + : new FileDeploymentLoader(deploymentDir, executionEventListener); const executionStrategy = new BasicExecutionStrategy((artifactId) => deploymentLoader.loadArtifact(artifactId) @@ -93,7 +117,8 @@ export async function deploy< executionStrategy, jsonRpcClient, artifactResolver, - deploymentLoader + deploymentLoader, + executionEventListener ); return deployer.deploy( diff --git a/packages/core/src/new-api/stored-deployment-serializer.ts b/packages/core/src/ignition-module-serializer.ts similarity index 90% rename from packages/core/src/new-api/stored-deployment-serializer.ts rename to packages/core/src/ignition-module-serializer.ts index d493fe68c..dfe5b60e9 100644 --- a/packages/core/src/new-api/stored-deployment-serializer.ts +++ b/packages/core/src/ignition-module-serializer.ts @@ -1,5 +1,4 @@ -import { IgnitionError } from "../errors"; - +import { IgnitionError } from "./errors"; import { AccountRuntimeValueImplementation, ArtifactContractAtFutureImplementation, @@ -30,6 +29,7 @@ import { AccountRuntimeValue, AddressResolvableFuture, ArgumentType, + ContractDeploymentFuture, ContractFuture, Future, FutureType, @@ -37,6 +37,8 @@ import { IgnitionModuleResult, ModuleParameterRuntimeValue, ModuleParameterType, + ContractCallFuture, + NamedArtifactContractDeploymentFuture, RuntimeValueType, } from "./types/module"; import { @@ -49,7 +51,9 @@ import { SerializedArtifactLibraryDeploymentFuture, SerializedBigInt, SerializedFuture, + SerializedIgnitionModule, SerializedLibraries, + SerializedModuleDescription, SerializedModuleParameterRuntimeValue, SerializedNamedContractAtFuture, SerializedNamedContractCallFuture, @@ -58,24 +62,21 @@ import { SerializedNamedStaticCallFuture, SerializedReadEventArgumentFuture, SerializedSendDataFuture, - SerializedStoredDeployment, - SerializedStoredModule, - StoredDeployment, -} from "./types/serialized-deployment"; +} from "./types/serialization"; interface SerializeContext { argReplacer: (arg: ArgumentType) => SerializedArgumentType; } /** - * Serialize a deployment. + * Serialize an Ignition module. * * @beta */ -export class StoredDeploymentSerializer { +export class IgnitionModuleSerializer { public static serialize( - deployment: StoredDeployment - ): SerializedStoredDeployment { + ignitionModule: IgnitionModule> + ): SerializedIgnitionModule { const argReplacer = (arg: ArgumentType) => replaceWithinArg(arg, { accountRuntimeValue: this._serializeAccountRuntimeValue, @@ -85,13 +86,10 @@ export class StoredDeploymentSerializer { future: this._convertFutureToFutureToken, }); - const allModules = this._getModulesAndSubmoduleFor(deployment.module); + const allModules = this._getModulesAndSubmoduleFor(ignitionModule); return { - details: { - ...deployment.details, - }, - startModule: deployment.module.id, + startModule: ignitionModule.id, modules: Object.fromEntries( allModules.map((m) => [m.id, this._serializeModule(m, { argReplacer })]) ), @@ -101,7 +99,7 @@ export class StoredDeploymentSerializer { private static _serializeModule( userModule: IgnitionModule>, context: SerializeContext - ): SerializedStoredModule { + ): SerializedModuleDescription { return { id: userModule.id, futures: Array.from(userModule.futures).map((future) => @@ -122,7 +120,7 @@ export class StoredDeploymentSerializer { context: SerializeContext ): SerializedFuture { switch (future.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: const serializedNamedContractDeploymentFuture: SerializedNamedContractDeploymentFuture = { id: future.id, @@ -145,7 +143,7 @@ export class StoredDeploymentSerializer { }; return serializedNamedContractDeploymentFuture; - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: const serializedArtifactContractDeploymentFuture: SerializedArtifactContractDeploymentFuture = { id: future.id, @@ -169,7 +167,7 @@ export class StoredDeploymentSerializer { }; return serializedArtifactContractDeploymentFuture; - case FutureType.NAMED_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: const serializedNamedLibraryDeploymentFuture: SerializedNamedLibraryDeploymentFuture = { id: future.id, @@ -186,7 +184,7 @@ export class StoredDeploymentSerializer { }; return serializedNamedLibraryDeploymentFuture; - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: const serializedArtifactLibraryDeploymentFuture: SerializedArtifactLibraryDeploymentFuture = { id: future.id, @@ -204,7 +202,7 @@ export class StoredDeploymentSerializer { }; return serializedArtifactLibraryDeploymentFuture; - case FutureType.NAMED_CONTRACT_CALL: + case FutureType.CONTRACT_CALL: const serializedNamedContractCallFuture: SerializedNamedContractCallFuture = { id: future.id, @@ -225,7 +223,7 @@ export class StoredDeploymentSerializer { }; return serializedNamedContractCallFuture; - case FutureType.NAMED_STATIC_CALL: + case FutureType.STATIC_CALL: const serializedNamedStaticCallFuture: SerializedNamedStaticCallFuture = { id: future.id, @@ -237,13 +235,14 @@ export class StoredDeploymentSerializer { contract: this._convertFutureToFutureToken(future.contract), functionName: future.functionName, args: future.args.map((arg) => context.argReplacer(arg)), + nameOrIndex: future.nameOrIndex, from: isRuntimeValue(future.from) ? this._serializeAccountRuntimeValue(future.from) : future.from, }; return serializedNamedStaticCallFuture; - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: const serializedNamedContractAtFuture: SerializedNamedContractAtFuture = { id: future.id, @@ -262,7 +261,7 @@ export class StoredDeploymentSerializer { }; return serializedNamedContractAtFuture; - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: const serializedArtifactContractAtFuture: SerializedArtifactContractAtFuture = { id: future.id, @@ -296,7 +295,7 @@ export class StoredDeploymentSerializer { ), emitter: this._convertFutureToFutureToken(future.emitter), eventName: future.eventName, - argumentName: future.argumentName, + nameOrIndex: future.nameOrIndex, eventIndex: future.eventIndex, }; return serializedReadEventArgumentFuture; @@ -396,16 +395,18 @@ export class StoredDeploymentSerializer { } /** - * Deserialize a deployment that was previously serialized using StoredDeploymentSerialized. + * Deserialize an `IgnitionModule` that was previously serialized using + * IgnitionModuleSerializer. * * @beta */ -export class StoredDeploymentDeserializer { +export class IgnitionModuleDeserializer { public static deserialize( - serializedDeployment: SerializedStoredDeployment - ): StoredDeployment { - const sortedModules = - this._getSerializedModulesInReverseTopologicalOrder(serializedDeployment); + serializedIgnitionModule: SerializedIgnitionModule + ): IgnitionModule> { + const sortedModules = this._getSerializedModulesInReverseTopologicalOrder( + serializedIgnitionModule + ); const modulesLookup: Map = new Map(); for (const serializedModule of sortedModules) { @@ -418,8 +419,9 @@ export class StoredDeploymentDeserializer { } } - const sortedFutures = - this._getSerializedFuturesInReverseTopologicalOrder(serializedDeployment); + const sortedFutures = this._getSerializedFuturesInReverseTopologicalOrder( + serializedIgnitionModule + ); const futuresLookup: Map = new Map(); const contractFuturesLookup: Map< @@ -455,7 +457,7 @@ export class StoredDeploymentDeserializer { } for (const serializedModule of Object.values( - serializedDeployment.modules + serializedIgnitionModule.modules )) { const mod = this._lookup(modulesLookup, serializedModule.id); @@ -474,26 +476,21 @@ export class StoredDeploymentDeserializer { } } - return { - details: { - ...serializedDeployment.details, - }, - module: this._lookup(modulesLookup, serializedDeployment.startModule), - }; + return this._lookup(modulesLookup, serializedIgnitionModule.startModule); } private static _getSerializedModulesInReverseTopologicalOrder( - serializedDeployment: SerializedStoredDeployment - ): SerializedStoredModule[] { - const graph: Graph = new Map(); + serializedIgnitionModule: SerializedIgnitionModule + ): SerializedModuleDescription[] { + const graph: Graph = new Map(); - for (const mod of Object.values(serializedDeployment.modules)) { + for (const mod of Object.values(serializedIgnitionModule.modules)) { graph.set(mod, new Set()); } - for (const mod of Object.values(serializedDeployment.modules)) { + for (const mod of Object.values(serializedIgnitionModule.modules)) { for (const submodToken of mod.submodules) { - const submod = serializedDeployment.modules[submodToken.moduleId]; + const submod = serializedIgnitionModule.modules[submodToken.moduleId]; graph.get(submod)!.add(mod); } } @@ -502,9 +499,9 @@ export class StoredDeploymentDeserializer { } private static _getSerializedFuturesInReverseTopologicalOrder( - serializedDeployment: SerializedStoredDeployment + serializedIgnitionModule: SerializedIgnitionModule ): SerializedFuture[] { - const serializedFutures = this._getAllFuturesFor(serializedDeployment); + const serializedFutures = this._getAllFuturesFor(serializedIgnitionModule); const serializedFuturesMap = Object.fromEntries( serializedFutures.map((f) => [f.id, f]) ); @@ -539,7 +536,7 @@ export class StoredDeploymentDeserializer { } if ( - swappedFuture.type === FutureType.NAMED_CONTRACT_CALL || + swappedFuture.type === FutureType.CONTRACT_CALL || swappedFuture.type === FutureType.SEND_DATA ) { throw new IgnitionError( @@ -609,7 +606,7 @@ export class StoredDeploymentDeserializer { } private static _getAllFuturesFor( - deployment: SerializedStoredDeployment + deployment: SerializedIgnitionModule ): SerializedFuture[] { return Object.values(deployment.modules).flatMap((m) => Object.values(m.futures) @@ -629,7 +626,7 @@ export class StoredDeploymentDeserializer { const mod = this._lookup(modulesLookup, serializedFuture.moduleId); switch (serializedFuture.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: return new NamedContractDeploymentFutureImplementation( serializedFuture.id, mod, @@ -652,7 +649,7 @@ export class StoredDeploymentDeserializer { ? this._deserializeAccountRuntimeValue(serializedFuture.from) : serializedFuture.from ); - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: return new ArtifactContractDeploymentFutureImplementation( serializedFuture.id, mod, @@ -676,7 +673,7 @@ export class StoredDeploymentDeserializer { ? this._deserializeAccountRuntimeValue(serializedFuture.from) : serializedFuture.from ); - case FutureType.NAMED_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: return new NamedLibraryDeploymentFutureImplementation( serializedFuture.id, mod, @@ -691,7 +688,7 @@ export class StoredDeploymentDeserializer { ? this._deserializeAccountRuntimeValue(serializedFuture.from) : serializedFuture.from ); - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: return new ArtifactLibraryDeploymentFutureImplementation( serializedFuture.id, mod, @@ -707,7 +704,7 @@ export class StoredDeploymentDeserializer { ? this._deserializeAccountRuntimeValue(serializedFuture.from) : serializedFuture.from ); - case FutureType.NAMED_CONTRACT_CALL: + case FutureType.CONTRACT_CALL: return new NamedContractCallFutureImplementation( serializedFuture.id, mod, @@ -728,7 +725,7 @@ export class StoredDeploymentDeserializer { ? this._deserializeAccountRuntimeValue(serializedFuture.from) : serializedFuture.from ); - case FutureType.NAMED_STATIC_CALL: + case FutureType.STATIC_CALL: return new NamedStaticCallFutureImplementation( serializedFuture.id, mod, @@ -740,11 +737,12 @@ export class StoredDeploymentDeserializer { serializedFuture.args.map((arg) => this._deserializeArgument(arg, futuresLookup) ), + serializedFuture.nameOrIndex, this._isSerializedAccountRuntimeValue(serializedFuture.from) ? this._deserializeAccountRuntimeValue(serializedFuture.from) : serializedFuture.from ); - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: return new NamedContractAtFutureImplementation( serializedFuture.id, mod, @@ -762,7 +760,7 @@ export class StoredDeploymentDeserializer { ) as ModuleParameterRuntimeValue) // This is unsafe, but we only serialize valid values : serializedFuture.address ); - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: return new ArtifactContractAtFutureImplementation( serializedFuture.id, mod, @@ -788,9 +786,12 @@ export class StoredDeploymentDeserializer { this._lookup( futuresLookup, serializedFuture.futureToReadFrom.futureId - ), + ) as + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | ContractCallFuture, serializedFuture.eventName, - serializedFuture.argumentName, + serializedFuture.nameOrIndex, this._lookup( contractFuturesLookup, serializedFuture.emitter.futureId diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index e8e86c922..db4dbfeb5 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,14 +1,14 @@ +export { buildModule } from "./build-module"; +export { deploy } from "./deploy"; export * from "./errors"; -export { buildModule } from "./new-api/build-module"; -export { deploy } from "./new-api/deploy"; -export { plan } from "./new-api/plan"; -export { wipe } from "./new-api/wipe"; -export { StoredDeploymentSerializer } from "./new-api/stored-deployment-serializer"; -export * from "./new-api/type-guards"; -export * from "./new-api/types/artifact"; -export * from "./new-api/types/deploy"; -export * from "./new-api/types/module"; -export * from "./new-api/types/module-builder"; -export * from "./new-api/types/provider"; -export * from "./new-api/types/serialized-deployment"; -export { formatSolidityParameter } from "./new-api/internal/formatters"; +export { IgnitionModuleSerializer } from "./ignition-module-serializer"; +export { formatSolidityParameter } from "./internal/formatters"; +export * from "./type-guards"; +export * from "./types/artifact"; +export * from "./types/deploy"; +export * from "./types/execution-events"; +export * from "./types/module"; +export * from "./types/module-builder"; +export * from "./types/provider"; +export * from "./types/serialization"; +export { wipe } from "./wipe"; diff --git a/packages/core/src/new-api/internal/batcher.ts b/packages/core/src/internal/batcher.ts similarity index 95% rename from packages/core/src/new-api/internal/batcher.ts rename to packages/core/src/internal/batcher.ts index d50b7ef94..3c4ef0b90 100644 --- a/packages/core/src/new-api/internal/batcher.ts +++ b/packages/core/src/internal/batcher.ts @@ -1,7 +1,7 @@ import { Future, IgnitionModule } from "../types/module"; -import { DeploymentState } from "./new-execution/types/deployment-state"; -import { ExecutionStatus } from "./new-execution/types/execution-state"; +import { DeploymentState } from "./execution/types/deployment-state"; +import { ExecutionStatus } from "./execution/types/execution-state"; import { AdjacencyList } from "./utils/adjacency-list"; import { AdjacencyListConverter } from "./utils/adjacency-list-converter"; import { getFuturesFromModule } from "./utils/get-futures-from-module"; @@ -74,6 +74,7 @@ export class Batcher { switch (executionState.status) { case ExecutionStatus.FAILED: case ExecutionStatus.TIMEOUT: + case ExecutionStatus.HELD: case ExecutionStatus.STARTED: return [f.id, VisitStatus.UNVISITED]; case ExecutionStatus.SUCCESS: diff --git a/packages/core/src/new-api/internal/defaultConfig.ts b/packages/core/src/internal/defaultConfig.ts similarity index 100% rename from packages/core/src/new-api/internal/defaultConfig.ts rename to packages/core/src/internal/defaultConfig.ts diff --git a/packages/core/src/new-api/internal/deployer.ts b/packages/core/src/internal/deployer.ts similarity index 70% rename from packages/core/src/new-api/internal/deployer.ts rename to packages/core/src/internal/deployer.ts index a21d44cf4..3b3d0a8d8 100644 --- a/packages/core/src/new-api/internal/deployer.ts +++ b/packages/core/src/internal/deployer.ts @@ -8,21 +8,25 @@ import { DeploymentResult, DeploymentResultType, ExecutionErrorDeploymentResult, + PreviousRunErrorDeploymentResult, ReconciliationErrorDeploymentResult, SuccessfulDeploymentResult, } from "../types/deploy"; +import { + ExecutionEventListener, + ExecutionEventType, +} from "../types/execution-events"; import { Batcher } from "./batcher"; import { DeploymentLoader } from "./deployment-loader/types"; -import { formatExecutionError } from "./formatters"; import { initializeDeploymentState, loadDeploymentState, -} from "./new-execution/deployment-state-helpers"; -import { ExecutionEngine } from "./new-execution/execution-engine"; -import { JsonRpcClient } from "./new-execution/jsonrpc-client"; -import { DeploymentState } from "./new-execution/types/deployment-state"; -import { ExecutionResultType } from "./new-execution/types/execution-result"; +} from "./execution/deployment-state-helpers"; +import { ExecutionEngine } from "./execution/execution-engine"; +import { JsonRpcClient } from "./execution/jsonrpc-client"; +import { DeploymentState } from "./execution/types/deployment-state"; +import { ExecutionResultType } from "./execution/types/execution-result"; import { CallExecutionState, ContractAtExecutionState, @@ -32,8 +36,9 @@ import { ExecutionStatus, SendDataExecutionState, StaticCallExecutionState, -} from "./new-execution/types/execution-state"; -import { ExecutionStrategy } from "./new-execution/types/execution-strategy"; +} from "./execution/types/execution-state"; +import { ExecutionStrategy } from "./execution/types/execution-strategy"; +import { formatExecutionError } from "./formatters"; import { Reconciler } from "./reconciliation/reconciler"; import { assertIgnitionInvariant } from "./utils/assertions"; import { getFuturesFromModule } from "./utils/get-futures-from-module"; @@ -50,7 +55,8 @@ export class Deployer { private readonly _executionStrategy: ExecutionStrategy, private readonly _jsonRpcClient: JsonRpcClient, private readonly _artifactResolver: ArtifactResolver, - private readonly _deploymentLoader: DeploymentLoader + private readonly _deploymentLoader: DeploymentLoader, + private readonly _executionEventListener?: ExecutionEventListener ) { assertIgnitionInvariant( this._config.requiredConfirmations >= 1, @@ -80,10 +86,14 @@ export class Deployer { ); if (validationResult !== null) { + this._emitDeploymentCompleteEvent(validationResult); + return validationResult; } - let deploymentState = await this._getOrInitializeDeploymentState(); + let deploymentState = await this._getOrInitializeDeploymentState( + ignitionModule.id + ); const contracts = getFuturesFromModule(ignitionModule).filter(isContractFuture); @@ -129,10 +139,38 @@ export class Deployer { errors[futureId].push(failure); } - return { + const reconciliationErrorResult: ReconciliationErrorDeploymentResult = { type: DeploymentResultType.RECONCILIATION_ERROR, errors, }; + + this._emitDeploymentCompleteEvent(reconciliationErrorResult); + + return reconciliationErrorResult; + } + + const previousRunErrors = + Reconciler.checkForPreviousRunErrors(deploymentState); + + if (previousRunErrors.length > 0) { + const errors: PreviousRunErrorDeploymentResult["errors"] = {}; + + for (const { futureId, failure } of previousRunErrors) { + if (errors[futureId] === undefined) { + errors[futureId] = []; + } + + errors[futureId].push(failure); + } + + const previousRunErrorResult: PreviousRunErrorDeploymentResult = { + type: DeploymentResultType.PREVIOUS_RUN_ERROR, + errors, + }; + + this._emitDeploymentCompleteEvent(previousRunErrorResult); + + return previousRunErrorResult; } if (reconciliationResult.missingExecutedFutures.length > 0) { @@ -141,11 +179,14 @@ export class Deployer { const batches = Batcher.batch(ignitionModule, deploymentState); + this._emitDeploymentBatchEvent(batches); + const executionEngine = new ExecutionEngine( this._deploymentLoader, this._artifactResolver, this._executionStrategy, this._jsonRpcClient, + this._executionEventListener, this._config.requiredConfirmations, this._config.timeBeforeBumpingFees, this._config.maxFeeBumps, @@ -161,7 +202,14 @@ export class Deployer { defaultSender ); - return this._getDeploymentResult(deploymentState, ignitionModule); + const result = await this._getDeploymentResult( + deploymentState, + ignitionModule + ); + + this._emitDeploymentCompleteEvent(result); + + return result; } private async _getDeploymentResult< @@ -196,11 +244,15 @@ export class Deployer { }; } - private async _getOrInitializeDeploymentState(): Promise { + private async _getOrInitializeDeploymentState( + moduleId: string + ): Promise { const chainId = await this._jsonRpcClient.getChainId(); const deploymentState = await loadDeploymentState(this._deploymentLoader); if (deploymentState === undefined) { + this._emitDeploymentStartEvent(moduleId); + return initializeDeploymentState(chainId, this._deploymentLoader); } @@ -212,6 +264,41 @@ export class Deployer { return deploymentState; } + private _emitDeploymentStartEvent(moduleId: string): void { + if (this._executionEventListener === undefined) { + return; + } + + this._executionEventListener.deploymentStart({ + type: ExecutionEventType.DEPLOYMENT_START, + moduleName: moduleId, + }); + } + + private _emitDeploymentBatchEvent(batches: string[][]): void { + if (this._executionEventListener === undefined) { + return; + } + + this._executionEventListener.batchInitialize({ + type: ExecutionEventType.BATCH_INITIALIZE, + batches, + }); + } + + private _emitDeploymentCompleteEvent( + result: DeploymentResult> + ): void { + if (this._executionEventListener === undefined) { + return; + } + + this._executionEventListener.deploymentComplete({ + type: ExecutionEventType.DEPLOYMENT_COMPLETE, + result, + }); + } + private _isSuccessful(deploymentState: DeploymentState): boolean { return Object.values(deploymentState.executionStates).every( (ex) => ex.status === ExecutionStatus.SUCCESS @@ -229,12 +316,32 @@ export class Deployer { successful: Object.values(deploymentState.executionStates) .filter((ex) => ex.status === ExecutionStatus.SUCCESS) .map((ex) => ex.id), + held: Object.values(deploymentState.executionStates) + .filter(canFail) + .filter((ex) => ex.status === ExecutionStatus.HELD) + .map((ex) => { + assertIgnitionInvariant( + ex.result !== undefined, + `Execution state ${ex.id} is marked as held but has no result` + ); + + assertIgnitionInvariant( + ex.result.type === ExecutionResultType.STRATEGY_HELD, + `Execution state ${ex.id} is marked as held but has ${ex.result.type} instead of a held result` + ); + + return { + futureId: ex.id, + heldId: ex.result.heldId, + reason: ex.result.reason, + }; + }), timedOut: Object.values(deploymentState.executionStates) .filter(canTimeout) .filter((ex) => ex.status === ExecutionStatus.TIMEOUT) .map((ex) => ({ futureId: ex.id, - executionId: ex.networkInteractions.at(-1)!.id, + networkInteractionId: ex.networkInteractions.at(-1)!.id, })), failed: Object.values(deploymentState.executionStates) .filter(canFail) @@ -242,13 +349,14 @@ export class Deployer { .map((ex) => { assertIgnitionInvariant( ex.result !== undefined && - ex.result.type !== ExecutionResultType.SUCCESS, + ex.result.type !== ExecutionResultType.SUCCESS && + ex.result.type !== ExecutionResultType.STRATEGY_HELD, `Execution state ${ex.id} is marked as failed but has no error result` ); return { futureId: ex.id, - executionId: ex.networkInteractions.at(-1)!.id, + networkInteractionId: ex.networkInteractions.at(-1)!.id, error: formatExecutionError(ex.result), }; }), diff --git a/packages/core/src/new-api/internal/deployment-loader/ephemeral-deployment-loader.ts b/packages/core/src/internal/deployment-loader/ephemeral-deployment-loader.ts similarity index 83% rename from packages/core/src/new-api/internal/deployment-loader/ephemeral-deployment-loader.ts rename to packages/core/src/internal/deployment-loader/ephemeral-deployment-loader.ts index 4c131103a..3a481d413 100644 --- a/packages/core/src/new-api/internal/deployment-loader/ephemeral-deployment-loader.ts +++ b/packages/core/src/internal/deployment-loader/ephemeral-deployment-loader.ts @@ -1,7 +1,8 @@ import { Artifact, ArtifactResolver, BuildInfo } from "../../types/artifact"; +import { ExecutionEventListener } from "../../types/execution-events"; +import { JournalMessage } from "../execution/types/messages"; import { MemoryJournal } from "../journal/memory-journal"; import { Journal } from "../journal/types"; -import { JournalMessage } from "../new-execution/types/messages"; import { assertIgnitionInvariant } from "../utils/assertions"; import { DeploymentLoader } from "./types"; @@ -23,9 +24,9 @@ export class EphemeralDeploymentLoader implements DeploymentLoader { constructor( private _artifactResolver: ArtifactResolver, - private _verbose: boolean + private _executionEventListener?: ExecutionEventListener ) { - this._journal = new MemoryJournal(this._verbose); + this._journal = new MemoryJournal(this._executionEventListener); this._deployedAddresses = {}; this._savedArtifacts = {}; } @@ -45,7 +46,10 @@ export class EphemeralDeploymentLoader implements DeploymentLoader { this._deployedAddresses[futureId] = contractAddress; } - public async storeBuildInfo(_buildInfo: BuildInfo): Promise { + public async storeBuildInfo( + _futureId: string, + _buildInfo: BuildInfo + ): Promise { // For ephemeral we are ignoring build info } @@ -64,8 +68,8 @@ export class EphemeralDeploymentLoader implements DeploymentLoader { this._savedArtifacts[futureId] = { _kind: "artifact", artifact }; } - public async loadArtifact(artifactFutureId: string): Promise { - const futureId = artifactFutureId; + public async loadArtifact(artifactId: string): Promise { + const futureId = artifactId; const saved = this._savedArtifacts[futureId]; diff --git a/packages/core/src/new-api/internal/deployment-loader/file-deployment-loader.ts b/packages/core/src/internal/deployment-loader/file-deployment-loader.ts similarity index 82% rename from packages/core/src/new-api/internal/deployment-loader/file-deployment-loader.ts rename to packages/core/src/internal/deployment-loader/file-deployment-loader.ts index c96223399..d364d21fa 100644 --- a/packages/core/src/new-api/internal/deployment-loader/file-deployment-loader.ts +++ b/packages/core/src/internal/deployment-loader/file-deployment-loader.ts @@ -2,9 +2,10 @@ import { ensureDir, pathExists, readFile, writeFile } from "fs-extra"; import path from "path"; import { Artifact, BuildInfo } from "../../types/artifact"; +import { ExecutionEventListener } from "../../types/execution-events"; +import { JournalMessage } from "../execution/types/messages"; import { FileJournal } from "../journal/file-journal"; import { Journal } from "../journal/types"; -import { JournalMessage } from "../new-execution/types/messages"; import { DeploymentLoader } from "./types"; @@ -22,7 +23,7 @@ export class FileDeploymentLoader implements DeploymentLoader { constructor( private readonly _deploymentDirPath: string, - private readonly _verbose: boolean + private readonly _executionEventListener?: ExecutionEventListener ) { const artifactsDir = path.join(this._deploymentDirPath, "artifacts"); const buildInfoDir = path.join(this._deploymentDirPath, "build-info"); @@ -32,7 +33,7 @@ export class FileDeploymentLoader implements DeploymentLoader { "deployed_addresses.json" ); - this._journal = new FileJournal(journalPath, this._verbose); + this._journal = new FileJournal(journalPath, this._executionEventListener); this._paths = { deploymentDir: this._deploymentDirPath, @@ -80,7 +81,10 @@ export class FileDeploymentLoader implements DeploymentLoader { await writeFile(artifactFilePath, JSON.stringify(artifact, undefined, 2)); } - public async storeBuildInfo(buildInfo: BuildInfo): Promise { + public async storeBuildInfo( + futureId: string, + buildInfo: BuildInfo + ): Promise { await this._initialize(); const buildInfoFilePath = path.join( @@ -89,6 +93,28 @@ export class FileDeploymentLoader implements DeploymentLoader { ); await writeFile(buildInfoFilePath, JSON.stringify(buildInfo, undefined, 2)); + + const debugInfoFilePath = path.join( + this._paths.artifactsDir, + `${futureId}.dbg.json` + ); + + const relativeBuildInfoPath = path.relative( + this._paths.artifactsDir, + buildInfoFilePath + ); + + await writeFile( + debugInfoFilePath, + JSON.stringify( + { + _format: "hh-sol-dbg-1", + buildInfo: relativeBuildInfoPath, + }, + undefined, + 2 + ) + ); } public async loadArtifact(futureId: string): Promise { diff --git a/packages/core/src/new-api/internal/deployment-loader/types.ts b/packages/core/src/internal/deployment-loader/types.ts similarity index 75% rename from packages/core/src/new-api/internal/deployment-loader/types.ts rename to packages/core/src/internal/deployment-loader/types.ts index 25c57bd2d..74151367b 100644 --- a/packages/core/src/new-api/internal/deployment-loader/types.ts +++ b/packages/core/src/internal/deployment-loader/types.ts @@ -1,5 +1,5 @@ import { Artifact, BuildInfo } from "../../types/artifact"; -import { JournalMessage } from "../new-execution/types/messages"; +import { JournalMessage } from "../execution/types/messages"; /** * Read and write to the deployment storage. @@ -9,7 +9,7 @@ import { JournalMessage } from "../new-execution/types/messages"; export interface DeploymentLoader { recordToJournal(message: JournalMessage): Promise; readFromJournal(): AsyncGenerator; - loadArtifact(artifactFutureId: string): Promise; + loadArtifact(artifactId: string): Promise; storeUserProvidedArtifact( futureId: string, artifact: Artifact @@ -19,7 +19,7 @@ export interface DeploymentLoader { contractName: string, artifact: Artifact ): Promise; - storeBuildInfo(buildInfo: BuildInfo): Promise; + storeBuildInfo(futureId: string, buildInfo: BuildInfo): Promise; recordDeployedAddress( futureId: string, contractAddress: string diff --git a/packages/core/src/new-api/internal/new-execution/abi.ts b/packages/core/src/internal/execution/abi.ts similarity index 94% rename from packages/core/src/new-api/internal/new-execution/abi.ts rename to packages/core/src/internal/execution/abi.ts index a6e9ee1fb..9bdf9d866 100644 --- a/packages/core/src/new-api/internal/new-execution/abi.ts +++ b/packages/core/src/internal/execution/abi.ts @@ -10,7 +10,7 @@ import type { import { IgnitionValidationError, UnsupportedOperationError, -} from "../../../errors"; +} from "../../errors"; import { Artifact } from "../../types/artifact"; import { ArgumentType, SolidityParameterType } from "../../types/module"; import { assertIgnitionInvariant } from "../utils/assertions"; @@ -278,7 +278,7 @@ export function getEventArgumentFromReceipt( emitterAddress: string, eventName: string, eventIndex: number, - argument: string | number + nameOrIndex: string | number ): EvmValue { const emitterLogs = receipt.logs.filter((l) => l.address === emitterAddress); @@ -300,11 +300,11 @@ export function getEventArgumentFromReceipt( const evmTuple = ethersResultIntoEvmTuple(ethersResult, eventFragment.inputs); - if (typeof argument === "string") { - return evmTuple.named[argument]; + if (typeof nameOrIndex === "string") { + return evmTuple.named[nameOrIndex]; } - return evmTuple.positional[argument]; + return evmTuple.positional[nameOrIndex]; } /** @@ -697,6 +697,43 @@ function getEventArgumentParamType( return paramType; } +/** + * Validates the param type of a static call return value, throwing a validation error if it's not found. + */ +export function validateFunctionArgumentParamType( + contractName: string, + functionName: string, + artifact: Artifact, + argument: string | number +): void { + const { ethers } = require("ethers") as typeof import("ethers"); + const iface = new ethers.Interface(artifact.abi); + const functionFragment = getFunctionFragment(iface, functionName); + + if (typeof argument === "string") { + let hasArg = false; + for (const output of functionFragment.outputs) { + if (output.name === argument) { + hasArg = true; + } + } + + if (!hasArg) { + throw new IgnitionValidationError( + `Function ${functionName} of contract ${contractName} has no return value named ${argument}` + ); + } + } else { + const paramType = functionFragment.outputs[argument]; + + if (paramType === undefined) { + throw new IgnitionValidationError( + `Function ${functionName} of contract ${contractName} has only ${functionFragment.outputs.length} return values, but value ${argument} was requested` + ); + } + } +} + /** * Returns true if the given param type has a dynamic size. */ diff --git a/packages/core/src/new-api/internal/new-execution/basic-execution-strategy.ts b/packages/core/src/internal/execution/basic-execution-strategy.ts similarity index 99% rename from packages/core/src/new-api/internal/new-execution/basic-execution-strategy.ts rename to packages/core/src/internal/execution/basic-execution-strategy.ts index c9d2c49eb..7664ec31e 100644 --- a/packages/core/src/new-api/internal/new-execution/basic-execution-strategy.ts +++ b/packages/core/src/internal/execution/basic-execution-strategy.ts @@ -38,7 +38,7 @@ export class BasicExecutionStrategy implements ExecutionStrategy { public async *executeDeployment( executionState: DeploymentExecutionState ): DeploymentStrategyGenerator { - const artifact = await this._loadArtifact(executionState.artifactFutureId); + const artifact = await this._loadArtifact(executionState.artifactId); const transactionOrResult = yield* executeOnchainInteractionRequest( executionState.id, @@ -83,7 +83,7 @@ export class BasicExecutionStrategy implements ExecutionStrategy { public async *executeCall( executionState: CallExecutionState ): CallStrategyGenerator { - const artifact = await this._loadArtifact(executionState.artifactFutureId); + const artifact = await this._loadArtifact(executionState.artifactId); const transactionOrResult = yield* executeOnchainInteractionRequest( executionState.id, @@ -149,7 +149,7 @@ export class BasicExecutionStrategy implements ExecutionStrategy { public async *executeStaticCall( executionState: StaticCallExecutionState ): StaticCallStrategyGenerator { - const artifact = await this._loadArtifact(executionState.artifactFutureId); + const artifact = await this._loadArtifact(executionState.artifactId); const decodedResultOrError = yield* executeStaticCallRequest( { diff --git a/packages/core/src/new-api/internal/new-execution/deployment-state-helpers.ts b/packages/core/src/internal/execution/deployment-state-helpers.ts similarity index 99% rename from packages/core/src/new-api/internal/new-execution/deployment-state-helpers.ts rename to packages/core/src/internal/execution/deployment-state-helpers.ts index 661e22575..243073d3c 100644 --- a/packages/core/src/new-api/internal/new-execution/deployment-state-helpers.ts +++ b/packages/core/src/internal/execution/deployment-state-helpers.ts @@ -18,6 +18,7 @@ export async function loadDeploymentState( deploymentLoader: DeploymentLoader ): Promise { let deploymentState: DeploymentState | undefined; + for await (const message of deploymentLoader.readFromJournal()) { deploymentState = deploymentStateReducer(deploymentState, message); } diff --git a/packages/core/src/new-api/internal/new-execution/execution-engine.ts b/packages/core/src/internal/execution/execution-engine.ts similarity index 86% rename from packages/core/src/new-api/internal/new-execution/execution-engine.ts rename to packages/core/src/internal/execution/execution-engine.ts index 6afb29537..69b2bd6ac 100644 --- a/packages/core/src/new-api/internal/new-execution/execution-engine.ts +++ b/packages/core/src/internal/execution/execution-engine.ts @@ -1,6 +1,10 @@ -import { IgnitionError } from "../../../errors"; +import { IgnitionError } from "../../errors"; import { ArtifactResolver } from "../../types/artifact"; import { DeploymentParameters } from "../../types/deploy"; +import { + ExecutionEventListener, + ExecutionEventType, +} from "../../types/execution-events"; import { Future, IgnitionModule, @@ -8,6 +12,9 @@ import { } from "../../types/module"; import { DeploymentLoader } from "../deployment-loader/types"; import { getFuturesFromModule } from "../utils/get-futures-from-module"; +import { getPendingNonceAndSender } from "../views/execution-state/get-pending-nonce-and-sender"; +import { hasExecutionSucceeded } from "../views/has-execution-succeeded"; +import { isBatchFinished } from "../views/is-batch-finished"; import { applyNewMessage } from "./deployment-state-helpers"; import { FutureProcessor } from "./future-processor/future-processor"; @@ -20,8 +27,6 @@ import { import { TransactionTrackingTimer } from "./transaction-tracking-timer"; import { DeploymentState } from "./types/deployment-state"; import { ExecutionStrategy } from "./types/execution-strategy"; -import { getPendingNonceAndSender } from "./views/execution-state/get-pending-nonce-and-sender"; -import { hasExecutionFailed } from "./views/has-execution-failed"; /** * This class is used to execute a module to completion, returning the new @@ -33,6 +38,9 @@ export class ExecutionEngine { private readonly _artifactResolver: ArtifactResolver, private readonly _executionStrategy: ExecutionStrategy, private readonly _jsonRpcClient: JsonRpcClient, + private readonly _executionEventListener: + | ExecutionEventListener + | undefined, private readonly _requiredConfirmations: number, private readonly _millisecondBeforeBumpingFees: number, private readonly _maxFeeBumps: number, @@ -87,6 +95,8 @@ export class ExecutionEngine { const futures = getFuturesFromModule(module); for (const batch of batches) { + this._emitBeginNextBatchEvent(); + // TODO: consider changing batcher to return futures rather than ids const executionBatch = batch.map((futureId) => this._lookupFuture(futures, futureId) @@ -98,7 +108,9 @@ export class ExecutionEngine { deploymentState ); - if (executionBatch.some((f) => hasExecutionFailed(f, deploymentState))) { + if ( + !executionBatch.every((f) => hasExecutionSucceeded(f, deploymentState)) + ) { return deploymentState; } } @@ -127,20 +139,22 @@ export class ExecutionEngine { let block = await this._jsonRpcClient.getLatestBlock(); - let allCompleted = true; while (true) { for (const future of sortedFutures) { - const { futureCompleted, newState } = - await futureProcessor.processFuture(future, deploymentState); + const { newState } = await futureProcessor.processFuture( + future, + deploymentState + ); deploymentState = newState; - - if (!futureCompleted) { - allCompleted = false; - } } - if (allCompleted) { + if ( + isBatchFinished( + deploymentState, + sortedFutures.map((f) => f.id) + ) + ) { break; } @@ -256,4 +270,15 @@ export class ExecutionEngine { return sortedBatch.map((f) => f.future); } + + /** + * Emits an execution event signaling that execution of the next batch has begun. + */ + private _emitBeginNextBatchEvent(): void { + if (this._executionEventListener !== undefined) { + this._executionEventListener.beginNextBatch({ + type: ExecutionEventType.BEGIN_NEXT_BATCH, + }); + } + } } diff --git a/packages/core/src/new-api/internal/new-execution/execution-strategy-helpers.ts b/packages/core/src/internal/execution/execution-strategy-helpers.ts similarity index 95% rename from packages/core/src/new-api/internal/new-execution/execution-strategy-helpers.ts rename to packages/core/src/internal/execution/execution-strategy-helpers.ts index 92b7d6917..05326aaec 100644 --- a/packages/core/src/new-api/internal/new-execution/execution-strategy-helpers.ts +++ b/packages/core/src/internal/execution/execution-strategy-helpers.ts @@ -31,7 +31,6 @@ import { StaticCallResponse, SuccessfulTransaction, } from "./types/execution-strategy"; -import { convertEvmTupleToSolidityParam } from "./utils/convert-evm-tuple-to-solidity-param"; /** * Returns true if the given response is an onchain interaction response. @@ -205,12 +204,16 @@ export async function* executeStaticCallRequest( * @returns The value that should be used as the result of the static call execution state. */ export function getStaticCallExecutionStateResultValue( - _exState: StaticCallExecutionState, + exState: StaticCallExecutionState, lastStaticCallResult: SuccessfulEvmExecutionResult ): SolidityParameterType { - const values = convertEvmTupleToSolidityParam(lastStaticCallResult.values); - // TODO: We should have a way to handle other results. - return values[0]; + return typeof exState.nameOrIndex === "string" + ? (lastStaticCallResult.values.named[ + exState.nameOrIndex + ] as SolidityParameterType) + : (lastStaticCallResult.values.positional[ + exState.nameOrIndex + ] as SolidityParameterType); } export * from "./abi"; diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/future-processor.ts b/packages/core/src/internal/execution/future-processor/future-processor.ts similarity index 96% rename from packages/core/src/new-api/internal/new-execution/future-processor/future-processor.ts rename to packages/core/src/internal/execution/future-processor/future-processor.ts index c77a784ca..d4aa8b787 100644 --- a/packages/core/src/new-api/internal/new-execution/future-processor/future-processor.ts +++ b/packages/core/src/internal/execution/future-processor/future-processor.ts @@ -3,6 +3,7 @@ import { DeploymentParameters } from "../../../types/deploy"; import { Future } from "../../../types/module"; import { DeploymentLoader } from "../../deployment-loader/types"; import { assertIgnitionInvariant } from "../../utils/assertions"; +import { isExecutionStateComplete } from "../../views/is-execution-state-complete"; import { applyNewMessage } from "../deployment-state-helpers"; import { JsonRpcClient } from "../jsonrpc-client"; import { NonceManager } from "../nonce-management"; @@ -18,7 +19,6 @@ import { } from "../types/execution-state"; import { ExecutionStrategy } from "../types/execution-strategy"; import { JournalMessage, JournalMessageType } from "../types/messages"; -import { isExecutionStateComplete } from "../views/is-execution-state-complete"; import { monitorOnchainInteraction } from "./handlers/monitor-onchain-interaction"; import { queryStaticCall } from "./handlers/query-static-call"; @@ -64,7 +64,7 @@ export class FutureProcessor { public async processFuture( future: Future, deploymentState: DeploymentState - ): Promise<{ futureCompleted: boolean; newState: DeploymentState }> { + ): Promise<{ newState: DeploymentState }> { let exState = deploymentState.executionStates[future.id]; if (exState === undefined) { @@ -113,7 +113,7 @@ export class FutureProcessor { if (nextMessage === undefined) { // continue with the next future - return { futureCompleted: false, newState: deploymentState }; + return { newState: deploymentState }; } deploymentState = await applyNewMessage( @@ -127,7 +127,7 @@ export class FutureProcessor { await this._recordDeployedAddressIfNeeded(nextMessage); } - return { futureCompleted: true, newState: deploymentState }; + return { newState: deploymentState }; } /** diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/handlers/monitor-onchain-interaction.ts b/packages/core/src/internal/execution/future-processor/handlers/monitor-onchain-interaction.ts similarity index 98% rename from packages/core/src/new-api/internal/new-execution/future-processor/handlers/monitor-onchain-interaction.ts rename to packages/core/src/internal/execution/future-processor/handlers/monitor-onchain-interaction.ts index 5551103c5..bee8c5cea 100644 --- a/packages/core/src/new-api/internal/new-execution/future-processor/handlers/monitor-onchain-interaction.ts +++ b/packages/core/src/internal/execution/future-processor/handlers/monitor-onchain-interaction.ts @@ -1,4 +1,4 @@ -import { IgnitionError } from "../../../../../errors"; +import { IgnitionError } from "../../../../errors"; import { assertIgnitionInvariant } from "../../../utils/assertions"; import { JsonRpcClient } from "../../jsonrpc-client"; import { TransactionTrackingTimer } from "../../transaction-tracking-timer"; diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/handlers/query-static-call.ts b/packages/core/src/internal/execution/future-processor/handlers/query-static-call.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/future-processor/handlers/query-static-call.ts rename to packages/core/src/internal/execution/future-processor/handlers/query-static-call.ts diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/handlers/run-strategy.ts b/packages/core/src/internal/execution/future-processor/handlers/run-strategy.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/future-processor/handlers/run-strategy.ts rename to packages/core/src/internal/execution/future-processor/handlers/run-strategy.ts diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/handlers/send-transaction.ts b/packages/core/src/internal/execution/future-processor/handlers/send-transaction.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/future-processor/handlers/send-transaction.ts rename to packages/core/src/internal/execution/future-processor/handlers/send-transaction.ts diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/build-initialize-message-for.ts b/packages/core/src/internal/execution/future-processor/helpers/build-initialize-message-for.ts similarity index 90% rename from packages/core/src/new-api/internal/new-execution/future-processor/helpers/build-initialize-message-for.ts rename to packages/core/src/internal/execution/future-processor/helpers/build-initialize-message-for.ts index 9679a73a6..409a4b496 100644 --- a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/build-initialize-message-for.ts +++ b/packages/core/src/internal/execution/future-processor/helpers/build-initialize-message-for.ts @@ -33,8 +33,8 @@ export async function buildInitializeMessageFor( defaultSender: string ): Promise { switch (future.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: const deploymentExecStateInit: DeploymentExecutionStateInitializeMessage = _extendBaseInitWith( JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, @@ -42,7 +42,7 @@ export async function buildInitializeMessageFor( strategy, { futureType: future.type, - artifactFutureId: future.id, + artifactId: future.id, contractName: future.contractName, constructorArgs: resolveArgs( future.constructorArgs, @@ -57,8 +57,8 @@ export async function buildInitializeMessageFor( ); return deploymentExecStateInit; - case FutureType.NAMED_LIBRARY_DEPLOYMENT: - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: const libraryDeploymentInit: DeploymentExecutionStateInitializeMessage = _extendBaseInitWith( JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, @@ -66,7 +66,7 @@ export async function buildInitializeMessageFor( strategy, { futureType: future.type, - artifactFutureId: future.id, + artifactId: future.id, contractName: future.contractName, constructorArgs: [], libraries: resolveLibraries(future.libraries, deploymentState), @@ -76,7 +76,7 @@ export async function buildInitializeMessageFor( ); return libraryDeploymentInit; - case FutureType.NAMED_CONTRACT_CALL: { + case FutureType.CONTRACT_CALL: { const namedContractCallInit: CallExecutionStateInitializeMessage = _extendBaseInitWith( JournalMessageType.CALL_EXECUTION_STATE_INITIALIZE, @@ -94,7 +94,7 @@ export async function buildInitializeMessageFor( future.contract, deploymentState ), - artifactFutureId: future.contract.id, + artifactId: future.contract.id, value: resolveValue(future.value, deploymentParameters), from: resolveFutureFrom(future.from, accounts, defaultSender), } @@ -102,7 +102,7 @@ export async function buildInitializeMessageFor( return namedContractCallInit; } - case FutureType.NAMED_STATIC_CALL: { + case FutureType.STATIC_CALL: { const namedStaticCallInit: StaticCallExecutionStateInitializeMessage = _extendBaseInitWith( JournalMessageType.STATIC_CALL_EXECUTION_STATE_INITIALIZE, @@ -115,20 +115,21 @@ export async function buildInitializeMessageFor( deploymentParameters, accounts ), + nameOrIndex: future.nameOrIndex, functionName: future.functionName, contractAddress: resolveAddressForContractFuture( future.contract, deploymentState ), - artifactFutureId: future.contract.id, + artifactId: future.contract.id, from: resolveFutureFrom(future.from, accounts, defaultSender), } ); return namedStaticCallInit; } - case FutureType.NAMED_CONTRACT_AT: - case FutureType.ARTIFACT_CONTRACT_AT: { + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: { const contractAtInit: ContractAtExecutionStateInitializeMessage = _extendBaseInitWith( JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, @@ -142,7 +143,7 @@ export async function buildInitializeMessageFor( deploymentState, deploymentParameters ), - artifactFutureId: future.id, + artifactId: future.id, } ); @@ -155,7 +156,7 @@ export async function buildInitializeMessageFor( future.emitter, future.eventName, future.eventIndex, - future.argumentName, + future.nameOrIndex, deploymentState, deploymentLoader ); @@ -166,9 +167,9 @@ export async function buildInitializeMessageFor( future, strategy, { - artifactFutureId: future.emitter.id, + artifactId: future.emitter.id, eventName: future.eventName, - argumentName: future.argumentName, + nameOrIndex: future.nameOrIndex, eventIndex: future.eventIndex, txToReadFrom, emitterAddress, diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/future-resolvers.ts b/packages/core/src/internal/execution/future-processor/helpers/future-resolvers.ts similarity index 94% rename from packages/core/src/new-api/internal/new-execution/future-processor/helpers/future-resolvers.ts rename to packages/core/src/internal/execution/future-processor/helpers/future-resolvers.ts index 8477edc5f..e661cea69 100644 --- a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/future-resolvers.ts +++ b/packages/core/src/internal/execution/future-processor/helpers/future-resolvers.ts @@ -15,12 +15,12 @@ import { DeploymentLoader } from "../../../deployment-loader/types"; import { assertIgnitionInvariant } from "../../../utils/assertions"; import { replaceWithinArg } from "../../../utils/replace-within-arg"; import { resolveModuleParameter } from "../../../utils/resolve-module-parameter"; +import { findAddressForContractFuture } from "../../../views/find-address-for-contract-future-by-id"; +import { findConfirmedTransactionByFutureId } from "../../../views/find-confirmed-transaction-by-future-id"; +import { findResultForFutureById } from "../../../views/find-result-for-future-by-id"; import { getEventArgumentFromReceipt } from "../../abi"; import { DeploymentState } from "../../types/deployment-state"; import { convertEvmValueToSolidityParam } from "../../utils/convert-evm-tuple-to-solidity-param"; -import { findAddressForContractFuture } from "../../views/find-address-for-contract-future-by-id"; -import { findConfirmedTransactionByFutureId } from "../../views/find-confirmed-transaction-by-future-id"; -import { findResultForFutureById } from "../../views/find-result-for-future-by-id"; /** * Resolve a futures value to a bigint. @@ -185,7 +185,7 @@ export async function resolveReadEventArgumentResult( emitter: ContractFuture, eventName: string, eventIndex: number, - argumentName: string, + nameOrIndex: string | number, deploymentState: DeploymentState, deploymentLoader: DeploymentLoader ): Promise<{ @@ -211,7 +211,7 @@ export async function resolveReadEventArgumentResult( emitterAddress, eventName, eventIndex, - argumentName + nameOrIndex ); return { diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/messages-helpers.ts b/packages/core/src/internal/execution/future-processor/helpers/messages-helpers.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/future-processor/helpers/messages-helpers.ts rename to packages/core/src/internal/execution/future-processor/helpers/messages-helpers.ts diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/network-interaction-execution.ts b/packages/core/src/internal/execution/future-processor/helpers/network-interaction-execution.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/future-processor/helpers/network-interaction-execution.ts rename to packages/core/src/internal/execution/future-processor/helpers/network-interaction-execution.ts diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/next-action-for-execution-state.ts b/packages/core/src/internal/execution/future-processor/helpers/next-action-for-execution-state.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/future-processor/helpers/next-action-for-execution-state.ts rename to packages/core/src/internal/execution/future-processor/helpers/next-action-for-execution-state.ts diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/replay-strategy.ts b/packages/core/src/internal/execution/future-processor/helpers/replay-strategy.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/future-processor/helpers/replay-strategy.ts rename to packages/core/src/internal/execution/future-processor/helpers/replay-strategy.ts diff --git a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/save-artifacts-for-future.ts b/packages/core/src/internal/execution/future-processor/helpers/save-artifacts-for-future.ts similarity index 65% rename from packages/core/src/new-api/internal/new-execution/future-processor/helpers/save-artifacts-for-future.ts rename to packages/core/src/internal/execution/future-processor/helpers/save-artifacts-for-future.ts index b7c6025bf..e758ba82a 100644 --- a/packages/core/src/new-api/internal/new-execution/future-processor/helpers/save-artifacts-for-future.ts +++ b/packages/core/src/internal/execution/future-processor/helpers/save-artifacts-for-future.ts @@ -2,9 +2,9 @@ import { ArtifactResolver } from "../../../../types/artifact"; import { Future, FutureType, - NamedContractAtFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, + NamedArtifactContractAtFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, } from "../../../../types/module"; import { DeploymentLoader } from "../../../deployment-loader/types"; @@ -14,22 +14,22 @@ export async function saveArtifactsForFuture( deploymentLoader: DeploymentLoader ): Promise { switch (future.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: - case FutureType.NAMED_LIBRARY_DEPLOYMENT: - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: return _storeArtifactAndBuildInfoAgainstDeployment(future, { artifactResolver, deploymentLoader, }); - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: + case FutureType.CONTRACT_AT: return deploymentLoader.storeUserProvidedArtifact( future.id, future.artifact ); - case FutureType.NAMED_CONTRACT_CALL: - case FutureType.NAMED_STATIC_CALL: + case FutureType.CONTRACT_CALL: + case FutureType.STATIC_CALL: case FutureType.READ_EVENT_ARGUMENT: case FutureType.SEND_DATA: return; @@ -38,9 +38,9 @@ export async function saveArtifactsForFuture( async function _storeArtifactAndBuildInfoAgainstDeployment( future: - | NamedLibraryDeploymentFuture - | NamedContractDeploymentFuture - | NamedContractAtFuture, + | NamedArtifactLibraryDeploymentFuture + | NamedArtifactContractDeploymentFuture + | NamedArtifactContractAtFuture, { deploymentLoader, artifactResolver, @@ -58,6 +58,6 @@ async function _storeArtifactAndBuildInfoAgainstDeployment( const buildInfo = await artifactResolver.getBuildInfo(future.contractName); if (buildInfo !== undefined) { - await deploymentLoader.storeBuildInfo(buildInfo); + await deploymentLoader.storeBuildInfo(future.id, buildInfo); } } diff --git a/packages/core/src/new-api/internal/new-execution/jsonrpc-client.ts b/packages/core/src/internal/execution/jsonrpc-client.ts similarity index 99% rename from packages/core/src/new-api/internal/new-execution/jsonrpc-client.ts rename to packages/core/src/internal/execution/jsonrpc-client.ts index cd359ef57..4b07e96c6 100644 --- a/packages/core/src/new-api/internal/new-execution/jsonrpc-client.ts +++ b/packages/core/src/internal/execution/jsonrpc-client.ts @@ -1,4 +1,4 @@ -import { IgnitionError } from "../../../errors"; +import { IgnitionError } from "../../errors"; import { EIP1193Provider } from "../../types/provider"; import { diff --git a/packages/core/src/new-api/internal/new-execution/libraries.ts b/packages/core/src/internal/execution/libraries.ts similarity index 99% rename from packages/core/src/new-api/internal/new-execution/libraries.ts rename to packages/core/src/internal/execution/libraries.ts index c06617539..b450dca22 100644 --- a/packages/core/src/new-api/internal/new-execution/libraries.ts +++ b/packages/core/src/internal/execution/libraries.ts @@ -13,7 +13,7 @@ * @file */ -import { IgnitionValidationError } from "../../../errors"; +import { IgnitionValidationError } from "../../errors"; import { Artifact } from "../../types/artifact"; /** diff --git a/packages/core/src/new-api/internal/new-execution/nonce-management.ts b/packages/core/src/internal/execution/nonce-management.ts similarity index 97% rename from packages/core/src/new-api/internal/new-execution/nonce-management.ts rename to packages/core/src/internal/execution/nonce-management.ts index 3debbfae4..1894a51c4 100644 --- a/packages/core/src/new-api/internal/new-execution/nonce-management.ts +++ b/packages/core/src/internal/execution/nonce-management.ts @@ -1,4 +1,6 @@ -import { IgnitionError } from "../../../errors"; +import { IgnitionError } from "../../errors"; +import { getPendingNonceAndSender } from "../views/execution-state/get-pending-nonce-and-sender"; +import { getPendingOnchainInteraction } from "../views/execution-state/get-pending-onchain-interaction"; import { JsonRpcClient } from "./jsonrpc-client"; import { DeploymentState } from "./types/deployment-state"; @@ -8,8 +10,6 @@ import { OnchainInteractionDroppedMessage, OnchainInteractionReplacedByUserMessage, } from "./types/messages"; -import { getPendingNonceAndSender } from "./views/execution-state/get-pending-nonce-and-sender"; -import { getPendingOnchainInteraction } from "./views/execution-state/get-pending-onchain-interaction"; /** * This function is meant to be used to sync the local state's nonces diff --git a/packages/core/src/new-api/internal/new-execution/reducers/deployment-state-reducer.ts b/packages/core/src/internal/execution/reducers/deployment-state-reducer.ts similarity index 94% rename from packages/core/src/new-api/internal/new-execution/reducers/deployment-state-reducer.ts rename to packages/core/src/internal/execution/reducers/deployment-state-reducer.ts index f0f386500..185d38ae7 100644 --- a/packages/core/src/new-api/internal/new-execution/reducers/deployment-state-reducer.ts +++ b/packages/core/src/internal/execution/reducers/deployment-state-reducer.ts @@ -33,7 +33,7 @@ export function deploymentStateReducer( }; } - if (action.type === JournalMessageType.WIPE_EXECUTION_STATE) { + if (action.type === JournalMessageType.WIPE_APPLY) { return wipeExecutionState(state, action); } diff --git a/packages/core/src/new-api/internal/new-execution/reducers/execution-state-reducer.ts b/packages/core/src/internal/execution/reducers/execution-state-reducer.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/reducers/execution-state-reducer.ts rename to packages/core/src/internal/execution/reducers/execution-state-reducer.ts diff --git a/packages/core/src/new-api/internal/new-execution/reducers/helpers/complete-execution-state.ts b/packages/core/src/internal/execution/reducers/helpers/complete-execution-state.ts similarity index 96% rename from packages/core/src/new-api/internal/new-execution/reducers/helpers/complete-execution-state.ts rename to packages/core/src/internal/execution/reducers/helpers/complete-execution-state.ts index d99f80e95..ed81176a0 100644 --- a/packages/core/src/new-api/internal/new-execution/reducers/helpers/complete-execution-state.ts +++ b/packages/core/src/internal/execution/reducers/helpers/complete-execution-state.ts @@ -72,5 +72,7 @@ function _mapResultTypeToStatus( return ExecutionStatus.FAILED; case ExecutionResultType.STRATEGY_ERROR: return ExecutionStatus.FAILED; + case ExecutionResultType.STRATEGY_HELD: + return ExecutionStatus.HELD; } } diff --git a/packages/core/src/new-api/internal/new-execution/reducers/helpers/deployment-state-helpers.ts b/packages/core/src/internal/execution/reducers/helpers/deployment-state-helpers.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/reducers/helpers/deployment-state-helpers.ts rename to packages/core/src/internal/execution/reducers/helpers/deployment-state-helpers.ts diff --git a/packages/core/src/new-api/internal/new-execution/reducers/helpers/initializers.ts b/packages/core/src/internal/execution/reducers/helpers/initializers.ts similarity index 92% rename from packages/core/src/new-api/internal/new-execution/reducers/helpers/initializers.ts rename to packages/core/src/internal/execution/reducers/helpers/initializers.ts index abfdd27b5..cbee26b03 100644 --- a/packages/core/src/new-api/internal/new-execution/reducers/helpers/initializers.ts +++ b/packages/core/src/internal/execution/reducers/helpers/initializers.ts @@ -28,7 +28,7 @@ export function initialiseDeploymentExecutionStateFrom( strategy: action.strategy, status: ExecutionStatus.STARTED, dependencies: new Set(action.dependencies), - artifactFutureId: action.artifactFutureId, + artifactId: action.artifactId, contractName: action.contractName, constructorArgs: action.constructorArgs, libraries: action.libraries, @@ -46,14 +46,15 @@ export function initialiseStaticCallExecutionStateFrom( const callExecutionInitialState: StaticCallExecutionState = { id: action.futureId, type: ExecutionSateType.STATIC_CALL_EXECUTION_STATE, - futureType: FutureType.NAMED_STATIC_CALL, + futureType: FutureType.STATIC_CALL, strategy: action.strategy, status: ExecutionStatus.STARTED, dependencies: new Set(action.dependencies), - artifactFutureId: action.artifactFutureId, + artifactId: action.artifactId, contractAddress: action.contractAddress, functionName: action.functionName, args: action.args, + nameOrIndex: action.nameOrIndex, from: action.from, networkInteractions: [], }; @@ -92,9 +93,9 @@ export function initialiseReadEventArgumentExecutionStateFrom( strategy: action.strategy, status: ExecutionStatus.SUCCESS, dependencies: new Set(action.dependencies), - artifactFutureId: action.artifactFutureId, + artifactId: action.artifactId, eventName: action.eventName, - argumentName: action.argumentName, + nameOrIndex: action.nameOrIndex, txToReadFrom: action.txToReadFrom, emitterAddress: action.emitterAddress, eventIndex: action.eventIndex, @@ -114,7 +115,7 @@ export function initialiseContractAtExecutionStateFrom( strategy: action.strategy, status: ExecutionStatus.SUCCESS, dependencies: new Set(action.dependencies), - artifactFutureId: action.artifactFutureId, + artifactId: action.artifactId, contractName: action.contractName, contractAddress: action.contractAddress, }; @@ -128,11 +129,11 @@ export function initialiseCallExecutionStateFrom( const callExecutionInitialState: CallExecutionState = { id: action.futureId, type: ExecutionSateType.CALL_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_CALL, + futureType: FutureType.CONTRACT_CALL, strategy: action.strategy, status: ExecutionStatus.STARTED, dependencies: new Set(action.dependencies), - artifactFutureId: action.artifactFutureId, + artifactId: action.artifactId, contractAddress: action.contractAddress, functionName: action.functionName, args: action.args, diff --git a/packages/core/src/new-api/internal/new-execution/reducers/helpers/network-interaction-helpers.ts b/packages/core/src/internal/execution/reducers/helpers/network-interaction-helpers.ts similarity index 96% rename from packages/core/src/new-api/internal/new-execution/reducers/helpers/network-interaction-helpers.ts rename to packages/core/src/internal/execution/reducers/helpers/network-interaction-helpers.ts index 11902b9ce..50f667b63 100644 --- a/packages/core/src/new-api/internal/new-execution/reducers/helpers/network-interaction-helpers.ts +++ b/packages/core/src/internal/execution/reducers/helpers/network-interaction-helpers.ts @@ -1,6 +1,9 @@ import { produce } from "immer"; import { assertIgnitionInvariant } from "../../../utils/assertions"; +import { findOnchainInteractionBy } from "../../../views/execution-state/find-onchain-interaction-by"; +import { findStaticCallBy } from "../../../views/execution-state/find-static-call-by"; +import { findTransactionBy } from "../../../views/execution-state/find-transaction-by"; import { CallExecutionState, DeploymentExecutionState, @@ -20,9 +23,6 @@ import { TransactionSendMessage, } from "../../types/messages"; import { NetworkInteractionType } from "../../types/network-interaction"; -import { findOnchainInteractionBy } from "../../views/execution-state/find-onchain-interaction-by"; -import { findStaticCallBy } from "../../views/execution-state/find-static-call-by"; -import { findTransactionBy } from "../../views/execution-state/find-transaction-by"; /** * Add a new network interaction to the execution state. diff --git a/packages/core/src/new-api/internal/new-execution/transaction-tracking-timer.ts b/packages/core/src/internal/execution/transaction-tracking-timer.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/transaction-tracking-timer.ts rename to packages/core/src/internal/execution/transaction-tracking-timer.ts diff --git a/packages/core/src/new-api/internal/new-execution/type-helpers.ts b/packages/core/src/internal/execution/type-helpers.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/type-helpers.ts rename to packages/core/src/internal/execution/type-helpers.ts diff --git a/packages/core/src/new-api/internal/new-execution/types/deployment-state.ts b/packages/core/src/internal/execution/types/deployment-state.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/types/deployment-state.ts rename to packages/core/src/internal/execution/types/deployment-state.ts diff --git a/packages/core/src/new-api/internal/new-execution/types/evm-execution.ts b/packages/core/src/internal/execution/types/evm-execution.ts similarity index 96% rename from packages/core/src/new-api/internal/new-execution/types/evm-execution.ts rename to packages/core/src/internal/execution/types/evm-execution.ts index 51a54df1a..62f4e27c1 100644 --- a/packages/core/src/new-api/internal/new-execution/types/evm-execution.ts +++ b/packages/core/src/internal/execution/types/evm-execution.ts @@ -78,7 +78,7 @@ export interface SuccessfulEvmExecutionResult { } /** - * The execution was seemgly succseful, but the data returned by it was invalid. + * The execution was seemingly successful, but the data returned by it was invalid. */ export interface InvalidResultError { type: EvmExecutionResultTypes.INVALID_RESULT_ERROR; @@ -137,7 +137,7 @@ export interface RevertWithUnknownCustomError { /** * The execution failed due to some error whose kind we can recognize, but that - * we can't decode becase its data is invalid. This happens when the ABI decoding + * we can't decode because its data is invalid. This happens when the ABI decoding * of the error fails, or when a panic code is invalid. */ export interface RevertWithInvalidData { diff --git a/packages/core/src/new-api/internal/new-execution/types/execution-result.ts b/packages/core/src/internal/execution/types/execution-result.ts similarity index 86% rename from packages/core/src/new-api/internal/new-execution/types/execution-result.ts rename to packages/core/src/internal/execution/types/execution-result.ts index 52b4a009e..f43f41752 100644 --- a/packages/core/src/new-api/internal/new-execution/types/execution-result.ts +++ b/packages/core/src/internal/execution/types/execution-result.ts @@ -12,6 +12,7 @@ export enum ExecutionResultType { REVERTED_TRANSACTION = "REVERTED_TRANSACTION", STATIC_CALL_ERROR = "STATIC_CALL_ERROR", STRATEGY_ERROR = "STRATEGY_ERROR", + STRATEGY_HELD = "STRATEGY_HELD", } /** @@ -59,6 +60,16 @@ export interface StrategyErrorExecutionResult { error: string; } +/** + * The execution strategy returned a strategy-specific hold e.g. + * waiting for off-chain multi-sig confirmations. + */ +export interface StrategyHeldExecutionResult { + type: ExecutionResultType.STRATEGY_HELD; + heldId: number; + reason: string; +} + /** * A deployment was successfully executed. */ @@ -77,7 +88,8 @@ export type DeploymentExecutionResult = | StrategySimulationErrorExecutionResult | RevertedTransactionExecutionResult | FailedStaticCallExecutionResult - | StrategyErrorExecutionResult; + | StrategyErrorExecutionResult + | StrategyHeldExecutionResult; /** * A call future was successfully executed. @@ -95,7 +107,8 @@ export type CallExecutionResult = | StrategySimulationErrorExecutionResult | RevertedTransactionExecutionResult | FailedStaticCallExecutionResult - | StrategyErrorExecutionResult; + | StrategyErrorExecutionResult + | StrategyHeldExecutionResult; /** * A send data future was successfully executed. @@ -113,7 +126,8 @@ export type SendDataExecutionResult = | StrategySimulationErrorExecutionResult | RevertedTransactionExecutionResult | FailedStaticCallExecutionResult - | StrategyErrorExecutionResult; + | StrategyErrorExecutionResult + | StrategyHeldExecutionResult; /** * A static call future was successfully executed. @@ -129,4 +143,5 @@ export interface SuccessfulStaticCallExecutionResult { export type StaticCallExecutionResult = | SuccessfulStaticCallExecutionResult | FailedStaticCallExecutionResult - | StrategyErrorExecutionResult; + | StrategyErrorExecutionResult + | StrategyHeldExecutionResult; diff --git a/packages/core/src/new-api/internal/new-execution/types/execution-state.ts b/packages/core/src/internal/execution/types/execution-state.ts similarity index 90% rename from packages/core/src/new-api/internal/new-execution/types/execution-state.ts rename to packages/core/src/internal/execution/types/execution-state.ts index 29f066b12..39a536673 100644 --- a/packages/core/src/new-api/internal/new-execution/types/execution-state.ts +++ b/packages/core/src/internal/execution/types/execution-state.ts @@ -26,6 +26,7 @@ export enum ExecutionStatus { STARTED = "STARATED", TIMEOUT = "TIMEOUT", SUCCESS = "SUCCESS", + HELD = "HELD", FAILED = "FAILED", } @@ -60,10 +61,10 @@ interface BaseExecutionState< /** The future types that can be used with a DeploymentExecutionState */ export type DeploymentExecutionStateFutureTypes = - | FutureType.NAMED_CONTRACT_DEPLOYMENT - | FutureType.ARTIFACT_CONTRACT_DEPLOYMENT - | FutureType.NAMED_LIBRARY_DEPLOYMENT - | FutureType.ARTIFACT_LIBRARY_DEPLOYMENT; + | FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT + | FutureType.CONTRACT_DEPLOYMENT + | FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT + | FutureType.LIBRARY_DEPLOYMENT; /** * The execution state used for the different kinds of futures @@ -74,7 +75,7 @@ export interface DeploymentExecutionState ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, DeploymentExecutionStateFutureTypes > { - artifactFutureId: string; + artifactId: string; contractName: string; constructorArgs: SolidityParameterType[]; libraries: Record; @@ -90,9 +91,9 @@ export interface DeploymentExecutionState export interface CallExecutionState extends BaseExecutionState< ExecutionSateType.CALL_EXECUTION_STATE, - FutureType.NAMED_CONTRACT_CALL + FutureType.CONTRACT_CALL > { - artifactFutureId: string; + artifactId: string; contractAddress: string; functionName: string; args: SolidityParameterType[]; @@ -111,12 +112,13 @@ export interface CallExecutionState export interface StaticCallExecutionState extends BaseExecutionState< ExecutionSateType.STATIC_CALL_EXECUTION_STATE, - FutureType.NAMED_STATIC_CALL + FutureType.STATIC_CALL > { - artifactFutureId: string; + artifactId: string; contractAddress: string; functionName: string; args: SolidityParameterType[]; + nameOrIndex: string | number; from: string; networkInteractions: StaticCall[]; result?: StaticCallExecutionResult; @@ -149,9 +151,9 @@ export interface SendDataExecutionState export interface ContractAtExecutionState extends BaseExecutionState< ExecutionSateType.CONTRACT_AT_EXECUTION_STATE, - FutureType.NAMED_CONTRACT_AT | FutureType.ARTIFACT_CONTRACT_AT + FutureType.NAMED_ARTIFACT_CONTRACT_AT | FutureType.CONTRACT_AT > { - artifactFutureId: string; + artifactId: string; contractName: string; contractAddress: string; } @@ -167,9 +169,9 @@ export interface ReadEventArgumentExecutionState ExecutionSateType.READ_EVENT_ARGUMENT_EXECUTION_STATE, FutureType.READ_EVENT_ARGUMENT > { - artifactFutureId: string; + artifactId: string; eventName: string; - argumentName: string; + nameOrIndex: string | number; txToReadFrom: string; emitterAddress: string; eventIndex: number; diff --git a/packages/core/src/new-api/internal/new-execution/types/execution-strategy.ts b/packages/core/src/internal/execution/types/execution-strategy.ts similarity index 99% rename from packages/core/src/new-api/internal/new-execution/types/execution-strategy.ts rename to packages/core/src/internal/execution/types/execution-strategy.ts index f88d88753..c00c94702 100644 --- a/packages/core/src/new-api/internal/new-execution/types/execution-strategy.ts +++ b/packages/core/src/internal/execution/types/execution-strategy.ts @@ -23,9 +23,7 @@ import { OnchainInteraction, StaticCall } from "./network-interaction"; /** * A function that loads an artifact from the deployment's artifacts store. */ -export type LoadArtifactFunction = ( - artifactFutureId: string -) => Promise; +export type LoadArtifactFunction = (artifactId: string) => Promise; /** * A request to perform an onchain interaction. This leads to the execution engine diff --git a/packages/core/src/new-api/internal/new-execution/types/jsonrpc.ts b/packages/core/src/internal/execution/types/jsonrpc.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/types/jsonrpc.ts rename to packages/core/src/internal/execution/types/jsonrpc.ts diff --git a/packages/core/src/new-api/internal/new-execution/types/messages.ts b/packages/core/src/internal/execution/types/messages.ts similarity index 94% rename from packages/core/src/new-api/internal/new-execution/types/messages.ts rename to packages/core/src/internal/execution/types/messages.ts index b3e061049..c41f9b35b 100644 --- a/packages/core/src/new-api/internal/new-execution/types/messages.ts +++ b/packages/core/src/internal/execution/types/messages.ts @@ -39,9 +39,15 @@ export type JournalMessage = | OnchainInteractionReplacedByUserMessage | OnchainInteractionTimeoutMessage; +/** + * NOTE: + * + * when adding/removing/changing any of these + * be sure to update UiEventType accordingly + */ export enum JournalMessageType { RUN_START = "RUN_START", - WIPE_EXECUTION_STATE = "WIPE_EXECUTION_STATE", + WIPE_APPLY = "WIPE_APPLY", DEPLOYMENT_EXECUTION_STATE_INITIALIZE = "DEPLOYMENT_EXECUTION_STATE_INITIALIZE", DEPLOYMENT_EXECUTION_STATE_COMPLETE = "DEPLOYMENT_EXECUTION_STATE_COMPLETE", CALL_EXECUTION_STATE_INITIALIZE = "CALL_EXECUTION_STATE_INITIALIZE", @@ -73,7 +79,7 @@ export interface DeploymentExecutionStateInitializeMessage { futureType: DeploymentExecutionStateFutureTypes; strategy: string; dependencies: string[]; - artifactFutureId: string; + artifactId: string; contractName: string; constructorArgs: SolidityParameterType[]; libraries: Record; @@ -92,7 +98,7 @@ export interface CallExecutionStateInitializeMessage { futureId: string; strategy: string; dependencies: string[]; - artifactFutureId: string; + artifactId: string; contractAddress: string; functionName: string; args: SolidityParameterType[]; @@ -111,9 +117,10 @@ export interface StaticCallExecutionStateInitializeMessage { futureId: string; strategy: string; dependencies: string[]; - artifactFutureId: string; + artifactId: string; contractAddress: string; functionName: string; + nameOrIndex: string | number; args: SolidityParameterType[]; from: string; } @@ -143,11 +150,11 @@ export interface SendDataExecutionStateCompleteMessage { export interface ContractAtExecutionStateInitializeMessage { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE; - futureType: FutureType.NAMED_CONTRACT_AT | FutureType.ARTIFACT_CONTRACT_AT; + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT | FutureType.CONTRACT_AT; futureId: string; strategy: string; dependencies: string[]; - artifactFutureId: string; + artifactId: string; contractName: string; contractAddress: string; } @@ -157,9 +164,9 @@ export interface ReadEventArgExecutionStateInitializeMessage { futureId: string; strategy: string; dependencies: string[]; - artifactFutureId: string; + artifactId: string; eventName: string; - argumentName: string; + nameOrIndex: string | number; txToReadFrom: string; emitterAddress: string; eventIndex: number; @@ -222,6 +229,6 @@ export interface OnchainInteractionTimeoutMessage { } export interface WipeExecutionStateMessage { - type: JournalMessageType.WIPE_EXECUTION_STATE; + type: JournalMessageType.WIPE_APPLY; futureId: string; } diff --git a/packages/core/src/new-api/internal/new-execution/types/network-interaction.ts b/packages/core/src/internal/execution/types/network-interaction.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/types/network-interaction.ts rename to packages/core/src/internal/execution/types/network-interaction.ts diff --git a/packages/core/src/new-api/internal/new-execution/utils/convert-evm-tuple-to-solidity-param.ts b/packages/core/src/internal/execution/utils/convert-evm-tuple-to-solidity-param.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/utils/convert-evm-tuple-to-solidity-param.ts rename to packages/core/src/internal/execution/utils/convert-evm-tuple-to-solidity-param.ts diff --git a/packages/core/src/new-api/internal/new-execution/utils/get-default-sender.ts b/packages/core/src/internal/execution/utils/get-default-sender.ts similarity index 100% rename from packages/core/src/new-api/internal/new-execution/utils/get-default-sender.ts rename to packages/core/src/internal/execution/utils/get-default-sender.ts diff --git a/packages/core/src/new-api/internal/formatters.ts b/packages/core/src/internal/formatters.ts similarity index 92% rename from packages/core/src/new-api/internal/formatters.ts rename to packages/core/src/internal/formatters.ts index 7f4a4cc12..d027bc05b 100644 --- a/packages/core/src/new-api/internal/formatters.ts +++ b/packages/core/src/internal/formatters.ts @@ -4,7 +4,7 @@ import { EvmExecutionResultTypes, EvmTuple, FailedEvmExecutionResult, -} from "./new-execution/types/evm-execution"; +} from "./execution/types/evm-execution"; import { ExecutionResultType, FailedStaticCallExecutionResult, @@ -12,8 +12,8 @@ import { SimulationErrorExecutionResult, StrategyErrorExecutionResult, StrategySimulationErrorExecutionResult, -} from "./new-execution/types/execution-result"; -import { convertEvmTupleToSolidityParam } from "./new-execution/utils/convert-evm-tuple-to-solidity-param"; +} from "./execution/types/execution-result"; +import { convertEvmTupleToSolidityParam } from "./execution/utils/convert-evm-tuple-to-solidity-param"; /** * Formats an execution error result into a human-readable string. @@ -31,19 +31,14 @@ export function formatExecutionError( return `Simulating the transaction failed with error: ${formatFailedEvmExecutionResult( result.error )}`; - case ExecutionResultType.STRATEGY_SIMULATION_ERROR: return `Simulating the transaction failed with error: ${result.error}`; - - case ExecutionResultType.REVERTED_TRANSACTION: { + case ExecutionResultType.REVERTED_TRANSACTION: return `Transaction ${result.txHash} reverted`; - } - case ExecutionResultType.STATIC_CALL_ERROR: return `Static call failed with error: ${formatFailedEvmExecutionResult( result.error )}`; - case ExecutionResultType.STRATEGY_ERROR: return `Execution failed with error: ${result.error}`; } diff --git a/packages/core/src/new-api/internal/journal/file-journal.ts b/packages/core/src/internal/journal/file-journal.ts similarity index 77% rename from packages/core/src/new-api/internal/journal/file-journal.ts rename to packages/core/src/internal/journal/file-journal.ts index fd06bb032..b7b3d4c8f 100644 --- a/packages/core/src/new-api/internal/journal/file-journal.ts +++ b/packages/core/src/internal/journal/file-journal.ts @@ -2,11 +2,12 @@ import fs, { closeSync, constants, openSync, writeFileSync } from "fs"; import { parse } from "ndjson"; -import { JournalMessage } from "../new-execution/types/messages"; +import { ExecutionEventListener } from "../../types/execution-events"; +import { JournalMessage } from "../execution/types/messages"; import { Journal } from "./types"; import { deserializeReplacer } from "./utils/deserialize-replacer"; -import { logJournalableMessage } from "./utils/log"; +import { emitExecutionEvent } from "./utils/emitExecutionEvent"; import { serializeReplacer } from "./utils/serialize-replacer"; /** @@ -15,7 +16,10 @@ import { serializeReplacer } from "./utils/serialize-replacer"; * @beta */ export class FileJournal implements Journal { - constructor(private _filePath: string, private _verbose: boolean = false) {} + constructor( + private _filePath: string, + private _executionEventListener?: ExecutionEventListener + ) {} public record(message: JournalMessage): void { this._log(message); @@ -60,8 +64,8 @@ export class FileJournal implements Journal { } private _log(message: JournalMessage): void { - if (this._verbose) { - return logJournalableMessage(message); + if (this._executionEventListener !== undefined) { + emitExecutionEvent(message, this._executionEventListener); } } } diff --git a/packages/core/src/new-api/internal/journal/memory-journal.ts b/packages/core/src/internal/journal/memory-journal.ts similarity index 54% rename from packages/core/src/new-api/internal/journal/memory-journal.ts rename to packages/core/src/internal/journal/memory-journal.ts index 1f22ae094..56a2cc83b 100644 --- a/packages/core/src/new-api/internal/journal/memory-journal.ts +++ b/packages/core/src/internal/journal/memory-journal.ts @@ -1,7 +1,8 @@ -import { JournalMessage } from "../new-execution/types/messages"; +import { ExecutionEventListener } from "../../types/execution-events"; +import { JournalMessage } from "../execution/types/messages"; import { Journal } from "./types"; -import { logJournalableMessage } from "./utils/log"; +import { emitExecutionEvent } from "./utils/emitExecutionEvent"; /** * An in-memory journal. @@ -11,7 +12,7 @@ import { logJournalableMessage } from "./utils/log"; export class MemoryJournal implements Journal { private messages: JournalMessage[] = []; - constructor(private _verbose: boolean = false) {} + constructor(private _executionEventListener?: ExecutionEventListener) {} public record(message: JournalMessage): void { this._log(message); @@ -26,8 +27,8 @@ export class MemoryJournal implements Journal { } private _log(message: JournalMessage): void { - if (this._verbose) { - return logJournalableMessage(message); + if (this._executionEventListener !== undefined) { + emitExecutionEvent(message, this._executionEventListener); } } } diff --git a/packages/core/src/new-api/internal/journal/types/index.ts b/packages/core/src/internal/journal/types/index.ts similarity index 73% rename from packages/core/src/new-api/internal/journal/types/index.ts rename to packages/core/src/internal/journal/types/index.ts index 6fb99a170..db53f14ff 100644 --- a/packages/core/src/new-api/internal/journal/types/index.ts +++ b/packages/core/src/internal/journal/types/index.ts @@ -1,4 +1,4 @@ -import { JournalMessage } from "../../new-execution/types/messages"; +import { JournalMessage } from "../../execution/types/messages"; /** * Store a deployments execution state as a transaction log. diff --git a/packages/core/src/new-api/internal/journal/utils/deserialize-replacer.ts b/packages/core/src/internal/journal/utils/deserialize-replacer.ts similarity index 100% rename from packages/core/src/new-api/internal/journal/utils/deserialize-replacer.ts rename to packages/core/src/internal/journal/utils/deserialize-replacer.ts diff --git a/packages/core/src/internal/journal/utils/emitExecutionEvent.ts b/packages/core/src/internal/journal/utils/emitExecutionEvent.ts new file mode 100644 index 000000000..db7c4b12a --- /dev/null +++ b/packages/core/src/internal/journal/utils/emitExecutionEvent.ts @@ -0,0 +1,271 @@ +import { + ExecutionEventListener, + ExecutionEventNetworkInteractionType, + ExecutionEventResult, + ExecutionEventResultType, + ExecutionEventType, +} from "../../../types/execution-events"; +import { SolidityParameterType } from "../../../types/module"; +import { + CallExecutionResult, + DeploymentExecutionResult, + ExecutionResultType, + SendDataExecutionResult, + StaticCallExecutionResult, +} from "../../execution/types/execution-result"; +import { + JournalMessage, + JournalMessageType, +} from "../../execution/types/messages"; +import { NetworkInteractionType } from "../../execution/types/network-interaction"; + +import { failedEvmExecutionResultToErrorDescription } from "./failedEvmExecutionResultToErrorDescription"; + +export function emitExecutionEvent( + message: JournalMessage, + executionEventListener: ExecutionEventListener +): void { + switch (message.type) { + case JournalMessageType.RUN_START: { + executionEventListener.runStart({ + type: ExecutionEventType.RUN_START, + chainId: message.chainId, + }); + break; + } + case JournalMessageType.WIPE_APPLY: { + executionEventListener.wipeApply({ + type: ExecutionEventType.WIPE_APPLY, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE: { + executionEventListener.deploymentExecutionStateInitialize({ + type: ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.DEPLOYMENT_EXECUTION_STATE_COMPLETE: { + executionEventListener.deploymentExecutionStateComplete({ + type: ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_COMPLETE, + futureId: message.futureId, + result: convertExecutionResultToEventResult(message.result), + }); + break; + } + case JournalMessageType.CALL_EXECUTION_STATE_INITIALIZE: { + executionEventListener.callExecutionStateInitialize({ + type: ExecutionEventType.CALL_EXECUTION_STATE_INITIALIZE, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.CALL_EXECUTION_STATE_COMPLETE: { + executionEventListener.callExecutionStateComplete({ + type: ExecutionEventType.CALL_EXECUTION_STATE_COMPLETE, + futureId: message.futureId, + result: convertExecutionResultToEventResult(message.result), + }); + break; + } + case JournalMessageType.STATIC_CALL_EXECUTION_STATE_INITIALIZE: { + executionEventListener.staticCallExecutionStateInitialize({ + type: ExecutionEventType.STATIC_CALL_EXECUTION_STATE_INITIALIZE, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.STATIC_CALL_EXECUTION_STATE_COMPLETE: { + executionEventListener.staticCallExecutionStateComplete({ + type: ExecutionEventType.STATIC_CALL_EXECUTION_STATE_COMPLETE, + futureId: message.futureId, + result: convertStaticCallResultToExecutionEventResult(message.result), + }); + break; + } + case JournalMessageType.SEND_DATA_EXECUTION_STATE_INITIALIZE: { + executionEventListener.sendDataExecutionStateInitialize({ + type: ExecutionEventType.SEND_DATA_EXECUTION_STATE_INITIALIZE, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.SEND_DATA_EXECUTION_STATE_COMPLETE: { + executionEventListener.sendDataExecutionStateComplete({ + type: ExecutionEventType.SEND_DATA_EXECUTION_STATE_COMPLETE, + futureId: message.futureId, + result: convertExecutionResultToEventResult(message.result), + }); + break; + } + case JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE: { + executionEventListener.contractAtExecutionStateInitialize({ + type: ExecutionEventType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE: { + executionEventListener.readEventArgumentExecutionStateInitialize({ + type: ExecutionEventType.READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE, + futureId: message.futureId, + result: { + type: ExecutionEventResultType.SUCCESS, + result: solidityParamToString(message.result), + }, + }); + break; + } + case JournalMessageType.NETWORK_INTERACTION_REQUEST: { + executionEventListener.networkInteractionRequest({ + type: ExecutionEventType.NETWORK_INTERACTION_REQUEST, + networkInteractionType: + message.networkInteraction.type === + NetworkInteractionType.ONCHAIN_INTERACTION + ? ExecutionEventNetworkInteractionType.ONCHAIN_INTERACTION + : ExecutionEventNetworkInteractionType.STATIC_CALL, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.TRANSACTION_SEND: { + executionEventListener.transactionSend({ + type: ExecutionEventType.TRANSACTION_SEND, + futureId: message.futureId, + hash: message.transaction.hash, + }); + break; + } + case JournalMessageType.TRANSACTION_CONFIRM: { + executionEventListener.transactionConfirm({ + type: ExecutionEventType.TRANSACTION_CONFIRM, + futureId: message.futureId, + hash: message.hash, + }); + break; + } + case JournalMessageType.STATIC_CALL_COMPLETE: { + executionEventListener.staticCallComplete({ + type: ExecutionEventType.STATIC_CALL_COMPLETE, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.ONCHAIN_INTERACTION_BUMP_FEES: { + executionEventListener.onchainInteractionBumpFees({ + type: ExecutionEventType.ONCHAIN_INTERACTION_BUMP_FEES, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.ONCHAIN_INTERACTION_DROPPED: { + executionEventListener.onchainInteractionDropped({ + type: ExecutionEventType.ONCHAIN_INTERACTION_DROPPED, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.ONCHAIN_INTERACTION_REPLACED_BY_USER: { + executionEventListener.onchainInteractionReplacedByUser({ + type: ExecutionEventType.ONCHAIN_INTERACTION_REPLACED_BY_USER, + futureId: message.futureId, + }); + break; + } + case JournalMessageType.ONCHAIN_INTERACTION_TIMEOUT: { + executionEventListener.onchainInteractionTimeout({ + type: ExecutionEventType.ONCHAIN_INTERACTION_TIMEOUT, + futureId: message.futureId, + }); + break; + } + } +} + +function convertExecutionResultToEventResult( + result: + | DeploymentExecutionResult + | CallExecutionResult + | SendDataExecutionResult +): ExecutionEventResult { + switch (result.type) { + case ExecutionResultType.SUCCESS: { + return { + type: ExecutionEventResultType.SUCCESS, + result: "address" in result ? result.address : undefined, + }; + } + case ExecutionResultType.STATIC_CALL_ERROR: + case ExecutionResultType.SIMULATION_ERROR: { + return { + type: ExecutionEventResultType.ERROR, + error: failedEvmExecutionResultToErrorDescription(result.error), + }; + } + case ExecutionResultType.STRATEGY_ERROR: + case ExecutionResultType.STRATEGY_SIMULATION_ERROR: { + return { + type: ExecutionEventResultType.ERROR, + error: result.error, + }; + } + case ExecutionResultType.REVERTED_TRANSACTION: { + return { + type: ExecutionEventResultType.ERROR, + error: "Transaction reverted", + }; + } + case ExecutionResultType.STRATEGY_HELD: { + return { + type: ExecutionEventResultType.HELD, + heldId: result.heldId, + reason: result.reason, + }; + } + } +} + +function convertStaticCallResultToExecutionEventResult( + result: StaticCallExecutionResult +): ExecutionEventResult { + switch (result.type) { + case ExecutionResultType.SUCCESS: { + return { + type: ExecutionEventResultType.SUCCESS, + }; + } + case ExecutionResultType.STATIC_CALL_ERROR: { + return { + type: ExecutionEventResultType.ERROR, + error: failedEvmExecutionResultToErrorDescription(result.error), + }; + } + case ExecutionResultType.STRATEGY_ERROR: { + return { + type: ExecutionEventResultType.ERROR, + error: result.error, + }; + } + case ExecutionResultType.STRATEGY_HELD: { + return { + type: ExecutionEventResultType.HELD, + heldId: result.heldId, + reason: result.reason, + }; + } + } +} + +function solidityParamToString(param: SolidityParameterType): string { + if (typeof param === "object") { + return JSON.stringify(param); + } + + if (typeof param === "string") { + return param; + } + + return param.toString(); +} diff --git a/packages/core/src/internal/journal/utils/failedEvmExecutionResultToErrorDescription.ts b/packages/core/src/internal/journal/utils/failedEvmExecutionResultToErrorDescription.ts new file mode 100644 index 000000000..452453ee1 --- /dev/null +++ b/packages/core/src/internal/journal/utils/failedEvmExecutionResultToErrorDescription.ts @@ -0,0 +1,37 @@ +import { + EvmExecutionResultTypes, + FailedEvmExecutionResult, +} from "../../execution/types/evm-execution"; + +export function failedEvmExecutionResultToErrorDescription( + result: FailedEvmExecutionResult +): string { + switch (result.type) { + case EvmExecutionResultTypes.INVALID_RESULT_ERROR: { + return `Transaction appears to have succeeded, but has returned invalid data: '${result.data}'`; + } + case EvmExecutionResultTypes.REVERT_WITHOUT_REASON: { + return `Transaction reverted`; + } + case EvmExecutionResultTypes.REVERT_WITH_REASON: { + return `Transaction reverted with reason: '${result.message}'`; + } + case EvmExecutionResultTypes.REVERT_WITH_PANIC_CODE: { + return `Transaction reverted with panic code (${result.panicCode}): '${result.panicName}'`; + } + case EvmExecutionResultTypes.REVERT_WITH_CUSTOM_ERROR: { + return `Transaction reverted with custom error: '${ + result.errorName + }' args: ${JSON.stringify(result.args.positional)}`; + } + case EvmExecutionResultTypes.REVERT_WITH_UNKNOWN_CUSTOM_ERROR: { + return `Transaction reverted with unknown custom error. Error signature: '${result.signature}' data: '${result.data}'`; + } + case EvmExecutionResultTypes.REVERT_WITH_INVALID_DATA: { + return `Transaction reverted with invalid error data: '${result.data}'`; + } + case EvmExecutionResultTypes.REVERT_WITH_INVALID_DATA_OR_UNKNOWN_CUSTOM_ERROR: { + return `Transaction reverted with unknown error. Error signature: '${result.signature}' data: '${result.data}'`; + } + } +} diff --git a/packages/core/src/new-api/internal/journal/utils/log.ts b/packages/core/src/internal/journal/utils/log.ts similarity index 95% rename from packages/core/src/new-api/internal/journal/utils/log.ts rename to packages/core/src/internal/journal/utils/log.ts index 07e4960e2..d5d32b47f 100644 --- a/packages/core/src/new-api/internal/journal/utils/log.ts +++ b/packages/core/src/internal/journal/utils/log.ts @@ -1,10 +1,10 @@ -import { formatSolidityParameter } from "../../formatters"; -import { ExecutionResultType } from "../../new-execution/types/execution-result"; +import { ExecutionResultType } from "../../execution/types/execution-result"; import { JournalMessage, JournalMessageType, -} from "../../new-execution/types/messages"; -import { NetworkInteractionType } from "../../new-execution/types/network-interaction"; +} from "../../execution/types/messages"; +import { NetworkInteractionType } from "../../execution/types/network-interaction"; +import { formatSolidityParameter } from "../../formatters"; export function logJournalableMessage(message: JournalMessage): void { switch (message.type) { @@ -12,7 +12,7 @@ export function logJournalableMessage(message: JournalMessage): void { console.log(`Deployment started`); break; - case JournalMessageType.WIPE_EXECUTION_STATE: { + case JournalMessageType.WIPE_APPLY: { console.log( `Removing the execution of future ${message.futureId} from the journal` ); diff --git a/packages/core/src/new-api/internal/journal/utils/serialize-replacer.ts b/packages/core/src/internal/journal/utils/serialize-replacer.ts similarity index 100% rename from packages/core/src/new-api/internal/journal/utils/serialize-replacer.ts rename to packages/core/src/internal/journal/utils/serialize-replacer.ts diff --git a/packages/core/src/new-api/internal/module-builder.ts b/packages/core/src/internal/module-builder.ts similarity index 63% rename from packages/core/src/new-api/internal/module-builder.ts rename to packages/core/src/internal/module-builder.ts index 666072768..d93bf4318 100644 --- a/packages/core/src/new-api/internal/module-builder.ts +++ b/packages/core/src/internal/module-builder.ts @@ -1,11 +1,12 @@ import assert from "assert"; import { inspect } from "util"; -import { IgnitionError, IgnitionValidationError } from "../../errors"; +import { IgnitionError, IgnitionValidationError } from "../errors"; import { isAccountRuntimeValue, isAddressResolvableFuture, isArtifactType, + isCallableContractFuture, isContractFuture, isFuture, isModuleParameterRuntimeValue, @@ -15,30 +16,30 @@ import { AccountRuntimeValue, AddressResolvableFuture, ArgumentType, - ArtifactContractAtFuture, - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, + ContractAtFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, + CallableContractFuture, ContractFuture, + FutureType, IgnitionModule, IgnitionModuleResult, ModuleParameterRuntimeValue, ModuleParameterType, ModuleParameters, - NamedContractAtFuture, - NamedContractCallFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, - NamedStaticCallFuture, + NamedArtifactContractAtFuture, + ContractCallFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, + StaticCallFuture, ReadEventArgumentFuture, SendDataFuture, } from "../types/module"; import { CallOptions, ContractAtOptions, - ContractFromArtifactOptions, ContractOptions, IgnitionModuleBuilder, - LibraryFromArtifactOptions, LibraryOptions, ReadEventArgumentOptions, SendDataOptions, @@ -61,6 +62,17 @@ import { SendDataFutureImplementation, } from "./module"; import { resolveArgsToFutures } from "./utils"; +import { + toCallFutureId, + toDeploymentFutureId, + toReadEventArgumentFutureId, + toSendDataFutureId, +} from "./utils/future-id-builders"; +import { + isValidFunctionOrEventName, + isValidIgnitionIdentifier, + isValidSolidityIdentifier, +} from "./utils/identifier-validators"; const STUB_MODULE_RESULTS = { [inspect.custom](): string { @@ -165,16 +177,71 @@ class IgnitionModuleBuilderImplementation< } public contract( + contractName: ContractNameT, + args?: ArgumentType[], + options?: ContractOptions + ): NamedArtifactContractDeploymentFuture; + public contract( + contractName: string, + artifact: Artifact, + args?: ArgumentType[], + options?: ContractOptions + ): ContractDeploymentFuture; + public contract( + contractName: ContractNameT, + artifactOrArgs?: Artifact | ArgumentType[], + argsorOptions?: ArgumentType[] | ContractAtOptions, + maybeOptions?: ContractOptions + ): + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture { + if (artifactOrArgs === undefined || Array.isArray(artifactOrArgs)) { + if (Array.isArray(argsorOptions)) { + this._throwErrorWithStackTrace( + `Invalid parameter "options" provided to contract "${contractName}" in module "${this._module.id}"`, + this.contract + ); + } + + return this._namedArtifactContract( + contractName, + artifactOrArgs, + argsorOptions + ); + } + + if (argsorOptions !== undefined && !Array.isArray(argsorOptions)) { + this._throwErrorWithStackTrace( + `Invalid parameter "args" provided to contract "${contractName}" in module "${this._module.id}"`, + this.contract + ); + } + + return this._contractFromArtifact( + contractName, + artifactOrArgs, + argsorOptions, + maybeOptions + ); + } + + private _namedArtifactContract( contractName: ContractNameT, args: ArgumentType[] = [], options: ContractOptions = {} - ): NamedContractDeploymentFuture { - const id = options.id ?? contractName; - const futureId = `${this._module.id}:${id}`; + ): NamedArtifactContractDeploymentFuture { + const futureId = toDeploymentFutureId( + this._module.id, + options.id, + contractName + ); + options.libraries ??= {}; options.value ??= BigInt(0); /* validation start */ + this._assertValidId(options.id, this.contract); + this._assertValidContractName(contractName, this.contract); this._assertUniqueContractId(futureId); this._assertValidLibraries(options.libraries, this.contract); this._assertValidValue(options.value, this.contract); @@ -208,23 +275,28 @@ class IgnitionModuleBuilderImplementation< return future; } - public contractFromArtifact( + private _contractFromArtifact( contractName: string, artifact: Artifact, args: ArgumentType[] = [], - options: ContractFromArtifactOptions = {} - ): ArtifactContractDeploymentFuture { - const id = options.id ?? contractName; - const futureId = `${this._module.id}:${id}`; + options: ContractOptions = {} + ): ContractDeploymentFuture { + const futureId = toDeploymentFutureId( + this._module.id, + options.id, + contractName + ); options.libraries ??= {}; options.value ??= BigInt(0); /* validation start */ + this._assertValidId(options.id, this.contract); + this._assertValidContractName(contractName, this.contract); this._assertUniqueArtifactContractId(futureId); - this._assertValidLibraries(options.libraries, this.contractFromArtifact); - this._assertValidValue(options.value, this.contractFromArtifact); - this._assertValidFrom(options.from, this.contractFromArtifact); - this._assertValidArtifact(artifact, this.contractFromArtifact); + this._assertValidLibraries(options.libraries, this.contract); + this._assertValidValue(options.value, this.contract); + this._assertValidFrom(options.from, this.contract); + this._assertValidArtifact(artifact, this.contract); /* validation end */ const future = new ArtifactContractDeploymentFutureImplementation( @@ -258,14 +330,41 @@ class IgnitionModuleBuilderImplementation< } public library( + libraryName: LibraryNameT, + options?: LibraryOptions + ): NamedArtifactLibraryDeploymentFuture; + public library( + libraryName: string, + artifact: Artifact, + options?: LibraryOptions + ): LibraryDeploymentFuture; + public library( + libraryName: LibraryNameT, + artifactOrOptions?: Artifact | LibraryOptions, + options?: LibraryOptions + ) { + if (isArtifactType(artifactOrOptions)) { + return this._libraryFromArtifact(libraryName, artifactOrOptions, options); + } + + return this._namedArtifactLibrary(libraryName, artifactOrOptions); + } + + private _namedArtifactLibrary( libraryName: LibraryNameT, options: LibraryOptions = {} - ): NamedLibraryDeploymentFuture { - const id = options.id ?? libraryName; - const futureId = `${this._module.id}:${id}`; + ): NamedArtifactLibraryDeploymentFuture { + const futureId = toDeploymentFutureId( + this._module.id, + options.id, + libraryName + ); + options.libraries ??= {}; /* validation start */ + this._assertValidId(options.id, this.library); + this._assertValidContractName(libraryName, this.library); this._assertUniqueLibraryId(futureId); this._assertValidLibraries(options.libraries, this.library); this._assertValidFrom(options.from, this.library); @@ -292,20 +391,25 @@ class IgnitionModuleBuilderImplementation< return future; } - public libraryFromArtifact( + private _libraryFromArtifact( libraryName: string, artifact: Artifact, - options: LibraryFromArtifactOptions = {} - ): ArtifactLibraryDeploymentFuture { - const id = options.id ?? libraryName; - const futureId = `${this._module.id}:${id}`; + options: LibraryOptions = {} + ): LibraryDeploymentFuture { + const futureId = toDeploymentFutureId( + this._module.id, + options.id, + libraryName + ); options.libraries ??= {}; /* validation start */ + this._assertValidId(options.id, this.library); + this._assertValidContractName(libraryName, this.library); this._assertUniqueArtifactLibraryId(futureId); - this._assertValidLibraries(options.libraries, this.libraryFromArtifact); - this._assertValidFrom(options.from, this.libraryFromArtifact); - this._assertValidArtifact(artifact, this.libraryFromArtifact); + this._assertValidLibraries(options.libraries, this.library); + this._assertValidFrom(options.from, this.library); + this._assertValidArtifact(artifact, this.library); /* validation end */ const future = new ArtifactLibraryDeploymentFutureImplementation( @@ -331,20 +435,27 @@ class IgnitionModuleBuilderImplementation< } public call( - contractFuture: ContractFuture, + contractFuture: CallableContractFuture, functionName: FunctionNameT, args: ArgumentType[] = [], options: CallOptions = {} - ): NamedContractCallFuture { - const id = options.id ?? functionName; - const futureId = `${this._module.id}:${contractFuture.contractName}#${id}`; + ): ContractCallFuture { + const futureId = toCallFutureId( + this._module.id, + options.id, + contractFuture.contractName, + functionName + ); + options.value ??= BigInt(0); /* validation start */ + this._assertValidId(options.id, this.call); + this._assertValidFunctionName(functionName, this.call); this._assertUniqueCallId(futureId); this._assertValidValue(options.value, this.call); this._assertValidFrom(options.from, this.call); - this._assertValidContract(contractFuture, this.call); + this._assertValidCallableContract(contractFuture, this.call); /* validation end */ const future = new NamedContractCallFutureImplementation( @@ -373,18 +484,26 @@ class IgnitionModuleBuilderImplementation< } public staticCall( - contractFuture: ContractFuture, + contractFuture: CallableContractFuture, functionName: FunctionNameT, args: ArgumentType[] = [], + nameOrIndex: string | number = 0, options: StaticCallOptions = {} - ): NamedStaticCallFuture { - const id = options.id ?? functionName; - const futureId = `${this._module.id}:${contractFuture.contractName}#${id}`; + ): StaticCallFuture { + const futureId = toCallFutureId( + this._module.id, + options.id, + contractFuture.contractName, + functionName + ); /* validation start */ + this._assertValidId(options.id, this.staticCall); + this._assertValidFunctionName(functionName, this.staticCall); + this._assertValidNameOrIndex(nameOrIndex, this.staticCall); this._assertUniqueStaticCallId(futureId); this._assertValidFrom(options.from, this.staticCall); - this._assertValidContract(contractFuture, this.staticCall); + this._assertValidCallableContract(contractFuture, this.staticCall); /* validation end */ const future = new NamedStaticCallFutureImplementation( @@ -393,6 +512,7 @@ class IgnitionModuleBuilderImplementation< functionName, contractFuture, args, + nameOrIndex, options.from ); @@ -412,17 +532,64 @@ class IgnitionModuleBuilderImplementation< } public contractAt( + contractName: ContractNameT, + address: + | string + | AddressResolvableFuture + | ModuleParameterRuntimeValue, + options?: ContractAtOptions + ): NamedArtifactContractAtFuture; + public contractAt( + contractName: string, + address: + | string + | AddressResolvableFuture + | ModuleParameterRuntimeValue, + artifact: Artifact, + options?: ContractAtOptions + ): ContractAtFuture; + public contractAt( + contractName: ContractNameT, + address: + | string + | AddressResolvableFuture + | ModuleParameterRuntimeValue, + artifactOrOptions?: Artifact | ContractAtOptions, + options?: ContractAtOptions + ) { + if (isArtifactType(artifactOrOptions)) { + return this._contractAtFromArtifact( + contractName, + address, + artifactOrOptions, + options + ); + } + + return this._namedArtifactContractAt( + contractName, + address, + artifactOrOptions + ); + } + + private _namedArtifactContractAt( contractName: ContractNameT, address: | string | AddressResolvableFuture | ModuleParameterRuntimeValue, options: ContractAtOptions = {} - ): NamedContractAtFuture { - const id = options.id ?? contractName; - const futureId = `${this._module.id}:${id}`; + ): NamedArtifactContractAtFuture { + const futureId = toDeploymentFutureId( + this._module.id, + options.id, + contractName + ); /* validation start */ + this._assertValidId(options.id, this.contractAt); + this._assertValidContractName(contractName, this.contractAt); this._assertUniqueContractAtId(futureId); this._assertValidAddress(address, this.contractAt); /* validation end */ @@ -447,7 +614,7 @@ class IgnitionModuleBuilderImplementation< return future; } - public contractAtFromArtifact( + private _contractAtFromArtifact( contractName: string, address: | string @@ -455,14 +622,19 @@ class IgnitionModuleBuilderImplementation< | ModuleParameterRuntimeValue, artifact: Artifact, options: ContractAtOptions = {} - ): ArtifactContractAtFuture { - const id = options.id ?? contractName; - const futureId = `${this._module.id}:${id}`; + ): ContractAtFuture { + const futureId = toDeploymentFutureId( + this._module.id, + options.id, + contractName + ); /* validation start */ + this._assertValidId(options.id, this.contractAt); + this._assertValidContractName(contractName, this.contractAt); this._assertUniqueContractAtFromArtifactId(futureId); - this._assertValidAddress(address, this.contractAtFromArtifact); - this._assertValidArtifact(artifact, this.contractAtFromArtifact); + this._assertValidAddress(address, this.contractAt); + this._assertValidArtifact(artifact, this.contractAt); /* validation end */ const future = new ArtifactContractAtFutureImplementation( @@ -488,29 +660,47 @@ class IgnitionModuleBuilderImplementation< public readEventArgument( futureToReadFrom: - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedContractCallFuture, + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | SendDataFuture + | ContractCallFuture, eventName: string, - argumentName: string, + nameOrIndex: string | number, options: ReadEventArgumentOptions = {} ): ReadEventArgumentFuture { const eventIndex = options.eventIndex ?? 0; + if ( + futureToReadFrom.type === FutureType.SEND_DATA && + options.emitter === undefined + ) { + throw new IgnitionValidationError( + "`options.emitter` must be provided when reading an event from a SendDataFuture" + ); + } + const contractToReadFrom = "contract" in futureToReadFrom ? futureToReadFrom.contract - : futureToReadFrom; + : (futureToReadFrom as + | ContractDeploymentFuture + | NamedArtifactContractDeploymentFuture); const emitter = options.emitter ?? contractToReadFrom; - const id = - options.id ?? - `${emitter.contractName}#${eventName}#${argumentName}#${eventIndex}`; - - const futureId = `${this._module.id}:${id}`; + const futureId = toReadEventArgumentFutureId( + this._module.id, + options.id, + emitter.contractName, + eventName, + nameOrIndex, + eventIndex + ); /* validation start */ + this._assertValidId(options.id, this.readEventArgument); + this._assertValidEventName(eventName, this.readEventArgument); + this._assertValidNameOrIndex(nameOrIndex, this.readEventArgument); this._assertUniqueReadEventArgumentId(futureId); /* validation end */ @@ -519,7 +709,7 @@ class IgnitionModuleBuilderImplementation< this._module, futureToReadFrom, eventName, - argumentName, + nameOrIndex, emitter, eventIndex ); @@ -541,10 +731,11 @@ class IgnitionModuleBuilderImplementation< data?: string, options: SendDataOptions = {} ): SendDataFuture { - const futureId = `${this._module.id}:${options.id ?? id}`; + const futureId = toSendDataFutureId(this._module.id, id); const val = value ?? BigInt(0); /* validation start */ + this._assertValidId(id, this.send); this._assertUniqueSendId(futureId); this._assertValidAddress(to, this.send); this._assertValidValue(val, this.send); @@ -611,6 +802,63 @@ class IgnitionModuleBuilderImplementation< throw validationError; } + private _assertValidId(id: string | undefined, func: (...[]: any[]) => any) { + if (id === undefined) { + return; + } + + if (isValidIgnitionIdentifier(id)) { + return; + } + + this._throwErrorWithStackTrace( + `The id "${id}" contains banned characters, ids can only contain alphanumerics or underscores`, + func + ); + } + + private _assertValidContractName( + contractName: string, + func: (...[]: any[]) => any + ) { + if (isValidSolidityIdentifier(contractName)) { + return; + } + + this._throwErrorWithStackTrace( + `The contract "${contractName}" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs`, + func + ); + } + + private _assertValidEventName( + eventName: string, + func: (...[]: any[]) => any + ) { + if (isValidFunctionOrEventName(eventName)) { + return; + } + + this._throwErrorWithStackTrace( + `The event "${eventName}" contains banned characters, event names can only contain alphanumerics, underscores or dollar signs`, + func + ); + } + + private _assertValidFunctionName( + functionName: string, + func: (...[]: any[]) => any + ) { + if (isValidFunctionOrEventName(functionName)) { + return; + } + + this._throwErrorWithStackTrace( + `The function name "${functionName}" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs`, + func + ); + } + private _assertUniqueFutureId( futureId: string, message: string, @@ -634,8 +882,8 @@ class IgnitionModuleBuilderImplementation< private _assertUniqueArtifactContractId(futureId: string) { return this._assertUniqueFutureId( futureId, - `Duplicated id ${futureId} found in module ${this._module.id}, ensure the id passed is unique \`m.contractFromArtifact("MyContract", artifact, [], { id: "MyId"})\``, - this.contractFromArtifact + `Duplicated id ${futureId} found in module ${this._module.id}, ensure the id passed is unique \`m.contract("MyContract", artifact, [], { id: "MyId"})\``, + this.contract ); } @@ -650,8 +898,8 @@ class IgnitionModuleBuilderImplementation< private _assertUniqueArtifactLibraryId(futureId: string) { return this._assertUniqueFutureId( futureId, - `Duplicated id ${futureId} found in module ${this._module.id}, ensure the id passed is unique \`m.libraryFromArtifact("MyLibrary", artifact, { id: "MyId"})\``, - this.libraryFromArtifact + `Duplicated id ${futureId} found in module ${this._module.id}, ensure the id passed is unique \`m.library("MyLibrary", artifact, { id: "MyId"})\``, + this.library ); } @@ -682,8 +930,8 @@ class IgnitionModuleBuilderImplementation< private _assertUniqueContractAtFromArtifactId(futureId: string) { return this._assertUniqueFutureId( futureId, - `Duplicated id ${futureId} found in module ${this._module.id}, ensure the id passed is unique \`m.contractAtFromArtifact("MyContract", "0x123...", { id: "MyId"})\``, - this.contractAtFromArtifact + `Duplicated id ${futureId} found in module ${this._module.id}, ensure the id passed is unique \`m.contractAt("MyContract", "0x123...", { id: "MyId"})\``, + this.contractAt ); } @@ -749,18 +997,44 @@ class IgnitionModuleBuilderImplementation< artifact: Artifact, func: (...[]: any[]) => any ) { - if (!isArtifactType(artifact)) { - this._throwErrorWithStackTrace(`Invalid artifact given`, func); + if (isArtifactType(artifact)) { + return; } + + this._throwErrorWithStackTrace(`Invalid artifact given`, func); } - private _assertValidContract( - contract: ContractFuture, + private _assertValidCallableContract( + contract: CallableContractFuture, func: (...[]: any[]) => any ) { - if (!isContractFuture(contract)) { - this._throwErrorWithStackTrace(`Invalid contract given`, func); + if (isCallableContractFuture(contract)) { + return; } + + this._throwErrorWithStackTrace(`Invalid contract given`, func); + } + + private _assertValidNameOrIndex( + nameOrIndex: string | number, + func: (...[]: any[]) => any + ) { + if (typeof nameOrIndex !== "string" && typeof nameOrIndex !== "number") { + this._throwErrorWithStackTrace(`Invalid nameOrIndex given`, func); + } + + if (typeof nameOrIndex === "number") { + return; + } + + if (isValidSolidityIdentifier(nameOrIndex)) { + return; + } + + this._throwErrorWithStackTrace( + `The argument "${nameOrIndex}" contains banned characters, argument names can only contain alphanumerics, underscores or dollar signs`, + func + ); } private _assertValidAddress( diff --git a/packages/core/src/new-api/internal/module.ts b/packages/core/src/internal/module.ts similarity index 80% rename from packages/core/src/new-api/internal/module.ts rename to packages/core/src/internal/module.ts index cc2a89b37..966a6e24d 100644 --- a/packages/core/src/new-api/internal/module.ts +++ b/packages/core/src/internal/module.ts @@ -3,9 +3,9 @@ import { AccountRuntimeValue, AddressResolvableFuture, ArgumentType, - ArtifactContractAtFuture, - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, + ContractAtFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, ContractFuture, Future, FutureType, @@ -13,11 +13,11 @@ import { IgnitionModuleResult, ModuleParameterRuntimeValue, ModuleParameterType, - NamedContractAtFuture, - NamedContractCallFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, - NamedStaticCallFuture, + NamedArtifactContractAtFuture, + ContractCallFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, + StaticCallFuture, ReadEventArgumentFuture, RuntimeValueType, SendDataFuture, @@ -53,8 +53,8 @@ abstract class BaseFutureImplementation { export class NamedContractDeploymentFutureImplementation< ContractNameT extends string > - extends BaseFutureImplementation - implements NamedContractDeploymentFuture + extends BaseFutureImplementation + implements NamedArtifactContractDeploymentFuture { constructor( public readonly id: string, @@ -65,15 +65,15 @@ export class NamedContractDeploymentFutureImplementation< public readonly value: bigint | ModuleParameterRuntimeValue, public readonly from: string | AccountRuntimeValue | undefined ) { - super(id, FutureType.NAMED_CONTRACT_DEPLOYMENT, module); + super(id, FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, module); } } export class ArtifactContractDeploymentFutureImplementation< ContractNameT extends string > - extends BaseFutureImplementation - implements ArtifactContractDeploymentFuture + extends BaseFutureImplementation + implements ContractDeploymentFuture { constructor( public readonly id: string, @@ -85,15 +85,15 @@ export class ArtifactContractDeploymentFutureImplementation< public readonly value: bigint | ModuleParameterRuntimeValue, public readonly from: string | AccountRuntimeValue | undefined ) { - super(id, FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, module); + super(id, FutureType.CONTRACT_DEPLOYMENT, module); } } export class NamedLibraryDeploymentFutureImplementation< LibraryNameT extends string > - extends BaseFutureImplementation - implements NamedLibraryDeploymentFuture + extends BaseFutureImplementation + implements NamedArtifactLibraryDeploymentFuture { constructor( public readonly id: string, @@ -102,15 +102,15 @@ export class NamedLibraryDeploymentFutureImplementation< public readonly libraries: Record>, public readonly from: string | AccountRuntimeValue | undefined ) { - super(id, FutureType.NAMED_LIBRARY_DEPLOYMENT, module); + super(id, FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, module); } } export class ArtifactLibraryDeploymentFutureImplementation< LibraryNameT extends string > - extends BaseFutureImplementation - implements ArtifactLibraryDeploymentFuture + extends BaseFutureImplementation + implements LibraryDeploymentFuture { constructor( public readonly id: string, @@ -120,7 +120,7 @@ export class ArtifactLibraryDeploymentFutureImplementation< public readonly libraries: Record>, public readonly from: string | AccountRuntimeValue | undefined ) { - super(id, FutureType.ARTIFACT_LIBRARY_DEPLOYMENT, module); + super(id, FutureType.LIBRARY_DEPLOYMENT, module); } } @@ -128,8 +128,8 @@ export class NamedContractCallFutureImplementation< ContractNameT extends string, FunctionNameT extends string > - extends BaseFutureImplementation - implements NamedContractCallFuture + extends BaseFutureImplementation + implements ContractCallFuture { constructor( public readonly id: string, @@ -140,7 +140,7 @@ export class NamedContractCallFutureImplementation< public readonly value: bigint | ModuleParameterRuntimeValue, public readonly from: string | AccountRuntimeValue | undefined ) { - super(id, FutureType.NAMED_CONTRACT_CALL, module); + super(id, FutureType.CONTRACT_CALL, module); } } @@ -148,8 +148,8 @@ export class NamedStaticCallFutureImplementation< ContractNameT extends string, FunctionNameT extends string > - extends BaseFutureImplementation - implements NamedStaticCallFuture + extends BaseFutureImplementation + implements StaticCallFuture { constructor( public readonly id: string, @@ -157,15 +157,16 @@ export class NamedStaticCallFutureImplementation< public readonly functionName: FunctionNameT, public readonly contract: ContractFuture, public readonly args: ArgumentType[], + public readonly nameOrIndex: string | number, public readonly from: string | AccountRuntimeValue | undefined ) { - super(id, FutureType.NAMED_STATIC_CALL, module); + super(id, FutureType.STATIC_CALL, module); } } export class NamedContractAtFutureImplementation - extends BaseFutureImplementation - implements NamedContractAtFuture + extends BaseFutureImplementation + implements NamedArtifactContractAtFuture { constructor( public readonly id: string, @@ -176,13 +177,13 @@ export class NamedContractAtFutureImplementation | AddressResolvableFuture | ModuleParameterRuntimeValue ) { - super(id, FutureType.NAMED_CONTRACT_AT, module); + super(id, FutureType.NAMED_ARTIFACT_CONTRACT_AT, module); } } export class ArtifactContractAtFutureImplementation - extends BaseFutureImplementation - implements ArtifactContractAtFuture + extends BaseFutureImplementation + implements ContractAtFuture { constructor( public readonly id: string, @@ -194,7 +195,7 @@ export class ArtifactContractAtFutureImplementation | ModuleParameterRuntimeValue, public readonly artifact: Artifact ) { - super(id, FutureType.ARTIFACT_CONTRACT_AT, module); + super(id, FutureType.CONTRACT_AT, module); } } @@ -205,9 +206,13 @@ export class ReadEventArgumentFutureImplementation constructor( public readonly id: string, public readonly module: IgnitionModuleImplementation, - public readonly futureToReadFrom: Future, + public readonly futureToReadFrom: + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | SendDataFuture + | ContractCallFuture, public readonly eventName: string, - public readonly argumentName: string, + public readonly nameOrIndex: string | number, public readonly emitter: ContractFuture, public readonly eventIndex: number ) { diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactContractAt.ts b/packages/core/src/internal/reconciliation/futures/reconcileArtifactContractAt.ts similarity index 81% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactContractAt.ts rename to packages/core/src/internal/reconciliation/futures/reconcileArtifactContractAt.ts index 7ba2deb2d..82182cc8d 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactContractAt.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileArtifactContractAt.ts @@ -1,12 +1,12 @@ -import { ArtifactContractAtFuture } from "../../../types/module"; -import { ContractAtExecutionState } from "../../new-execution/types/execution-state"; +import { ContractAtFuture } from "../../../types/module"; +import { ContractAtExecutionState } from "../../execution/types/execution-state"; import { reconcileAddress } from "../helpers/reconcile-address"; import { reconcileArtifacts } from "../helpers/reconcile-artifacts"; import { reconcileContractName } from "../helpers/reconcile-contract-name"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; export async function reconcileArtifactContractAt( - future: ArtifactContractAtFuture, + future: ContractAtFuture, executionState: ContractAtExecutionState, context: ReconciliationContext ): Promise { diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactContractDeployment.ts b/packages/core/src/internal/reconciliation/futures/reconcileArtifactContractDeployment.ts similarity index 87% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactContractDeployment.ts rename to packages/core/src/internal/reconciliation/futures/reconcileArtifactContractDeployment.ts index 9d497b4be..33abd0ac8 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactContractDeployment.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileArtifactContractDeployment.ts @@ -1,5 +1,5 @@ -import { ArtifactContractDeploymentFuture } from "../../../types/module"; -import { DeploymentExecutionState } from "../../new-execution/types/execution-state"; +import { ContractDeploymentFuture } from "../../../types/module"; +import { DeploymentExecutionState } from "../../execution/types/execution-state"; import { reconcileArguments } from "../helpers/reconcile-arguments"; import { reconcileArtifacts } from "../helpers/reconcile-artifacts"; import { reconcileContractName } from "../helpers/reconcile-contract-name"; @@ -9,7 +9,7 @@ import { reconcileValue } from "../helpers/reconcile-value"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; export async function reconcileArtifactContractDeployment( - future: ArtifactContractDeploymentFuture, + future: ContractDeploymentFuture, executionState: DeploymentExecutionState, context: ReconciliationContext ): Promise { diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactLibraryDeployment.ts b/packages/core/src/internal/reconciliation/futures/reconcileArtifactLibraryDeployment.ts similarity index 83% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactLibraryDeployment.ts rename to packages/core/src/internal/reconciliation/futures/reconcileArtifactLibraryDeployment.ts index 7bff954e9..0bcaebf58 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileArtifactLibraryDeployment.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileArtifactLibraryDeployment.ts @@ -1,5 +1,5 @@ -import { ArtifactLibraryDeploymentFuture } from "../../../types/module"; -import { DeploymentExecutionState } from "../../new-execution/types/execution-state"; +import { LibraryDeploymentFuture } from "../../../types/module"; +import { DeploymentExecutionState } from "../../execution/types/execution-state"; import { reconcileArtifacts } from "../helpers/reconcile-artifacts"; import { reconcileContractName } from "../helpers/reconcile-contract-name"; import { reconcileFrom } from "../helpers/reconcile-from"; @@ -7,7 +7,7 @@ import { reconcileLibraries } from "../helpers/reconcile-libraries"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; export async function reconcileArtifactLibraryDeployment( - future: ArtifactLibraryDeploymentFuture, + future: LibraryDeploymentFuture, executionState: DeploymentExecutionState, context: ReconciliationContext ): Promise { diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractAt.ts b/packages/core/src/internal/reconciliation/futures/reconcileNamedContractAt.ts similarity index 80% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractAt.ts rename to packages/core/src/internal/reconciliation/futures/reconcileNamedContractAt.ts index 12873e8a9..fbe46daa0 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractAt.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileNamedContractAt.ts @@ -1,12 +1,12 @@ -import { NamedContractAtFuture } from "../../../types/module"; -import { ContractAtExecutionState } from "../../new-execution/types/execution-state"; +import { NamedArtifactContractAtFuture } from "../../../types/module"; +import { ContractAtExecutionState } from "../../execution/types/execution-state"; import { reconcileAddress } from "../helpers/reconcile-address"; import { reconcileArtifacts } from "../helpers/reconcile-artifacts"; import { reconcileContractName } from "../helpers/reconcile-contract-name"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; export async function reconcileNamedContractAt( - future: NamedContractAtFuture, + future: NamedArtifactContractAtFuture, executionState: ContractAtExecutionState, context: ReconciliationContext ): Promise { diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractCall.ts b/packages/core/src/internal/reconciliation/futures/reconcileNamedContractCall.ts similarity index 85% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractCall.ts rename to packages/core/src/internal/reconciliation/futures/reconcileNamedContractCall.ts index 1d5dc68c4..02f2195c9 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractCall.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileNamedContractCall.ts @@ -1,5 +1,5 @@ -import { NamedContractCallFuture } from "../../../types/module"; -import { CallExecutionState } from "../../new-execution/types/execution-state"; +import { ContractCallFuture } from "../../../types/module"; +import { CallExecutionState } from "../../execution/types/execution-state"; import { reconcileArguments } from "../helpers/reconcile-arguments"; import { reconcileContract } from "../helpers/reconcile-contract"; import { reconcileFrom } from "../helpers/reconcile-from"; @@ -8,7 +8,7 @@ import { reconcileValue } from "../helpers/reconcile-value"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; export function reconcileNamedContractCall( - future: NamedContractCallFuture, + future: ContractCallFuture, executionState: CallExecutionState, context: ReconciliationContext ): ReconciliationFutureResult { diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractDeployment.ts b/packages/core/src/internal/reconciliation/futures/reconcileNamedContractDeployment.ts similarity index 86% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractDeployment.ts rename to packages/core/src/internal/reconciliation/futures/reconcileNamedContractDeployment.ts index 33571febf..5d34bcd12 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedContractDeployment.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileNamedContractDeployment.ts @@ -1,5 +1,5 @@ -import { NamedContractDeploymentFuture } from "../../../types/module"; -import { DeploymentExecutionState } from "../../new-execution/types/execution-state"; +import { NamedArtifactContractDeploymentFuture } from "../../../types/module"; +import { DeploymentExecutionState } from "../../execution/types/execution-state"; import { reconcileArguments } from "../helpers/reconcile-arguments"; import { reconcileArtifacts } from "../helpers/reconcile-artifacts"; import { reconcileContractName } from "../helpers/reconcile-contract-name"; @@ -9,7 +9,7 @@ import { reconcileValue } from "../helpers/reconcile-value"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; export async function reconcileNamedContractDeployment( - future: NamedContractDeploymentFuture, + future: NamedArtifactContractDeploymentFuture, executionState: DeploymentExecutionState, context: ReconciliationContext ): Promise { diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedLibraryDeployment.ts b/packages/core/src/internal/reconciliation/futures/reconcileNamedLibraryDeployment.ts similarity index 82% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedLibraryDeployment.ts rename to packages/core/src/internal/reconciliation/futures/reconcileNamedLibraryDeployment.ts index f63445180..41400165a 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedLibraryDeployment.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileNamedLibraryDeployment.ts @@ -1,5 +1,5 @@ -import { NamedLibraryDeploymentFuture } from "../../../types/module"; -import { DeploymentExecutionState } from "../../new-execution/types/execution-state"; +import { NamedArtifactLibraryDeploymentFuture } from "../../../types/module"; +import { DeploymentExecutionState } from "../../execution/types/execution-state"; import { reconcileArtifacts } from "../helpers/reconcile-artifacts"; import { reconcileContractName } from "../helpers/reconcile-contract-name"; import { reconcileFrom } from "../helpers/reconcile-from"; @@ -7,7 +7,7 @@ import { reconcileLibraries } from "../helpers/reconcile-libraries"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; export async function reconcileNamedLibraryDeployment( - future: NamedLibraryDeploymentFuture, + future: NamedArtifactLibraryDeploymentFuture, executionState: DeploymentExecutionState, context: ReconciliationContext ): Promise { diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedStaticCall.ts b/packages/core/src/internal/reconciliation/futures/reconcileNamedStaticCall.ts similarity index 71% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedStaticCall.ts rename to packages/core/src/internal/reconciliation/futures/reconcileNamedStaticCall.ts index 8f15b405f..a816fd53f 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileNamedStaticCall.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileNamedStaticCall.ts @@ -1,5 +1,6 @@ -import { NamedStaticCallFuture } from "../../../types/module"; -import { StaticCallExecutionState } from "../../new-execution/types/execution-state"; +import { StaticCallFuture } from "../../../types/module"; +import { StaticCallExecutionState } from "../../execution/types/execution-state"; +import { compare } from "../helpers/compare"; import { reconcileArguments } from "../helpers/reconcile-arguments"; import { reconcileContract } from "../helpers/reconcile-contract"; import { reconcileFrom } from "../helpers/reconcile-from"; @@ -7,7 +8,7 @@ import { reconcileFunctionName } from "../helpers/reconcile-function-name"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; export function reconcileNamedStaticCall( - future: NamedStaticCallFuture, + future: StaticCallFuture, executionState: StaticCallExecutionState, context: ReconciliationContext ): ReconciliationFutureResult { @@ -31,5 +32,15 @@ export function reconcileNamedStaticCall( return result; } + result = compare( + future, + "Argument name or index", + executionState.nameOrIndex, + future.nameOrIndex + ); + if (result !== undefined) { + return result; + } + return { success: true }; } diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileReadEventArgument.ts b/packages/core/src/internal/reconciliation/futures/reconcileReadEventArgument.ts similarity index 80% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileReadEventArgument.ts rename to packages/core/src/internal/reconciliation/futures/reconcileReadEventArgument.ts index 7788651ab..ff5f6e6e2 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileReadEventArgument.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileReadEventArgument.ts @@ -1,6 +1,6 @@ import { ReadEventArgumentFuture } from "../../../types/module"; -import { resolveAddressForContractFuture } from "../../new-execution/future-processor/helpers/future-resolvers"; -import { ReadEventArgumentExecutionState } from "../../new-execution/types/execution-state"; +import { resolveAddressForContractFuture } from "../../execution/future-processor/helpers/future-resolvers"; +import { ReadEventArgumentExecutionState } from "../../execution/types/execution-state"; import { compare } from "../helpers/compare"; import { ReconciliationContext, ReconciliationFutureResult } from "../types"; @@ -47,9 +47,9 @@ export function reconcileReadEventArgument( result = compare( future, - "Argument name", - executionState.argumentName, - future.argumentName + "Argument name or index", + executionState.nameOrIndex, + future.nameOrIndex ); if (result !== undefined) { return result; diff --git a/packages/core/src/new-api/internal/reconciliation/futures/reconcileSendData.ts b/packages/core/src/internal/reconciliation/futures/reconcileSendData.ts similarity index 86% rename from packages/core/src/new-api/internal/reconciliation/futures/reconcileSendData.ts rename to packages/core/src/internal/reconciliation/futures/reconcileSendData.ts index 7ec085928..bb74949b9 100644 --- a/packages/core/src/new-api/internal/reconciliation/futures/reconcileSendData.ts +++ b/packages/core/src/internal/reconciliation/futures/reconcileSendData.ts @@ -1,6 +1,6 @@ import { SendDataFuture } from "../../../types/module"; -import { resolveAddressLike } from "../../new-execution/future-processor/helpers/future-resolvers"; -import { SendDataExecutionState } from "../../new-execution/types/execution-state"; +import { resolveAddressLike } from "../../execution/future-processor/helpers/future-resolvers"; +import { SendDataExecutionState } from "../../execution/types/execution-state"; import { compare } from "../helpers/compare"; import { reconcileData } from "../helpers/reconcile-data"; import { reconcileFrom } from "../helpers/reconcile-from"; diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/compare.ts b/packages/core/src/internal/reconciliation/helpers/compare.ts similarity index 100% rename from packages/core/src/new-api/internal/reconciliation/helpers/compare.ts rename to packages/core/src/internal/reconciliation/helpers/compare.ts diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-address.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-address.ts similarity index 64% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-address.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-address.ts index a839d5de0..23e16d052 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-address.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-address.ts @@ -1,9 +1,9 @@ import { - ArtifactContractAtFuture, - NamedContractAtFuture, + ContractAtFuture, + NamedArtifactContractAtFuture, } from "../../../types/module"; -import { resolveAddressLike } from "../../new-execution/future-processor/helpers/future-resolvers"; -import { ContractAtExecutionState } from "../../new-execution/types/execution-state"; +import { resolveAddressLike } from "../../execution/future-processor/helpers/future-resolvers"; +import { ContractAtExecutionState } from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -12,7 +12,7 @@ import { import { compare } from "./compare"; export function reconcileAddress( - future: NamedContractAtFuture | ArtifactContractAtFuture, + future: NamedArtifactContractAtFuture | ContractAtFuture, exState: ContractAtExecutionState, context: ReconciliationContext ): ReconciliationFutureResultFailure | undefined { diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-arguments.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-arguments.ts similarity index 76% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-arguments.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-arguments.ts index 7945c1618..071c09529 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-arguments.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-arguments.ts @@ -1,17 +1,17 @@ import { isDeploymentFuture } from "../../../type-guards"; import { - ArtifactContractDeploymentFuture, - NamedContractCallFuture, - NamedContractDeploymentFuture, - NamedStaticCallFuture, + ContractDeploymentFuture, + ContractCallFuture, + NamedArtifactContractDeploymentFuture, + StaticCallFuture, } from "../../../types/module"; -import { resolveArgs } from "../../new-execution/future-processor/helpers/future-resolvers"; +import { resolveArgs } from "../../execution/future-processor/helpers/future-resolvers"; import { CallExecutionState, DeploymentExecutionState, ExecutionSateType, StaticCallExecutionState, -} from "../../new-execution/types/execution-state"; +} from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -20,10 +20,10 @@ import { fail } from "../utils"; export function reconcileArguments( future: - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedStaticCallFuture - | NamedContractCallFuture, + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | StaticCallFuture + | ContractCallFuture, exState: | DeploymentExecutionState | CallExecutionState diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-artifacts.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-artifacts.ts similarity index 66% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-artifacts.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-artifacts.ts index ce9b782f1..6318280c8 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-artifacts.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-artifacts.ts @@ -1,15 +1,15 @@ import { - ArtifactContractAtFuture, - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, - NamedContractAtFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, + ContractAtFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, + NamedArtifactContractAtFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, } from "../../../types/module"; import { ContractAtExecutionState, DeploymentExecutionState, -} from "../../new-execution/types/execution-state"; +} from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -18,12 +18,12 @@ import { fail, getBytecodeWithoutMetadata } from "../utils"; export async function reconcileArtifacts( future: - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedLibraryDeploymentFuture - | ArtifactLibraryDeploymentFuture - | NamedContractAtFuture - | ArtifactContractAtFuture, + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | NamedArtifactLibraryDeploymentFuture + | LibraryDeploymentFuture + | NamedArtifactContractAtFuture + | ContractAtFuture, exState: DeploymentExecutionState | ContractAtExecutionState, context: ReconciliationContext ): Promise { @@ -33,7 +33,7 @@ export async function reconcileArtifacts( : await context.artifactResolver.loadArtifact(future.contractName); const storedArtifact = await context.deploymentLoader.loadArtifact( - exState.artifactFutureId + exState.artifactId ); const moduleArtifactBytecode = getBytecodeWithoutMetadata( diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-contract-name.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-contract-name.ts similarity index 53% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-contract-name.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-contract-name.ts index 83d7fe3a2..c3e1d04ec 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-contract-name.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-contract-name.ts @@ -1,15 +1,15 @@ import { - ArtifactContractAtFuture, - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, - NamedContractAtFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, + ContractAtFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, + NamedArtifactContractAtFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, } from "../../../types/module"; import { ContractAtExecutionState, DeploymentExecutionState, -} from "../../new-execution/types/execution-state"; +} from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -19,12 +19,12 @@ import { compare } from "./compare"; export function reconcileContractName( future: - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedLibraryDeploymentFuture - | ArtifactLibraryDeploymentFuture - | NamedContractAtFuture - | ArtifactContractAtFuture, + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | NamedArtifactLibraryDeploymentFuture + | LibraryDeploymentFuture + | NamedArtifactContractAtFuture + | ContractAtFuture, exState: DeploymentExecutionState | ContractAtExecutionState, _context: ReconciliationContext ): ReconciliationFutureResultFailure | undefined { diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-contract.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-contract.ts similarity index 65% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-contract.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-contract.ts index 202bb229c..c1292106b 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-contract.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-contract.ts @@ -1,12 +1,9 @@ -import { - NamedContractCallFuture, - NamedStaticCallFuture, -} from "../../../types/module"; -import { resolveAddressLike } from "../../new-execution/future-processor/helpers/future-resolvers"; +import { ContractCallFuture, StaticCallFuture } from "../../../types/module"; +import { resolveAddressLike } from "../../execution/future-processor/helpers/future-resolvers"; import { CallExecutionState, StaticCallExecutionState, -} from "../../new-execution/types/execution-state"; +} from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -15,9 +12,7 @@ import { import { compare } from "./compare"; export function reconcileContract( - future: - | NamedContractCallFuture - | NamedStaticCallFuture, + future: ContractCallFuture | StaticCallFuture, exState: CallExecutionState | StaticCallExecutionState, context: ReconciliationContext ): ReconciliationFutureResultFailure | undefined { diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-data.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-data.ts similarity index 83% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-data.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-data.ts index 4df63232e..95ac4c946 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-data.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-data.ts @@ -1,5 +1,5 @@ import { SendDataFuture } from "../../../types/module"; -import { SendDataExecutionState } from "../../new-execution/types/execution-state"; +import { SendDataExecutionState } from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-from.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-from.ts similarity index 56% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-from.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-from.ts index 03cd9fb8b..287be1562 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-from.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-from.ts @@ -1,19 +1,19 @@ import { - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, - NamedContractCallFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, - NamedStaticCallFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, + ContractCallFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, + StaticCallFuture, SendDataFuture, } from "../../../types/module"; -import { resolveFutureFrom } from "../../new-execution/future-processor/helpers/future-resolvers"; +import { resolveFutureFrom } from "../../execution/future-processor/helpers/future-resolvers"; import { CallExecutionState, DeploymentExecutionState, SendDataExecutionState, StaticCallExecutionState, -} from "../../new-execution/types/execution-state"; +} from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -23,12 +23,12 @@ import { compare } from "./compare"; export function reconcileFrom( future: - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedLibraryDeploymentFuture - | ArtifactLibraryDeploymentFuture - | NamedContractCallFuture - | NamedStaticCallFuture + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | NamedArtifactLibraryDeploymentFuture + | LibraryDeploymentFuture + | ContractCallFuture + | StaticCallFuture | SendDataFuture, exState: | DeploymentExecutionState diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-function-name.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-function-name.ts similarity index 66% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-function-name.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-function-name.ts index a6ac0fb6c..023005d9d 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-function-name.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-function-name.ts @@ -1,11 +1,8 @@ -import { - NamedContractCallFuture, - NamedStaticCallFuture, -} from "../../../types/module"; +import { ContractCallFuture, StaticCallFuture } from "../../../types/module"; import { CallExecutionState, StaticCallExecutionState, -} from "../../new-execution/types/execution-state"; +} from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -14,9 +11,7 @@ import { import { compare } from "./compare"; export function reconcileFunctionName( - future: - | NamedContractCallFuture - | NamedStaticCallFuture, + future: ContractCallFuture | StaticCallFuture, exState: CallExecutionState | StaticCallExecutionState, _context: ReconciliationContext ): ReconciliationFutureResultFailure | undefined { diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-libraries.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-libraries.ts similarity index 66% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-libraries.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-libraries.ts index d2585fc76..0e26ba6a1 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-libraries.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-libraries.ts @@ -1,11 +1,11 @@ import { - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, } from "../../../types/module"; -import { resolveLibraries } from "../../new-execution/future-processor/helpers/future-resolvers"; -import { DeploymentExecutionState } from "../../new-execution/types/execution-state"; +import { resolveLibraries } from "../../execution/future-processor/helpers/future-resolvers"; +import { DeploymentExecutionState } from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -14,10 +14,10 @@ import { fail } from "../utils"; export function reconcileLibraries( future: - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedLibraryDeploymentFuture - | ArtifactLibraryDeploymentFuture, + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | NamedArtifactLibraryDeploymentFuture + | LibraryDeploymentFuture, exState: DeploymentExecutionState, context: ReconciliationContext ): ReconciliationFutureResultFailure | undefined { diff --git a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-value.ts b/packages/core/src/internal/reconciliation/helpers/reconcile-value.ts similarity index 64% rename from packages/core/src/new-api/internal/reconciliation/helpers/reconcile-value.ts rename to packages/core/src/internal/reconciliation/helpers/reconcile-value.ts index bea9ce122..67d5e58e3 100644 --- a/packages/core/src/new-api/internal/reconciliation/helpers/reconcile-value.ts +++ b/packages/core/src/internal/reconciliation/helpers/reconcile-value.ts @@ -1,15 +1,15 @@ import { - ArtifactContractDeploymentFuture, - NamedContractCallFuture, - NamedContractDeploymentFuture, + ContractDeploymentFuture, + ContractCallFuture, + NamedArtifactContractDeploymentFuture, SendDataFuture, } from "../../../types/module"; -import { resolveValue } from "../../new-execution/future-processor/helpers/future-resolvers"; +import { resolveValue } from "../../execution/future-processor/helpers/future-resolvers"; import { CallExecutionState, DeploymentExecutionState, SendDataExecutionState, -} from "../../new-execution/types/execution-state"; +} from "../../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResultFailure, @@ -19,9 +19,9 @@ import { compare } from "./compare"; export function reconcileValue( future: - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedContractCallFuture + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | ContractCallFuture | SendDataFuture, exState: | DeploymentExecutionState diff --git a/packages/core/src/new-api/internal/reconciliation/reconcile-current-and-previous-type-match.ts b/packages/core/src/internal/reconciliation/reconcile-current-and-previous-type-match.ts similarity index 89% rename from packages/core/src/new-api/internal/reconciliation/reconcile-current-and-previous-type-match.ts rename to packages/core/src/internal/reconciliation/reconcile-current-and-previous-type-match.ts index 1509ea42e..ab27963ad 100644 --- a/packages/core/src/new-api/internal/reconciliation/reconcile-current-and-previous-type-match.ts +++ b/packages/core/src/internal/reconciliation/reconcile-current-and-previous-type-match.ts @@ -1,5 +1,5 @@ import { Future, FutureType } from "../../types/module"; -import { ExecutionState } from "../new-execution/types/execution-state"; +import { ExecutionState } from "../execution/types/execution-state"; import { ReconciliationContext, ReconciliationFutureResult } from "./types"; import { fail } from "./utils"; diff --git a/packages/core/src/new-api/internal/reconciliation/reconcile-dependency-rules.ts b/packages/core/src/internal/reconciliation/reconcile-dependency-rules.ts similarity index 92% rename from packages/core/src/new-api/internal/reconciliation/reconcile-dependency-rules.ts rename to packages/core/src/internal/reconciliation/reconcile-dependency-rules.ts index 01a8bd89d..5ce8aae77 100644 --- a/packages/core/src/new-api/internal/reconciliation/reconcile-dependency-rules.ts +++ b/packages/core/src/internal/reconciliation/reconcile-dependency-rules.ts @@ -1,11 +1,11 @@ import difference from "lodash/difference"; import { Future } from "../../types/module"; -import { DeploymentState } from "../new-execution/types/deployment-state"; +import { DeploymentState } from "../execution/types/deployment-state"; import { ExecutionState, ExecutionStatus, -} from "../new-execution/types/execution-state"; +} from "../execution/types/execution-state"; import { ReconciliationFutureResult } from "./types"; import { fail } from "./utils"; diff --git a/packages/core/src/new-api/internal/reconciliation/reconcile-future-specific-reconciliations.ts b/packages/core/src/internal/reconciliation/reconcile-future-specific-reconciliations.ts similarity index 87% rename from packages/core/src/new-api/internal/reconciliation/reconcile-future-specific-reconciliations.ts rename to packages/core/src/internal/reconciliation/reconcile-future-specific-reconciliations.ts index 156454e58..1eb90b1aa 100644 --- a/packages/core/src/new-api/internal/reconciliation/reconcile-future-specific-reconciliations.ts +++ b/packages/core/src/internal/reconciliation/reconcile-future-specific-reconciliations.ts @@ -7,7 +7,7 @@ import { ReadEventArgumentExecutionState, SendDataExecutionState, StaticCallExecutionState, -} from "../new-execution/types/execution-state"; +} from "../execution/types/execution-state"; import { reconcileArtifactContractAt } from "./futures/reconcileArtifactContractAt"; import { reconcileArtifactContractDeployment } from "./futures/reconcileArtifactContractDeployment"; @@ -27,49 +27,49 @@ export async function reconcileFutureSpecificReconciliations( context: ReconciliationContext ): Promise { switch (future.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: return reconcileNamedContractDeployment( future, executionState as DeploymentExecutionState, context ); - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: return reconcileArtifactContractDeployment( future, executionState as DeploymentExecutionState, context ); - case FutureType.NAMED_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: return reconcileNamedLibraryDeployment( future, executionState as DeploymentExecutionState, context ); - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: return reconcileArtifactLibraryDeployment( future, executionState as DeploymentExecutionState, context ); - case FutureType.NAMED_CONTRACT_CALL: + case FutureType.CONTRACT_CALL: return reconcileNamedContractCall( future, executionState as CallExecutionState, context ); - case FutureType.NAMED_STATIC_CALL: + case FutureType.STATIC_CALL: return reconcileNamedStaticCall( future, executionState as StaticCallExecutionState, context ); - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: return reconcileNamedContractAt( future, executionState as ContractAtExecutionState, context ); - case FutureType.ARTIFACT_CONTRACT_AT: { + case FutureType.CONTRACT_AT: { return reconcileArtifactContractAt( future, executionState as ContractAtExecutionState, diff --git a/packages/core/src/new-api/internal/reconciliation/reconciler.ts b/packages/core/src/internal/reconciliation/reconciler.ts similarity index 91% rename from packages/core/src/new-api/internal/reconciliation/reconciler.ts rename to packages/core/src/internal/reconciliation/reconciler.ts index f87317967..ad6499ca8 100644 --- a/packages/core/src/new-api/internal/reconciliation/reconciler.ts +++ b/packages/core/src/internal/reconciliation/reconciler.ts @@ -1,13 +1,13 @@ -import { IgnitionError } from "../../../errors"; +import { IgnitionError } from "../../errors"; import { ArtifactResolver } from "../../types/artifact"; import { DeploymentParameters } from "../../types/deploy"; import { Future, IgnitionModule } from "../../types/module"; import { DeploymentLoader } from "../deployment-loader/types"; -import { DeploymentState } from "../new-execution/types/deployment-state"; +import { DeploymentState } from "../execution/types/deployment-state"; import { ExecutionState, ExecutionStatus, -} from "../new-execution/types/execution-state"; +} from "../execution/types/execution-state"; import { AdjacencyList } from "../utils/adjacency-list"; import { AdjacencyListConverter } from "../utils/adjacency-list-converter"; import { getFuturesFromModule } from "../utils/get-futures-from-module"; @@ -33,7 +33,7 @@ export class Reconciler { artifactResolver: ArtifactResolver, defaultSender: string ): Promise { - let reconciliationFailures = await this._reconcileEachFutureInModule( + const reconciliationFailures = await this._reconcileEachFutureInModule( module, { deploymentState, @@ -50,10 +50,6 @@ export class Reconciler { ] ); - if (reconciliationFailures.length === 0) { - reconciliationFailures = this._reconcileNoErroredFutures(deploymentState); - } - // TODO: Reconcile sender of incomplete futures. const missingExecutedFutures = this._missingPreviouslyExecutedFutures( @@ -64,35 +60,7 @@ export class Reconciler { return { reconciliationFailures, missingExecutedFutures }; } - private static async _reconcileEachFutureInModule( - module: IgnitionModule, - context: ReconciliationContext, - checks: ReconciliationCheck[] - ): Promise { - // TODO: swap this out for linearization of execution state - // once execution is fleshed out. - const futures = this._getFuturesInReverseTopoligicalOrder(module); - - const failures = []; - - for (const future of futures) { - const exState = context.deploymentState.executionStates[future.id]; - if (exState === undefined) { - continue; - } - - const result = await this._check(future, exState, context, checks); - if (result.success) { - continue; - } - - failures.push(result.failure); - } - - return failures; - } - - private static _reconcileNoErroredFutures( + public static checkForPreviousRunErrors( deploymentState: DeploymentState ): ReconciliationFailure[] { const failuresOrTimeouts = Object.values( @@ -121,6 +89,34 @@ export class Reconciler { throw new IgnitionError(`Unsupported execution status: ${exState.status}`); } + private static async _reconcileEachFutureInModule( + module: IgnitionModule, + context: ReconciliationContext, + checks: ReconciliationCheck[] + ): Promise { + // TODO: swap this out for linearization of execution state + // once execution is fleshed out. + const futures = this._getFuturesInReverseTopoligicalOrder(module); + + const failures = []; + + for (const future of futures) { + const exState = context.deploymentState.executionStates[future.id]; + if (exState === undefined) { + continue; + } + + const result = await this._check(future, exState, context, checks); + if (result.success) { + continue; + } + + failures.push(result.failure); + } + + return failures; + } + private static _missingPreviouslyExecutedFutures( module: IgnitionModule, deploymentState: DeploymentState diff --git a/packages/core/src/new-api/internal/reconciliation/types.ts b/packages/core/src/internal/reconciliation/types.ts similarity index 88% rename from packages/core/src/new-api/internal/reconciliation/types.ts rename to packages/core/src/internal/reconciliation/types.ts index 7b9a24ab7..a7f62bb2c 100644 --- a/packages/core/src/new-api/internal/reconciliation/types.ts +++ b/packages/core/src/internal/reconciliation/types.ts @@ -2,8 +2,8 @@ import { ArtifactResolver } from "../../types/artifact"; import { DeploymentParameters } from "../../types/deploy"; import { Future } from "../../types/module"; import { DeploymentLoader } from "../deployment-loader/types"; -import { DeploymentState } from "../new-execution/types/deployment-state"; -import { ExecutionState } from "../new-execution/types/execution-state"; +import { DeploymentState } from "../execution/types/deployment-state"; +import { ExecutionState } from "../execution/types/execution-state"; export interface ReconciliationFailure { futureId: string; diff --git a/packages/core/src/new-api/internal/reconciliation/utils.ts b/packages/core/src/internal/reconciliation/utils.ts similarity index 100% rename from packages/core/src/new-api/internal/reconciliation/utils.ts rename to packages/core/src/internal/reconciliation/utils.ts diff --git a/packages/core/src/new-api/internal/topological-order.ts b/packages/core/src/internal/topological-order.ts similarity index 100% rename from packages/core/src/new-api/internal/topological-order.ts rename to packages/core/src/internal/topological-order.ts diff --git a/packages/core/src/new-api/internal/utils.ts b/packages/core/src/internal/utils.ts similarity index 100% rename from packages/core/src/new-api/internal/utils.ts rename to packages/core/src/internal/utils.ts diff --git a/packages/core/src/new-api/internal/utils/adjacency-list-converter.ts b/packages/core/src/internal/utils/adjacency-list-converter.ts similarity index 100% rename from packages/core/src/new-api/internal/utils/adjacency-list-converter.ts rename to packages/core/src/internal/utils/adjacency-list-converter.ts diff --git a/packages/core/src/new-api/internal/utils/adjacency-list.ts b/packages/core/src/internal/utils/adjacency-list.ts similarity index 100% rename from packages/core/src/new-api/internal/utils/adjacency-list.ts rename to packages/core/src/internal/utils/adjacency-list.ts diff --git a/packages/core/src/new-api/internal/utils/assertions.ts b/packages/core/src/internal/utils/assertions.ts similarity index 82% rename from packages/core/src/new-api/internal/utils/assertions.ts rename to packages/core/src/internal/utils/assertions.ts index cbf1d89b1..bf2c4b4f0 100644 --- a/packages/core/src/new-api/internal/utils/assertions.ts +++ b/packages/core/src/internal/utils/assertions.ts @@ -1,4 +1,4 @@ -import { IgnitionError } from "../../../errors"; +import { IgnitionError } from "../../errors"; export function assertIgnitionInvariant( invariant: boolean, diff --git a/packages/core/src/new-api/internal/utils/check-automined-network.ts b/packages/core/src/internal/utils/check-automined-network.ts similarity index 100% rename from packages/core/src/new-api/internal/utils/check-automined-network.ts rename to packages/core/src/internal/utils/check-automined-network.ts diff --git a/packages/core/src/internal/utils/future-id-builders.ts b/packages/core/src/internal/utils/future-id-builders.ts new file mode 100644 index 000000000..0768e1b36 --- /dev/null +++ b/packages/core/src/internal/utils/future-id-builders.ts @@ -0,0 +1,95 @@ +/** + * The seperator in ids that indicated before as the module id and after + * as the parts making up the particular future. + */ +const MODULE_SEPERATOR = "#"; + +/** + * The seperator in ids that indicated different subparts of the future key. + */ +const SUBKEY_SEPERATOR = "."; + +/** + * Construct the future id for a contract or library deployment, namespaced by the + * moduleId. + * + * @param moduleId - the id of the module the future is part of + * @param userProvidedId - the overriding id provided by the user (it will still + * be namespaced) + * @param contractOrLibraryName - the contract or library name as a fallback + * @returns the future id + */ +export function toDeploymentFutureId( + moduleId: string, + userProvidedId: string | undefined, + contractOrLibraryName: string +) { + return `${moduleId}${MODULE_SEPERATOR}${ + userProvidedId ?? contractOrLibraryName + }`; +} + +/** + * Construct the future id for a call or static call, namespaced by the moduleId. + * + * @param moduleId - the id of the module the future is part of + * @param userProvidedId - the overriding id provided by the user (it will still + * be namespaced) + * @param contractName - the contract or library name that forms part of the + * fallback + * @param functionName - the function name that forms part of the fallback + * @returns the future id + */ +export function toCallFutureId( + moduleId: string, + userProvidedId: string | undefined, + contractName: string, + functionName: string +) { + const futureKey = + userProvidedId ?? `${contractName}${SUBKEY_SEPERATOR}${functionName}`; + + return `${moduleId}${MODULE_SEPERATOR}${futureKey}`; +} + +/** + * Construct the future id for a read event argument future, namespaced by + * the moduleId. + * + * @param moduleId - the id of the module the future is part of + * @param userProvidedId - the overriding id provided by the user (it will still + * be namespaced) + * @param contractName - the contract or library name that forms part of the + * fallback + * @param eventName - the event name that forms part of the fallback + * @param nameOrIndex - the argument name or argumentindex that forms part + * of the fallback + * @param eventIndex - the event index that forms part of the fallback + * @returns the future id + */ +export function toReadEventArgumentFutureId( + moduleId: string, + userProvidedId: string | undefined, + contractName: string, + eventName: string, + nameOrIndex: string | number, + eventIndex: number +) { + const futureKey = + userProvidedId ?? + `${contractName}${SUBKEY_SEPERATOR}${eventName}${SUBKEY_SEPERATOR}${nameOrIndex}${SUBKEY_SEPERATOR}${eventIndex}`; + + return `${moduleId}${MODULE_SEPERATOR}${futureKey}`; +} + +/** + * Construct the future id for a send data future, namespaced by the moduleId. + * + * @param moduleId - the id of the module the future is part of + * @param userProvidedId - the overriding id provided by the user (it will still + * be namespaced) + * @returns the future id + */ +export function toSendDataFutureId(moduleId: string, userProvidedId: string) { + return `${moduleId}${MODULE_SEPERATOR}${userProvidedId}`; +} diff --git a/packages/core/src/new-api/internal/utils/get-futures-from-module.ts b/packages/core/src/internal/utils/get-futures-from-module.ts similarity index 100% rename from packages/core/src/new-api/internal/utils/get-futures-from-module.ts rename to packages/core/src/internal/utils/get-futures-from-module.ts diff --git a/packages/core/src/internal/utils/identifier-validators.ts b/packages/core/src/internal/utils/identifier-validators.ts new file mode 100644 index 000000000..f7c812720 --- /dev/null +++ b/packages/core/src/internal/utils/identifier-validators.ts @@ -0,0 +1,51 @@ +/** + * A regex that captures Ignitions rules for user provided ids, specifically + * that they can only contain alphanumerics and underscores, and that they + * start with a letter. + */ +const ignitionIdRegex = /^[a-zA-Z][a-zA-Z0-9_]*$/; + +/** + * The regex that captures Solidity's identifier rule. + */ +const solidityIdentifierRegex = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/; + +/** + * A regex capturing the solidity identifier rule but extended to support + * the `myfun(uint256,bool)` parameter syntax + */ +const functionNameRegex = /^[a-zA-Z$_][a-zA-Z0-9$_,()]*$/; + +/** + * Does the identifier match Ignition's rules for ids. Specifically that they + * started with a letter and only contain alphanumerics and underscores. + * + * @param identifier - the id to test + * @returns true if the identifier is valid + */ +export function isValidIgnitionIdentifier(identifier: string): boolean { + return ignitionIdRegex.test(identifier); +} + +/** + * Does the identifier match Solidity's rules for ids. See the Solidity + * language spec for more details. + * + * @param identifier - the id to test + * @returns true if the identifier is a valid Solidity identifier + */ +export function isValidSolidityIdentifier(identifier: string): boolean { + return solidityIdentifierRegex.test(identifier); +} + +/** + * Does the function or event name match Ignition's rules. This is + * looser than Solidity's rules, but allows Ethers style `myfun(uint256,bool)` + * function/event specifications. + * + * @param functionName - the function name to test + * @returns true if the function name is valid + */ +export function isValidFunctionOrEventName(functionName: string): boolean { + return functionNameRegex.test(functionName); +} diff --git a/packages/core/src/new-api/internal/utils/replace-within-arg.ts b/packages/core/src/internal/utils/replace-within-arg.ts similarity index 100% rename from packages/core/src/new-api/internal/utils/replace-within-arg.ts rename to packages/core/src/internal/utils/replace-within-arg.ts diff --git a/packages/core/src/new-api/internal/utils/resolve-module-parameter.ts b/packages/core/src/internal/utils/resolve-module-parameter.ts similarity index 100% rename from packages/core/src/new-api/internal/utils/resolve-module-parameter.ts rename to packages/core/src/internal/utils/resolve-module-parameter.ts diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateArtifactContractAt.ts b/packages/core/src/internal/validation/stageOne/validateArtifactContractAt.ts similarity index 62% rename from packages/core/src/new-api/internal/validation/stageOne/validateArtifactContractAt.ts rename to packages/core/src/internal/validation/stageOne/validateArtifactContractAt.ts index 6b8ec9487..56917f654 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateArtifactContractAt.ts +++ b/packages/core/src/internal/validation/stageOne/validateArtifactContractAt.ts @@ -1,8 +1,8 @@ import { ArtifactResolver } from "../../../types/artifact"; -import { ArtifactContractAtFuture } from "../../../types/module"; +import { ContractAtFuture } from "../../../types/module"; export async function validateArtifactContractAt( - _future: ArtifactContractAtFuture, + _future: ContractAtFuture, _artifactLoader: ArtifactResolver ) { return; // no-op diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateArtifactContractDeployment.ts b/packages/core/src/internal/validation/stageOne/validateArtifactContractDeployment.ts similarity index 58% rename from packages/core/src/new-api/internal/validation/stageOne/validateArtifactContractDeployment.ts rename to packages/core/src/internal/validation/stageOne/validateArtifactContractDeployment.ts index b05070d90..f98fd9a1f 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateArtifactContractDeployment.ts +++ b/packages/core/src/internal/validation/stageOne/validateArtifactContractDeployment.ts @@ -1,10 +1,10 @@ import { ArtifactResolver } from "../../../types/artifact"; -import { ArtifactContractDeploymentFuture } from "../../../types/module"; -import { validateContractConstructorArgsLength } from "../../new-execution/abi"; -import { validateLibraryNames } from "../../new-execution/libraries"; +import { ContractDeploymentFuture } from "../../../types/module"; +import { validateContractConstructorArgsLength } from "../../execution/abi"; +import { validateLibraryNames } from "../../execution/libraries"; export async function validateArtifactContractDeployment( - future: ArtifactContractDeploymentFuture, + future: ContractDeploymentFuture, _artifactLoader: ArtifactResolver ) { const artifact = future.artifact; diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateArtifactLibraryDeployment.ts b/packages/core/src/internal/validation/stageOne/validateArtifactLibraryDeployment.ts similarity index 60% rename from packages/core/src/new-api/internal/validation/stageOne/validateArtifactLibraryDeployment.ts rename to packages/core/src/internal/validation/stageOne/validateArtifactLibraryDeployment.ts index 93fbe7082..54ae6b9f8 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateArtifactLibraryDeployment.ts +++ b/packages/core/src/internal/validation/stageOne/validateArtifactLibraryDeployment.ts @@ -1,8 +1,8 @@ import { ArtifactResolver } from "../../../types/artifact"; -import { ArtifactLibraryDeploymentFuture } from "../../../types/module"; +import { LibraryDeploymentFuture } from "../../../types/module"; export async function validateArtifactLibraryDeployment( - _future: ArtifactLibraryDeploymentFuture, + _future: LibraryDeploymentFuture, _artifactLoader: ArtifactResolver ) { return; // no-op diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateNamedContractAt.ts b/packages/core/src/internal/validation/stageOne/validateNamedContractAt.ts similarity index 70% rename from packages/core/src/new-api/internal/validation/stageOne/validateNamedContractAt.ts rename to packages/core/src/internal/validation/stageOne/validateNamedContractAt.ts index 6c6c89f1f..48c3a4eee 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateNamedContractAt.ts +++ b/packages/core/src/internal/validation/stageOne/validateNamedContractAt.ts @@ -1,10 +1,10 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isArtifactType } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; -import { NamedContractAtFuture } from "../../../types/module"; +import { NamedArtifactContractAtFuture } from "../../../types/module"; export async function validateNamedContractAt( - future: NamedContractAtFuture, + future: NamedArtifactContractAtFuture, artifactLoader: ArtifactResolver ) { const artifact = await artifactLoader.loadArtifact(future.contractName); diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateNamedContractCall.ts b/packages/core/src/internal/validation/stageOne/validateNamedContractCall.ts similarity index 78% rename from packages/core/src/new-api/internal/validation/stageOne/validateNamedContractCall.ts rename to packages/core/src/internal/validation/stageOne/validateNamedContractCall.ts index 5cf634986..c5212e7dd 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateNamedContractCall.ts +++ b/packages/core/src/internal/validation/stageOne/validateNamedContractCall.ts @@ -1,14 +1,14 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isArtifactType } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; -import { NamedContractCallFuture } from "../../../types/module"; +import { ContractCallFuture } from "../../../types/module"; import { validateArtifactFunction, validateArtifactFunctionName, -} from "../../new-execution/abi"; +} from "../../execution/abi"; export async function validateNamedContractCall( - future: NamedContractCallFuture, + future: ContractCallFuture, artifactLoader: ArtifactResolver ) { const artifact = diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateNamedContractDeployment.ts b/packages/core/src/internal/validation/stageOne/validateNamedContractDeployment.ts similarity index 64% rename from packages/core/src/new-api/internal/validation/stageOne/validateNamedContractDeployment.ts rename to packages/core/src/internal/validation/stageOne/validateNamedContractDeployment.ts index e4dc983e7..edf99355d 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateNamedContractDeployment.ts +++ b/packages/core/src/internal/validation/stageOne/validateNamedContractDeployment.ts @@ -1,12 +1,12 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isArtifactType } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; -import { NamedContractDeploymentFuture } from "../../../types/module"; -import { validateContractConstructorArgsLength } from "../../new-execution/abi"; -import { validateLibraryNames } from "../../new-execution/libraries"; +import { NamedArtifactContractDeploymentFuture } from "../../../types/module"; +import { validateContractConstructorArgsLength } from "../../execution/abi"; +import { validateLibraryNames } from "../../execution/libraries"; export async function validateNamedContractDeployment( - future: NamedContractDeploymentFuture, + future: NamedArtifactContractDeploymentFuture, artifactLoader: ArtifactResolver ) { const artifact = await artifactLoader.loadArtifact(future.contractName); diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateNamedLibraryDeployment.ts b/packages/core/src/internal/validation/stageOne/validateNamedLibraryDeployment.ts similarity index 66% rename from packages/core/src/new-api/internal/validation/stageOne/validateNamedLibraryDeployment.ts rename to packages/core/src/internal/validation/stageOne/validateNamedLibraryDeployment.ts index e745ac28b..1025bc98d 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateNamedLibraryDeployment.ts +++ b/packages/core/src/internal/validation/stageOne/validateNamedLibraryDeployment.ts @@ -1,11 +1,11 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isArtifactType } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; -import { NamedLibraryDeploymentFuture } from "../../../types/module"; -import { validateLibraryNames } from "../../new-execution/libraries"; +import { NamedArtifactLibraryDeploymentFuture } from "../../../types/module"; +import { validateLibraryNames } from "../../execution/libraries"; export async function validateNamedLibraryDeployment( - future: NamedLibraryDeploymentFuture, + future: NamedArtifactLibraryDeploymentFuture, artifactLoader: ArtifactResolver ) { const artifact = await artifactLoader.loadArtifact(future.contractName); diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateNamedStaticCall.ts b/packages/core/src/internal/validation/stageOne/validateNamedStaticCall.ts similarity index 61% rename from packages/core/src/new-api/internal/validation/stageOne/validateNamedStaticCall.ts rename to packages/core/src/internal/validation/stageOne/validateNamedStaticCall.ts index d592b0f6c..dec782b6a 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateNamedStaticCall.ts +++ b/packages/core/src/internal/validation/stageOne/validateNamedStaticCall.ts @@ -1,11 +1,14 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isArtifactType } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; -import { NamedStaticCallFuture } from "../../../types/module"; -import { validateArtifactFunction } from "../../new-execution/abi"; +import { StaticCallFuture } from "../../../types/module"; +import { + validateArtifactFunction, + validateFunctionArgumentParamType, +} from "../../execution/abi"; export async function validateNamedStaticCall( - future: NamedStaticCallFuture, + future: StaticCallFuture, artifactLoader: ArtifactResolver ) { const artifact = @@ -26,4 +29,11 @@ export async function validateNamedStaticCall( future.args, true ); + + validateFunctionArgumentParamType( + future.contract.contractName, + future.functionName, + artifact, + future.nameOrIndex + ); } diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateReadEventArgument.ts b/packages/core/src/internal/validation/stageOne/validateReadEventArgument.ts similarity index 80% rename from packages/core/src/new-api/internal/validation/stageOne/validateReadEventArgument.ts rename to packages/core/src/internal/validation/stageOne/validateReadEventArgument.ts index b35723b63..f537a3844 100644 --- a/packages/core/src/new-api/internal/validation/stageOne/validateReadEventArgument.ts +++ b/packages/core/src/internal/validation/stageOne/validateReadEventArgument.ts @@ -1,8 +1,8 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isArtifactType } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { ReadEventArgumentFuture } from "../../../types/module"; -import { validateArtifactEventArgumentParams } from "../../new-execution/abi"; +import { validateArtifactEventArgumentParams } from "../../execution/abi"; export async function validateReadEventArgument( future: ReadEventArgumentFuture, @@ -22,6 +22,6 @@ export async function validateReadEventArgument( validateArtifactEventArgumentParams( artifact, future.eventName, - future.argumentName + future.nameOrIndex ); } diff --git a/packages/core/src/new-api/internal/validation/stageOne/validateSendData.ts b/packages/core/src/internal/validation/stageOne/validateSendData.ts similarity index 100% rename from packages/core/src/new-api/internal/validation/stageOne/validateSendData.ts rename to packages/core/src/internal/validation/stageOne/validateSendData.ts diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateArtifactContractAt.ts b/packages/core/src/internal/validation/stageTwo/validateArtifactContractAt.ts similarity index 85% rename from packages/core/src/new-api/internal/validation/stageTwo/validateArtifactContractAt.ts rename to packages/core/src/internal/validation/stageTwo/validateArtifactContractAt.ts index ef973ed47..eeac6e55a 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateArtifactContractAt.ts +++ b/packages/core/src/internal/validation/stageTwo/validateArtifactContractAt.ts @@ -1,11 +1,11 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isModuleParameterRuntimeValue } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { DeploymentParameters } from "../../../types/deploy"; -import { ArtifactContractAtFuture } from "../../../types/module"; +import { ContractAtFuture } from "../../../types/module"; export async function validateArtifactContractAt( - future: ArtifactContractAtFuture, + future: ContractAtFuture, _artifactLoader: ArtifactResolver, deploymentParameters: DeploymentParameters, _accounts: string[] diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateArtifactContractDeployment.ts b/packages/core/src/internal/validation/stageTwo/validateArtifactContractDeployment.ts similarity index 90% rename from packages/core/src/new-api/internal/validation/stageTwo/validateArtifactContractDeployment.ts rename to packages/core/src/internal/validation/stageTwo/validateArtifactContractDeployment.ts index d2189ed14..4ed1068e2 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateArtifactContractDeployment.ts +++ b/packages/core/src/internal/validation/stageTwo/validateArtifactContractDeployment.ts @@ -1,18 +1,18 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isAccountRuntimeValue, isModuleParameterRuntimeValue, } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { DeploymentParameters } from "../../../types/deploy"; -import { ArtifactContractDeploymentFuture } from "../../../types/module"; +import { ContractDeploymentFuture } from "../../../types/module"; import { retrieveNestedRuntimeValues, validateAccountRuntimeValue, } from "../utils"; export async function validateArtifactContractDeployment( - future: ArtifactContractDeploymentFuture, + future: ContractDeploymentFuture, _artifactLoader: ArtifactResolver, deploymentParameters: DeploymentParameters, accounts: string[] diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateArtifactLibraryDeployment.ts b/packages/core/src/internal/validation/stageTwo/validateArtifactLibraryDeployment.ts similarity index 75% rename from packages/core/src/new-api/internal/validation/stageTwo/validateArtifactLibraryDeployment.ts rename to packages/core/src/internal/validation/stageTwo/validateArtifactLibraryDeployment.ts index fd1ebe1a9..ee5c974d4 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateArtifactLibraryDeployment.ts +++ b/packages/core/src/internal/validation/stageTwo/validateArtifactLibraryDeployment.ts @@ -1,12 +1,12 @@ import { isAccountRuntimeValue } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { DeploymentParameters } from "../../../types/deploy"; -import { ArtifactLibraryDeploymentFuture } from "../../../types/module"; -import { validateLibraryNames } from "../../new-execution/libraries"; +import { LibraryDeploymentFuture } from "../../../types/module"; +import { validateLibraryNames } from "../../execution/libraries"; import { validateAccountRuntimeValue } from "../utils"; export async function validateArtifactLibraryDeployment( - future: ArtifactLibraryDeploymentFuture, + future: LibraryDeploymentFuture, _artifactLoader: ArtifactResolver, _deploymentParameters: DeploymentParameters, accounts: string[] diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractAt.ts b/packages/core/src/internal/validation/stageTwo/validateNamedContractAt.ts similarity index 83% rename from packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractAt.ts rename to packages/core/src/internal/validation/stageTwo/validateNamedContractAt.ts index 75e295d81..1f9c64e9c 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractAt.ts +++ b/packages/core/src/internal/validation/stageTwo/validateNamedContractAt.ts @@ -1,11 +1,11 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isModuleParameterRuntimeValue } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { DeploymentParameters } from "../../../types/deploy"; -import { NamedContractAtFuture } from "../../../types/module"; +import { NamedArtifactContractAtFuture } from "../../../types/module"; export async function validateNamedContractAt( - future: NamedContractAtFuture, + future: NamedArtifactContractAtFuture, _artifactLoader: ArtifactResolver, deploymentParameters: DeploymentParameters, _accounts: string[] diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractCall.ts b/packages/core/src/internal/validation/stageTwo/validateNamedContractCall.ts similarity index 90% rename from packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractCall.ts rename to packages/core/src/internal/validation/stageTwo/validateNamedContractCall.ts index b561b4c6d..e8cbe454e 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractCall.ts +++ b/packages/core/src/internal/validation/stageTwo/validateNamedContractCall.ts @@ -1,18 +1,18 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isAccountRuntimeValue, isModuleParameterRuntimeValue, } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { DeploymentParameters } from "../../../types/deploy"; -import { NamedContractCallFuture } from "../../../types/module"; +import { ContractCallFuture } from "../../../types/module"; import { retrieveNestedRuntimeValues, validateAccountRuntimeValue, } from "../utils"; export async function validateNamedContractCall( - future: NamedContractCallFuture, + future: ContractCallFuture, _artifactLoader: ArtifactResolver, deploymentParameters: DeploymentParameters, accounts: string[] diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractDeployment.ts b/packages/core/src/internal/validation/stageTwo/validateNamedContractDeployment.ts similarity index 90% rename from packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractDeployment.ts rename to packages/core/src/internal/validation/stageTwo/validateNamedContractDeployment.ts index 0585f8f43..f8b76dad8 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedContractDeployment.ts +++ b/packages/core/src/internal/validation/stageTwo/validateNamedContractDeployment.ts @@ -1,18 +1,18 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isAccountRuntimeValue, isModuleParameterRuntimeValue, } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { DeploymentParameters } from "../../../types/deploy"; -import { NamedContractDeploymentFuture } from "../../../types/module"; +import { NamedArtifactContractDeploymentFuture } from "../../../types/module"; import { retrieveNestedRuntimeValues, validateAccountRuntimeValue, } from "../utils"; export async function validateNamedContractDeployment( - future: NamedContractDeploymentFuture, + future: NamedArtifactContractDeploymentFuture, artifactLoader: ArtifactResolver, deploymentParameters: DeploymentParameters, accounts: string[] diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedLibraryDeployment.ts b/packages/core/src/internal/validation/stageTwo/validateNamedLibraryDeployment.ts similarity index 79% rename from packages/core/src/new-api/internal/validation/stageTwo/validateNamedLibraryDeployment.ts rename to packages/core/src/internal/validation/stageTwo/validateNamedLibraryDeployment.ts index 8787fd30d..705c8e55f 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedLibraryDeployment.ts +++ b/packages/core/src/internal/validation/stageTwo/validateNamedLibraryDeployment.ts @@ -1,11 +1,11 @@ import { isAccountRuntimeValue } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { DeploymentParameters } from "../../../types/deploy"; -import { NamedLibraryDeploymentFuture } from "../../../types/module"; +import { NamedArtifactLibraryDeploymentFuture } from "../../../types/module"; import { validateAccountRuntimeValue } from "../utils"; export async function validateNamedLibraryDeployment( - future: NamedLibraryDeploymentFuture, + future: NamedArtifactLibraryDeploymentFuture, _artifactLoader: ArtifactResolver, _deploymentParameters: DeploymentParameters, accounts: string[] diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedStaticCall.ts b/packages/core/src/internal/validation/stageTwo/validateNamedStaticCall.ts similarity index 87% rename from packages/core/src/new-api/internal/validation/stageTwo/validateNamedStaticCall.ts rename to packages/core/src/internal/validation/stageTwo/validateNamedStaticCall.ts index e2a219514..36becb052 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateNamedStaticCall.ts +++ b/packages/core/src/internal/validation/stageTwo/validateNamedStaticCall.ts @@ -1,18 +1,18 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isAccountRuntimeValue, isModuleParameterRuntimeValue, } from "../../../type-guards"; import { ArtifactResolver } from "../../../types/artifact"; import { DeploymentParameters } from "../../../types/deploy"; -import { NamedStaticCallFuture } from "../../../types/module"; +import { StaticCallFuture } from "../../../types/module"; import { retrieveNestedRuntimeValues, validateAccountRuntimeValue, } from "../utils"; export async function validateNamedStaticCall( - future: NamedStaticCallFuture, + future: StaticCallFuture, _artifactLoader: ArtifactResolver, deploymentParameters: DeploymentParameters, accounts: string[] diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateReadEventArgument.ts b/packages/core/src/internal/validation/stageTwo/validateReadEventArgument.ts similarity index 100% rename from packages/core/src/new-api/internal/validation/stageTwo/validateReadEventArgument.ts rename to packages/core/src/internal/validation/stageTwo/validateReadEventArgument.ts diff --git a/packages/core/src/new-api/internal/validation/stageTwo/validateSendData.ts b/packages/core/src/internal/validation/stageTwo/validateSendData.ts similarity index 96% rename from packages/core/src/new-api/internal/validation/stageTwo/validateSendData.ts rename to packages/core/src/internal/validation/stageTwo/validateSendData.ts index a2d05e914..fb878e00f 100644 --- a/packages/core/src/new-api/internal/validation/stageTwo/validateSendData.ts +++ b/packages/core/src/internal/validation/stageTwo/validateSendData.ts @@ -1,4 +1,4 @@ -import { IgnitionValidationError } from "../../../../errors"; +import { IgnitionValidationError } from "../../../errors"; import { isAccountRuntimeValue, isModuleParameterRuntimeValue, diff --git a/packages/core/src/new-api/internal/validation/utils.ts b/packages/core/src/internal/validation/utils.ts similarity index 95% rename from packages/core/src/new-api/internal/validation/utils.ts rename to packages/core/src/internal/validation/utils.ts index 12428d3fc..014a4650d 100644 --- a/packages/core/src/new-api/internal/validation/utils.ts +++ b/packages/core/src/internal/validation/utils.ts @@ -1,4 +1,4 @@ -import { IgnitionValidationError } from "../../../errors"; +import { IgnitionValidationError } from "../../errors"; import { isFuture, isRuntimeValue } from "../../type-guards"; import { AccountRuntimeValue, diff --git a/packages/core/src/internal/validation/validateStageOne.ts b/packages/core/src/internal/validation/validateStageOne.ts new file mode 100644 index 000000000..6c648c80a --- /dev/null +++ b/packages/core/src/internal/validation/validateStageOne.ts @@ -0,0 +1,86 @@ +import { IgnitionValidationError } from "../../errors"; +import { ArtifactResolver } from "../../types/artifact"; +import { + DeploymentResultType, + ValidationErrorDeploymentResult, +} from "../../types/deploy"; +import { Future, FutureType, IgnitionModule } from "../../types/module"; +import { assertIgnitionInvariant } from "../utils/assertions"; +import { getFuturesFromModule } from "../utils/get-futures-from-module"; + +import { validateArtifactContractAt } from "./stageOne/validateArtifactContractAt"; +import { validateArtifactContractDeployment } from "./stageOne/validateArtifactContractDeployment"; +import { validateArtifactLibraryDeployment } from "./stageOne/validateArtifactLibraryDeployment"; +import { validateNamedContractAt } from "./stageOne/validateNamedContractAt"; +import { validateNamedContractCall } from "./stageOne/validateNamedContractCall"; +import { validateNamedContractDeployment } from "./stageOne/validateNamedContractDeployment"; +import { validateNamedLibraryDeployment } from "./stageOne/validateNamedLibraryDeployment"; +import { validateNamedStaticCall } from "./stageOne/validateNamedStaticCall"; +import { validateReadEventArgument } from "./stageOne/validateReadEventArgument"; +import { validateSendData } from "./stageOne/validateSendData"; + +export async function validateStageOne( + module: IgnitionModule, + artifactLoader: ArtifactResolver +): Promise { + const futures = getFuturesFromModule(module); + + for (const future of futures) { + try { + await _validateFuture(future, artifactLoader); + } catch (err) { + assertIgnitionInvariant( + err instanceof IgnitionValidationError, + `Expected an IgnitionValidationError when validating the future ${future.id}` + ); + + return { + type: DeploymentResultType.VALIDATION_ERROR, + errors: { + [future.id]: [err.message], + }, + }; + } + } + + // No validation errors + return null; +} + +async function _validateFuture( + future: Future, + artifactLoader: ArtifactResolver +): Promise { + switch (future.type) { + case FutureType.CONTRACT_DEPLOYMENT: + await validateArtifactContractDeployment(future, artifactLoader); + break; + case FutureType.LIBRARY_DEPLOYMENT: + await validateArtifactLibraryDeployment(future, artifactLoader); + break; + case FutureType.CONTRACT_AT: + await validateArtifactContractAt(future, artifactLoader); + break; + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: + await validateNamedContractDeployment(future, artifactLoader); + break; + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: + await validateNamedLibraryDeployment(future, artifactLoader); + break; + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: + await validateNamedContractAt(future, artifactLoader); + break; + case FutureType.CONTRACT_CALL: + await validateNamedContractCall(future, artifactLoader); + break; + case FutureType.STATIC_CALL: + await validateNamedStaticCall(future, artifactLoader); + break; + case FutureType.READ_EVENT_ARGUMENT: + await validateReadEventArgument(future, artifactLoader); + break; + case FutureType.SEND_DATA: + await validateSendData(future, artifactLoader); + break; + } +} diff --git a/packages/core/src/new-api/internal/validation/validateStageTwo.ts b/packages/core/src/internal/validation/validateStageTwo.ts similarity index 90% rename from packages/core/src/new-api/internal/validation/validateStageTwo.ts rename to packages/core/src/internal/validation/validateStageTwo.ts index a6b6d8e27..1e5623d06 100644 --- a/packages/core/src/new-api/internal/validation/validateStageTwo.ts +++ b/packages/core/src/internal/validation/validateStageTwo.ts @@ -1,4 +1,4 @@ -import { IgnitionValidationError } from "../../../errors"; +import { IgnitionValidationError } from "../../errors"; import { ArtifactResolver } from "../../types/artifact"; import { DeploymentParameters, @@ -62,7 +62,7 @@ async function _validateFuture( accounts: string[] ) { switch (future.type) { - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: await validateArtifactContractDeployment( future, artifactLoader, @@ -70,7 +70,7 @@ async function _validateFuture( accounts ); break; - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: await validateArtifactLibraryDeployment( future, artifactLoader, @@ -78,7 +78,7 @@ async function _validateFuture( accounts ); break; - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: await validateArtifactContractAt( future, artifactLoader, @@ -86,7 +86,7 @@ async function _validateFuture( accounts ); break; - case FutureType.NAMED_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: await validateNamedContractDeployment( future, artifactLoader, @@ -94,7 +94,7 @@ async function _validateFuture( accounts ); break; - case FutureType.NAMED_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: await validateNamedLibraryDeployment( future, artifactLoader, @@ -102,7 +102,7 @@ async function _validateFuture( accounts ); break; - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: await validateNamedContractAt( future, artifactLoader, @@ -110,7 +110,7 @@ async function _validateFuture( accounts ); break; - case FutureType.NAMED_CONTRACT_CALL: + case FutureType.CONTRACT_CALL: await validateNamedContractCall( future, artifactLoader, @@ -118,7 +118,7 @@ async function _validateFuture( accounts ); break; - case FutureType.NAMED_STATIC_CALL: + case FutureType.STATIC_CALL: await validateNamedStaticCall( future, artifactLoader, diff --git a/packages/core/src/new-api/internal/new-execution/views/execution-state/find-onchain-interaction-by.ts b/packages/core/src/internal/views/execution-state/find-onchain-interaction-by.ts similarity index 85% rename from packages/core/src/new-api/internal/new-execution/views/execution-state/find-onchain-interaction-by.ts rename to packages/core/src/internal/views/execution-state/find-onchain-interaction-by.ts index a49fc6b2f..8778c0ba3 100644 --- a/packages/core/src/new-api/internal/new-execution/views/execution-state/find-onchain-interaction-by.ts +++ b/packages/core/src/internal/views/execution-state/find-onchain-interaction-by.ts @@ -1,14 +1,14 @@ -import { assertIgnitionInvariant } from "../../../utils/assertions"; import { CallExecutionState, DeploymentExecutionState, SendDataExecutionState, StaticCallExecutionState, -} from "../../types/execution-state"; +} from "../../execution/types/execution-state"; import { NetworkInteractionType, OnchainInteraction, -} from "../../types/network-interaction"; +} from "../../execution/types/network-interaction"; +import { assertIgnitionInvariant } from "../../utils/assertions"; export function findOnchainInteractionBy( executionState: diff --git a/packages/core/src/new-api/internal/new-execution/views/execution-state/find-static-call-by.ts b/packages/core/src/internal/views/execution-state/find-static-call-by.ts similarity index 84% rename from packages/core/src/new-api/internal/new-execution/views/execution-state/find-static-call-by.ts rename to packages/core/src/internal/views/execution-state/find-static-call-by.ts index b5ec92157..80931a21c 100644 --- a/packages/core/src/new-api/internal/new-execution/views/execution-state/find-static-call-by.ts +++ b/packages/core/src/internal/views/execution-state/find-static-call-by.ts @@ -1,14 +1,14 @@ -import { assertIgnitionInvariant } from "../../../utils/assertions"; import { CallExecutionState, DeploymentExecutionState, SendDataExecutionState, StaticCallExecutionState, -} from "../../types/execution-state"; +} from "../../execution/types/execution-state"; import { NetworkInteractionType, StaticCall, -} from "../../types/network-interaction"; +} from "../../execution/types/network-interaction"; +import { assertIgnitionInvariant } from "../../utils/assertions"; export function findStaticCallBy( executionState: diff --git a/packages/core/src/new-api/internal/new-execution/views/execution-state/find-transaction-by.ts b/packages/core/src/internal/views/execution-state/find-transaction-by.ts similarity index 82% rename from packages/core/src/new-api/internal/new-execution/views/execution-state/find-transaction-by.ts rename to packages/core/src/internal/views/execution-state/find-transaction-by.ts index 5adb68b2e..d5682b198 100644 --- a/packages/core/src/new-api/internal/new-execution/views/execution-state/find-transaction-by.ts +++ b/packages/core/src/internal/views/execution-state/find-transaction-by.ts @@ -1,11 +1,11 @@ -import { assertIgnitionInvariant } from "../../../utils/assertions"; import { CallExecutionState, DeploymentExecutionState, SendDataExecutionState, StaticCallExecutionState, -} from "../../types/execution-state"; -import { Transaction } from "../../types/jsonrpc"; +} from "../../execution/types/execution-state"; +import { Transaction } from "../../execution/types/jsonrpc"; +import { assertIgnitionInvariant } from "../../utils/assertions"; import { findOnchainInteractionBy } from "./find-onchain-interaction-by"; diff --git a/packages/core/src/new-api/internal/new-execution/views/execution-state/get-pending-nonce-and-sender.ts b/packages/core/src/internal/views/execution-state/get-pending-nonce-and-sender.ts similarity index 90% rename from packages/core/src/new-api/internal/new-execution/views/execution-state/get-pending-nonce-and-sender.ts rename to packages/core/src/internal/views/execution-state/get-pending-nonce-and-sender.ts index 448766bf3..fb8aef898 100644 --- a/packages/core/src/new-api/internal/new-execution/views/execution-state/get-pending-nonce-and-sender.ts +++ b/packages/core/src/internal/views/execution-state/get-pending-nonce-and-sender.ts @@ -1,4 +1,7 @@ -import { ExecutionSateType, ExecutionState } from "../../types/execution-state"; +import { + ExecutionSateType, + ExecutionState, +} from "../../execution/types/execution-state"; import { getPendingOnchainInteraction } from "./get-pending-onchain-interaction"; diff --git a/packages/core/src/new-api/internal/new-execution/views/execution-state/get-pending-onchain-interaction.ts b/packages/core/src/internal/views/execution-state/get-pending-onchain-interaction.ts similarity index 84% rename from packages/core/src/new-api/internal/new-execution/views/execution-state/get-pending-onchain-interaction.ts rename to packages/core/src/internal/views/execution-state/get-pending-onchain-interaction.ts index 8f20dfd09..90f9209af 100644 --- a/packages/core/src/new-api/internal/new-execution/views/execution-state/get-pending-onchain-interaction.ts +++ b/packages/core/src/internal/views/execution-state/get-pending-onchain-interaction.ts @@ -1,9 +1,12 @@ -import { assertIgnitionInvariant } from "../../../utils/assertions"; -import { ExecutionSateType, ExecutionState } from "../../types/execution-state"; +import { + ExecutionSateType, + ExecutionState, +} from "../../execution/types/execution-state"; import { NetworkInteractionType, OnchainInteraction, -} from "../../types/network-interaction"; +} from "../../execution/types/network-interaction"; +import { assertIgnitionInvariant } from "../../utils/assertions"; /** * Returns the last NetworkInteraction if there's one and it's an diff --git a/packages/core/src/new-api/internal/new-execution/views/find-address-for-contract-future-by-id.ts b/packages/core/src/internal/views/find-address-for-contract-future-by-id.ts similarity index 82% rename from packages/core/src/new-api/internal/new-execution/views/find-address-for-contract-future-by-id.ts rename to packages/core/src/internal/views/find-address-for-contract-future-by-id.ts index 00f2a6417..2bd4b3e23 100644 --- a/packages/core/src/new-api/internal/new-execution/views/find-address-for-contract-future-by-id.ts +++ b/packages/core/src/internal/views/find-address-for-contract-future-by-id.ts @@ -1,7 +1,7 @@ -import { assertIgnitionInvariant } from "../../utils/assertions"; -import { DeploymentState } from "../types/deployment-state"; -import { ExecutionResultType } from "../types/execution-result"; -import { ExecutionSateType } from "../types/execution-state"; +import { DeploymentState } from "../execution/types/deployment-state"; +import { ExecutionResultType } from "../execution/types/execution-result"; +import { ExecutionSateType } from "../execution/types/execution-state"; +import { assertIgnitionInvariant } from "../utils/assertions"; /** * Find the address for the future by its id. Only works for ContractAt, NamedLibrary, diff --git a/packages/core/src/new-api/internal/new-execution/views/find-confirmed-transaction-by-future-id.ts b/packages/core/src/internal/views/find-confirmed-transaction-by-future-id.ts similarity index 80% rename from packages/core/src/new-api/internal/new-execution/views/find-confirmed-transaction-by-future-id.ts rename to packages/core/src/internal/views/find-confirmed-transaction-by-future-id.ts index feee05d66..86272fbed 100644 --- a/packages/core/src/new-api/internal/new-execution/views/find-confirmed-transaction-by-future-id.ts +++ b/packages/core/src/internal/views/find-confirmed-transaction-by-future-id.ts @@ -1,8 +1,8 @@ -import { assertIgnitionInvariant } from "../../utils/assertions"; -import { DeploymentState } from "../types/deployment-state"; -import { ExecutionSateType } from "../types/execution-state"; -import { Transaction, TransactionReceipt } from "../types/jsonrpc"; -import { NetworkInteractionType } from "../types/network-interaction"; +import { DeploymentState } from "../execution/types/deployment-state"; +import { ExecutionSateType } from "../execution/types/execution-state"; +import { Transaction, TransactionReceipt } from "../execution/types/jsonrpc"; +import { NetworkInteractionType } from "../execution/types/network-interaction"; +import { assertIgnitionInvariant } from "../utils/assertions"; export function findConfirmedTransactionByFutureId( deploymentState: DeploymentState, diff --git a/packages/core/src/new-api/internal/new-execution/views/find-deployed-contracts.ts b/packages/core/src/internal/views/find-deployed-contracts.ts similarity index 85% rename from packages/core/src/new-api/internal/new-execution/views/find-deployed-contracts.ts rename to packages/core/src/internal/views/find-deployed-contracts.ts index 5a01ff50e..3d754d7f6 100644 --- a/packages/core/src/new-api/internal/new-execution/views/find-deployed-contracts.ts +++ b/packages/core/src/internal/views/find-deployed-contracts.ts @@ -1,12 +1,12 @@ -import { assertIgnitionInvariant } from "../../utils/assertions"; -import { DeploymentState } from "../types/deployment-state"; -import { ExecutionResultType } from "../types/execution-result"; +import { DeploymentState } from "../execution/types/deployment-state"; +import { ExecutionResultType } from "../execution/types/execution-result"; import { ContractAtExecutionState, DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../types/execution-state"; +} from "../execution/types/execution-state"; +import { assertIgnitionInvariant } from "../utils/assertions"; interface DeployedContract { futureId: string; diff --git a/packages/core/src/new-api/internal/new-execution/views/find-execution-state-by-id.ts b/packages/core/src/internal/views/find-execution-state-by-id.ts similarity index 68% rename from packages/core/src/new-api/internal/new-execution/views/find-execution-state-by-id.ts rename to packages/core/src/internal/views/find-execution-state-by-id.ts index 88f4904c0..d7373eaa6 100644 --- a/packages/core/src/new-api/internal/new-execution/views/find-execution-state-by-id.ts +++ b/packages/core/src/internal/views/find-execution-state-by-id.ts @@ -1,7 +1,7 @@ -import { assertIgnitionInvariant } from "../../utils/assertions"; -import { MapExStateTypeToExState } from "../type-helpers"; -import { DeploymentState } from "../types/deployment-state"; -import { ExecutionSateType } from "../types/execution-state"; +import { MapExStateTypeToExState } from "../execution/type-helpers"; +import { DeploymentState } from "../execution/types/deployment-state"; +import { ExecutionSateType } from "../execution/types/execution-state"; +import { assertIgnitionInvariant } from "../utils/assertions"; export function findExecutionStateById( exStateType: ExStateT, diff --git a/packages/core/src/new-api/internal/new-execution/views/find-result-for-future-by-id.ts b/packages/core/src/internal/views/find-result-for-future-by-id.ts similarity index 81% rename from packages/core/src/new-api/internal/new-execution/views/find-result-for-future-by-id.ts rename to packages/core/src/internal/views/find-result-for-future-by-id.ts index cdf2d9478..72c2e4530 100644 --- a/packages/core/src/new-api/internal/new-execution/views/find-result-for-future-by-id.ts +++ b/packages/core/src/internal/views/find-result-for-future-by-id.ts @@ -1,8 +1,8 @@ -import { SolidityParameterType } from "../../../types/module"; -import { assertIgnitionInvariant } from "../../utils/assertions"; -import { DeploymentState } from "../types/deployment-state"; -import { ExecutionResultType } from "../types/execution-result"; -import { ExecutionSateType } from "../types/execution-state"; +import { SolidityParameterType } from "../../types/module"; +import { DeploymentState } from "../execution/types/deployment-state"; +import { ExecutionResultType } from "../execution/types/execution-result"; +import { ExecutionSateType } from "../execution/types/execution-state"; +import { assertIgnitionInvariant } from "../utils/assertions"; export function findResultForFutureById( deploymentState: DeploymentState, diff --git a/packages/core/src/internal/views/has-execution-succeeded.ts b/packages/core/src/internal/views/has-execution-succeeded.ts new file mode 100644 index 000000000..16389ed55 --- /dev/null +++ b/packages/core/src/internal/views/has-execution-succeeded.ts @@ -0,0 +1,23 @@ +import { Future } from "../../types/module"; +import { DeploymentState } from "../execution/types/deployment-state"; +import { ExecutionStatus } from "../execution/types/execution-state"; + +/** + * Returns true if the execution of the given future has succeeded. + * + * @param future The future. + * @param deploymentState The deployment state to check against. + * @returns true if it succeeded. + */ +export function hasExecutionSucceeded( + future: Future, + deploymentState: DeploymentState +): boolean { + const exState = deploymentState.executionStates[future.id]; + + if (exState === undefined) { + return false; + } + + return exState.status === ExecutionStatus.SUCCESS; +} diff --git a/packages/core/src/internal/views/is-batch-finished.ts b/packages/core/src/internal/views/is-batch-finished.ts new file mode 100644 index 000000000..e9a1d26d3 --- /dev/null +++ b/packages/core/src/internal/views/is-batch-finished.ts @@ -0,0 +1,22 @@ +import { DeploymentState } from "../execution/types/deployment-state"; +import { ExecutionStatus } from "../execution/types/execution-state"; + +/** + * Have the futures making up a batch finished executing, as defined by + * no longer being `STARTED`, so they have succeeded, failed, or timed out. + * + * @param deploymentState - the deployment state + * @param batch - the list of future ids of the futures in the batch + * @returns true if all futures in the batch have finished executing + */ +export function isBatchFinished( + deploymentState: DeploymentState, + batch: string[] +): boolean { + return batch + .map((futureId) => deploymentState.executionStates[futureId]) + .every( + (exState) => + exState !== undefined && exState.status !== ExecutionStatus.STARTED + ); +} diff --git a/packages/core/src/new-api/internal/new-execution/views/is-execution-state-complete.ts b/packages/core/src/internal/views/is-execution-state-complete.ts similarity index 81% rename from packages/core/src/new-api/internal/new-execution/views/is-execution-state-complete.ts rename to packages/core/src/internal/views/is-execution-state-complete.ts index 3b9d01a0e..962571345 100644 --- a/packages/core/src/new-api/internal/new-execution/views/is-execution-state-complete.ts +++ b/packages/core/src/internal/views/is-execution-state-complete.ts @@ -1,4 +1,7 @@ -import { ExecutionState, ExecutionStatus } from "../types/execution-state"; +import { + ExecutionState, + ExecutionStatus, +} from "../execution/types/execution-state"; /** * Determine if an execution state has reached completion, either diff --git a/packages/core/src/new-api/internal/wiper.ts b/packages/core/src/internal/wiper.ts similarity index 87% rename from packages/core/src/new-api/internal/wiper.ts rename to packages/core/src/internal/wiper.ts index 5c520cb54..f8faf7c91 100644 --- a/packages/core/src/new-api/internal/wiper.ts +++ b/packages/core/src/internal/wiper.ts @@ -1,14 +1,14 @@ -import { IgnitionError } from "../../errors"; +import { IgnitionError } from "../errors"; import { DeploymentLoader } from "./deployment-loader/types"; import { applyNewMessage, loadDeploymentState, -} from "./new-execution/deployment-state-helpers"; +} from "./execution/deployment-state-helpers"; import { JournalMessageType, WipeExecutionStateMessage, -} from "./new-execution/types/messages"; +} from "./execution/types/messages"; export class Wiper { constructor(private _deploymentLoader: DeploymentLoader) {} @@ -43,7 +43,7 @@ export class Wiper { } const wipeMessage: WipeExecutionStateMessage = { - type: JournalMessageType.WIPE_EXECUTION_STATE, + type: JournalMessageType.WIPE_APPLY, futureId, }; diff --git a/packages/core/src/new-api/internal/new-execution/views/has-execution-failed.ts b/packages/core/src/new-api/internal/new-execution/views/has-execution-failed.ts deleted file mode 100644 index 3c2daae86..000000000 --- a/packages/core/src/new-api/internal/new-execution/views/has-execution-failed.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Future } from "../../../types/module"; -import { DeploymentState } from "../types/deployment-state"; -import { ExecutionStatus } from "../types/execution-state"; - -/** - * Returns true if the execution of the given future has failed. - * - * @param future The future. - * @param deploymentState The deployment state to check against. - * @returns true if it failed. - */ -export function hasExecutionFailed( - future: Future, - deploymentState: DeploymentState -): boolean { - const exState = deploymentState.executionStates[future.id]; - if (exState === undefined) { - return false; - } - - return ( - exState.status === ExecutionStatus.FAILED || - exState.status === ExecutionStatus.TIMEOUT - ); -} diff --git a/packages/core/src/new-api/internal/validation/validateStageOne.ts b/packages/core/src/new-api/internal/validation/validateStageOne.ts deleted file mode 100644 index d291e78fa..000000000 --- a/packages/core/src/new-api/internal/validation/validateStageOne.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { ArtifactResolver } from "../../types/artifact"; -import { FutureType, IgnitionModule } from "../../types/module"; -import { getFuturesFromModule } from "../utils/get-futures-from-module"; - -import { validateArtifactContractAt } from "./stageOne/validateArtifactContractAt"; -import { validateArtifactContractDeployment } from "./stageOne/validateArtifactContractDeployment"; -import { validateArtifactLibraryDeployment } from "./stageOne/validateArtifactLibraryDeployment"; -import { validateNamedContractAt } from "./stageOne/validateNamedContractAt"; -import { validateNamedContractCall } from "./stageOne/validateNamedContractCall"; -import { validateNamedContractDeployment } from "./stageOne/validateNamedContractDeployment"; -import { validateNamedLibraryDeployment } from "./stageOne/validateNamedLibraryDeployment"; -import { validateNamedStaticCall } from "./stageOne/validateNamedStaticCall"; -import { validateReadEventArgument } from "./stageOne/validateReadEventArgument"; -import { validateSendData } from "./stageOne/validateSendData"; - -export async function validateStageOne( - module: IgnitionModule, - artifactLoader: ArtifactResolver -): Promise { - const futures = getFuturesFromModule(module); - - // originally, I wrote a getSubmodulesFromModule function similar to the one above - // that recursively retrieved all submodules regardless of how deeply nested they were. - // however, by taking only the top level submodules of the current depth and recursively - // validating each of those, we achieve the same effect. - const submodules = module.submodules; - for (const submodule of submodules) { - await validateStageOne(submodule, artifactLoader); - } - - for (const future of futures) { - switch (future.type) { - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: - await validateArtifactContractDeployment(future, artifactLoader); - break; - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: - await validateArtifactLibraryDeployment(future, artifactLoader); - break; - case FutureType.ARTIFACT_CONTRACT_AT: - await validateArtifactContractAt(future, artifactLoader); - break; - case FutureType.NAMED_CONTRACT_DEPLOYMENT: - await validateNamedContractDeployment(future, artifactLoader); - break; - case FutureType.NAMED_LIBRARY_DEPLOYMENT: - await validateNamedLibraryDeployment(future, artifactLoader); - break; - case FutureType.NAMED_CONTRACT_AT: - await validateNamedContractAt(future, artifactLoader); - break; - case FutureType.NAMED_CONTRACT_CALL: - await validateNamedContractCall(future, artifactLoader); - break; - case FutureType.NAMED_STATIC_CALL: - await validateNamedStaticCall(future, artifactLoader); - break; - case FutureType.READ_EVENT_ARGUMENT: - await validateReadEventArgument(future, artifactLoader); - break; - case FutureType.SEND_DATA: - await validateSendData(future, artifactLoader); - break; - } - } -} diff --git a/packages/core/src/new-api/plan.ts b/packages/core/src/new-api/plan.ts deleted file mode 100644 index ffc88a550..000000000 --- a/packages/core/src/new-api/plan.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { - SerializedStoredDeployment, - StoredDeployment, - StoredDeploymentSerializer, -} from "../ui-helpers"; - -import { validateStageOne } from "./internal/validation/validateStageOne"; -import { ArtifactResolver } from "./types/artifact"; - -/** - * Serialize an IgnitionModule for displaying to the user - * - * @beta - */ -export async function plan({ - artifactResolver, - storedDeployment, -}: { - artifactResolver: ArtifactResolver; - storedDeployment: StoredDeployment; -}): Promise { - await validateStageOne(storedDeployment.module, artifactResolver); - - return StoredDeploymentSerializer.serialize(storedDeployment); -} diff --git a/packages/core/src/new-api/type-guards.ts b/packages/core/src/type-guards.ts similarity index 72% rename from packages/core/src/new-api/type-guards.ts rename to packages/core/src/type-guards.ts index d9eda251a..eec1dc584 100644 --- a/packages/core/src/new-api/type-guards.ts +++ b/packages/core/src/type-guards.ts @@ -2,19 +2,20 @@ import { Artifact } from "./types/artifact"; import { AccountRuntimeValue, AddressResolvableFuture, - ArtifactContractAtFuture, - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, + ContractAtFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, + CallableContractFuture, ContractFuture, DeploymentFuture, FunctionCallFuture, Future, FutureType, ModuleParameterRuntimeValue, - NamedContractAtFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, - NamedStaticCallFuture, + NamedArtifactContractAtFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, + StaticCallFuture, ReadEventArgumentFuture, RuntimeValue, RuntimeValueType, @@ -89,12 +90,32 @@ export function isContractFuture( future: Future ): future is ContractFuture { switch (future.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: - case FutureType.NAMED_LIBRARY_DEPLOYMENT: - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: - case FutureType.NAMED_CONTRACT_AT: - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: + return true; + + default: + return false; + } +} + +/** + * Returns true if future is of type CallableContractFuture. + * + * @beta + */ +export function isCallableContractFuture( + future: Future +): future is CallableContractFuture { + switch (future.type) { + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: return true; default: @@ -112,7 +133,7 @@ export function isAddressResolvableFuture( ): future is AddressResolvableFuture { return ( isContractFuture(future) || - future.type === FutureType.NAMED_STATIC_CALL || + future.type === FutureType.STATIC_CALL || future.type === FutureType.READ_EVENT_ARGUMENT ); } @@ -126,8 +147,8 @@ export function isFunctionCallFuture( future: Future ): future is FunctionCallFuture { return ( - future.type === FutureType.NAMED_CONTRACT_CALL || - future.type === FutureType.NAMED_STATIC_CALL + future.type === FutureType.CONTRACT_CALL || + future.type === FutureType.STATIC_CALL ); } @@ -138,8 +159,8 @@ export function isFunctionCallFuture( */ export function isNamedStaticCallFuture( future: Future -): future is NamedStaticCallFuture { - return future.type === FutureType.NAMED_STATIC_CALL; +): future is StaticCallFuture { + return future.type === FutureType.STATIC_CALL; } /** @@ -149,7 +170,7 @@ export function isNamedStaticCallFuture( */ export function isReadEventArgumentFuture( future: Future -): future is NamedStaticCallFuture { +): future is StaticCallFuture { return future.type === FutureType.READ_EVENT_ARGUMENT; } @@ -160,8 +181,8 @@ export function isReadEventArgumentFuture( */ export function isNamedContractDeploymentFuture( future: Future -): future is NamedContractDeploymentFuture { - return future.type === FutureType.NAMED_CONTRACT_DEPLOYMENT; +): future is NamedArtifactContractDeploymentFuture { + return future.type === FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT; } /** @@ -171,8 +192,8 @@ export function isNamedContractDeploymentFuture( */ export function isArtifactContractDeploymentFuture( future: Future -): future is ArtifactContractDeploymentFuture { - return future.type === FutureType.ARTIFACT_CONTRACT_DEPLOYMENT; +): future is ContractDeploymentFuture { + return future.type === FutureType.CONTRACT_DEPLOYMENT; } /** @@ -182,8 +203,8 @@ export function isArtifactContractDeploymentFuture( */ export function isNamedLibraryDeploymentFuture( future: Future -): future is NamedLibraryDeploymentFuture { - return future.type === FutureType.NAMED_LIBRARY_DEPLOYMENT; +): future is NamedArtifactLibraryDeploymentFuture { + return future.type === FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT; } /** @@ -193,8 +214,8 @@ export function isNamedLibraryDeploymentFuture( */ export function isArtifactLibraryDeploymentFuture( future: Future -): future is ArtifactLibraryDeploymentFuture { - return future.type === FutureType.ARTIFACT_LIBRARY_DEPLOYMENT; +): future is LibraryDeploymentFuture { + return future.type === FutureType.LIBRARY_DEPLOYMENT; } /** @@ -204,8 +225,8 @@ export function isArtifactLibraryDeploymentFuture( */ export function isNamedContractAtFuture( future: Future -): future is NamedContractAtFuture { - return future.type === FutureType.NAMED_CONTRACT_AT; +): future is NamedArtifactContractAtFuture { + return future.type === FutureType.NAMED_ARTIFACT_CONTRACT_AT; } /** @@ -215,8 +236,8 @@ export function isNamedContractAtFuture( */ export function isArtifactContractAtFuture( future: Future -): future is ArtifactContractAtFuture { - return future.type === FutureType.ARTIFACT_CONTRACT_AT; +): future is ContractAtFuture { + return future.type === FutureType.CONTRACT_AT; } /** @@ -228,10 +249,10 @@ export function isDeploymentType( potential: unknown ): potential is DeploymentFuture["type"] { const deploymentTypes = [ - FutureType.NAMED_CONTRACT_DEPLOYMENT, - FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, - FutureType.NAMED_LIBRARY_DEPLOYMENT, - FutureType.ARTIFACT_LIBRARY_DEPLOYMENT, + FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, + FutureType.CONTRACT_DEPLOYMENT, + FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, + FutureType.LIBRARY_DEPLOYMENT, ]; return ( @@ -261,12 +282,12 @@ export function isFutureThatSubmitsOnchainTransaction( ): f is Exclude< Exclude< Exclude< - Exclude>, + Exclude>, ReadEventArgumentFuture >, - NamedContractAtFuture + NamedArtifactContractAtFuture >, - ArtifactContractAtFuture + ContractAtFuture > { return ( !isNamedStaticCallFuture(f) && diff --git a/packages/core/src/new-api/types/artifact.ts b/packages/core/src/types/artifact.ts similarity index 100% rename from packages/core/src/new-api/types/artifact.ts rename to packages/core/src/types/artifact.ts diff --git a/packages/core/src/new-api/types/deploy.ts b/packages/core/src/types/deploy.ts similarity index 74% rename from packages/core/src/new-api/types/deploy.ts rename to packages/core/src/types/deploy.ts index 4178ab76e..26544f632 100644 --- a/packages/core/src/new-api/types/deploy.ts +++ b/packages/core/src/types/deploy.ts @@ -42,6 +42,7 @@ export type DeploymentResult< | ValidationErrorDeploymentResult | ReconciliationErrorDeploymentResult | ExecutionErrorDeploymentResult + | PreviousRunErrorDeploymentResult | SuccessfulDeploymentResult; /** @@ -66,6 +67,11 @@ export enum DeploymentResultType { */ EXECUTION_ERROR = "EXECUTION_ERROR", + /** + * One or more futures from a previous run failed or timed out. + */ + PREVIOUS_RUN_ERROR = "PREVIOUS_RUN_ERROR", + /** * The entire deployment was successful. */ @@ -114,22 +120,32 @@ export interface ExecutionErrorDeploymentResult { type: DeploymentResultType.EXECUTION_ERROR; /** - * A list of all the future that have started executed but have not + * A list of all the futures that have started executing but have not * finished, neither successfully nor unsuccessfully. */ started: string[]; /** - * A list of all the future that have timed out and the id of the execution - * that timed out. + * A list of all the futures that have timed out, including details of the + * network interaction that timed out. */ - timedOut: Array<{ futureId: string; executionId: number }>; + timedOut: Array<{ futureId: string; networkInteractionId: number }>; /** - * A list of all the future that have failed and the id of the execution - * that failed, and a string explaining the failure. + * A list of all the futures that are being Held as determined by the execution + * strategy, i.e. an off-chain process is not yet complete. */ - failed: Array<{ futureId: string; executionId: number; error: string }>; + held: Array<{ futureId: string; heldId: number; reason: string }>; + + /** + * A list of all the future that have failed, including the details of + * the network interaction that errored. + */ + failed: Array<{ + futureId: string; + networkInteractionId: number; + error: string; + }>; /** * A list with the id of all the future that have successfully executed. @@ -137,6 +153,23 @@ export interface ExecutionErrorDeploymentResult { successful: string[]; } +/** + * A deployment result where one or more futures from a previous run failed or timed out + * and need their state wiped. + * + * @beta + */ +export interface PreviousRunErrorDeploymentResult { + type: DeploymentResultType.PREVIOUS_RUN_ERROR; + + /** + * A map from future id to a list of all of its previous run errors. + */ + errors: { + [futureId: string]: string[]; + }; +} + /** * A deployment result where all of the futures of the module have completed * successfully. diff --git a/packages/core/src/types/execution-events.ts b/packages/core/src/types/execution-events.ts new file mode 100644 index 000000000..a29d6f2c9 --- /dev/null +++ b/packages/core/src/types/execution-events.ts @@ -0,0 +1,459 @@ +import { DeploymentResult } from "./deploy"; +import { IgnitionModuleResult } from "./module"; + +/** + * Events emitted by the execution engine to allow tracking + * progress of a deploy. + * + * @beta + */ +export type ExecutionEvent = + | RunStartEvent + | WipeApplyEvent + | DeploymentExecutionStateInitializeEvent + | DeploymentExecutionStateCompleteEvent + | CallExecutionStateInitializeEvent + | CallExecutionStateCompleteEvent + | StaticCallExecutionStateInitializeEvent + | StaticCallExecutionStateCompleteEvent + | SendDataExecutionStateInitializeEvent + | SendDataExecutionStateCompleteEvent + | ContractAtExecutionStateInitializeEvent + | ReadEventArgExecutionStateInitializeEvent + | NetworkInteractionRequestEvent + | TransactionSendEvent + | TransactionConfirmEvent + | StaticCallCompleteEvent + | OnchainInteractionBumpFeesEvent + | OnchainInteractionDroppedEvent + | OnchainInteractionReplacedByUserEvent + | OnchainInteractionTimeoutEvent + | BatchInitializeEvent + | DeploymentStartEvent + | BeginNextBatchEvent + | SetModuleIdEvent; + +/** + * The types of diagnostic events emitted during a deploy. + * + * @beta + */ +export enum ExecutionEventType { + RUN_START = "RUN_START", + WIPE_APPLY = "WIPE_APPLY", + DEPLOYMENT_EXECUTION_STATE_INITIALIZE = "DEPLOYMENT_EXECUTION_STATE_INITIALIZE", + DEPLOYMENT_EXECUTION_STATE_COMPLETE = "DEPLOYMENT_EXECUTION_STATE_COMPLETE", + CALL_EXECUTION_STATE_INITIALIZE = "CALL_EXECUTION_STATE_INITIALIZE", + CALL_EXECUTION_STATE_COMPLETE = "CALL_EXECUTION_STATE_COMPLETE", + STATIC_CALL_EXECUTION_STATE_INITIALIZE = "STATIC_CALL_EXECUTION_STATE_INITIALIZE", + STATIC_CALL_EXECUTION_STATE_COMPLETE = "STATIC_CALL_EXECUTION_STATE_COMPLETE", + SEND_DATA_EXECUTION_STATE_INITIALIZE = "SEND_DATA_EXECUTION_STATE_INITIALIZE", + SEND_DATA_EXECUTION_STATE_COMPLETE = "SEND_DATA_EXECUTION_STATE_COMPLETE", + CONTRACT_AT_EXECUTION_STATE_INITIALIZE = "CONTRACT_AT_EXECUTION_STATE_INITIALIZE", + READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE = "READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE", + NETWORK_INTERACTION_REQUEST = "NETWORK_INTERACTION_REQUEST", + TRANSACTION_SEND = "TRANSACTION_SEND", + TRANSACTION_CONFIRM = "TRANSACTION_CONFIRM", + STATIC_CALL_COMPLETE = "STATIC_CALL_COMPLETE", + ONCHAIN_INTERACTION_BUMP_FEES = "ONCHAIN_INTERACTION_BUMP_FEES", + ONCHAIN_INTERACTION_DROPPED = "ONCHAIN_INTERACTION_DROPPED", + ONCHAIN_INTERACTION_REPLACED_BY_USER = "ONCHAIN_INTERACTION_REPLACED_BY_USER", + ONCHAIN_INTERACTION_TIMEOUT = "ONCHAIN_INTERACTION_TIMEOUT", + BATCH_INITIALIZE = "BATCH_INITIALIZE", + DEPLOYMENT_START = "DEPLOYMENT_START", + BEGIN_NEXT_BATCH = "BEGIN_NEXT_BATCH", + DEPLOYMENT_COMPLETE = "DEPLOYMENT_COMPLETE", + SET_MODULE_ID = "SET_MODULE_ID", +} + +/** + * An event indicating that a deployment has started. + * + * @beta + */ +export interface DeploymentStartEvent { + type: ExecutionEventType.DEPLOYMENT_START; + moduleName: string; +} + +/** + * An event indicating a new run has started. + * + * @beta + */ +export interface RunStartEvent { + type: ExecutionEventType.RUN_START; + chainId: number; +} + +/** + * An event indicating that batches have been generated for a deployment run. + * + * @beta + */ +export interface BatchInitializeEvent { + type: ExecutionEventType.BATCH_INITIALIZE; + batches: string[][]; +} + +/** + * An event indicating that the execution engine has moved onto + * the next batch. + * + * @beta + */ +export interface BeginNextBatchEvent { + type: ExecutionEventType.BEGIN_NEXT_BATCH; +} + +/** + * An event indicating that a deployment has started. + * + * @beta + */ +export interface DeploymentCompleteEvent { + type: ExecutionEventType.DEPLOYMENT_COMPLETE; + result: DeploymentResult>; +} + +/** + * An event indicating a future that deploys a contract + * or library has started execution. + * + * @beta + */ +export interface DeploymentExecutionStateInitializeEvent { + type: ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE; + futureId: string; +} + +/** + * An event indicating that a future that deploys a contract + * or library has completed execution. + * + * @beta + */ +export interface DeploymentExecutionStateCompleteEvent { + type: ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_COMPLETE; + futureId: string; + result: ExecutionEventResult; +} + +/** + * An event indicating a future that calls a function onchain + * via transactions has started execution. + * + * @beta + */ +export interface CallExecutionStateInitializeEvent { + type: ExecutionEventType.CALL_EXECUTION_STATE_INITIALIZE; + futureId: string; +} + +/** + * An event indicating a future that calls a function onchain + * via transactions has completed execution. + * + * @beta + */ +export interface CallExecutionStateCompleteEvent { + type: ExecutionEventType.CALL_EXECUTION_STATE_COMPLETE; + futureId: string; + result: ExecutionEventResult; +} + +/** + * An event indicating that a future that makes a static call + * has started execution. + * + * @beta + */ +export interface StaticCallExecutionStateInitializeEvent { + type: ExecutionEventType.STATIC_CALL_EXECUTION_STATE_INITIALIZE; + futureId: string; +} + +/** + * An event indicating that a future that makes a static call + * has completed execution. + * + * @beta + */ +export interface StaticCallExecutionStateCompleteEvent { + type: ExecutionEventType.STATIC_CALL_EXECUTION_STATE_COMPLETE; + futureId: string; + result: ExecutionEventResult; +} + +/** + * An event indicationing that a future that sends data or eth to a contract + * has started execution. + * + * @beta + */ +export interface SendDataExecutionStateInitializeEvent { + type: ExecutionEventType.SEND_DATA_EXECUTION_STATE_INITIALIZE; + futureId: string; +} + +/** + * An event indicationing that a future that sends data or eth to a contract + * has completed execution. + * + * @beta + */ +export interface SendDataExecutionStateCompleteEvent { + type: ExecutionEventType.SEND_DATA_EXECUTION_STATE_COMPLETE; + futureId: string; + result: ExecutionEventResult; +} + +/** + * An event indicating that a future that represents an existing contract + * has been initialized, there is no complete event as it initializes + * as complete. + * + * @beta + */ +export interface ContractAtExecutionStateInitializeEvent { + type: ExecutionEventType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE; + futureId: string; +} + +/** + * An event indicating that a future that represents resolving an event + * from a previous futures onchain interaction, there is no complete event + * as it initializes as complete. + * + * @beta + */ +export interface ReadEventArgExecutionStateInitializeEvent { + type: ExecutionEventType.READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE; + futureId: string; + result: ExecutionEventSuccess; +} + +/** + * An event indicating the user has clear the previous execution of a future. + * + * @beta + */ +export interface WipeApplyEvent { + type: ExecutionEventType.WIPE_APPLY; + futureId: string; +} + +/** + * An event indicating that a future has requested a network interaction, + * either a transaction or a static call query. + * + * @beta + */ +export interface NetworkInteractionRequestEvent { + type: ExecutionEventType.NETWORK_INTERACTION_REQUEST; + networkInteractionType: ExecutionEventNetworkInteractionType; + futureId: string; +} + +/** + * An event indicating that a transaction has been sent to the network. + * + * @beta + */ +export interface TransactionSendEvent { + type: ExecutionEventType.TRANSACTION_SEND; + futureId: string; + hash: string; +} + +/** + * An event indicating has been detected as confirmed on-chain. + * + * @beta + */ +export interface TransactionConfirmEvent { + type: ExecutionEventType.TRANSACTION_CONFIRM; + futureId: string; + hash: string; +} + +/** + * An event indicating that a static call has been successfully run + * against the chain. + * + * @beta + */ +export interface StaticCallCompleteEvent { + type: ExecutionEventType.STATIC_CALL_COMPLETE; + futureId: string; +} + +/** + * An event indicating that a future's onchain interaction has had + * its its latest transaction fee bumped. + * + * @beta + */ +export interface OnchainInteractionBumpFeesEvent { + type: ExecutionEventType.ONCHAIN_INTERACTION_BUMP_FEES; + futureId: string; +} + +/** + * An event indicating that a future's onchain interaction has + * had its transaction dropped and will be resent. + * + * @beta + */ +export interface OnchainInteractionDroppedEvent { + type: ExecutionEventType.ONCHAIN_INTERACTION_DROPPED; + futureId: string; +} + +/** + * An event indicating that a future's onchain interaction has + * been replaced by a transaction from the user. + * + * @beta + */ +export interface OnchainInteractionReplacedByUserEvent { + type: ExecutionEventType.ONCHAIN_INTERACTION_REPLACED_BY_USER; + futureId: string; +} + +/** + * An event indicating that a future's onchain interaction has + * timed out. + * + * @beta + */ +export interface OnchainInteractionTimeoutEvent { + type: ExecutionEventType.ONCHAIN_INTERACTION_TIMEOUT; + futureId: string; +} + +/** + * An event indicating the current moduleId being validated. + * + * @beta + */ +export interface SetModuleIdEvent { + type: ExecutionEventType.SET_MODULE_ID; + moduleName: string; +} + +/** + * The types of network interactions that can be requested by a future. + * + * @beta + */ +export enum ExecutionEventNetworkInteractionType { + ONCHAIN_INTERACTION = "ONCHAIN_INTERACTION", + STATIC_CALL = "STATIC_CALL", +} + +/** + * The status of a future's completed execution. + * + * @beta + */ +export enum ExecutionEventResultType { + SUCCESS = "SUCCESS", + ERROR = "ERROR", + HELD = "HELD", +} + +/** + * The result of a future's completed execution. + * + * @beta + */ +export type ExecutionEventResult = + | ExecutionEventSuccess + | ExecutionEventError + | ExecutionEventHeld; + +/** + * A successful result of a future's execution. + * + * @beta + */ +export interface ExecutionEventSuccess { + type: ExecutionEventResultType.SUCCESS; + result?: string; +} + +/** + * An errored result of a future's execution. + * + * @beta + */ +export interface ExecutionEventError { + type: ExecutionEventResultType.ERROR; + error: string; +} + +/** + * A hold result of a future's execution. + * + * @beta + */ +export interface ExecutionEventHeld { + type: ExecutionEventResultType.HELD; + heldId: number; + reason: string; +} + +/** + * A mapping of execution event types to their corresponding event. + * + * @beta + */ +export interface ExecutionEventTypeMap { + [ExecutionEventType.RUN_START]: RunStartEvent; + [ExecutionEventType.WIPE_APPLY]: WipeApplyEvent; + [ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE]: DeploymentExecutionStateInitializeEvent; + [ExecutionEventType.DEPLOYMENT_EXECUTION_STATE_COMPLETE]: DeploymentExecutionStateCompleteEvent; + [ExecutionEventType.CALL_EXECUTION_STATE_INITIALIZE]: CallExecutionStateInitializeEvent; + [ExecutionEventType.CALL_EXECUTION_STATE_COMPLETE]: CallExecutionStateCompleteEvent; + [ExecutionEventType.STATIC_CALL_EXECUTION_STATE_INITIALIZE]: StaticCallExecutionStateInitializeEvent; + [ExecutionEventType.STATIC_CALL_EXECUTION_STATE_COMPLETE]: StaticCallExecutionStateCompleteEvent; + [ExecutionEventType.SEND_DATA_EXECUTION_STATE_INITIALIZE]: SendDataExecutionStateInitializeEvent; + [ExecutionEventType.SEND_DATA_EXECUTION_STATE_COMPLETE]: SendDataExecutionStateCompleteEvent; + [ExecutionEventType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE]: ContractAtExecutionStateInitializeEvent; + [ExecutionEventType.READ_EVENT_ARGUMENT_EXECUTION_STATE_INITIALIZE]: ReadEventArgExecutionStateInitializeEvent; + [ExecutionEventType.NETWORK_INTERACTION_REQUEST]: NetworkInteractionRequestEvent; + [ExecutionEventType.TRANSACTION_SEND]: TransactionSendEvent; + [ExecutionEventType.TRANSACTION_CONFIRM]: TransactionConfirmEvent; + [ExecutionEventType.STATIC_CALL_COMPLETE]: StaticCallCompleteEvent; + [ExecutionEventType.ONCHAIN_INTERACTION_BUMP_FEES]: OnchainInteractionBumpFeesEvent; + [ExecutionEventType.ONCHAIN_INTERACTION_DROPPED]: OnchainInteractionDroppedEvent; + [ExecutionEventType.ONCHAIN_INTERACTION_REPLACED_BY_USER]: OnchainInteractionReplacedByUserEvent; + [ExecutionEventType.ONCHAIN_INTERACTION_TIMEOUT]: OnchainInteractionTimeoutEvent; + [ExecutionEventType.BATCH_INITIALIZE]: BatchInitializeEvent; + [ExecutionEventType.DEPLOYMENT_START]: DeploymentStartEvent; + [ExecutionEventType.BEGIN_NEXT_BATCH]: BeginNextBatchEvent; + [ExecutionEventType.DEPLOYMENT_COMPLETE]: DeploymentCompleteEvent; + [ExecutionEventType.SET_MODULE_ID]: SetModuleIdEvent; +} + +/** + * A utility type for mapping enum values to function names + * + * @beta + */ +export type SnakeToCamelCase = + S extends `${infer T}_${infer U}` + ? `${Lowercase}${Capitalize>>}` + : S; + +/** + * A listener for execution events. + * + * @beta + */ +export type ExecutionEventListener = { + [eventType in ExecutionEventType as SnakeToCamelCase]: ( + event: ExecutionEventTypeMap[eventType] + ) => void; +}; diff --git a/packages/core/src/new-api/types/module-builder.ts b/packages/core/src/types/module-builder.ts similarity index 71% rename from packages/core/src/new-api/types/module-builder.ts rename to packages/core/src/types/module-builder.ts index 8a1163611..b24d5fea2 100644 --- a/packages/core/src/new-api/types/module-builder.ts +++ b/packages/core/src/types/module-builder.ts @@ -3,26 +3,27 @@ import { AccountRuntimeValue, AddressResolvableFuture, ArgumentType, - ArtifactContractAtFuture, - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, + ContractAtFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, + CallableContractFuture, ContractFuture, Future, IgnitionModule, IgnitionModuleResult, ModuleParameterRuntimeValue, ModuleParameterType, - NamedContractAtFuture, - NamedContractCallFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, - NamedStaticCallFuture, + NamedArtifactContractAtFuture, + ContractCallFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, + StaticCallFuture, ReadEventArgumentFuture, SendDataFuture, } from "./module"; /** - * The options for a `ContractOptions` call. + * The options for a `contract` call. * * @beta */ @@ -34,19 +35,6 @@ export interface ContractOptions { from?: string | AccountRuntimeValue; } -/** - * The options for a `contractFromArtifact` call. - * - * @beta - */ -export interface ContractFromArtifactOptions { - id?: string; - after?: Future[]; - libraries?: Record>; - value?: bigint | ModuleParameterRuntimeValue; - from?: string | AccountRuntimeValue; -} - /** * The options for a `library` call. * @@ -59,18 +47,6 @@ export interface LibraryOptions { from?: string | AccountRuntimeValue; } -/** - * The options for a `libraryFromArtifact` call. - * - * @beta - */ -export interface LibraryFromArtifactOptions { - id?: string; - after?: Future[]; - libraries?: Record>; - from?: string | AccountRuntimeValue; -} - /** * The options for a `call` call. * @@ -134,7 +110,6 @@ export interface ReadEventArgumentOptions { * @beta */ export interface SendDataOptions { - id?: string; after?: Future[]; from?: string | AccountRuntimeValue; } @@ -156,39 +131,40 @@ export interface IgnitionModuleBuilder { contractName: ContractNameT, args?: ArgumentType[], options?: ContractOptions - ): NamedContractDeploymentFuture; + ): NamedArtifactContractDeploymentFuture; - contractFromArtifact( + contract( contractName: string, artifact: Artifact, args?: ArgumentType[], - options?: ContractFromArtifactOptions - ): ArtifactContractDeploymentFuture; + options?: ContractOptions + ): ContractDeploymentFuture; library( libraryName: LibraryNameT, options?: LibraryOptions - ): NamedLibraryDeploymentFuture; + ): NamedArtifactLibraryDeploymentFuture; - libraryFromArtifact( + library( libraryName: string, artifact: Artifact, - options?: LibraryFromArtifactOptions - ): ArtifactLibraryDeploymentFuture; + options?: LibraryOptions + ): LibraryDeploymentFuture; call( - contractFuture: ContractFuture, + contractFuture: CallableContractFuture, functionName: FunctionNameT, args?: ArgumentType[], options?: CallOptions - ): NamedContractCallFuture; + ): ContractCallFuture; staticCall( - contractFuture: ContractFuture, + contractFuture: CallableContractFuture, functionName: FunctionNameT, args?: ArgumentType[], + nameOrIndex?: string | number, options?: StaticCallOptions - ): NamedStaticCallFuture; + ): StaticCallFuture; contractAt( contractName: ContractNameT, @@ -197,9 +173,9 @@ export interface IgnitionModuleBuilder { | AddressResolvableFuture | ModuleParameterRuntimeValue, options?: ContractAtOptions - ): NamedContractAtFuture; + ): NamedArtifactContractAtFuture; - contractAtFromArtifact( + contractAt( contractName: string, address: | string @@ -207,15 +183,16 @@ export interface IgnitionModuleBuilder { | ModuleParameterRuntimeValue, artifact: Artifact, options?: ContractAtOptions - ): ArtifactContractAtFuture; + ): ContractAtFuture; readEventArgument( futureToReadFrom: - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedContractCallFuture, + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | SendDataFuture + | ContractCallFuture, eventName: string, - argumentName: string, + nameOrIndex: string | number, options?: ReadEventArgumentOptions ): ReadEventArgumentFuture; diff --git a/packages/core/src/new-api/types/module.ts b/packages/core/src/types/module.ts similarity index 74% rename from packages/core/src/new-api/types/module.ts rename to packages/core/src/types/module.ts index 0f35810e5..70b45a490 100644 --- a/packages/core/src/new-api/types/module.ts +++ b/packages/core/src/types/module.ts @@ -12,7 +12,7 @@ export type BaseArgumentType = | string | boolean | ContractFuture - | NamedStaticCallFuture + | StaticCallFuture | ReadEventArgumentFuture | RuntimeValue; @@ -32,14 +32,14 @@ export type ArgumentType = * @beta */ export enum FutureType { - NAMED_CONTRACT_DEPLOYMENT = "NAMED_CONTRACT_DEPLOYMENT", - ARTIFACT_CONTRACT_DEPLOYMENT = "ARTIFACT_CONTRACT_DEPLOYMENT", - NAMED_LIBRARY_DEPLOYMENT = "NAMED_LIBRARY_DEPLOYMENT", - ARTIFACT_LIBRARY_DEPLOYMENT = "ARTIFACT_LIBRARY_DEPLOYMENT", - NAMED_CONTRACT_CALL = "NAMED_CONTRACT_CALL", - NAMED_STATIC_CALL = "NAMED_STATIC_CALL", - NAMED_CONTRACT_AT = "NAMED_CONTRACT_AT", - ARTIFACT_CONTRACT_AT = "ARTIFACT_CONTRACT_AT", + NAMED_ARTIFACT_CONTRACT_DEPLOYMENT = "NAMED_ARTIFACT_CONTRACT_DEPLOYMENT", + CONTRACT_DEPLOYMENT = "CONTRACT_DEPLOYMENT", + NAMED_ARTIFACT_LIBRARY_DEPLOYMENT = "NAMED_ARTIFACT_LIBRARY_DEPLOYMENT", + LIBRARY_DEPLOYMENT = "LIBRARY_DEPLOYMENT", + CONTRACT_CALL = "CONTRACT_CALL", + STATIC_CALL = "STATIC_CALL", + NAMED_ARTIFACT_CONTRACT_AT = "NAMED_ARTIFACT_CONTRACT_AT", + CONTRACT_AT = "CONTRACT_AT", READ_EVENT_ARGUMENT = "READ_EVENT_ARGUMENT", SEND_DATA = "SEND_DATA", } @@ -50,14 +50,14 @@ export enum FutureType { * @beta */ export type Future = - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedLibraryDeploymentFuture - | ArtifactLibraryDeploymentFuture - | NamedContractCallFuture - | NamedStaticCallFuture - | NamedContractAtFuture - | ArtifactContractAtFuture + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | NamedArtifactLibraryDeploymentFuture + | LibraryDeploymentFuture + | ContractCallFuture + | StaticCallFuture + | NamedArtifactContractAtFuture + | ContractAtFuture | ReadEventArgumentFuture | SendDataFuture; @@ -68,12 +68,24 @@ export type Future = * @beta */ export type ContractFuture = - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedLibraryDeploymentFuture - | ArtifactLibraryDeploymentFuture - | NamedContractAtFuture - | ArtifactContractAtFuture; + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | NamedArtifactLibraryDeploymentFuture + | LibraryDeploymentFuture + | NamedArtifactContractAtFuture + | ContractAtFuture; + +/** + * A future representing only contracts that can be called off-chain (i.e. not libraries). + * Either an existing one or one that will be deployed. + * + * @beta + */ +export type CallableContractFuture = + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | NamedArtifactContractAtFuture + | ContractAtFuture; /** * A future representing a deployment. @@ -81,10 +93,10 @@ export type ContractFuture = * @beta */ export type DeploymentFuture = - | NamedContractDeploymentFuture - | ArtifactContractDeploymentFuture - | NamedLibraryDeploymentFuture - | ArtifactLibraryDeploymentFuture; + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | NamedArtifactLibraryDeploymentFuture + | LibraryDeploymentFuture; /** * A future representing a call. Either a static one or one that modifies contract state @@ -95,8 +107,8 @@ export type FunctionCallFuture< ContractNameT extends string, FunctionNameT extends string > = - | NamedContractCallFuture - | NamedStaticCallFuture; + | ContractCallFuture + | StaticCallFuture; /** * A future that can be resolved to a standard Ethereum address. @@ -105,7 +117,7 @@ export type FunctionCallFuture< */ export type AddressResolvableFuture = | ContractFuture - | NamedStaticCallFuture + | StaticCallFuture | ReadEventArgumentFuture; /** @@ -113,8 +125,10 @@ export type AddressResolvableFuture = * * @beta */ -export interface NamedContractDeploymentFuture { - type: FutureType.NAMED_CONTRACT_DEPLOYMENT; +export interface NamedArtifactContractDeploymentFuture< + ContractNameT extends string +> { + type: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT; id: string; module: IgnitionModule; dependencies: Set; @@ -131,8 +145,8 @@ export interface NamedContractDeploymentFuture { * * @beta */ -export interface ArtifactContractDeploymentFuture { - type: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT; +export interface ContractDeploymentFuture { + type: FutureType.CONTRACT_DEPLOYMENT; id: string; module: IgnitionModule; dependencies: Set; @@ -149,8 +163,10 @@ export interface ArtifactContractDeploymentFuture { * * @beta */ -export interface NamedLibraryDeploymentFuture { - type: FutureType.NAMED_LIBRARY_DEPLOYMENT; +export interface NamedArtifactLibraryDeploymentFuture< + LibraryNameT extends string +> { + type: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT; id: string; module: IgnitionModule; dependencies: Set; @@ -165,8 +181,8 @@ export interface NamedLibraryDeploymentFuture { * * @beta */ -export interface ArtifactLibraryDeploymentFuture { - type: FutureType.ARTIFACT_LIBRARY_DEPLOYMENT; +export interface LibraryDeploymentFuture { + type: FutureType.LIBRARY_DEPLOYMENT; id: string; module: IgnitionModule; dependencies: Set; @@ -181,11 +197,11 @@ export interface ArtifactLibraryDeploymentFuture { * * @beta */ -export interface NamedContractCallFuture< +export interface ContractCallFuture< ContractNameT extends string, FunctionNameT extends string > { - type: FutureType.NAMED_CONTRACT_CALL; + type: FutureType.CONTRACT_CALL; id: string; module: IgnitionModule; dependencies: Set; @@ -201,16 +217,17 @@ export interface NamedContractCallFuture< * * @beta */ -export interface NamedStaticCallFuture< +export interface StaticCallFuture< ContractNameT extends string, FunctionNameT extends string > { - type: FutureType.NAMED_STATIC_CALL; + type: FutureType.STATIC_CALL; id: string; module: IgnitionModule; dependencies: Set; contract: ContractFuture; functionName: FunctionNameT; + nameOrIndex: string | number; args: ArgumentType[]; from: string | AccountRuntimeValue | undefined; } @@ -220,8 +237,8 @@ export interface NamedStaticCallFuture< * * @beta */ -export interface NamedContractAtFuture { - type: FutureType.NAMED_CONTRACT_AT; +export interface NamedArtifactContractAtFuture { + type: FutureType.NAMED_ARTIFACT_CONTRACT_AT; id: string; module: IgnitionModule; dependencies: Set; @@ -238,8 +255,8 @@ export interface NamedContractAtFuture { * * @beta */ -export interface ArtifactContractAtFuture { - type: FutureType.ARTIFACT_CONTRACT_AT; +export interface ContractAtFuture { + type: FutureType.CONTRACT_AT; id: string; module: IgnitionModule; dependencies: Set; @@ -262,9 +279,13 @@ export interface ReadEventArgumentFuture { id: string; module: IgnitionModule; dependencies: Set; - futureToReadFrom: Future; + futureToReadFrom: + | NamedArtifactContractDeploymentFuture + | ContractDeploymentFuture + | SendDataFuture + | ContractCallFuture; eventName: string; - argumentName: string; + nameOrIndex: string | number; emitter: ContractFuture; eventIndex: number; } diff --git a/packages/core/src/new-api/types/provider.ts b/packages/core/src/types/provider.ts similarity index 100% rename from packages/core/src/new-api/types/provider.ts rename to packages/core/src/types/provider.ts diff --git a/packages/core/src/new-api/types/serialized-deployment.ts b/packages/core/src/types/serialization.ts similarity index 79% rename from packages/core/src/new-api/types/serialized-deployment.ts rename to packages/core/src/types/serialization.ts index ff8dc7cf5..26fd30bbd 100644 --- a/packages/core/src/new-api/types/serialized-deployment.ts +++ b/packages/core/src/types/serialization.ts @@ -1,5 +1,5 @@ import { Artifact } from "./artifact"; -import { FutureType, IgnitionModule, IgnitionModuleResult } from "./module"; +import { FutureType } from "./module"; /** * A serialized bigint. @@ -75,7 +75,7 @@ export interface BaseSerializedFuture { */ export interface SerializedNamedContractDeploymentFuture extends BaseSerializedFuture { - type: FutureType.NAMED_CONTRACT_DEPLOYMENT; + type: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT; contractName: string; constructorArgs: SerializedArgumentType[]; libraries: SerializedLibraries; @@ -90,7 +90,7 @@ export interface SerializedNamedContractDeploymentFuture */ export interface SerializedArtifactContractDeploymentFuture extends BaseSerializedFuture { - type: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT; + type: FutureType.CONTRACT_DEPLOYMENT; contractName: string; constructorArgs: SerializedArgumentType[]; artifact: Artifact; @@ -106,7 +106,7 @@ export interface SerializedArtifactContractDeploymentFuture */ export interface SerializedNamedLibraryDeploymentFuture extends BaseSerializedFuture { - type: FutureType.NAMED_LIBRARY_DEPLOYMENT; + type: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT; contractName: string; libraries: SerializedLibraries; from: string | SerializedAccountRuntimeValue | undefined; @@ -119,7 +119,7 @@ export interface SerializedNamedLibraryDeploymentFuture */ export interface SerializedArtifactLibraryDeploymentFuture extends BaseSerializedFuture { - type: FutureType.ARTIFACT_LIBRARY_DEPLOYMENT; + type: FutureType.LIBRARY_DEPLOYMENT; contractName: string; artifact: Artifact; libraries: SerializedLibraries; @@ -133,7 +133,7 @@ export interface SerializedArtifactLibraryDeploymentFuture */ export interface SerializedNamedContractCallFuture extends BaseSerializedFuture { - type: FutureType.NAMED_CONTRACT_CALL; + type: FutureType.CONTRACT_CALL; functionName: string; contract: FutureToken; args: SerializedArgumentType[]; @@ -147,10 +147,11 @@ export interface SerializedNamedContractCallFuture * @beta */ export interface SerializedNamedStaticCallFuture extends BaseSerializedFuture { - type: FutureType.NAMED_STATIC_CALL; + type: FutureType.STATIC_CALL; functionName: string; contract: FutureToken; args: SerializedArgumentType[]; + nameOrIndex: string | number; from: string | SerializedAccountRuntimeValue | undefined; } @@ -160,7 +161,7 @@ export interface SerializedNamedStaticCallFuture extends BaseSerializedFuture { * @beta */ export interface SerializedNamedContractAtFuture extends BaseSerializedFuture { - type: FutureType.NAMED_CONTRACT_AT; + type: FutureType.NAMED_ARTIFACT_CONTRACT_AT; contractName: string; address: string | FutureToken | SerializedModuleParameterRuntimeValue; } @@ -172,7 +173,7 @@ export interface SerializedNamedContractAtFuture extends BaseSerializedFuture { */ export interface SerializedArtifactContractAtFuture extends BaseSerializedFuture { - type: FutureType.ARTIFACT_CONTRACT_AT; + type: FutureType.CONTRACT_AT; contractName: string; address: string | FutureToken | SerializedModuleParameterRuntimeValue; artifact: Artifact; @@ -188,7 +189,7 @@ export interface SerializedReadEventArgumentFuture type: FutureType.READ_EVENT_ARGUMENT; futureToReadFrom: FutureToken; eventName: string; - argumentName: string; + nameOrIndex: string | number; emitter: FutureToken; eventIndex: number; } @@ -237,71 +238,33 @@ export interface SerializedModuleParameterRuntimeValue { defaultValue: string | undefined; } -/** - * The details of a deployment that will be used in the UI. - * - * @beta - */ -export interface StoredDeployment { - details: { - networkName: string; - chainId: number; - }; - module: IgnitionModule>; -} - // Serialized Deployments /** - * The serialized version of a complete deployment, combining the - * chain details with the module to be deployed. + * The serialized version of an Ignition module and its submodules. * * @beta */ -export interface SerializedStoredDeployment { - details: { - networkName: string; - chainId: number; - }; +export interface SerializedIgnitionModule { startModule: string; modules: { - [key: string]: SerializedStoredModule; + [key: string]: SerializedModuleDescription; }; } /** - * The serialized version of an Ignition module. + * A subpart of the `SerializedIgnitionModule` that describes one + * module/submodule and its relations to futures and other submodule. * * @beta */ -export interface SerializedStoredModule { +export interface SerializedModuleDescription { id: string; submodules: ModuleToken[]; - futures: SerializedStoredFutures; - results: SerializedStoredResults; + futures: SerializedFuture[]; + results: Array<[name: string, token: FutureToken]>; } -/** - * Serialized versions of a modules used submodules. - * - * @beta - */ -export type SerializedStoredSubmodules = SerializedStoredModule[]; - -/** - * The serialized futures that are executed in deploying a module. - * - * @beta - */ -export type SerializedStoredFutures = SerializedFuture[]; - -/** - * The serialized results of a module. - * - * @beta - */ -export type SerializedStoredResults = Array<[name: string, token: FutureToken]>; - /** * The serialized libraries, where each library * has been replaced by a token. diff --git a/packages/core/src/ui-helpers.ts b/packages/core/src/ui-helpers.ts index 00c31db01..edf1f988b 100644 --- a/packages/core/src/ui-helpers.ts +++ b/packages/core/src/ui-helpers.ts @@ -1,8 +1,8 @@ export { - StoredDeploymentDeserializer, - StoredDeploymentSerializer, -} from "./new-api/stored-deployment-serializer"; -export * from "./new-api/type-guards"; -export * from "./new-api/types/module"; -export * from "./new-api/types/serialized-deployment"; -export { formatSolidityParameter } from "./new-api/internal/formatters"; + IgnitionModuleDeserializer, + IgnitionModuleSerializer, +} from "./ignition-module-serializer"; +export { formatSolidityParameter } from "./internal/formatters"; +export * from "./type-guards"; +export * from "./types/module"; +export * from "./types/serialization"; diff --git a/packages/core/src/new-api/wipe.ts b/packages/core/src/wipe.ts similarity index 86% rename from packages/core/src/new-api/wipe.ts rename to packages/core/src/wipe.ts index 6d5ec8a9d..b3ae1c6b8 100644 --- a/packages/core/src/new-api/wipe.ts +++ b/packages/core/src/wipe.ts @@ -18,8 +18,8 @@ export async function wipe( ): Promise { const deploymentLoader = deploymentDir !== undefined - ? new FileDeploymentLoader(deploymentDir, false) - : new EphemeralDeploymentLoader(artifactResolver, false); + ? new FileDeploymentLoader(deploymentDir) + : new EphemeralDeploymentLoader(artifactResolver); const wiper = new Wiper(deploymentLoader); diff --git a/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/contracts/Lock.sol b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/contracts/Lock.sol new file mode 100644 index 000000000..9e0e189d9 --- /dev/null +++ b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/contracts/Lock.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.9; + +// Uncomment this line to use console.log +// import "hardhat/console.sol"; + +contract Lock { + uint public unlockTime; + address payable public owner; + + event Withdrawal(uint amount, uint when); + + constructor(uint _unlockTime) payable { + require( + block.timestamp < _unlockTime, + "Unlock time should be in the future" + ); + + unlockTime = _unlockTime; + owner = payable(msg.sender); + } + + function withdraw() public { + // Uncomment this line, and the import of "hardhat/console.sol", to print a log in your terminal + // console.log("Unlock time is %o and block timestamp is %o", unlockTime, block.timestamp); + + require(block.timestamp >= unlockTime, "You can't withdraw yet"); + require(msg.sender == owner, "You aren't the owner"); + + emit Withdrawal(address(this).balance, block.timestamp); + + owner.transfer(address(this).balance); + } +} diff --git a/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/hardhat.config.js b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/hardhat.config.js new file mode 100644 index 000000000..c76e2c9b8 --- /dev/null +++ b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/hardhat.config.js @@ -0,0 +1,14 @@ +require("@nomicfoundation/hardhat-ignition"); + +/** @type import('hardhat/config').HardhatUserConfig */ +module.exports = { + solidity: { + version: "0.8.19", + settings: { + metadata: { + // We disable the metadata to keep the fixtures more stables + appendCBOR: false, + }, + }, + }, +}; diff --git a/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/LockModule.js b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/LockModule.js new file mode 100644 index 000000000..6ed59e192 --- /dev/null +++ b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/LockModule.js @@ -0,0 +1,18 @@ +const { buildModule } = require("@nomicfoundation/hardhat-ignition"); + +const currentTimestampInSeconds = Math.round(new Date(2023, 0, 1) / 1000); +const TEN_YEAR_IN_SECS = 10 * 365 * 24 * 60 * 60; +const TEN_YEARS_IN_FUTURE = currentTimestampInSeconds + TEN_YEAR_IN_SECS; + +const ONE_GWEI = BigInt(hre.ethers.parseUnits("1", "gwei")); + +module.exports = buildModule("LockModule", (m) => { + const unlockTime = m.getParameter("unlockTime", TEN_YEARS_IN_FUTURE); + const lockedAmount = m.getParameter("lockedAmount", ONE_GWEI); + + const lock = m.contract("Lock", [unlockTime], { + value: lockedAmount, + }); + + return { lock }; +}); diff --git a/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/deployments/network-31337/deployed_addresses.json b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/deployments/network-31337/deployed_addresses.json new file mode 100644 index 000000000..ea65493e3 --- /dev/null +++ b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/deployments/network-31337/deployed_addresses.json @@ -0,0 +1,3 @@ +{ + "LockModule:Lock": "0x5fbdb2315678afecb367f032d93f642f64180aa3" +} diff --git a/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/deployments/network-31337/journal.jsonl b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/deployments/network-31337/journal.jsonl new file mode 100644 index 000000000..3904c1961 --- /dev/null +++ b/packages/core/test-integrations/fixture-projects/default-with-new-chain-id/ignition/deployments/network-31337/journal.jsonl @@ -0,0 +1,7 @@ + +{"chainId":123,"type":"RUN_START"} +{"artifactId":"LockModule:Lock","constructorArgs":[1987909200],"contractName":"Lock","dependencies":[],"from":"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266","futureId":"LockModule:Lock","futureType":"NAMED_CONTRACT_DEPLOYMENT","libraries":{},"strategy":"basic","type":"DEPLOYMENT_EXECUTION_STATE_INITIALIZE","value":{"_kind":"bigint","value":"1000000000"}} +{"futureId":"LockModule:Lock","networkInteraction":{"data":"0x60806040526040516105a23803806105a2833981810160405281019061002591906100f0565b804210610067576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161005e906101a0565b60405180910390fd5b8060008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550506101c0565b600080fd5b6000819050919050565b6100cd816100ba565b81146100d857600080fd5b50565b6000815190506100ea816100c4565b92915050565b600060208284031215610106576101056100b5565b5b6000610114848285016100db565b91505092915050565b600082825260208201905092915050565b7f556e6c6f636b2074696d652073686f756c6420626520696e207468652066757460008201527f7572650000000000000000000000000000000000000000000000000000000000602082015250565b600061018a60238361011d565b91506101958261012e565b604082019050919050565b600060208201905081810360008301526101b98161017d565b9050919050565b6103d3806101cf6000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c8063251c1aa3146100465780633ccfd60b146100645780638da5cb5b1461006e575b600080fd5b61004e61008c565b60405161005b919061024a565b60405180910390f35b61006c610092565b005b61007661020b565b60405161008391906102a6565b60405180910390f35b60005481565b6000544210156100d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016100ce9061031e565b60405180910390fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610167576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161015e9061038a565b60405180910390fd5b7fbf2ed60bd5b5965d685680c01195c9514e4382e28e3a5a2d2d5244bf59411b9347426040516101989291906103aa565b60405180910390a1600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc479081150290604051600060405180830381858888f19350505050158015610208573d6000803e3d6000fd5b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000819050919050565b61024481610231565b82525050565b600060208201905061025f600083018461023b565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061029082610265565b9050919050565b6102a081610285565b82525050565b60006020820190506102bb6000830184610297565b92915050565b600082825260208201905092915050565b7f596f752063616e27742077697468647261772079657400000000000000000000600082015250565b60006103086016836102c1565b9150610313826102d2565b602082019050919050565b60006020820190508181036000830152610337816102fb565b9050919050565b7f596f75206172656e277420746865206f776e6572000000000000000000000000600082015250565b60006103746014836102c1565b915061037f8261033e565b602082019050919050565b600060208201905081810360008301526103a381610367565b9050919050565b60006040820190506103bf600083018561023b565b6103cc602083018461023b565b93925050505600000000000000000000000000000000000000000000000000000000767d1650","id":1,"type":"ONCHAIN_INTERACTION","value":{"_kind":"bigint","value":"1000000000"}},"type":"NETWORK_INTERACTION_REQUEST"} +{"futureId":"LockModule:Lock","networkInteractionId":1,"nonce":0,"transaction":{"fees":{"maxFeePerGas":{"_kind":"bigint","value":"3000000000"},"maxPriorityFeePerGas":{"_kind":"bigint","value":"1000000000"}},"hash":"0x6b9830b7fe0d88787e8a757496c71ece7740ba1f10b4ff1be26ab8ec6d8ed61d"},"type":"TRANSACTION_SEND"} +{"futureId":"LockModule:Lock","hash":"0x6b9830b7fe0d88787e8a757496c71ece7740ba1f10b4ff1be26ab8ec6d8ed61d","networkInteractionId":1,"receipt":{"blockHash":"0xf35aacce8d5fc6276fc544712013691b75fd980178c2a58e63bc37ee1cd76371","blockNumber":1,"contractAddress":"0x5fbdb2315678afecb367f032d93f642f64180aa3","logs":[],"status":"SUCCESS"},"type":"TRANSACTION_CONFIRM"} +{"futureId":"LockModule:Lock","result":{"address":"0x5fbdb2315678afecb367f032d93f642f64180aa3","type":"SUCCESS"},"type":"DEPLOYMENT_EXECUTION_STATE_COMPLETE"} \ No newline at end of file diff --git a/packages/core/test-integrations/new-api/internal/new-execution/jsonrpc-client.ts b/packages/core/test-integrations/new-api/internal/new-execution/jsonrpc-client.ts index f8cc59f24..4364de6c8 100644 --- a/packages/core/test-integrations/new-api/internal/new-execution/jsonrpc-client.ts +++ b/packages/core/test-integrations/new-api/internal/new-execution/jsonrpc-client.ts @@ -4,13 +4,13 @@ import { Artifact } from "../../../../src"; import { encodeArtifactDeploymentData, encodeArtifactFunctionCall, -} from "../../../../src/new-api/internal/new-execution/abi"; -import { EIP1193JsonRpcClient } from "../../../../src/new-api/internal/new-execution/jsonrpc-client"; +} from "../../../../src/internal/execution/abi"; +import { EIP1193JsonRpcClient } from "../../../../src/internal/execution/jsonrpc-client"; import { NetworkFees, TransactionReceiptStatus, -} from "../../../../src/new-api/internal/new-execution/types/jsonrpc"; -import { assertIgnitionInvariant } from "../../../../src/new-api/internal/utils/assertions"; +} from "../../../../src/internal/execution/types/jsonrpc"; +import { assertIgnitionInvariant } from "../../../../src/internal/utils/assertions"; import { useHardhatProject } from "../../../helpers/hardhat-projects"; describe("JSON-RPC client", function () { diff --git a/packages/core/test-integrations/new-api/internal/reconciliation/chainId.ts b/packages/core/test-integrations/new-api/internal/reconciliation/chainId.ts new file mode 100644 index 000000000..909d3e7c7 --- /dev/null +++ b/packages/core/test-integrations/new-api/internal/reconciliation/chainId.ts @@ -0,0 +1,18 @@ +import { assert } from "chai"; + +import { useHardhatProject } from "../../../helpers/hardhat-projects"; + +describe("chainId reconciliation", function () { + this.timeout(60000); + + useHardhatProject("default-with-new-chain-id"); + + it("should halt when running a deployment on a different chain", async function () { + this.hre.network.name = "something-else"; + + await assert.isRejected( + this.hre.run("deploy", { moduleNameOrPath: "./ignition/LockModule.js" }), + /Previous chain id: 123\. Current chain id: 31337/ + ); + }); +}); diff --git a/packages/core/test-integrations/test-execution-result-fixtures.ts b/packages/core/test-integrations/test-execution-result-fixtures.ts index 7911a2abf..4d2dd34fe 100644 --- a/packages/core/test-integrations/test-execution-result-fixtures.ts +++ b/packages/core/test-integrations/test-execution-result-fixtures.ts @@ -3,8 +3,8 @@ import { assert } from "chai"; import { encodeArtifactDeploymentData, encodeArtifactFunctionCall, -} from "../src/new-api/internal/new-execution/abi"; -import { EIP1193JsonRpcClient } from "../src/new-api/internal/new-execution/jsonrpc-client"; +} from "../src/internal/execution/abi"; +import { EIP1193JsonRpcClient } from "../src/internal/execution/jsonrpc-client"; import { callEncodingFixtures, deploymentFixturesArtifacts, diff --git a/packages/core/test/new-api/batcher.ts b/packages/core/test/batcher.ts similarity index 79% rename from packages/core/test/new-api/batcher.ts rename to packages/core/test/batcher.ts index fd923ee89..dd86c49c7 100644 --- a/packages/core/test/new-api/batcher.ts +++ b/packages/core/test/batcher.ts @@ -1,26 +1,26 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../src/new-api/build-module"; -import { Batcher } from "../../src/new-api/internal/batcher"; -import { DeploymentState } from "../../src/new-api/internal/new-execution/types/deployment-state"; +import { buildModule } from "../src/build-module"; +import { Batcher } from "../src/internal/batcher"; +import { DeploymentState } from "../src/internal/execution/types/deployment-state"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType, IgnitionModule } from "../../src/new-api/types/module"; +} from "../src/internal/execution/types/execution-state"; +import { FutureType, IgnitionModule } from "../src/types/module"; describe("batcher", () => { const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -35,7 +35,7 @@ describe("batcher", () => { return { contract1 }; }); - assertBatching({ ignitionModule }, [["Module1:Contract1"]]); + assertBatching({ ignitionModule }, [["Module1#Contract1"]]); }); it("should batch through dependencies", () => { @@ -57,9 +57,9 @@ describe("batcher", () => { }); assertBatching({ ignitionModule }, [ - ["Module1:Contract1", "Module1:Contract2"], - ["Module1:Contract3"], - ["Module1:Contract4", "Module1:Contract5"], + ["Module1#Contract1", "Module1#Contract2"], + ["Module1#Contract3"], + ["Module1#Contract4", "Module1#Contract5"], ]); }); @@ -98,15 +98,15 @@ describe("batcher", () => { }); assertBatching({ ignitionModule }, [ - ["SubmoduleLeft:Contract1", "SubmoduleRight:Contract2"], + ["SubmoduleLeft#Contract1", "SubmoduleRight#Contract2"], [ - "SubmoduleLeft:Contract1#configure", - "SubmoduleRight:Contract2#configure", + "SubmoduleLeft#Contract1.configure", + "SubmoduleRight#Contract2.configure", ], - ["SubmoduleMiddle:Contract3"], - ["SubmoduleMiddle:Contract3#configure"], - ["Module:Contract4"], - ["Module:Contract4#configure"], + ["SubmoduleMiddle#Contract3"], + ["SubmoduleMiddle#Contract3.configure"], + ["Module#Contract4"], + ["Module#Contract4.configure"], ]); }); @@ -141,8 +141,8 @@ describe("batcher", () => { }); assertBatching({ ignitionModule }, [ - ["Left:Contract1", "Middle:Contract3", "Right:Contract2"], - ["Module:Contract4"], + ["Left#Contract1", "Middle#Contract3", "Right#Contract2"], + ["Module#Contract4"], ]); }); @@ -162,15 +162,15 @@ describe("batcher", () => { deploymentState: { chainId: 123, executionStates: { - "Module1:Contract2": { + "Module1#Contract2": { ...exampleDeploymentState, - id: "Module1:Contract2", + id: "Module1#Contract2", status: ExecutionStatus.SUCCESS, }, }, }, }, - [["Module1:Contract1"], ["Module1:Contract3"]] + [["Module1#Contract1"], ["Module1#Contract3"]] ); }); }); diff --git a/packages/core/test/new-api/call.ts b/packages/core/test/call.ts similarity index 87% rename from packages/core/test/new-api/call.ts rename to packages/core/test/call.ts index 327c50f7c..ba9e0c4e2 100644 --- a/packages/core/test/new-api/call.ts +++ b/packages/core/test/call.ts @@ -1,15 +1,15 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; +import { Artifact } from "../src"; +import { buildModule } from "../src/build-module"; import { AccountRuntimeValueImplementation, ModuleParameterRuntimeValueImplementation, NamedContractCallFutureImplementation, -} from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; -import { FutureType } from "../../src/new-api/types/module"; +} from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; +import { FutureType } from "../src/types/module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; @@ -29,18 +29,18 @@ describe("call", () => { assert.equal(moduleWithASingleContract.id, "Module1"); assert.equal( moduleWithASingleContract.results.contract1.id, - "Module1:Contract1" + "Module1#Contract1" ); // 1 contract future & 1 call future assert.equal(moduleWithASingleContract.futures.size, 2); assert.equal( [...moduleWithASingleContract.futures][0].type, - FutureType.NAMED_CONTRACT_DEPLOYMENT + FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT ); assert.equal( [...moduleWithASingleContract.futures][1].type, - FutureType.NAMED_CONTRACT_CALL + FutureType.CONTRACT_CALL ); // No submodules @@ -60,15 +60,15 @@ describe("call", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedContractCallFutureImplementation)) { @@ -93,15 +93,15 @@ describe("call", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedContractCallFutureImplementation)) { @@ -125,7 +125,7 @@ describe("call", () => { assert.isDefined(moduleWithDependentContracts); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedContractCallFutureImplementation)) { @@ -147,7 +147,7 @@ describe("call", () => { assert.isDefined(moduleWithDependentContracts); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedContractCallFutureImplementation)) { @@ -172,7 +172,7 @@ describe("call", () => { assert.isDefined(moduleWithDependentContracts); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedContractCallFutureImplementation)) { @@ -194,7 +194,7 @@ describe("call", () => { assert.isDefined(moduleWithDependentContracts); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedContractCallFutureImplementation)) { @@ -215,7 +215,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -231,7 +231,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -247,7 +247,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -263,7 +263,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -279,7 +279,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -296,7 +296,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -314,7 +314,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -335,7 +335,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -357,7 +357,7 @@ describe("call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_CONTRACT_CALL + ({ type }) => type === FutureType.CONTRACT_CALL ); assertInstanceOf(future, NamedContractCallFutureImplementation); @@ -383,11 +383,11 @@ describe("call", () => { assert.equal(moduleWithSameCallTwice.id, "Module1"); const callFuture = [...moduleWithSameCallTwice.futures].find( - ({ id }) => id === "Module1:Example#first" + ({ id }) => id === "Module1#first" ); const callFuture2 = [...moduleWithSameCallTwice.futures].find( - ({ id }) => id === "Module1:Example#second" + ({ id }) => id === "Module1#second" ); assert.isDefined(callFuture); @@ -404,7 +404,7 @@ describe("call", () => { return { sameContract1 }; }), - /Duplicated id Module1:SameContract#test found in module Module1/ + /Duplicated id Module1#SameContract.test found in module Module1/ ); }); @@ -417,7 +417,7 @@ describe("call", () => { m.call(sameContract1, "test", [], { id: "first" }); return { sameContract1 }; }), - /Duplicated id Module1:SameContract#first found in module Module1/ + /Duplicated id Module1#first found in module Module1/ ); }); }); @@ -464,15 +464,29 @@ describe("call", () => { /Invalid contract given/ ); }); + + it("should not validate a library", () => { + assert.throws( + () => + buildModule("Module1", (m) => { + const another = m.library("Another"); + + m.call(another as any, "test"); + + return { another }; + }), + /Invalid contract given/ + ); + }); }); describe("stage one", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageOne/validateNamedContractCall"); + let vm: typeof import("../src/internal/validation/stageOne/validateNamedContractCall"); let validateNamedContractCall: typeof vm.validateNamedContractCall; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageOne/validateNamedContractCall" + "../src/internal/validation/stageOne/validateNamedContractCall" ); validateNamedContractCall = vm.validateNamedContractCall; @@ -487,7 +501,7 @@ describe("call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( @@ -508,14 +522,14 @@ describe("call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "test"); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( @@ -547,14 +561,14 @@ describe("call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "inc", [1, 2]); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( @@ -604,14 +618,14 @@ describe("call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "inc(bool,uint256)", [1, 2, 3]); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( @@ -622,12 +636,12 @@ describe("call", () => { }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateNamedContractCall"); + let vm: typeof import("../src/internal/validation/stageTwo/validateNamedContractCall"); let validateNamedContractCall: typeof vm.validateNamedContractCall; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateNamedContractCall" + "../src/internal/validation/stageTwo/validateNamedContractCall" ); validateNamedContractCall = vm.validateNamedContractCall; @@ -644,14 +658,14 @@ describe("call", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p"); - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "test", [p]); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( @@ -676,14 +690,14 @@ describe("call", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", false as unknown as bigint); - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "test", [], { value: p }); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( @@ -716,14 +730,14 @@ describe("call", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", 42n); - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "test", [], { value: p }); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isFulfilled( @@ -761,14 +775,14 @@ describe("call", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", true); - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "test", [p]); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isFulfilled( @@ -792,7 +806,7 @@ describe("call", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p"); - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "test", [ [123, { really: { deeply: { nested: [p] } } }], ]); @@ -801,7 +815,7 @@ describe("call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( @@ -840,7 +854,7 @@ describe("call", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", true); - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.call(another, "test", [ [123, { really: { deeply: { nested: [p] } } }], ]); @@ -849,7 +863,7 @@ describe("call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isFulfilled( @@ -885,7 +899,7 @@ describe("call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); const account = m.getAccount(-1); m.call(another, "inc", [1], { from: account }); @@ -893,7 +907,7 @@ describe("call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( @@ -930,7 +944,7 @@ describe("call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); const account = m.getAccount(1); m.call(another, "inc", [1], { from: account }); @@ -938,7 +952,7 @@ describe("call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_CALL + (v) => v.type === FutureType.CONTRACT_CALL ); await assert.isRejected( diff --git a/packages/core/test/new-api/contract.ts b/packages/core/test/contract.ts similarity index 94% rename from packages/core/test/new-api/contract.ts rename to packages/core/test/contract.ts index 50da32b39..dfcc44dba 100644 --- a/packages/core/test/new-api/contract.ts +++ b/packages/core/test/contract.ts @@ -1,15 +1,15 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; +import { Artifact } from "../src"; +import { buildModule } from "../src/build-module"; import { AccountRuntimeValueImplementation, ModuleParameterRuntimeValueImplementation, NamedContractDeploymentFutureImplementation, -} from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; -import { FutureType } from "../../src/new-api/types/module"; +} from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; +import { FutureType } from "../src/types/module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; @@ -27,14 +27,14 @@ describe("contract", () => { assert.equal(moduleWithASingleContract.id, "Module1"); assert.equal( moduleWithASingleContract.results.contract1.id, - "Module1:Contract1" + "Module1#Contract1" ); // 1 contract future assert.equal(moduleWithASingleContract.futures.size, 1); assert.equal( [...moduleWithASingleContract.futures][0].type, - FutureType.NAMED_CONTRACT_DEPLOYMENT + FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT ); // No submodules @@ -52,11 +52,11 @@ describe("contract", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -80,11 +80,11 @@ describe("contract", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -110,11 +110,11 @@ describe("contract", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -138,7 +138,7 @@ describe("contract", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -162,7 +162,7 @@ describe("contract", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -187,7 +187,7 @@ describe("contract", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -209,7 +209,7 @@ describe("contract", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -368,11 +368,11 @@ describe("contract", () => { assert.equal(moduleWithSameContractTwice.id, "Module1"); assert.equal( moduleWithSameContractTwice.results.sameContract1.id, - "Module1:first" + "Module1#first" ); assert.equal( moduleWithSameContractTwice.results.sameContract2.id, - "Module1:second" + "Module1#second" ); }); @@ -385,7 +385,7 @@ describe("contract", () => { return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:SameContract found in module Module1/ + /Duplicated id Module1#SameContract found in module Module1/ ); }); @@ -402,7 +402,7 @@ describe("contract", () => { return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:same found in module Module1/ + /Duplicated id Module1#same found in module Module1/ ); }); }); @@ -452,12 +452,12 @@ describe("contract", () => { }); describe("stage one", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageOne/validateNamedContractDeployment"); + let vm: typeof import("../src/internal/validation/stageOne/validateNamedContractDeployment"); let validateNamedContractDeployment: typeof vm.validateNamedContractDeployment; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageOne/validateNamedContractDeployment" + "../src/internal/validation/stageOne/validateNamedContractDeployment" ); validateNamedContractDeployment = vm.validateNamedContractDeployment; @@ -510,12 +510,12 @@ describe("contract", () => { }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateNamedContractDeployment"); + let vm: typeof import("../src/internal/validation/stageTwo/validateNamedContractDeployment"); let validateNamedContractDeployment: typeof vm.validateNamedContractDeployment; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateNamedContractDeployment" + "../src/internal/validation/stageTwo/validateNamedContractDeployment" ); validateNamedContractDeployment = vm.validateNamedContractDeployment; diff --git a/packages/core/test/new-api/contractAt.ts b/packages/core/test/contractAt.ts similarity index 89% rename from packages/core/test/new-api/contractAt.ts rename to packages/core/test/contractAt.ts index 5936aebe5..edf459fc9 100644 --- a/packages/core/test/new-api/contractAt.ts +++ b/packages/core/test/contractAt.ts @@ -1,10 +1,10 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact, FutureType } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; -import { ModuleParameterRuntimeValueImplementation } from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; +import { Artifact, FutureType } from "../src"; +import { buildModule } from "../src/build-module"; +import { ModuleParameterRuntimeValueImplementation } from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; @@ -29,7 +29,7 @@ describe("contractAt", () => { assert.equal(moduleWithContractFromArtifact.id, "Module1"); assert.equal( moduleWithContractFromArtifact.results.contract1.id, - "Module1:Contract1" + "Module1#Contract1" ); // Stores the address @@ -79,7 +79,7 @@ describe("contractAt", () => { const anotherFuture = moduleWithDependentContracts.results.another; const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#getAddress" + ({ id }) => id === "Module1#Example.getAddress" ); assert.equal(anotherFuture.dependencies.size, 1); @@ -139,11 +139,11 @@ describe("contractAt", () => { assert.equal(moduleWithSameContractTwice.id, "Module1"); assert.equal( moduleWithSameContractTwice.results.sameContract1.id, - "Module1:first" + "Module1#first" ); assert.equal( moduleWithSameContractTwice.results.sameContract2.id, - "Module1:second" + "Module1#second" ); }); @@ -156,7 +156,7 @@ describe("contractAt", () => { return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:SameContract found in module Module1/ + /Duplicated id Module1#SameContract found in module Module1/ ); }); @@ -183,7 +183,7 @@ describe("contractAt", () => { return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:same found in module Module1/ + /Duplicated id Module1#same found in module Module1/ ); }); }); @@ -204,12 +204,12 @@ describe("contractAt", () => { }); describe("stage one", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageOne/validateNamedContractAt"); + let vm: typeof import("../src/internal/validation/stageOne/validateNamedContractAt"); let validateNamedContractAt: typeof vm.validateNamedContractAt; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageOne/validateNamedContractAt" + "../src/internal/validation/stageOne/validateNamedContractAt" ); validateNamedContractAt = vm.validateNamedContractAt; @@ -237,12 +237,12 @@ describe("contractAt", () => { }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateNamedContractAt"); + let vm: typeof import("../src/internal/validation/stageTwo/validateNamedContractAt"); let validateNamedContractAt: typeof vm.validateNamedContractAt; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateNamedContractAt" + "../src/internal/validation/stageTwo/validateNamedContractAt" ); validateNamedContractAt = vm.validateNamedContractAt; @@ -257,7 +257,7 @@ describe("contractAt", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_AT + (v) => v.type === FutureType.NAMED_ARTIFACT_CONTRACT_AT ); await assert.isRejected( @@ -282,7 +282,7 @@ describe("contractAt", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_AT + (v) => v.type === FutureType.NAMED_ARTIFACT_CONTRACT_AT ); await assert.isFulfilled( @@ -306,7 +306,7 @@ describe("contractAt", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_CONTRACT_AT + (v) => v.type === FutureType.NAMED_ARTIFACT_CONTRACT_AT ); await assert.isRejected( diff --git a/packages/core/test/new-api/contractAtFromArtifact.ts b/packages/core/test/contractAtFromArtifact.ts similarity index 74% rename from packages/core/test/new-api/contractAtFromArtifact.ts rename to packages/core/test/contractAtFromArtifact.ts index 398fda535..63b70b590 100644 --- a/packages/core/test/new-api/contractAtFromArtifact.ts +++ b/packages/core/test/contractAtFromArtifact.ts @@ -1,10 +1,10 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact, FutureType } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; -import { ModuleParameterRuntimeValueImplementation } from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; +import { Artifact, FutureType } from "../src"; +import { buildModule } from "../src/build-module"; +import { ModuleParameterRuntimeValueImplementation } from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; @@ -18,11 +18,7 @@ describe("contractAtFromArtifact", () => { it("should be able to setup a contract at a given address", () => { const moduleWithContractFromArtifact = buildModule("Module1", (m) => { - const contract1 = m.contractAtFromArtifact( - "Contract1", - "0xtest", - fakeArtifact - ); + const contract1 = m.contractAt("Contract1", "0xtest", fakeArtifact); return { contract1 }; }); @@ -33,7 +29,7 @@ describe("contractAtFromArtifact", () => { assert.equal(moduleWithContractFromArtifact.id, "Module1"); assert.equal( moduleWithContractFromArtifact.results.contract1.id, - "Module1:Contract1" + "Module1#Contract1" ); // Stores the address @@ -52,14 +48,9 @@ describe("contractAtFromArtifact", () => { it("should be able to pass an after dependency", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.contract("Example"); - const another = m.contractAtFromArtifact( - "Another", - "0xtest", - fakeArtifact, - { - after: [example], - } - ); + const another = m.contractAt("Another", "0xtest", fakeArtifact, { + after: [example], + }); return { example, another }; }); @@ -78,7 +69,7 @@ describe("contractAtFromArtifact", () => { const example = m.contract("Example"); const call = m.staticCall(example, "getAddress"); - const another = m.contractAtFromArtifact("Another", call, fakeArtifact); + const another = m.contractAt("Another", call, fakeArtifact); return { example, another }; }); @@ -88,7 +79,7 @@ describe("contractAtFromArtifact", () => { const anotherFuture = moduleWithDependentContracts.results.another; const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#getAddress" + ({ id }) => id === "Module1#Example.getAddress" ); assert.equal(anotherFuture.dependencies.size, 1); @@ -100,12 +91,8 @@ describe("contractAtFromArtifact", () => { const paramWithDefault = m.getParameter("addressWithDefault", "0x000000"); const paramWithoutDefault = m.getParameter("addressWithoutDefault"); - const withDefault = m.contractAtFromArtifact( - "C", - paramWithDefault, - fakeArtifact - ); - const withoutDefault = m.contractAtFromArtifact( + const withDefault = m.contractAt("C", paramWithDefault, fakeArtifact); + const withoutDefault = m.contractAt( "C2", paramWithoutDefault, fakeArtifact @@ -135,13 +122,13 @@ describe("contractAtFromArtifact", () => { describe("passing id", () => { it("should be able to deploy the same contract twice by passing an id", () => { const moduleWithSameContractTwice = buildModule("Module1", (m) => { - const sameContract1 = m.contractAtFromArtifact( + const sameContract1 = m.contractAt( "SameContract", "0x123", fakeArtifact, { id: "first" } ); - const sameContract2 = m.contractAtFromArtifact( + const sameContract2 = m.contractAt( "SameContract", "0x123", fakeArtifact, @@ -156,11 +143,11 @@ describe("contractAtFromArtifact", () => { assert.equal(moduleWithSameContractTwice.id, "Module1"); assert.equal( moduleWithSameContractTwice.results.sameContract1.id, - "Module1:first" + "Module1#first" ); assert.equal( moduleWithSameContractTwice.results.sameContract2.id, - "Module1:second" + "Module1#second" ); }); @@ -168,12 +155,12 @@ describe("contractAtFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const sameContract1 = m.contractAtFromArtifact( + const sameContract1 = m.contractAt( "SameContract", "0x123", fakeArtifact ); - const sameContract2 = m.contractAtFromArtifact( + const sameContract2 = m.contractAt( "SameContract", "0x123", fakeArtifact @@ -181,7 +168,7 @@ describe("contractAtFromArtifact", () => { return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:SameContract found in module Module1/ + /Duplicated id Module1#SameContract found in module Module1/ ); }); @@ -189,7 +176,7 @@ describe("contractAtFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const sameContract1 = m.contractAtFromArtifact( + const sameContract1 = m.contractAt( "SameContract", "0x123", fakeArtifact, @@ -197,7 +184,7 @@ describe("contractAtFromArtifact", () => { id: "same", } ); - const sameContract2 = m.contractAtFromArtifact( + const sameContract2 = m.contractAt( "SameContract", "0x123", fakeArtifact, @@ -208,7 +195,7 @@ describe("contractAtFromArtifact", () => { return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:same found in module Module1/ + /Duplicated id Module1#same found in module Module1/ ); }); }); @@ -219,42 +206,22 @@ describe("contractAtFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const another = m.contractAtFromArtifact( - "Another", - 42 as any, - fakeArtifact - ); + const another = m.contractAt("Another", 42 as any, fakeArtifact); return { another }; }), /Invalid address given/ ); }); - - it("should not validate an invalid artifact", () => { - assert.throws( - () => - buildModule("Module1", (m) => { - const another = m.contractAtFromArtifact( - "Another", - "", - {} as Artifact - ); - - return { another }; - }), - /Invalid artifact given/ - ); - }); }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateArtifactContractAt"); + let vm: typeof import("../src/internal/validation/stageTwo/validateArtifactContractAt"); let validateArtifactContractAt: typeof vm.validateArtifactContractAt; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateArtifactContractAt" + "../src/internal/validation/stageTwo/validateArtifactContractAt" ); validateArtifactContractAt = vm.validateArtifactContractAt; @@ -263,13 +230,13 @@ describe("contractAtFromArtifact", () => { it("should not validate a missing module parameter", async () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p"); - const another = m.contractAtFromArtifact("Another", p, fakeArtifact); + const another = m.contractAt("Another", p, fakeArtifact); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_AT + (v) => v.type === FutureType.CONTRACT_AT ); await assert.isRejected( @@ -288,13 +255,13 @@ describe("contractAtFromArtifact", () => { it("should validate a missing module parameter if a default parameter is present", async () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", "0x1234"); - const another = m.contractAtFromArtifact("Another", p, fakeArtifact); + const another = m.contractAt("Another", p, fakeArtifact); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_AT + (v) => v.type === FutureType.CONTRACT_AT ); await assert.isFulfilled( @@ -312,13 +279,13 @@ describe("contractAtFromArtifact", () => { it("should not validate a module parameter of the wrong type", async () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", 123 as unknown as string); - const another = m.contractAtFromArtifact("Another", p, fakeArtifact); + const another = m.contractAt("Another", p, fakeArtifact); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_AT + (v) => v.type === FutureType.CONTRACT_AT ); await assert.isRejected( diff --git a/packages/core/test/new-api/contractFromArtifact.ts b/packages/core/test/contractFromArtifact.ts similarity index 78% rename from packages/core/test/new-api/contractFromArtifact.ts rename to packages/core/test/contractFromArtifact.ts index 53bdabe4b..029607783 100644 --- a/packages/core/test/new-api/contractFromArtifact.ts +++ b/packages/core/test/contractFromArtifact.ts @@ -1,14 +1,14 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact, FutureType } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; +import { Artifact, FutureType } from "../src"; +import { buildModule } from "../src/build-module"; import { AccountRuntimeValueImplementation, ArtifactContractDeploymentFutureImplementation, ModuleParameterRuntimeValueImplementation, -} from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; +} from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; @@ -22,7 +22,7 @@ describe("contractFromArtifact", () => { it("should be able to deploy with a contract based on an artifact", () => { const moduleWithContractFromArtifact = buildModule("Module1", (m) => { - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, [ + const contract1 = m.contract("Contract1", fakeArtifact, [ 1, "a", BigInt("9007199254740991"), @@ -37,7 +37,7 @@ describe("contractFromArtifact", () => { assert.equal(moduleWithContractFromArtifact.id, "Module1"); assert.equal( moduleWithContractFromArtifact.results.contract1.id, - "Module1:Contract1" + "Module1#Contract1" ); // Stores the arguments @@ -56,9 +56,7 @@ describe("contractFromArtifact", () => { it("should be able to pass an arg dependency", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.contract("Example"); - const another = m.contractFromArtifact("Another", fakeArtifact, [ - example, - ]); + const another = m.contract("Another", fakeArtifact, [example]); return { example, another }; }); @@ -75,7 +73,7 @@ describe("contractFromArtifact", () => { it("should be able to pass an after dependency", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.contract("Example"); - const another = m.contractFromArtifact("Another", fakeArtifact, [], { + const another = m.contract("Another", fakeArtifact, [], { after: [example], }); @@ -94,7 +92,7 @@ describe("contractFromArtifact", () => { it("should be able to pass a library as a dependency of a contract", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.library("Example"); - const another = m.contractFromArtifact("Another", fakeArtifact, [], { + const another = m.contract("Another", fakeArtifact, [], { libraries: { Example: example }, }); @@ -104,11 +102,11 @@ describe("contractFromArtifact", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -124,7 +122,7 @@ describe("contractFromArtifact", () => { it("should be able to pass value as an option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, [], { + const another = m.contract("Another", fakeArtifact, [], { value: BigInt(42), }); @@ -134,7 +132,7 @@ describe("contractFromArtifact", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -148,7 +146,7 @@ describe("contractFromArtifact", () => { it("Should be able to pass a ModuleParameterRuntimeValue as a value option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, [], { + const another = m.contract("Another", fakeArtifact, [], { value: m.getParameter("value"), }); @@ -158,7 +156,7 @@ describe("contractFromArtifact", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -175,7 +173,7 @@ describe("contractFromArtifact", () => { it("should be able to pass a string as from option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, [], { + const another = m.contract("Another", fakeArtifact, [], { from: "0x2", }); @@ -185,7 +183,7 @@ describe("contractFromArtifact", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -199,7 +197,7 @@ describe("contractFromArtifact", () => { it("Should be able to pass an AccountRuntimeValue as from option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, [], { + const another = m.contract("Another", fakeArtifact, [], { from: m.getAccount(1), }); @@ -209,7 +207,7 @@ describe("contractFromArtifact", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -225,7 +223,7 @@ describe("contractFromArtifact", () => { describe("Arguments", () => { it("Should support base values as arguments", () => { const module = buildModule("Module", (m) => { - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, [ + const contract1 = m.contract("Contract1", fakeArtifact, [ 1, true, "string", @@ -245,9 +243,7 @@ describe("contractFromArtifact", () => { it("Should support arrays as arguments", () => { const module = buildModule("Module", (m) => { - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, [ - [1, 2, 3n], - ]); + const contract1 = m.contract("Contract1", fakeArtifact, [[1, 2, 3n]]); return { contract1 }; }); @@ -257,7 +253,7 @@ describe("contractFromArtifact", () => { it("Should support objects as arguments", () => { const module = buildModule("Module", (m) => { - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, [ + const contract1 = m.contract("Contract1", fakeArtifact, [ { a: 1, b: [1, 2] }, ]); @@ -273,9 +269,7 @@ describe("contractFromArtifact", () => { it("Should support futures as arguments", () => { const module = buildModule("Module", (m) => { const contract1 = m.contract("Contract1"); - const contract2 = m.contractFromArtifact("Contract2", fakeArtifact, [ - contract1, - ]); + const contract2 = m.contract("Contract2", fakeArtifact, [contract1]); return { contract1, contract2 }; }); @@ -289,7 +283,7 @@ describe("contractFromArtifact", () => { it("should support nested futures as arguments", () => { const module = buildModule("Module", (m) => { const contract1 = m.contract("Contract1"); - const contract2 = m.contractFromArtifact("Contract2", fakeArtifact, [ + const contract2 = m.contract("Contract2", fakeArtifact, [ { arr: [contract1] }, ]); @@ -305,9 +299,7 @@ describe("contractFromArtifact", () => { it("should support AccountRuntimeValues as arguments", () => { const module = buildModule("Module", (m) => { const account1 = m.getAccount(1); - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, [ - account1, - ]); + const contract1 = m.contract("Contract1", fakeArtifact, [account1]); return { contract1 }; }); @@ -322,7 +314,7 @@ describe("contractFromArtifact", () => { it("should support nested AccountRuntimeValues as arguments", () => { const module = buildModule("Module", (m) => { const account1 = m.getAccount(1); - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, [ + const contract1 = m.contract("Contract1", fakeArtifact, [ { arr: [account1] }, ]); @@ -340,9 +332,7 @@ describe("contractFromArtifact", () => { it("should support ModuleParameterRuntimeValue as arguments", () => { const module = buildModule("Module", (m) => { const p = m.getParameter("p", 123); - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, [ - p, - ]); + const contract1 = m.contract("Contract1", fakeArtifact, [p]); return { contract1 }; }); @@ -361,9 +351,7 @@ describe("contractFromArtifact", () => { it("should support nested ModuleParameterRuntimeValue as arguments", () => { const module = buildModule("Module", (m) => { const p = m.getParameter("p", 123); - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, [ - { arr: [p] }, - ]); + const contract1 = m.contract("Contract1", fakeArtifact, [{ arr: [p] }]); return { contract1 }; }); @@ -378,20 +366,12 @@ describe("contractFromArtifact", () => { describe("passing id", () => { it("should use contract from artifact twice by passing an id", () => { const moduleWithSameContractTwice = buildModule("Module1", (m) => { - const sameContract1 = m.contractFromArtifact( - "SameContract", - fakeArtifact, - [], - { id: "first" } - ); - const sameContract2 = m.contractFromArtifact( - "SameContract", - fakeArtifact, - [], - { - id: "second", - } - ); + const sameContract1 = m.contract("SameContract", fakeArtifact, [], { + id: "first", + }); + const sameContract2 = m.contract("SameContract", fakeArtifact, [], { + id: "second", + }); return { sameContract1, sameContract2 }; }); @@ -400,11 +380,11 @@ describe("contractFromArtifact", () => { assert.equal(moduleWithSameContractTwice.id, "Module1"); assert.equal( moduleWithSameContractTwice.results.sameContract1.id, - "Module1:first" + "Module1#first" ); assert.equal( moduleWithSameContractTwice.results.sameContract2.id, - "Module1:second" + "Module1#second" ); }); @@ -412,18 +392,12 @@ describe("contractFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const sameContract1 = m.contractFromArtifact( - "SameContract", - fakeArtifact - ); - const sameContract2 = m.contractFromArtifact( - "SameContract", - fakeArtifact - ); + const sameContract1 = m.contract("SameContract", fakeArtifact); + const sameContract2 = m.contract("SameContract", fakeArtifact); return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:SameContract found in module Module1/ + /Duplicated id Module1#SameContract found in module Module1/ ); }); @@ -431,26 +405,16 @@ describe("contractFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const sameContract1 = m.contractFromArtifact( - "SameContract", - fakeArtifact, - [], - { - id: "same", - } - ); - const sameContract2 = m.contractFromArtifact( - "SameContract", - fakeArtifact, - [], - { - id: "same", - } - ); + const sameContract1 = m.contract("SameContract", fakeArtifact, [], { + id: "same", + }); + const sameContract2 = m.contract("SameContract", fakeArtifact, [], { + id: "same", + }); return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:same found in module Module1/ + /Duplicated id Module1#same found in module Module1/ ); }); }); @@ -461,14 +425,9 @@ describe("contractFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const another = m.contractFromArtifact( - "Another", - fakeArtifact, - [], - { - value: 42 as any, - } - ); + const another = m.contract("Another", fakeArtifact, [], { + value: 42 as any, + }); return { another }; }), @@ -480,14 +439,9 @@ describe("contractFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const another = m.contractFromArtifact( - "Another", - fakeArtifact, - [], - { - from: 1 as any, - } - ); + const another = m.contract("Another", fakeArtifact, [], { + from: 1 as any, + }); return { another }; }), @@ -502,7 +456,7 @@ describe("contractFromArtifact", () => { const another = m.contract("Another", []); const call = m.call(another, "test"); - const test = m.contractFromArtifact("Test", fakeArtifact, [], { + const test = m.contract("Test", fakeArtifact, [], { libraries: { Call: call as any }, }); @@ -516,11 +470,7 @@ describe("contractFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const another = m.contractFromArtifact( - "Another", - {} as Artifact, - [] - ); + const another = m.contract("Another", {} as Artifact, []); return { another }; }), @@ -530,12 +480,12 @@ describe("contractFromArtifact", () => { }); describe("stage one", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageOne/validateArtifactContractDeployment"); + let vm: typeof import("../src/internal/validation/stageOne/validateArtifactContractDeployment"); let validateArtifactContractDeployment: typeof vm.validateArtifactContractDeployment; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageOne/validateArtifactContractDeployment" + "../src/internal/validation/stageOne/validateArtifactContractDeployment" ); validateArtifactContractDeployment = @@ -544,11 +494,7 @@ describe("contractFromArtifact", () => { it("should not validate an incorrect number of constructor args", async () => { const module = buildModule("Module1", (m) => { - const contract1 = m.contractFromArtifact( - "Test", - fakeArtifact, - [1, 2, 3] - ); + const contract1 = m.contract("Test", fakeArtifact, [1, 2, 3]); return { contract1 }; }); @@ -566,12 +512,12 @@ describe("contractFromArtifact", () => { }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateArtifactContractDeployment"); + let vm: typeof import("../src/internal/validation/stageTwo/validateArtifactContractDeployment"); let validateArtifactContractDeployment: typeof vm.validateArtifactContractDeployment; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateArtifactContractDeployment" + "../src/internal/validation/stageTwo/validateArtifactContractDeployment" ); validateArtifactContractDeployment = @@ -581,13 +527,13 @@ describe("contractFromArtifact", () => { it("should not validate a missing module parameter", async () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p"); - const contract1 = m.contractFromArtifact("Test", fakeArtifact, [p]); + const contract1 = m.contract("Test", fakeArtifact, [p]); return { contract1 }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_DEPLOYMENT + (v) => v.type === FutureType.CONTRACT_DEPLOYMENT ); await assert.isRejected( @@ -623,13 +569,13 @@ describe("contractFromArtifact", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", 123); - const contract1 = m.contractFromArtifact("Test", fakerArtifact, [p]); + const contract1 = m.contract("Test", fakerArtifact, [p]); return { contract1 }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_DEPLOYMENT + (v) => v.type === FutureType.CONTRACT_DEPLOYMENT ); await assert.isFulfilled( @@ -658,7 +604,7 @@ describe("contractFromArtifact", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", false as unknown as bigint); - const contract1 = m.contractFromArtifact("Test", fakerArtifact, [], { + const contract1 = m.contract("Test", fakerArtifact, [], { value: p, }); @@ -666,7 +612,7 @@ describe("contractFromArtifact", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_DEPLOYMENT + (v) => v.type === FutureType.CONTRACT_DEPLOYMENT ); await assert.isRejected( @@ -696,7 +642,7 @@ describe("contractFromArtifact", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", 42n); - const contract1 = m.contractFromArtifact("Test", fakerArtifact, [], { + const contract1 = m.contract("Test", fakerArtifact, [], { value: p, }); @@ -704,7 +650,7 @@ describe("contractFromArtifact", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_DEPLOYMENT + (v) => v.type === FutureType.CONTRACT_DEPLOYMENT ); await assert.isFulfilled( @@ -720,7 +666,7 @@ describe("contractFromArtifact", () => { it("should not validate a missing module parameter (deeply nested)", async () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p"); - const contract1 = m.contractFromArtifact("Test", fakeArtifact, [ + const contract1 = m.contract("Test", fakeArtifact, [ [123, { really: { deeply: { nested: [p] } } }], ]); @@ -728,7 +674,7 @@ describe("contractFromArtifact", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_DEPLOYMENT + (v) => v.type === FutureType.CONTRACT_DEPLOYMENT ); await assert.isRejected( @@ -764,7 +710,7 @@ describe("contractFromArtifact", () => { const module = buildModule("Module1", (m) => { const p = m.getParameter("p", 123); - const contract1 = m.contractFromArtifact("Test", fakerArtifact, [ + const contract1 = m.contract("Test", fakerArtifact, [ [123, { really: { deeply: { nested: [p] } } }], ]); @@ -772,7 +718,7 @@ describe("contractFromArtifact", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.ARTIFACT_CONTRACT_DEPLOYMENT + (v) => v.type === FutureType.CONTRACT_DEPLOYMENT ); await assert.isFulfilled( @@ -788,7 +734,7 @@ describe("contractFromArtifact", () => { it("should not validate a negative account index", async () => { const module = buildModule("Module1", (m) => { const account = m.getAccount(-1); - const contract1 = m.contractFromArtifact("Test", fakeArtifact, [], { + const contract1 = m.contract("Test", fakeArtifact, [], { from: account, }); @@ -811,7 +757,7 @@ describe("contractFromArtifact", () => { it("should not validate an account index greater than the number of available accounts", async () => { const module = buildModule("Module1", (m) => { const account = m.getAccount(1); - const contract1 = m.contractFromArtifact("Test", fakeArtifact, [], { + const contract1 = m.contract("Test", fakeArtifact, [], { from: account, }); diff --git a/packages/core/test/new-api/new-execution/abi.ts b/packages/core/test/execution/abi.ts similarity index 98% rename from packages/core/test/new-api/new-execution/abi.ts rename to packages/core/test/execution/abi.ts index d6aff4d22..e2b658f46 100644 --- a/packages/core/test/new-api/new-execution/abi.ts +++ b/packages/core/test/execution/abi.ts @@ -1,7 +1,7 @@ import { assert } from "chai"; import { Artifact } from "hardhat/types"; -import { SolidityParameterType } from "../../../src"; +import { SolidityParameterType } from "../../src"; import { decodeArtifactCustomError, decodeArtifactFunctionCallResult, @@ -9,15 +9,15 @@ import { encodeArtifactDeploymentData, encodeArtifactFunctionCall, validateArtifactFunctionName, -} from "../../../src/new-api/internal/new-execution/abi"; -import { linkLibraries } from "../../../src/new-api/internal/new-execution/libraries"; -import { EvmExecutionResultTypes } from "../../../src/new-api/internal/new-execution/types/evm-execution"; +} from "../../src/internal/execution/abi"; +import { linkLibraries } from "../../src/internal/execution/libraries"; +import { EvmExecutionResultTypes } from "../../src/internal/execution/types/evm-execution"; import { callEncodingFixtures, deploymentFixturesArtifacts, staticCallResultFixtures, staticCallResultFixturesArtifacts, -} from "../../helpers/execution-result-fixtures"; +} from "../helpers/execution-result-fixtures"; describe("abi", () => { // These tests validate that type conversions from the underlying abi library diff --git a/packages/core/test/new-api/new-execution/future-processor/helpers/build-initialize-message-for.ts b/packages/core/test/execution/future-processor/helpers/build-initialize-message-for.ts similarity index 88% rename from packages/core/test/new-api/new-execution/future-processor/helpers/build-initialize-message-for.ts rename to packages/core/test/execution/future-processor/helpers/build-initialize-message-for.ts index 7466d813d..a5c0a72de 100644 --- a/packages/core/test/new-api/new-execution/future-processor/helpers/build-initialize-message-for.ts +++ b/packages/core/test/execution/future-processor/helpers/build-initialize-message-for.ts @@ -1,36 +1,21 @@ import { assert } from "chai"; -import { DeploymentLoader } from "../../../../../src/new-api/internal/deployment-loader/types"; -import { MemoryJournal } from "../../../../../src/new-api/internal/journal/memory-journal"; -import { - AccountRuntimeValueImplementation, - ArtifactContractAtFutureImplementation, - ArtifactContractDeploymentFutureImplementation, - ArtifactLibraryDeploymentFutureImplementation, - ModuleParameterRuntimeValueImplementation, - NamedContractAtFutureImplementation, - NamedContractCallFutureImplementation, - NamedContractDeploymentFutureImplementation, - NamedLibraryDeploymentFutureImplementation, - NamedStaticCallFutureImplementation, - ReadEventArgumentFutureImplementation, - SendDataFutureImplementation, -} from "../../../../../src/new-api/internal/module"; -import { buildInitializeMessageFor } from "../../../../../src/new-api/internal/new-execution/future-processor/helpers/build-initialize-message-for"; -import { deploymentStateReducer } from "../../../../../src/new-api/internal/new-execution/reducers/deployment-state-reducer"; -import { DeploymentState } from "../../../../../src/new-api/internal/new-execution/types/deployment-state"; -import { ExecutionResultType } from "../../../../../src/new-api/internal/new-execution/types/execution-result"; +import { DeploymentLoader } from "../../../../src/internal/deployment-loader/types"; +import { buildInitializeMessageFor } from "../../../../src/internal/execution/future-processor/helpers/build-initialize-message-for"; +import { deploymentStateReducer } from "../../../../src/internal/execution/reducers/deployment-state-reducer"; +import { DeploymentState } from "../../../../src/internal/execution/types/deployment-state"; +import { ExecutionResultType } from "../../../../src/internal/execution/types/execution-result"; import { ContractAtExecutionState, DeploymentExecutionState, ExecutionSateType, ReadEventArgumentExecutionState, StaticCallExecutionState, -} from "../../../../../src/new-api/internal/new-execution/types/execution-state"; +} from "../../../../src/internal/execution/types/execution-state"; import { Transaction, TransactionReceiptStatus, -} from "../../../../../src/new-api/internal/new-execution/types/jsonrpc"; +} from "../../../../src/internal/execution/types/jsonrpc"; import { CallExecutionStateInitializeMessage, ContractAtExecutionStateInitializeMessage, @@ -39,25 +24,40 @@ import { ReadEventArgExecutionStateInitializeMessage, SendDataExecutionStateInitializeMessage, StaticCallExecutionStateInitializeMessage, -} from "../../../../../src/new-api/internal/new-execution/types/messages"; +} from "../../../../src/internal/execution/types/messages"; import { NetworkInteractionType, OnchainInteraction, -} from "../../../../../src/new-api/internal/new-execution/types/network-interaction"; -import { getDefaultSender } from "../../../../../src/new-api/internal/new-execution/utils/get-default-sender"; +} from "../../../../src/internal/execution/types/network-interaction"; +import { getDefaultSender } from "../../../../src/internal/execution/utils/get-default-sender"; +import { MemoryJournal } from "../../../../src/internal/journal/memory-journal"; +import { + AccountRuntimeValueImplementation, + ArtifactContractAtFutureImplementation, + ArtifactContractDeploymentFutureImplementation, + ArtifactLibraryDeploymentFutureImplementation, + ModuleParameterRuntimeValueImplementation, + NamedContractAtFutureImplementation, + NamedContractCallFutureImplementation, + NamedContractDeploymentFutureImplementation, + NamedLibraryDeploymentFutureImplementation, + NamedStaticCallFutureImplementation, + ReadEventArgumentFutureImplementation, + SendDataFutureImplementation, +} from "../../../../src/internal/module"; import { - ArtifactContractAtFuture, - ArtifactContractDeploymentFuture, - ArtifactLibraryDeploymentFuture, + ContractAtFuture, + ContractDeploymentFuture, + LibraryDeploymentFuture, FutureType, - NamedContractAtFuture, - NamedContractCallFuture, - NamedContractDeploymentFuture, - NamedLibraryDeploymentFuture, - NamedStaticCallFuture, + NamedArtifactContractAtFuture, + ContractCallFuture, + NamedArtifactContractDeploymentFuture, + NamedArtifactLibraryDeploymentFuture, + StaticCallFuture, ReadEventArgumentFuture, SendDataFuture, -} from "../../../../../src/new-api/types/module"; +} from "../../../../src/types/module"; import { exampleAccounts, fakeArtifact, @@ -69,16 +69,16 @@ describe("buildInitializeMessageFor", () => { const libraryAddress = "0x742d35Cc6634C0532925a3b844Bc454e4438f44e"; const basicStrategy = { name: "basic" } as any; - let namedContractDeployment: NamedContractDeploymentFuture; - let anotherNamedContractDeployment: NamedContractDeploymentFuture; - let safeMathLibraryDeployment: NamedLibraryDeploymentFuture; - let artifactContractDeployment: ArtifactContractDeploymentFuture; - let namedLibraryDeployment: NamedLibraryDeploymentFuture; - let artifactLibraryDeployment: ArtifactLibraryDeploymentFuture; - let namedContractCall: NamedContractCallFuture; - let staticCall: NamedStaticCallFuture; - let namedContractAt: NamedContractAtFuture; - let artifactContractAt: ArtifactContractAtFuture; + let namedContractDeployment: NamedArtifactContractDeploymentFuture; + let anotherNamedContractDeployment: NamedArtifactContractDeploymentFuture; + let safeMathLibraryDeployment: NamedArtifactLibraryDeploymentFuture; + let artifactContractDeployment: ContractDeploymentFuture; + let namedLibraryDeployment: NamedArtifactLibraryDeploymentFuture; + let artifactLibraryDeployment: LibraryDeploymentFuture; + let namedContractCall: ContractCallFuture; + let staticCall: StaticCallFuture; + let namedContractAt: NamedArtifactContractAtFuture; + let artifactContractAt: ContractAtFuture; let readEventArgument: ReadEventArgumentFuture; let sendData: SendDataFuture; @@ -187,6 +187,7 @@ describe("buildInitializeMessageFor", () => { "staticTest", anotherNamedContractDeployment, [BigInt(1), "b", safeMathLibraryDeployment, { sub: "d" }], + 0, exampleAccounts[0] ); @@ -291,7 +292,7 @@ describe("buildInitializeMessageFor", () => { const safeMathExState: Partial = { type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, result: { type: ExecutionResultType.SUCCESS, address: libraryAddress, @@ -389,10 +390,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(message, { type: JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:ArtifactContract", - futureType: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, + futureType: FutureType.CONTRACT_DEPLOYMENT, strategy: "basic", dependencies: ["MyModule:AnotherContract", "MyModule:SafeMath"], - artifactFutureId: "MyModule:ArtifactContract", + artifactId: "MyModule:ArtifactContract", constructorArgs: [ 1n, "b", @@ -428,10 +429,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(message, { type: JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:NamedLibrary", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, strategy: "basic", dependencies: ["MyModule:SafeMath"], - artifactFutureId: "MyModule:NamedLibrary", + artifactId: "MyModule:NamedLibrary", constructorArgs: [], contractName: "NamedLibrary", libraries: { @@ -460,10 +461,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(message, { type: JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:ArtifactLibrary", - futureType: FutureType.ARTIFACT_LIBRARY_DEPLOYMENT, + futureType: FutureType.LIBRARY_DEPLOYMENT, strategy: "basic", dependencies: ["MyModule:SafeMath"], - artifactFutureId: "MyModule:ArtifactLibrary", + artifactId: "MyModule:ArtifactLibrary", constructorArgs: [], contractName: "ArtifactLibrary", libraries: { @@ -565,7 +566,7 @@ describe("buildInitializeMessageFor", () => { futureId: "MyModule:Call", strategy: "basic", dependencies: ["MyModule:AnotherContract", "MyModule:SafeMath"], - artifactFutureId: "MyModule:AnotherContract", + artifactId: "MyModule:AnotherContract", contractAddress: differentAddress, functionName: "test", args: [1n, "b", libraryAddress, { sub: "d" }], @@ -598,10 +599,11 @@ describe("buildInitializeMessageFor", () => { futureId: "MyModule:StaticCall", strategy: "basic", dependencies: ["MyModule:AnotherContract", "MyModule:SafeMath"], - artifactFutureId: "MyModule:AnotherContract", + artifactId: "MyModule:AnotherContract", contractAddress: differentAddress, functionName: "staticTest", args: [1n, "b", libraryAddress, { sub: "d" }], + nameOrIndex: 0, from: exampleAccounts[0], }); }); @@ -628,10 +630,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(message, { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:NamedContractAt", - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, strategy: "basic", dependencies: [], - artifactFutureId: "MyModule:NamedContractAt", + artifactId: "MyModule:NamedContractAt", contractAddress: differentAddress, contractName: "NamedContractAt", }); @@ -655,10 +657,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(message, { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:ArtifactContractAt", - futureType: FutureType.ARTIFACT_CONTRACT_AT, + futureType: FutureType.CONTRACT_AT, strategy: "basic", dependencies: [], - artifactFutureId: "MyModule:ArtifactContractAt", + artifactId: "MyModule:ArtifactContractAt", contractAddress: differentAddress, contractName: "ArtifactContractAt", }); @@ -693,10 +695,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(m, { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:NamedContractAt", - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, strategy: "basic", dependencies: [], - artifactFutureId: "MyModule:NamedContractAt", + artifactId: "MyModule:NamedContractAt", contractAddress: differentAddress, contractName: "ArtifactContractAt", }); @@ -723,10 +725,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(m, { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:NamedContractAt", - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, strategy: "basic", dependencies: [], - artifactFutureId: "MyModule:NamedContractAt", + artifactId: "MyModule:NamedContractAt", contractAddress: differentAddress, contractName: "NamedContractAt", }); @@ -737,7 +739,7 @@ describe("buildInitializeMessageFor", () => { beforeEach(() => { const namedContractAtExState: Partial = { type: ExecutionSateType.CONTRACT_AT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, contractAddress: differentAddress, }; @@ -769,10 +771,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(m, { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:SecondNamedContractAt", - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, strategy: "basic", dependencies: [], - artifactFutureId: "MyModule:SecondNamedContractAt", + artifactId: "MyModule:SecondNamedContractAt", contractAddress: differentAddress, contractName: "SecondNamedContractAt", }); @@ -814,10 +816,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(m, { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:NamedContractAt", - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, strategy: "basic", dependencies: [], - artifactFutureId: "MyModule:NamedContractAt", + artifactId: "MyModule:NamedContractAt", contractName: "NamedContractAt", contractAddress: differentAddress, }); @@ -862,10 +864,10 @@ describe("buildInitializeMessageFor", () => { assert.deepStrictEqual(m, { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, futureId: "MyModule:NamedContractAt", - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, strategy: "basic", dependencies: [], - artifactFutureId: "MyModule:NamedContractAt", + artifactId: "MyModule:NamedContractAt", contractName: "NamedContractAt", contractAddress: differentAddress, }); @@ -894,9 +896,9 @@ describe("buildInitializeMessageFor", () => { futureId: "MyModule:ReadEventArg", strategy: "basic", dependencies: [], - artifactFutureId: "MyModule:AnotherContract", + artifactId: "MyModule:AnotherContract", eventName: "event1", - argumentName: "arg1", + nameOrIndex: "arg1", txToReadFrom: "0x1234", emitterAddress: differentAddress, eventIndex: 0, diff --git a/packages/core/test/new-api/new-execution/future-processor/helpers/network-interaction-execution.ts b/packages/core/test/execution/future-processor/helpers/network-interaction-execution.ts similarity index 92% rename from packages/core/test/new-api/new-execution/future-processor/helpers/network-interaction-execution.ts rename to packages/core/test/execution/future-processor/helpers/network-interaction-execution.ts index 52c93775e..20524cc26 100644 --- a/packages/core/test/new-api/new-execution/future-processor/helpers/network-interaction-execution.ts +++ b/packages/core/test/execution/future-processor/helpers/network-interaction-execution.ts @@ -1,23 +1,23 @@ import { assert } from "chai"; -import { runStaticCall } from "../../../../../src/new-api/internal/new-execution/future-processor/helpers/network-interaction-execution"; +import { runStaticCall } from "../../../../src/internal/execution/future-processor/helpers/network-interaction-execution"; import { JsonRpcClient, CallParams, EstimateGasParams, TransactionParams, Block, -} from "../../../../../src/new-api/internal/new-execution/jsonrpc-client"; +} from "../../../../src/internal/execution/jsonrpc-client"; import { NetworkFees, RawStaticCallResult, Transaction, TransactionReceipt, -} from "../../../../../src/new-api/internal/new-execution/types/jsonrpc"; +} from "../../../../src/internal/execution/types/jsonrpc"; import { NetworkInteractionType, StaticCall, -} from "../../../../../src/new-api/internal/new-execution/types/network-interaction"; +} from "../../../../src/internal/execution/types/network-interaction"; class StubJsonRpcClient implements JsonRpcClient { public async getChainId(): Promise { diff --git a/packages/core/test/new-api/new-execution/future-processor/named-contract-deploy.ts b/packages/core/test/execution/future-processor/named-contract-deploy.ts similarity index 71% rename from packages/core/test/new-api/new-execution/future-processor/named-contract-deploy.ts rename to packages/core/test/execution/future-processor/named-contract-deploy.ts index 646298714..8f82a9ccf 100644 --- a/packages/core/test/new-api/new-execution/future-processor/named-contract-deploy.ts +++ b/packages/core/test/execution/future-processor/named-contract-deploy.ts @@ -1,16 +1,16 @@ import { assert } from "chai"; -import { NamedContractDeploymentFuture } from "../../../../src"; -import { NamedContractDeploymentFutureImplementation } from "../../../../src/new-api/internal/module"; -import { TransactionParams } from "../../../../src/new-api/internal/new-execution/jsonrpc-client"; -import { deploymentStateReducer } from "../../../../src/new-api/internal/new-execution/reducers/deployment-state-reducer"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { NamedArtifactContractDeploymentFuture } from "../../../src"; +import { TransactionParams } from "../../../src/internal/execution/jsonrpc-client"; +import { deploymentStateReducer } from "../../../src/internal/execution/reducers/deployment-state-reducer"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { TransactionReceiptStatus } from "../../../../src/new-api/internal/new-execution/types/jsonrpc"; -import { assertIgnitionInvariant } from "../../../../src/new-api/internal/utils/assertions"; +} from "../../../src/internal/execution/types/execution-state"; +import { TransactionReceiptStatus } from "../../../src/internal/execution/types/jsonrpc"; +import { NamedContractDeploymentFutureImplementation } from "../../../src/internal/module"; +import { assertIgnitionInvariant } from "../../../src/internal/utils/assertions"; import { exampleAccounts } from "../../helpers"; import { setupFutureProcessor } from "./utils"; @@ -27,7 +27,7 @@ describe("future processor", () => { // Arrange const fakeModule = {} as any; - const deploymentFuture: NamedContractDeploymentFuture = + const deploymentFuture: NamedArtifactContractDeploymentFuture = new NamedContractDeploymentFutureImplementation( "MyModule:TestContract", fakeModule, @@ -60,7 +60,6 @@ describe("future processor", () => { ); // Assert - assert.isTrue(result.futureCompleted); assert.equal( storedDeployedAddresses["MyModule:TestContract"], exampleAddress diff --git a/packages/core/test/new-api/new-execution/future-processor/utils.ts b/packages/core/test/execution/future-processor/utils.ts similarity index 81% rename from packages/core/test/new-api/new-execution/future-processor/utils.ts rename to packages/core/test/execution/future-processor/utils.ts index 3e9dc79f7..bf536d395 100644 --- a/packages/core/test/new-api/new-execution/future-processor/utils.ts +++ b/packages/core/test/execution/future-processor/utils.ts @@ -1,23 +1,23 @@ -import { MemoryJournal } from "../../../../src/new-api/internal/journal/memory-journal"; -import { BasicExecutionStrategy } from "../../../../src/new-api/internal/new-execution/basic-execution-strategy"; -import { FutureProcessor } from "../../../../src/new-api/internal/new-execution/future-processor/future-processor"; +import { BasicExecutionStrategy } from "../../../src/internal/execution/basic-execution-strategy"; +import { FutureProcessor } from "../../../src/internal/execution/future-processor/future-processor"; import { Block, CallParams, EstimateGasParams, JsonRpcClient, TransactionParams, -} from "../../../../src/new-api/internal/new-execution/jsonrpc-client"; -import { NonceManager } from "../../../../src/new-api/internal/new-execution/nonce-management"; -import { TransactionTrackingTimer } from "../../../../src/new-api/internal/new-execution/transaction-tracking-timer"; +} from "../../../src/internal/execution/jsonrpc-client"; +import { NonceManager } from "../../../src/internal/execution/nonce-management"; +import { TransactionTrackingTimer } from "../../../src/internal/execution/transaction-tracking-timer"; import { NetworkFees, RawStaticCallResult, Transaction, TransactionReceipt, -} from "../../../../src/new-api/internal/new-execution/types/jsonrpc"; -import { getDefaultSender } from "../../../../src/new-api/internal/new-execution/utils/get-default-sender"; -import { assertIgnitionInvariant } from "../../../../src/new-api/internal/utils/assertions"; +} from "../../../src/internal/execution/types/jsonrpc"; +import { getDefaultSender } from "../../../src/internal/execution/utils/get-default-sender"; +import { MemoryJournal } from "../../../src/internal/journal/memory-journal"; +import { assertIgnitionInvariant } from "../../../src/internal/utils/assertions"; import { exampleAccounts, setupMockArtifactResolver, diff --git a/packages/core/test/new-api/new-execution/libraries.ts b/packages/core/test/execution/libraries.ts similarity index 96% rename from packages/core/test/new-api/new-execution/libraries.ts rename to packages/core/test/execution/libraries.ts index abb9d06db..a87ab366c 100644 --- a/packages/core/test/new-api/new-execution/libraries.ts +++ b/packages/core/test/execution/libraries.ts @@ -3,8 +3,8 @@ import { assert } from "chai"; import { linkLibraries, validateLibraryNames, -} from "../../../src/new-api/internal/new-execution/libraries"; -import { deploymentFixturesArtifacts } from "../../helpers/execution-result-fixtures"; +} from "../../src/internal/execution/libraries"; +import { deploymentFixturesArtifacts } from "../helpers/execution-result-fixtures"; const mockAddress = "0x1122334455667788990011223344556677889900"; const mockAddress2 = "0x0011223344556677889900112233445566778899"; diff --git a/packages/core/test/new-api/new-execution/reducers/running-a-call.ts b/packages/core/test/execution/reducers/running-a-call.ts similarity index 91% rename from packages/core/test/new-api/new-execution/reducers/running-a-call.ts rename to packages/core/test/execution/reducers/running-a-call.ts index 97425d095..cac7e8832 100644 --- a/packages/core/test/new-api/new-execution/reducers/running-a-call.ts +++ b/packages/core/test/execution/reducers/running-a-call.ts @@ -1,14 +1,14 @@ import { assert } from "chai"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; -import { EvmExecutionResultTypes } from "../../../../src/new-api/internal/new-execution/types/evm-execution"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; +import { EvmExecutionResultTypes } from "../../../src/internal/execution/types/evm-execution"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { CallExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { TransactionReceiptStatus } from "../../../../src/new-api/internal/new-execution/types/jsonrpc"; +} from "../../../src/internal/execution/types/execution-state"; +import { TransactionReceiptStatus } from "../../../src/internal/execution/types/jsonrpc"; import { CallExecutionStateCompleteMessage, CallExecutionStateInitializeMessage, @@ -16,12 +16,12 @@ import { NetworkInteractionRequestMessage, TransactionConfirmMessage, TransactionSendMessage, -} from "../../../../src/new-api/internal/new-execution/types/messages"; -import { NetworkInteractionType } from "../../../../src/new-api/internal/new-execution/types/network-interaction"; -import { findOnchainInteractionBy } from "../../../../src/new-api/internal/new-execution/views/execution-state/find-onchain-interaction-by"; -import { findTransactionBy } from "../../../../src/new-api/internal/new-execution/views/execution-state/find-transaction-by"; -import { findExecutionStateById } from "../../../../src/new-api/internal/new-execution/views/find-execution-state-by-id"; -import { assertIgnitionInvariant } from "../../../../src/new-api/internal/utils/assertions"; +} from "../../../src/internal/execution/types/messages"; +import { NetworkInteractionType } from "../../../src/internal/execution/types/network-interaction"; +import { assertIgnitionInvariant } from "../../../src/internal/utils/assertions"; +import { findOnchainInteractionBy } from "../../../src/internal/views/execution-state/find-onchain-interaction-by"; +import { findTransactionBy } from "../../../src/internal/views/execution-state/find-transaction-by"; +import { findExecutionStateById } from "../../../src/internal/views/find-execution-state-by-id"; import { applyMessages } from "./utils"; @@ -42,7 +42,7 @@ describe("DeploymentStateReducer", () => { futureId: "Call1", strategy: "basic", dependencies: [], - artifactFutureId: "Contract1", + artifactId: "Contract1", contractAddress: exampleAddress, functionName: "configure", args: ["a", BigInt(2)], diff --git a/packages/core/test/new-api/new-execution/reducers/running-a-named-contract-deploy.ts b/packages/core/test/execution/reducers/running-a-named-contract-deploy.ts similarity index 91% rename from packages/core/test/new-api/new-execution/reducers/running-a-named-contract-deploy.ts rename to packages/core/test/execution/reducers/running-a-named-contract-deploy.ts index 79d85a7b2..3d98ae8c8 100644 --- a/packages/core/test/new-api/new-execution/reducers/running-a-named-contract-deploy.ts +++ b/packages/core/test/execution/reducers/running-a-named-contract-deploy.ts @@ -1,14 +1,14 @@ import { assert } from "chai"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; -import { EvmExecutionResultTypes } from "../../../../src/new-api/internal/new-execution/types/evm-execution"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; +import { EvmExecutionResultTypes } from "../../../src/internal/execution/types/evm-execution"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { TransactionReceiptStatus } from "../../../../src/new-api/internal/new-execution/types/jsonrpc"; +} from "../../../src/internal/execution/types/execution-state"; +import { TransactionReceiptStatus } from "../../../src/internal/execution/types/jsonrpc"; import { DeploymentExecutionStateCompleteMessage, DeploymentExecutionStateInitializeMessage, @@ -16,13 +16,13 @@ import { NetworkInteractionRequestMessage, TransactionConfirmMessage, TransactionSendMessage, -} from "../../../../src/new-api/internal/new-execution/types/messages"; -import { NetworkInteractionType } from "../../../../src/new-api/internal/new-execution/types/network-interaction"; -import { findOnchainInteractionBy } from "../../../../src/new-api/internal/new-execution/views/execution-state/find-onchain-interaction-by"; -import { findTransactionBy } from "../../../../src/new-api/internal/new-execution/views/execution-state/find-transaction-by"; -import { findExecutionStateById } from "../../../../src/new-api/internal/new-execution/views/find-execution-state-by-id"; -import { assertIgnitionInvariant } from "../../../../src/new-api/internal/utils/assertions"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/messages"; +import { NetworkInteractionType } from "../../../src/internal/execution/types/network-interaction"; +import { assertIgnitionInvariant } from "../../../src/internal/utils/assertions"; +import { findOnchainInteractionBy } from "../../../src/internal/views/execution-state/find-onchain-interaction-by"; +import { findTransactionBy } from "../../../src/internal/views/execution-state/find-transaction-by"; +import { findExecutionStateById } from "../../../src/internal/views/find-execution-state-by-id"; +import { FutureType } from "../../../src/types/module"; import { applyMessages } from "./utils"; @@ -41,10 +41,10 @@ describe("DeploymentStateReducer", () => { { type: JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, futureId: "future1", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", dependencies: [], - artifactFutureId: "future1", + artifactId: "future1", contractName: "MyContract", constructorArgs: [], libraries: {}, diff --git a/packages/core/test/new-api/new-execution/reducers/running-a-named-library-deploy.ts b/packages/core/test/execution/reducers/running-a-named-library-deploy.ts similarity index 82% rename from packages/core/test/new-api/new-execution/reducers/running-a-named-library-deploy.ts rename to packages/core/test/execution/reducers/running-a-named-library-deploy.ts index b1c3b940c..4e0bf15d7 100644 --- a/packages/core/test/new-api/new-execution/reducers/running-a-named-library-deploy.ts +++ b/packages/core/test/execution/reducers/running-a-named-library-deploy.ts @@ -1,13 +1,13 @@ import { assert } from "chai"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { TransactionReceiptStatus } from "../../../../src/new-api/internal/new-execution/types/jsonrpc"; +} from "../../../src/internal/execution/types/execution-state"; +import { TransactionReceiptStatus } from "../../../src/internal/execution/types/jsonrpc"; import { DeploymentExecutionStateCompleteMessage, DeploymentExecutionStateInitializeMessage, @@ -15,10 +15,10 @@ import { NetworkInteractionRequestMessage, TransactionConfirmMessage, TransactionSendMessage, -} from "../../../../src/new-api/internal/new-execution/types/messages"; -import { NetworkInteractionType } from "../../../../src/new-api/internal/new-execution/types/network-interaction"; -import { findExecutionStateById } from "../../../../src/new-api/internal/new-execution/views/find-execution-state-by-id"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/messages"; +import { NetworkInteractionType } from "../../../src/internal/execution/types/network-interaction"; +import { findExecutionStateById } from "../../../src/internal/views/find-execution-state-by-id"; +import { FutureType } from "../../../src/types/module"; import { applyMessages } from "./utils"; @@ -34,10 +34,10 @@ describe("DeploymentStateReducer", () => { { type: JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, futureId: "future1", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, strategy: "basic", dependencies: [], - artifactFutureId: "future1", + artifactId: "future1", contractName: "MyLibrary", constructorArgs: [], libraries: {}, diff --git a/packages/core/test/new-api/new-execution/reducers/running-a-read-event-arg.ts b/packages/core/test/execution/reducers/running-a-read-event-arg.ts similarity index 79% rename from packages/core/test/new-api/new-execution/reducers/running-a-read-event-arg.ts rename to packages/core/test/execution/reducers/running-a-read-event-arg.ts index a8fb7dc0e..b9366517d 100644 --- a/packages/core/test/new-api/new-execution/reducers/running-a-read-event-arg.ts +++ b/packages/core/test/execution/reducers/running-a-read-event-arg.ts @@ -1,16 +1,16 @@ import { assert } from "chai"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; import { ExecutionSateType, ExecutionStatus, ReadEventArgumentExecutionState, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; +} from "../../../src/internal/execution/types/execution-state"; import { JournalMessageType, ReadEventArgExecutionStateInitializeMessage, -} from "../../../../src/new-api/internal/new-execution/types/messages"; -import { findExecutionStateById } from "../../../../src/new-api/internal/new-execution/views/find-execution-state-by-id"; +} from "../../../src/internal/execution/types/messages"; +import { findExecutionStateById } from "../../../src/internal/views/find-execution-state-by-id"; import { applyMessages } from "./utils"; @@ -27,9 +27,9 @@ describe("DeploymentStateReducer", () => { futureId: "ReadEventArg1", strategy: "basic", dependencies: [], - artifactFutureId: "ReadEventArg1", + artifactId: "ReadEventArg1", eventName: "event1", - argumentName: "arg1", + nameOrIndex: "arg1", txToReadFrom: "0x1234", emitterAddress: exampleAddress, eventIndex: 1, @@ -68,9 +68,9 @@ describe("DeploymentStateReducer", () => { }); it("should record the details of the event being looked up", () => { - assert.equal(updatedReadEventExState.artifactFutureId, "ReadEventArg1"); + assert.equal(updatedReadEventExState.artifactId, "ReadEventArg1"); assert.equal(updatedReadEventExState.eventName, "event1"); - assert.equal(updatedReadEventExState.argumentName, "arg1"); + assert.equal(updatedReadEventExState.nameOrIndex, "arg1"); assert.equal(updatedReadEventExState.txToReadFrom, "0x1234"); assert.equal(updatedReadEventExState.emitterAddress, exampleAddress); assert.equal(updatedReadEventExState.eventIndex, 1); diff --git a/packages/core/test/new-api/new-execution/reducers/running-a-static-call.ts b/packages/core/test/execution/reducers/running-a-static-call.ts similarity index 92% rename from packages/core/test/new-api/new-execution/reducers/running-a-static-call.ts rename to packages/core/test/execution/reducers/running-a-static-call.ts index c4dca2a95..fc59bd81d 100644 --- a/packages/core/test/new-api/new-execution/reducers/running-a-static-call.ts +++ b/packages/core/test/execution/reducers/running-a-static-call.ts @@ -1,22 +1,22 @@ import { assert } from "chai"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; -import { EvmExecutionResultTypes } from "../../../../src/new-api/internal/new-execution/types/evm-execution"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; +import { EvmExecutionResultTypes } from "../../../src/internal/execution/types/evm-execution"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { ExecutionSateType, ExecutionStatus, StaticCallExecutionState, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; +} from "../../../src/internal/execution/types/execution-state"; import { JournalMessageType, NetworkInteractionRequestMessage, StaticCallCompleteMessage, StaticCallExecutionStateCompleteMessage, StaticCallExecutionStateInitializeMessage, -} from "../../../../src/new-api/internal/new-execution/types/messages"; -import { NetworkInteractionType } from "../../../../src/new-api/internal/new-execution/types/network-interaction"; -import { findExecutionStateById } from "../../../../src/new-api/internal/new-execution/views/find-execution-state-by-id"; +} from "../../../src/internal/execution/types/messages"; +import { NetworkInteractionType } from "../../../src/internal/execution/types/network-interaction"; +import { findExecutionStateById } from "../../../src/internal/views/find-execution-state-by-id"; import { applyMessages } from "./utils"; @@ -35,10 +35,11 @@ describe("DeploymentStateReducer", () => { futureId: "StaticCall1", strategy: "basic", dependencies: [], - artifactFutureId: "Contract1", + artifactId: "Contract1", contractAddress: exampleAddress, functionName: "configure", args: ["a", BigInt(2)], + nameOrIndex: 0, from: senderAddress, }; diff --git a/packages/core/test/new-api/new-execution/reducers/running-contract-at.ts b/packages/core/test/execution/reducers/running-contract-at.ts similarity index 75% rename from packages/core/test/new-api/new-execution/reducers/running-contract-at.ts rename to packages/core/test/execution/reducers/running-contract-at.ts index 803909196..3119fa483 100644 --- a/packages/core/test/new-api/new-execution/reducers/running-contract-at.ts +++ b/packages/core/test/execution/reducers/running-contract-at.ts @@ -1,17 +1,17 @@ import { assert } from "chai"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; import { ContractAtExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; +} from "../../../src/internal/execution/types/execution-state"; import { ContractAtExecutionStateInitializeMessage, JournalMessageType, -} from "../../../../src/new-api/internal/new-execution/types/messages"; -import { findExecutionStateById } from "../../../../src/new-api/internal/new-execution/views/find-execution-state-by-id"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/messages"; +import { findExecutionStateById } from "../../../src/internal/views/find-execution-state-by-id"; +import { FutureType } from "../../../src/types/module"; import { applyMessages } from "./utils"; @@ -27,10 +27,10 @@ describe("DeploymentStateReducer", () => { { type: JournalMessageType.CONTRACT_AT_EXECUTION_STATE_INITIALIZE, futureId: "ContractAt1", - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, strategy: "basic", dependencies: [], - artifactFutureId: "ContractAt1", + artifactId: "ContractAt1", contractName: "ContractAt1", contractAddress: exampleAddress, }; @@ -60,7 +60,7 @@ describe("DeploymentStateReducer", () => { }); it("should populate the relevant contract fields", () => { - assert.equal(updatedContractAtExState.artifactFutureId, "ContractAt1"); + assert.equal(updatedContractAtExState.artifactId, "ContractAt1"); assert.equal(updatedContractAtExState.contractName, "ContractAt1"); assert.equal(updatedContractAtExState.contractAddress, exampleAddress); }); diff --git a/packages/core/test/new-api/new-execution/reducers/running-send-data.ts b/packages/core/test/execution/reducers/running-send-data.ts similarity index 91% rename from packages/core/test/new-api/new-execution/reducers/running-send-data.ts rename to packages/core/test/execution/reducers/running-send-data.ts index 176bfe906..49e7cb1c0 100644 --- a/packages/core/test/new-api/new-execution/reducers/running-send-data.ts +++ b/packages/core/test/execution/reducers/running-send-data.ts @@ -1,14 +1,14 @@ import { assert } from "chai"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; -import { EvmExecutionResultTypes } from "../../../../src/new-api/internal/new-execution/types/evm-execution"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; +import { EvmExecutionResultTypes } from "../../../src/internal/execution/types/evm-execution"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { ExecutionSateType, ExecutionStatus, SendDataExecutionState, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { TransactionReceiptStatus } from "../../../../src/new-api/internal/new-execution/types/jsonrpc"; +} from "../../../src/internal/execution/types/execution-state"; +import { TransactionReceiptStatus } from "../../../src/internal/execution/types/jsonrpc"; import { JournalMessageType, NetworkInteractionRequestMessage, @@ -16,12 +16,12 @@ import { SendDataExecutionStateInitializeMessage, TransactionConfirmMessage, TransactionSendMessage, -} from "../../../../src/new-api/internal/new-execution/types/messages"; -import { NetworkInteractionType } from "../../../../src/new-api/internal/new-execution/types/network-interaction"; -import { findOnchainInteractionBy } from "../../../../src/new-api/internal/new-execution/views/execution-state/find-onchain-interaction-by"; -import { findTransactionBy } from "../../../../src/new-api/internal/new-execution/views/execution-state/find-transaction-by"; -import { findExecutionStateById } from "../../../../src/new-api/internal/new-execution/views/find-execution-state-by-id"; -import { assertIgnitionInvariant } from "../../../../src/new-api/internal/utils/assertions"; +} from "../../../src/internal/execution/types/messages"; +import { NetworkInteractionType } from "../../../src/internal/execution/types/network-interaction"; +import { assertIgnitionInvariant } from "../../../src/internal/utils/assertions"; +import { findOnchainInteractionBy } from "../../../src/internal/views/execution-state/find-onchain-interaction-by"; +import { findTransactionBy } from "../../../src/internal/views/execution-state/find-transaction-by"; +import { findExecutionStateById } from "../../../src/internal/views/find-execution-state-by-id"; import { applyMessages } from "./utils"; diff --git a/packages/core/test/new-api/new-execution/reducers/start-a-new-run.ts b/packages/core/test/execution/reducers/start-a-new-run.ts similarity index 68% rename from packages/core/test/new-api/new-execution/reducers/start-a-new-run.ts rename to packages/core/test/execution/reducers/start-a-new-run.ts index 304389afd..a1befb229 100644 --- a/packages/core/test/new-api/new-execution/reducers/start-a-new-run.ts +++ b/packages/core/test/execution/reducers/start-a-new-run.ts @@ -1,8 +1,8 @@ import { assert } from "chai"; -import { deploymentStateReducer } from "../../../../src/new-api/internal/new-execution/reducers/deployment-state-reducer"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; -import { JournalMessageType } from "../../../../src/new-api/internal/new-execution/types/messages"; +import { deploymentStateReducer } from "../../../src/internal/execution/reducers/deployment-state-reducer"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; +import { JournalMessageType } from "../../../src/internal/execution/types/messages"; describe("DeploymentStateReducer", () => { let initialState: DeploymentState; diff --git a/packages/core/test/execution/reducers/utils.ts b/packages/core/test/execution/reducers/utils.ts new file mode 100644 index 000000000..4545bb78a --- /dev/null +++ b/packages/core/test/execution/reducers/utils.ts @@ -0,0 +1,11 @@ +import { deploymentStateReducer } from "../../../src/internal/execution/reducers/deployment-state-reducer"; +import { DeploymentState } from "../../../src/internal/execution/types/deployment-state"; +import { JournalMessage } from "../../../src/internal/execution/types/messages"; + +export function applyMessages(messages: JournalMessage[]): DeploymentState { + const initialState = deploymentStateReducer(undefined); + + const updatedState = messages.reduce(deploymentStateReducer, initialState); + + return updatedState; +} diff --git a/packages/core/test/new-api/new-execution/utils/convert-evm-tuple-to-solidity-param.ts b/packages/core/test/execution/utils/convert-evm-tuple-to-solidity-param.ts similarity index 79% rename from packages/core/test/new-api/new-execution/utils/convert-evm-tuple-to-solidity-param.ts rename to packages/core/test/execution/utils/convert-evm-tuple-to-solidity-param.ts index 138240502..40f8cb2e6 100644 --- a/packages/core/test/new-api/new-execution/utils/convert-evm-tuple-to-solidity-param.ts +++ b/packages/core/test/execution/utils/convert-evm-tuple-to-solidity-param.ts @@ -1,7 +1,7 @@ import { assert } from "chai"; -import { EvmTuple } from "../../../../src/new-api/internal/new-execution/types/evm-execution"; -import { convertEvmTupleToSolidityParam } from "../../../../src/new-api/internal/new-execution/utils/convert-evm-tuple-to-solidity-param"; +import { EvmTuple } from "../../../src/internal/execution/types/evm-execution"; +import { convertEvmTupleToSolidityParam } from "../../../src/internal/execution/utils/convert-evm-tuple-to-solidity-param"; describe("converting evm tuples to solidity params", () => { it("should convert a tuple", () => { diff --git a/packages/core/test/new-api/new-execution/views/find-result-for-future-by-id.ts b/packages/core/test/execution/views/find-result-for-future-by-id.ts similarity index 88% rename from packages/core/test/new-api/new-execution/views/find-result-for-future-by-id.ts rename to packages/core/test/execution/views/find-result-for-future-by-id.ts index 0163a4330..db91ca26a 100644 --- a/packages/core/test/new-api/new-execution/views/find-result-for-future-by-id.ts +++ b/packages/core/test/execution/views/find-result-for-future-by-id.ts @@ -1,8 +1,8 @@ import { assert } from "chai"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; -import { ExecutionSateType } from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { findResultForFutureById } from "../../../../src/new-api/internal/new-execution/views/find-result-for-future-by-id"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; +import { ExecutionSateType } from "../../../src/internal/execution/types/execution-state"; +import { findResultForFutureById } from "../../../src/internal/views/find-result-for-future-by-id"; describe("find result by future by", () => { const futureId = "MyFuture"; diff --git a/packages/core/test/new-api/getAccount.ts b/packages/core/test/getAccount.ts similarity index 79% rename from packages/core/test/new-api/getAccount.ts rename to packages/core/test/getAccount.ts index 95aaf2d12..7798a1ea3 100644 --- a/packages/core/test/new-api/getAccount.ts +++ b/packages/core/test/getAccount.ts @@ -1,8 +1,8 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../src/new-api/build-module"; -import { AccountRuntimeValueImplementation } from "../../src/new-api/internal/module"; +import { buildModule } from "../src/build-module"; +import { AccountRuntimeValueImplementation } from "../src/internal/module"; import { assertInstanceOf } from "./helpers"; diff --git a/packages/core/test/new-api/getParameter.ts b/packages/core/test/getParameter.ts similarity index 94% rename from packages/core/test/new-api/getParameter.ts rename to packages/core/test/getParameter.ts index caeb7aa23..2f5bea215 100644 --- a/packages/core/test/new-api/getParameter.ts +++ b/packages/core/test/getParameter.ts @@ -1,9 +1,9 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../src/new-api/build-module"; -import { ModuleParameterRuntimeValueImplementation } from "../../src/new-api/internal/module"; -import { ModuleParameterType } from "../../src/new-api/types/module"; +import { buildModule } from "../src/build-module"; +import { ModuleParameterRuntimeValueImplementation } from "../src/internal/module"; +import { ModuleParameterType } from "../src/types/module"; import { assertInstanceOf } from "./helpers"; diff --git a/packages/core/test/new-api/helpers.ts b/packages/core/test/helpers.ts similarity index 75% rename from packages/core/test/new-api/helpers.ts rename to packages/core/test/helpers.ts index b89679238..aae403bf4 100644 --- a/packages/core/test/new-api/helpers.ts +++ b/packages/core/test/helpers.ts @@ -1,8 +1,8 @@ import { assert } from "chai"; -import { Artifact, ArtifactResolver } from "../../src"; -import { DeploymentLoader } from "../../src/new-api/internal/deployment-loader/types"; -import { Journal } from "../../src/new-api/internal/journal/types"; +import { Artifact, ArtifactResolver } from "../src"; +import { DeploymentLoader } from "../src/internal/deployment-loader/types"; +import { Journal } from "../src/internal/journal/types"; export const exampleAccounts: string[] = [ "0x70997970C51812dc3A010C7d01b50e0d17dc79C8", @@ -72,18 +72,18 @@ export function setupMockDeploymentLoader( recordDeployedAddress: async (futureId, contractAddress) => { storedDeployedAddresses[futureId] = contractAddress; }, - storeUserProvidedArtifact: async (artifactFutureId, artifact) => { - storedArtifacts[artifactFutureId] = artifact; + storeUserProvidedArtifact: async (artifactId, artifact) => { + storedArtifacts[artifactId] = artifact; }, - storeNamedArtifact: async (artifactFutureId, _contractName, artifact) => { - storedArtifacts[artifactFutureId] = artifact; + storeNamedArtifact: async (artifactId, _contractName, artifact) => { + storedArtifacts[artifactId] = artifact; }, storeBuildInfo: async () => {}, - loadArtifact: async (artifactFutureId: string) => { - const artifact = storedArtifacts[artifactFutureId]; + loadArtifact: async (artifactId: string) => { + const artifact = storedArtifacts[artifactId]; if (artifact === undefined) { - throw new Error(`Artifact not stored for ${artifactFutureId}`); + throw new Error(`Artifact not stored for ${artifactId}`); } return artifact; diff --git a/packages/core/test/helpers/execution-result-fixtures.ts b/packages/core/test/helpers/execution-result-fixtures.ts index 255405ba5..6cbef0dff 100644 --- a/packages/core/test/helpers/execution-result-fixtures.ts +++ b/packages/core/test/helpers/execution-result-fixtures.ts @@ -7,7 +7,7 @@ // We use Hardhat artifacts here, that's why we import this type import { Artifact } from "hardhat/types"; -import { RawStaticCallResult } from "../../src/new-api/internal/new-execution/types/jsonrpc"; +import { RawStaticCallResult } from "../../src/internal/execution/types/jsonrpc"; export const staticCallResultFixtures: { [contractName: string]: { [functionName: string]: RawStaticCallResult }; diff --git a/packages/core/test/new-api/library.ts b/packages/core/test/library.ts similarity index 88% rename from packages/core/test/new-api/library.ts rename to packages/core/test/library.ts index 723ceee6c..928ac3b50 100644 --- a/packages/core/test/new-api/library.ts +++ b/packages/core/test/library.ts @@ -1,13 +1,13 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../src/new-api/build-module"; +import { buildModule } from "../src/build-module"; import { AccountRuntimeValueImplementation, NamedLibraryDeploymentFutureImplementation, -} from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; -import { FutureType } from "../../src/new-api/types/module"; +} from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; +import { FutureType } from "../src/types/module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; @@ -25,14 +25,14 @@ describe("library", () => { assert.equal(moduleWithASingleContract.id, "Module1"); assert.equal( moduleWithASingleContract.results.library1.id, - "Module1:Library1" + "Module1#Library1" ); // 1 contract future assert.equal(moduleWithASingleContract.futures.size, 1); assert.equal( [...moduleWithASingleContract.futures][0].type, - FutureType.NAMED_LIBRARY_DEPLOYMENT + FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT ); // No submodules @@ -50,11 +50,11 @@ describe("library", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -80,11 +80,11 @@ describe("library", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -110,7 +110,7 @@ describe("library", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -134,7 +134,7 @@ describe("library", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -161,11 +161,11 @@ describe("library", () => { assert.equal(moduleWithSameContractTwice.id, "Module1"); assert.equal( moduleWithSameContractTwice.results.sameContract1.id, - "Module1:first" + "Module1#first" ); assert.equal( moduleWithSameContractTwice.results.sameContract2.id, - "Module1:second" + "Module1#second" ); }); @@ -178,7 +178,7 @@ describe("library", () => { return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:SameContract found in module Module1/ + /Duplicated id Module1#SameContract found in module Module1/ ); }); @@ -195,7 +195,7 @@ describe("library", () => { return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:same found in module Module1/ + /Duplicated id Module1#same found in module Module1/ ); }); }); @@ -233,12 +233,12 @@ describe("library", () => { }); describe("stage one", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageOne/validateNamedLibraryDeployment"); + let vm: typeof import("../src/internal/validation/stageOne/validateNamedLibraryDeployment"); let validateNamedLibraryDeployment: typeof vm.validateNamedLibraryDeployment; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageOne/validateNamedLibraryDeployment" + "../src/internal/validation/stageOne/validateNamedLibraryDeployment" ); validateNamedLibraryDeployment = vm.validateNamedLibraryDeployment; @@ -264,12 +264,12 @@ describe("library", () => { }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateNamedLibraryDeployment"); + let vm: typeof import("../src/internal/validation/stageTwo/validateNamedLibraryDeployment"); let validateNamedLibraryDeployment: typeof vm.validateNamedLibraryDeployment; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateNamedLibraryDeployment" + "../src/internal/validation/stageTwo/validateNamedLibraryDeployment" ); validateNamedLibraryDeployment = vm.validateNamedLibraryDeployment; diff --git a/packages/core/test/new-api/libraryFromArtifact.ts b/packages/core/test/libraryFromArtifact.ts similarity index 72% rename from packages/core/test/new-api/libraryFromArtifact.ts rename to packages/core/test/libraryFromArtifact.ts index b8281670a..2c657b24c 100644 --- a/packages/core/test/new-api/libraryFromArtifact.ts +++ b/packages/core/test/libraryFromArtifact.ts @@ -1,13 +1,13 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; +import { Artifact } from "../src"; +import { buildModule } from "../src/build-module"; import { AccountRuntimeValueImplementation, ArtifactLibraryDeploymentFutureImplementation, -} from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; +} from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; @@ -21,7 +21,7 @@ describe("libraryFromArtifact", () => { it("should be able to deploy with a library based on an artifact", () => { const moduleWithContractFromArtifact = buildModule("Module1", (m) => { - const library1 = m.libraryFromArtifact("Library1", fakeArtifact); + const library1 = m.library("Library1", fakeArtifact); return { library1 }; }); @@ -32,7 +32,7 @@ describe("libraryFromArtifact", () => { assert.equal(moduleWithContractFromArtifact.id, "Module1"); assert.equal( moduleWithContractFromArtifact.results.library1.id, - "Module1:Library1" + "Module1#Library1" ); // 1 contract future @@ -45,7 +45,7 @@ describe("libraryFromArtifact", () => { it("should be able to pass an after dependency", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.library("Example"); - const another = m.libraryFromArtifact("Another", fakeArtifact, { + const another = m.library("Another", fakeArtifact, { after: [example], }); @@ -64,7 +64,7 @@ describe("libraryFromArtifact", () => { it("should be able to pass a library as a dependency of a library", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.library("Example"); - const another = m.libraryFromArtifact("Another", fakeArtifact, { + const another = m.library("Another", fakeArtifact, { libraries: { Example: example }, }); @@ -74,11 +74,11 @@ describe("libraryFromArtifact", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -94,7 +94,7 @@ describe("libraryFromArtifact", () => { it("should be able to pass a string as from option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - const another = m.libraryFromArtifact("Another", fakeArtifact, { + const another = m.library("Another", fakeArtifact, { from: "0x2", }); @@ -104,7 +104,7 @@ describe("libraryFromArtifact", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -118,7 +118,7 @@ describe("libraryFromArtifact", () => { it("Should be able to pass an AccountRuntimeValue as from option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - const another = m.libraryFromArtifact("Another", fakeArtifact, { + const another = m.library("Another", fakeArtifact, { from: m.getAccount(1), }); @@ -128,7 +128,7 @@ describe("libraryFromArtifact", () => { assert.isDefined(moduleWithDependentContracts); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); if ( @@ -144,18 +144,12 @@ describe("libraryFromArtifact", () => { describe("passing id", () => { it("should use library from artifact twice by passing an id", () => { const moduleWithSameContractTwice = buildModule("Module1", (m) => { - const sameContract1 = m.libraryFromArtifact( - "SameContract", - fakeArtifact, - { id: "first" } - ); - const sameContract2 = m.libraryFromArtifact( - "SameContract", - fakeArtifact, - { - id: "second", - } - ); + const sameContract1 = m.library("SameContract", fakeArtifact, { + id: "first", + }); + const sameContract2 = m.library("SameContract", fakeArtifact, { + id: "second", + }); return { sameContract1, sameContract2 }; }); @@ -164,11 +158,11 @@ describe("libraryFromArtifact", () => { assert.equal(moduleWithSameContractTwice.id, "Module1"); assert.equal( moduleWithSameContractTwice.results.sameContract1.id, - "Module1:first" + "Module1#first" ); assert.equal( moduleWithSameContractTwice.results.sameContract2.id, - "Module1:second" + "Module1#second" ); }); @@ -176,18 +170,12 @@ describe("libraryFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const sameContract1 = m.libraryFromArtifact( - "SameContract", - fakeArtifact - ); - const sameContract2 = m.libraryFromArtifact( - "SameContract", - fakeArtifact - ); + const sameContract1 = m.library("SameContract", fakeArtifact); + const sameContract2 = m.library("SameContract", fakeArtifact); return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:SameContract found in module Module1/ + /Duplicated id Module1#SameContract found in module Module1/ ); }); @@ -195,24 +183,16 @@ describe("libraryFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const sameContract1 = m.libraryFromArtifact( - "SameContract", - fakeArtifact, - { - id: "same", - } - ); - const sameContract2 = m.libraryFromArtifact( - "SameContract", - fakeArtifact, - { - id: "same", - } - ); + const sameContract1 = m.library("SameContract", fakeArtifact, { + id: "same", + }); + const sameContract2 = m.library("SameContract", fakeArtifact, { + id: "same", + }); return { sameContract1, sameContract2 }; }), - /Duplicated id Module1:same found in module Module1/ + /Duplicated id Module1#same found in module Module1/ ); }); }); @@ -223,7 +203,7 @@ describe("libraryFromArtifact", () => { assert.throws( () => buildModule("Module1", (m) => { - const another = m.libraryFromArtifact("Another", fakeArtifact, { + const another = m.library("Another", fakeArtifact, { from: 1 as any, }); @@ -240,7 +220,7 @@ describe("libraryFromArtifact", () => { const another = m.contract("Another", []); const call = m.call(another, "test"); - const test = m.libraryFromArtifact("Test", fakeArtifact, { + const test = m.library("Test", fakeArtifact, { libraries: { Call: call as any }, }); @@ -249,27 +229,15 @@ describe("libraryFromArtifact", () => { /Given library 'Call' is not a valid Future/ ); }); - - it("should not validate an invalid artifact", () => { - assert.throws( - () => - buildModule("Module1", (m) => { - const another = m.libraryFromArtifact("Another", {} as Artifact); - - return { another }; - }), - /Invalid artifact given/ - ); - }); }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateArtifactLibraryDeployment"); + let vm: typeof import("../src/internal/validation/stageTwo/validateArtifactLibraryDeployment"); let validateArtifactLibraryDeployment: typeof vm.validateArtifactLibraryDeployment; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateArtifactLibraryDeployment" + "../src/internal/validation/stageTwo/validateArtifactLibraryDeployment" ); validateArtifactLibraryDeployment = @@ -279,7 +247,7 @@ describe("libraryFromArtifact", () => { it("should not validate a negative account index", async () => { const module = buildModule("Module1", (m) => { const account = m.getAccount(-1); - const test = m.libraryFromArtifact("Test", fakeArtifact, { + const test = m.library("Test", fakeArtifact, { from: account, }); @@ -302,7 +270,7 @@ describe("libraryFromArtifact", () => { it("should not validate an account index greater than the number of available accounts", async () => { const module = buildModule("Module1", (m) => { const account = m.getAccount(1); - const test = m.libraryFromArtifact("Test", fakeArtifact, { + const test = m.library("Test", fakeArtifact, { from: account, }); diff --git a/packages/core/test/new-api/new-execution/reducers/utils.ts b/packages/core/test/new-api/new-execution/reducers/utils.ts deleted file mode 100644 index fb647eaad..000000000 --- a/packages/core/test/new-api/new-execution/reducers/utils.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { deploymentStateReducer } from "../../../../src/new-api/internal/new-execution/reducers/deployment-state-reducer"; -import { DeploymentState } from "../../../../src/new-api/internal/new-execution/types/deployment-state"; -import { JournalMessage } from "../../../../src/new-api/internal/new-execution/types/messages"; - -export function applyMessages(messages: JournalMessage[]): DeploymentState { - const initialState = deploymentStateReducer(undefined); - - const updatedState = messages.reduce(deploymentStateReducer, initialState); - - return updatedState; -} diff --git a/packages/core/test/new-api/readEventArgument.ts b/packages/core/test/readEventArgument.ts similarity index 79% rename from packages/core/test/new-api/readEventArgument.ts rename to packages/core/test/readEventArgument.ts index 4ab19a9b9..536b45794 100644 --- a/packages/core/test/new-api/readEventArgument.ts +++ b/packages/core/test/readEventArgument.ts @@ -1,9 +1,9 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact, FutureType, ReadEventArgumentFuture } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; +import { Artifact, FutureType, ReadEventArgumentFuture } from "../src"; +import { buildModule } from "../src/build-module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; import { setupMockArtifactResolver } from "./helpers"; @@ -19,7 +19,7 @@ describe("Read event argument", () => { const mod = buildModule("Module1", (m) => { const contract = m.contract("Contract"); - const contractFromArtifact = m.contractFromArtifact( + const contractFromArtifact = m.contract( "ContractFromArtifact", fakeArtifact ); @@ -33,7 +33,7 @@ describe("Read event argument", () => { }); const callFuture = Array.from(mod.futures).find( - (f) => f.type === FutureType.NAMED_CONTRACT_CALL + (f) => f.type === FutureType.CONTRACT_CALL ); const [read1, read2, read3] = Array.from(mod.futures).filter( @@ -84,13 +84,13 @@ describe("Read event argument", () => { assert.equal(read2.emitter, mod.results.emitter); }); - it("should set the right eventName and argumentName", () => { + it("should set the right eventName and nameOrIndex", () => { const mod = buildModule("Module1", (m) => { const contract = m.contract("Contract"); const call = m.call(contract, "fuc"); m.readEventArgument(contract, "EventName1", "arg1"); - m.readEventArgument(call, "EventName2", "arg2"); + m.readEventArgument(call, "EventName2", 2); return { contract }; }); @@ -100,10 +100,10 @@ describe("Read event argument", () => { ) as ReadEventArgumentFuture[]; assert.equal(read1.eventName, "EventName1"); - assert.equal(read1.argumentName, "arg1"); + assert.equal(read1.nameOrIndex, "arg1"); assert.equal(read2.eventName, "EventName2"); - assert.equal(read2.argumentName, "arg2"); + assert.equal(read2.nameOrIndex, 2); }); it("should default the eventIndex to 0", () => { @@ -161,8 +161,8 @@ describe("Read event argument", () => { assert.equal(mod.id, "Module1"); const futuresIds = Array.from(mod.futures).map((f) => f.id); - assert.include(futuresIds, "Module1:Main#EventName#arg1#0"); - assert.include(futuresIds, "Module1:Emitter#EventName2#arg2#1"); + assert.include(futuresIds, "Module1#Main.EventName.arg1.0"); + assert.include(futuresIds, "Module1#Emitter.EventName2.arg2.1"); }); it("should be able to read the same argument twice by passing a explicit id", () => { @@ -185,19 +185,49 @@ describe("Read event argument", () => { moduleWithSameReadEventArgumentTwice.futures ).map((f) => f.id); - assert.include(futuresIds, "Module1:Example#EventName#arg1#0"); - assert.include(futuresIds, "Module1:second"); + assert.include(futuresIds, "Module1#Example.EventName.arg1.0"); + assert.include(futuresIds, "Module1#second"); }); }); describe("validation", () => { + describe("module stage", () => { + it("should not validate a SendDataFuture if no emitter is provided", () => { + assert.throws( + () => + buildModule("Module1", (m) => { + const send = m.send("id", "test", 42n); + + m.readEventArgument(send, "SomeEvent", "someArg"); + + return {}; + }), + /`options.emitter` must be provided when reading an event from a SendDataFuture/ + ); + }); + + it("should not validate a nameOrIndex that is not a number or string", () => { + assert.throws( + () => + buildModule("Module1", (m) => { + const another = m.contract("Another", []); + + m.readEventArgument(another, "test", {} as any); + + return { another }; + }), + /Invalid nameOrIndex given/ + ); + }); + }); + describe("stage one", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageOne/validateReadEventArgument"); + let vm: typeof import("../src/internal/validation/stageOne/validateReadEventArgument"); let validateReadEventArgument: typeof vm.validateReadEventArgument; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageOne/validateReadEventArgument" + "../src/internal/validation/stageOne/validateReadEventArgument" ); validateReadEventArgument = vm.validateReadEventArgument; @@ -233,7 +263,7 @@ describe("Read event argument", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.readEventArgument(another, "test", "arg"); return { another }; diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileArtifactContractAt.ts b/packages/core/test/reconciliation/futures/reconcileArtifactContractAt.ts similarity index 73% rename from packages/core/test/new-api/reconciliation/futures/reconcileArtifactContractAt.ts rename to packages/core/test/reconciliation/futures/reconcileArtifactContractAt.ts index 85f488892..ca8e5bbec 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileArtifactContractAt.ts +++ b/packages/core/test/reconciliation/futures/reconcileArtifactContractAt.ts @@ -1,16 +1,16 @@ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { ContractAtExecutionState, DeploymentExecutionState, ExecutionSateType, ExecutionStatus, StaticCallExecutionState, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { getDefaultSender } from "../../../../src/new-api/internal/new-execution/utils/get-default-sender"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { getDefaultSender } from "../../../src/internal/execution/utils/get-default-sender"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -26,23 +26,23 @@ describe("Reconciliation - artifact contract at", () => { const exampleContractAtState: ContractAtExecutionState = { id: "Example", type: ExecutionSateType.CONTRACT_AT_EXECUTION_STATE, - futureType: FutureType.ARTIFACT_CONTRACT_AT, + futureType: FutureType.CONTRACT_AT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), contractName: "Contract1", contractAddress: exampleAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", }; const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), - artifactFutureId: "Example", + artifactId: "Example", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -54,25 +54,22 @@ describe("Reconciliation - artifact contract at", () => { const exampleStaticCallState: StaticCallExecutionState = { id: "Example", type: ExecutionSateType.STATIC_CALL_EXECUTION_STATE, - futureType: FutureType.NAMED_STATIC_CALL, + futureType: FutureType.STATIC_CALL, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), contractAddress: exampleAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", functionName: "function", args: [], + nameOrIndex: 0, from: getDefaultSender(exampleAccounts), networkInteractions: [], }; it("should reconcile when using an address string", async () => { const submoduleDefinition = buildModule("Submodule", (m) => { - const contract1 = m.contractAtFromArtifact( - "Contract1", - exampleAddress, - mockArtifact - ); + const contract1 = m.contractAt("Contract1", exampleAddress, mockArtifact); return { contract1 }; }); @@ -85,11 +82,11 @@ describe("Reconciliation - artifact contract at", () => { const deploymentState = createDeploymentState({ ...exampleContractAtState, - id: `Submodule:Contract1`, - futureType: FutureType.ARTIFACT_CONTRACT_AT, + id: `Submodule#Contract1`, + futureType: FutureType.CONTRACT_AT, status: ExecutionStatus.STARTED, contractAddress: exampleAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", }); await assertSuccessReconciliation(moduleDefinition, deploymentState); @@ -100,7 +97,7 @@ describe("Reconciliation - artifact contract at", () => { const example = m.contract("Example"); const call = m.staticCall(example, "getAddress"); - const another = m.contractAtFromArtifact("Another", call, mockArtifact); + const another = m.contractAt("Another", call, mockArtifact); return { another }; }); @@ -108,8 +105,8 @@ describe("Reconciliation - artifact contract at", () => { const deploymentState = createDeploymentState( { ...exampleDeploymentState, - id: "Module:Example", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Example", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Example", result: { @@ -119,8 +116,8 @@ describe("Reconciliation - artifact contract at", () => { }, { ...exampleStaticCallState, - id: "Module:Example#getAddress", - futureType: FutureType.NAMED_STATIC_CALL, + id: "Module#Example.getAddress", + futureType: FutureType.STATIC_CALL, status: ExecutionStatus.SUCCESS, functionName: "getAddress", result: { @@ -130,12 +127,12 @@ describe("Reconciliation - artifact contract at", () => { }, { ...exampleContractAtState, - id: "Module:Another", - futureType: FutureType.ARTIFACT_CONTRACT_AT, + id: "Module#Another", + futureType: FutureType.CONTRACT_AT, status: ExecutionStatus.STARTED, contractName: "Another", contractAddress: differentAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", } ); @@ -144,7 +141,7 @@ describe("Reconciliation - artifact contract at", () => { it("should find changes to contract name unreconciliable", async () => { const moduleDefinition = buildModule("Module", (m) => { - const contract1 = m.contractAtFromArtifact( + const contract1 = m.contractAt( "ContractChanged", exampleAddress, mockArtifact, @@ -160,18 +157,18 @@ describe("Reconciliation - artifact contract at", () => { moduleDefinition, createDeploymentState({ ...exampleContractAtState, - id: "Module:Factory", - futureType: FutureType.ARTIFACT_CONTRACT_AT, + id: "Module#Factory", + futureType: FutureType.CONTRACT_AT, status: ExecutionStatus.STARTED, contractName: "ContractUnchanged", contractAddress: differentAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", }) ); assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Factory", + futureId: "Module#Factory", failure: "Contract name has been changed from ContractUnchanged to ContractChanged", }, @@ -180,7 +177,7 @@ describe("Reconciliation - artifact contract at", () => { it("should find changes to contract address as a literal unreconciliable", async () => { const moduleDefinition = buildModule("Module", (m) => { - const contract1 = m.contractAtFromArtifact( + const contract1 = m.contractAt( "Contract1", exampleAddress, mockArtifact, @@ -196,8 +193,8 @@ describe("Reconciliation - artifact contract at", () => { moduleDefinition, createDeploymentState({ ...exampleContractAtState, - id: "Module:Factory", - futureType: FutureType.ARTIFACT_CONTRACT_AT, + id: "Module#Factory", + futureType: FutureType.CONTRACT_AT, status: ExecutionStatus.STARTED, contractAddress: differentAddress, }) @@ -205,7 +202,7 @@ describe("Reconciliation - artifact contract at", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Factory", + futureId: "Module#Factory", failure: "Address has been changed from 0xBA12222222228d8Ba445958a75a0704d566BF2C8 to 0x1F98431c8aD98523631AE4a59f267346ea31F984", }, diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileArtifactContractDeployment.ts b/packages/core/test/reconciliation/futures/reconcileArtifactContractDeployment.ts similarity index 73% rename from packages/core/test/new-api/reconciliation/futures/reconcileArtifactContractDeployment.ts rename to packages/core/test/reconciliation/futures/reconcileArtifactContractDeployment.ts index a426a6856..fa6981068 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileArtifactContractDeployment.ts +++ b/packages/core/test/reconciliation/futures/reconcileArtifactContractDeployment.ts @@ -1,13 +1,13 @@ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -23,13 +23,13 @@ describe("Reconciliation - artifact contract", () => { const exampleDeploymentState: DeploymentExecutionState = { id: "Example", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -42,16 +42,11 @@ describe("Reconciliation - artifact contract", () => { const supply = m.getParameter("supply", BigInt(1000)); const safeMath = m.library("SafeMath"); - const contract1 = m.contractFromArtifact( - "Contract1", - mockArtifact, - [{ supply }], - { - libraries: { - SafeMath: safeMath, - }, - } - ); + const contract1 = m.contract("Contract1", mockArtifact, [{ supply }], { + libraries: { + SafeMath: safeMath, + }, + }); return { contract1 }; }); @@ -67,8 +62,8 @@ describe("Reconciliation - artifact contract", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Submodule:SafeMath", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Submodule#SafeMath", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "SafeMath", result: { @@ -78,8 +73,8 @@ describe("Reconciliation - artifact contract", () => { }, { ...exampleDeploymentState, - id: "Submodule:Contract1", - futureType: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, + id: "Submodule#Contract1", + futureType: FutureType.CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, constructorArgs: [{ supply: BigInt(1000) }], libraries: { @@ -92,12 +87,9 @@ describe("Reconciliation - artifact contract", () => { it("should find changes to contract name unreconciliable", async () => { const moduleDefinition = buildModule("Module", (m) => { - const contract1 = m.contractFromArtifact( - "ContractChanged", - mockArtifact, - [], - { id: "Example" } - ); + const contract1 = m.contract("ContractChanged", mockArtifact, [], { + id: "Example", + }); return { contract1 }; }); @@ -106,8 +98,8 @@ describe("Reconciliation - artifact contract", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", - futureType: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, + id: "Module#Example", + futureType: FutureType.CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "ContractUnchanged", }) @@ -115,7 +107,7 @@ describe("Reconciliation - artifact contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: "Contract name has been changed from ContractUnchanged to ContractChanged", }, @@ -128,7 +120,7 @@ describe("Reconciliation - artifact contract", () => { const supply = m.getParameter("supply", BigInt(500)); const ticker = m.getParameter("ticker", "CodeCoin"); - const contract1 = m.contractFromArtifact("Contract1", mockArtifact, [ + const contract1 = m.contract("Contract1", mockArtifact, [ owner, { nested: { supply } }, [1, ticker, 3], @@ -141,8 +133,8 @@ describe("Reconciliation - artifact contract", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Contract1", - futureType: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, + id: "Module#Contract1", + futureType: FutureType.CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, constructorArgs: [ "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", @@ -154,7 +146,7 @@ describe("Reconciliation - artifact contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1", + futureId: "Module#Contract1", failure: "Argument at index 2 has been changed", }, ]); @@ -164,7 +156,7 @@ describe("Reconciliation - artifact contract", () => { const moduleDefinition = buildModule("Module", (m) => { const safeMath = m.library("SafeMath"); - const contract1 = m.contractFromArtifact("Contract1", mockArtifact, [], { + const contract1 = m.contract("Contract1", mockArtifact, [], { libraries: { SafeMath: safeMath, }, @@ -178,8 +170,8 @@ describe("Reconciliation - artifact contract", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:SafeMath", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Module#SafeMath", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "SafeMath", result: { @@ -189,8 +181,8 @@ describe("Reconciliation - artifact contract", () => { }, { ...exampleDeploymentState, - id: "Module:Contract1", - futureType: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, + id: "Module#Contract1", + futureType: FutureType.CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, libraries: {}, } @@ -199,7 +191,7 @@ describe("Reconciliation - artifact contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1", + futureId: "Module#Contract1", failure: "Library SafeMath has been added", }, ]); @@ -207,7 +199,7 @@ describe("Reconciliation - artifact contract", () => { it("should find changes to value unreconciliable", async () => { const moduleDefinition = buildModule("Module", (m) => { - const contract1 = m.contractFromArtifact("Contract1", mockArtifact, [], { + const contract1 = m.contract("Contract1", mockArtifact, [], { id: "Example", value: BigInt(4), }); @@ -219,8 +211,8 @@ describe("Reconciliation - artifact contract", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", - futureType: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, + id: "Module#Example", + futureType: FutureType.CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, value: BigInt(3), }) @@ -228,7 +220,7 @@ describe("Reconciliation - artifact contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: "Value has been changed from 3 to 4", }, ]); @@ -236,7 +228,7 @@ describe("Reconciliation - artifact contract", () => { it("should find changes to from unreconciliable", async () => { const moduleDefinition = buildModule("Module", (m) => { - const contract1 = m.contractFromArtifact("Contract1", mockArtifact, [], { + const contract1 = m.contract("Contract1", mockArtifact, [], { id: "Example", from: twoAddress, }); @@ -248,8 +240,8 @@ describe("Reconciliation - artifact contract", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", - futureType: FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, + id: "Module#Example", + futureType: FutureType.CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, from: oneAddress, }) @@ -257,7 +249,7 @@ describe("Reconciliation - artifact contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: `From account has been changed from ${oneAddress} to ${twoAddress}`, }, ]); diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileArtifactLibraryDeployment.ts b/packages/core/test/reconciliation/futures/reconcileArtifactLibraryDeployment.ts similarity index 75% rename from packages/core/test/new-api/reconciliation/futures/reconcileArtifactLibraryDeployment.ts rename to packages/core/test/reconciliation/futures/reconcileArtifactLibraryDeployment.ts index b009fc734..0244f7e08 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileArtifactLibraryDeployment.ts +++ b/packages/core/test/reconciliation/futures/reconcileArtifactLibraryDeployment.ts @@ -1,13 +1,13 @@ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -24,12 +24,12 @@ describe("Reconciliation - artifact library", () => { const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -41,7 +41,7 @@ describe("Reconciliation - artifact library", () => { const submoduleDefinition = buildModule("Submodule", (m) => { const safeMath = m.library("SafeMath"); - const mainLib = m.libraryFromArtifact("MainLibrary", mockArtifact, { + const mainLib = m.library("MainLibrary", mockArtifact, { libraries: { SafeMath: safeMath }, }); @@ -59,8 +59,8 @@ describe("Reconciliation - artifact library", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Submodule:SafeMath", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Submodule#SafeMath", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "SafeMath", result: { @@ -70,8 +70,8 @@ describe("Reconciliation - artifact library", () => { }, { ...exampleDeploymentState, - id: "Submodule:MainLibrary", - futureType: FutureType.ARTIFACT_LIBRARY_DEPLOYMENT, + id: "Submodule#MainLibrary", + futureType: FutureType.LIBRARY_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "MainLibrary", libraries: { @@ -84,7 +84,7 @@ describe("Reconciliation - artifact library", () => { it("should find changes to contract name unreconciliable", async () => { const moduleDefinition = buildModule("Module", (m) => { - const library1 = m.libraryFromArtifact("LibraryChanged", mockArtifact, { + const library1 = m.library("LibraryChanged", mockArtifact, { id: "Example", }); @@ -95,8 +95,8 @@ describe("Reconciliation - artifact library", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", - futureType: FutureType.ARTIFACT_LIBRARY_DEPLOYMENT, + id: "Module#Example", + futureType: FutureType.LIBRARY_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "LibraryUnchanged", }) @@ -104,7 +104,7 @@ describe("Reconciliation - artifact library", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: "Contract name has been changed from LibraryUnchanged to LibraryChanged", }, @@ -115,7 +115,7 @@ describe("Reconciliation - artifact library", () => { const moduleDefinition = buildModule("Module", (m) => { const safeMath = m.library("SafeMath"); - const mainLib = m.libraryFromArtifact("MainLibrary", mockArtifact, { + const mainLib = m.library("MainLibrary", mockArtifact, { libraries: { Changed: safeMath }, }); @@ -127,8 +127,8 @@ describe("Reconciliation - artifact library", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:SafeMath", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Module#SafeMath", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "SafeMath", result: { @@ -138,8 +138,8 @@ describe("Reconciliation - artifact library", () => { }, { ...exampleDeploymentState, - id: "Module:MainLibrary", - futureType: FutureType.ARTIFACT_LIBRARY_DEPLOYMENT, + id: "Module#MainLibrary", + futureType: FutureType.LIBRARY_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "MainLibrary", libraries: { @@ -151,7 +151,7 @@ describe("Reconciliation - artifact library", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:MainLibrary", + futureId: "Module#MainLibrary", failure: "Library Unchanged has been removed", }, ]); @@ -159,7 +159,7 @@ describe("Reconciliation - artifact library", () => { it("should find changes to contract name unreconciliable", async () => { const moduleDefinition = buildModule("Module", (m) => { - const library1 = m.libraryFromArtifact("Library1", mockArtifact, { + const library1 = m.library("Library1", mockArtifact, { id: "Example", from: twoAddress, }); @@ -171,8 +171,8 @@ describe("Reconciliation - artifact library", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", - futureType: FutureType.ARTIFACT_LIBRARY_DEPLOYMENT, + id: "Module#Example", + futureType: FutureType.LIBRARY_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "Library1", from: oneAddress, @@ -181,7 +181,7 @@ describe("Reconciliation - artifact library", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: `From account has been changed from ${oneAddress} to ${twoAddress}`, }, ]); diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileNamedContractAt.ts b/packages/core/test/reconciliation/futures/reconcileNamedContractAt.ts similarity index 81% rename from packages/core/test/new-api/reconciliation/futures/reconcileNamedContractAt.ts rename to packages/core/test/reconciliation/futures/reconcileNamedContractAt.ts index ccac801c4..8b717ca65 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileNamedContractAt.ts +++ b/packages/core/test/reconciliation/futures/reconcileNamedContractAt.ts @@ -1,16 +1,16 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { ContractAtExecutionState, DeploymentExecutionState, ExecutionSateType, ExecutionStatus, StaticCallExecutionState, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -25,24 +25,24 @@ describe("Reconciliation - named contract at", () => { const exampleContractAtState: ContractAtExecutionState = { id: "Example", type: ExecutionSateType.CONTRACT_AT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_AT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), contractName: "Contract1", contractAddress: exampleAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", }; const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -53,15 +53,16 @@ describe("Reconciliation - named contract at", () => { const exampleStaticCallState: StaticCallExecutionState = { id: "Example", type: ExecutionSateType.STATIC_CALL_EXECUTION_STATE, - futureType: FutureType.NAMED_STATIC_CALL, + futureType: FutureType.STATIC_CALL, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], contractAddress: exampleAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", functionName: "function", args: [], + nameOrIndex: 0, from: exampleAccounts[0], }; @@ -80,8 +81,8 @@ describe("Reconciliation - named contract at", () => { const deploymentState = createDeploymentState({ ...exampleContractAtState, - id: `Submodule:Contract1`, - futureType: FutureType.NAMED_CONTRACT_AT, + id: `Submodule#Contract1`, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, status: ExecutionStatus.STARTED, contractAddress: exampleAddress, }); @@ -102,8 +103,8 @@ describe("Reconciliation - named contract at", () => { const previousExecutionState = createDeploymentState( { ...exampleDeploymentState, - id: "Module:Example", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Example", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Example", result: { @@ -113,8 +114,8 @@ describe("Reconciliation - named contract at", () => { }, { ...exampleStaticCallState, - id: "Module:Example#getAddress", - futureType: FutureType.NAMED_STATIC_CALL, + id: "Module#Example.getAddress", + futureType: FutureType.STATIC_CALL, status: ExecutionStatus.SUCCESS, functionName: "getAddress", result: { @@ -124,8 +125,8 @@ describe("Reconciliation - named contract at", () => { }, { ...exampleContractAtState, - id: "Module:Another", - futureType: FutureType.NAMED_CONTRACT_AT, + id: "Module#Another", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, status: ExecutionStatus.STARTED, contractAddress: differentAddress, contractName: "Another", @@ -148,8 +149,8 @@ describe("Reconciliation - named contract at", () => { moduleDefinition, createDeploymentState({ ...exampleContractAtState, - id: "Module:Factory", - futureType: FutureType.NAMED_CONTRACT_AT, + id: "Module#Factory", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, status: ExecutionStatus.STARTED, contractName: "ContractUnchanged", contractAddress: exampleAddress, @@ -158,7 +159,7 @@ describe("Reconciliation - named contract at", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Factory", + futureId: "Module#Factory", failure: "Contract name has been changed from ContractUnchanged to ContractChanged", }, @@ -178,8 +179,8 @@ describe("Reconciliation - named contract at", () => { moduleDefinition, createDeploymentState({ ...exampleContractAtState, - id: "Module:Factory", - futureType: FutureType.NAMED_CONTRACT_AT, + id: "Module#Factory", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_AT, status: ExecutionStatus.STARTED, contractAddress: differentAddress, }) @@ -187,7 +188,7 @@ describe("Reconciliation - named contract at", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Factory", + futureId: "Module#Factory", failure: "Address has been changed from 0xBA12222222228d8Ba445958a75a0704d566BF2C8 to 0x1F98431c8aD98523631AE4a59f267346ea31F984", }, diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileNamedContractCall.ts b/packages/core/test/reconciliation/futures/reconcileNamedContractCall.ts similarity index 82% rename from packages/core/test/new-api/reconciliation/futures/reconcileNamedContractCall.ts rename to packages/core/test/reconciliation/futures/reconcileNamedContractCall.ts index b3e6ab09d..37aa17c44 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileNamedContractCall.ts +++ b/packages/core/test/reconciliation/futures/reconcileNamedContractCall.ts @@ -1,15 +1,15 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { CallExecutionState, DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -26,12 +26,12 @@ describe("Reconciliation - named contract call", () => { const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -42,13 +42,13 @@ describe("Reconciliation - named contract call", () => { const exampleContractCallState: CallExecutionState = { id: "Example", type: ExecutionSateType.CALL_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_CALL, + futureType: FutureType.CONTRACT_CALL, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], contractAddress: differentAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", functionName: "function", args: [], value: BigInt("0"), @@ -75,7 +75,7 @@ describe("Reconciliation - named contract call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Submodule:Contract1", + id: "Submodule#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -84,8 +84,8 @@ describe("Reconciliation - named contract call", () => { }, { ...exampleContractCallState, - id: "Submodule:Contract1#function1", - futureType: FutureType.NAMED_CONTRACT_CALL, + id: "Submodule#Contract1.function1", + futureType: FutureType.CONTRACT_CALL, status: ExecutionStatus.SUCCESS, functionName: "function1", args: [1, "a", differentAddress], @@ -108,7 +108,7 @@ describe("Reconciliation - named contract call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -117,8 +117,8 @@ describe("Reconciliation - named contract call", () => { }, { ...exampleContractCallState, - id: "Module:Contract1#config", - futureType: FutureType.NAMED_CONTRACT_CALL, + id: "Module#config", + futureType: FutureType.CONTRACT_CALL, status: ExecutionStatus.STARTED, functionName: "function1", contractAddress: exampleAddress, @@ -128,9 +128,9 @@ describe("Reconciliation - named contract call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#config", + futureId: "Module#config", failure: - "Contract address has been changed from 0x1F98431c8aD98523631AE4a59f267346ea31F984 to 0xBA12222222228d8Ba445958a75a0704d566BF2C8 (future Module:Contract1)", + "Contract address has been changed from 0x1F98431c8aD98523631AE4a59f267346ea31F984 to 0xBA12222222228d8Ba445958a75a0704d566BF2C8 (future Module#Contract1)", }, ]); }); @@ -149,7 +149,7 @@ describe("Reconciliation - named contract call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -158,8 +158,8 @@ describe("Reconciliation - named contract call", () => { }, { ...exampleContractCallState, - id: "Module:Contract1#config", - futureType: FutureType.NAMED_CONTRACT_CALL, + id: "Module#config", + futureType: FutureType.CONTRACT_CALL, status: ExecutionStatus.STARTED, functionName: "functionUnchanged", } @@ -168,7 +168,7 @@ describe("Reconciliation - named contract call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#config", + futureId: "Module#config", failure: "Function name has been changed from functionUnchanged to functionChanged", }, @@ -191,7 +191,7 @@ describe("Reconciliation - named contract call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -200,8 +200,8 @@ describe("Reconciliation - named contract call", () => { }, { ...exampleContractCallState, - id: "Module:Contract1#function1", - futureType: FutureType.NAMED_CONTRACT_CALL, + id: "Module#Contract1.function1", + futureType: FutureType.CONTRACT_CALL, status: ExecutionStatus.STARTED, functionName: "function1", args: [["UNCHANGED"]], @@ -211,7 +211,7 @@ describe("Reconciliation - named contract call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#function1", + futureId: "Module#Contract1.function1", failure: "Argument at index 0 has been changed", }, ]); @@ -231,7 +231,7 @@ describe("Reconciliation - named contract call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -240,8 +240,8 @@ describe("Reconciliation - named contract call", () => { }, { ...exampleContractCallState, - id: "Module:Contract1#config", - futureType: FutureType.NAMED_CONTRACT_CALL, + id: "Module#config", + futureType: FutureType.CONTRACT_CALL, status: ExecutionStatus.STARTED, functionName: "function1", value: BigInt(2), @@ -251,7 +251,7 @@ describe("Reconciliation - named contract call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#config", + futureId: "Module#config", failure: "Value has been changed from 2 to 3", }, ]); @@ -271,7 +271,7 @@ describe("Reconciliation - named contract call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -280,8 +280,8 @@ describe("Reconciliation - named contract call", () => { }, { ...exampleContractCallState, - id: "Module:Contract1#config", - futureType: FutureType.NAMED_CONTRACT_CALL, + id: "Module#config", + futureType: FutureType.CONTRACT_CALL, status: ExecutionStatus.STARTED, functionName: "function1", from: oneAddress, @@ -291,7 +291,7 @@ describe("Reconciliation - named contract call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#config", + futureId: "Module#config", failure: `From account has been changed from ${oneAddress} to ${twoAddress}`, }, ]); diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileNamedContractDeployment.ts b/packages/core/test/reconciliation/futures/reconcileNamedContractDeployment.ts similarity index 86% rename from packages/core/test/new-api/reconciliation/futures/reconcileNamedContractDeployment.ts rename to packages/core/test/reconciliation/futures/reconcileNamedContractDeployment.ts index 04c5cf0db..7271abf4e 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileNamedContractDeployment.ts +++ b/packages/core/test/reconciliation/futures/reconcileNamedContractDeployment.ts @@ -1,14 +1,14 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -24,12 +24,12 @@ describe("Reconciliation - named contract", () => { const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -69,8 +69,8 @@ describe("Reconciliation - named contract", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Submodule:SafeMath", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Submodule#SafeMath", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "SafeMath", result: { @@ -80,7 +80,7 @@ describe("Reconciliation - named contract", () => { }, { ...exampleDeploymentState, - id: "Submodule:Contract1", + id: "Submodule#Contract1", status: ExecutionStatus.STARTED, constructorArgs: [ "0x15d34AAf54267DB7D7c367839AAf71A00a2C6A65", @@ -109,7 +109,7 @@ describe("Reconciliation - named contract", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", + id: "Module#Example", status: ExecutionStatus.STARTED, contractName: "ContractUnchanged", }) @@ -117,7 +117,7 @@ describe("Reconciliation - named contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: "Contract name has been changed from ContractUnchanged to ContractChanged", }, @@ -145,7 +145,7 @@ describe("Reconciliation - named contract", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", + id: "Module#Example", status: ExecutionStatus.STARTED, contractName: "ContractUnchanged", constructorArgs: [1, 2, 3], @@ -154,7 +154,7 @@ describe("Reconciliation - named contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: "Contract name has been changed from ContractUnchanged to ContractChanged", }, @@ -179,8 +179,8 @@ describe("Reconciliation - named contract", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:SafeMath", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Module#SafeMath", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "SafeMath", result: { @@ -190,7 +190,7 @@ describe("Reconciliation - named contract", () => { }, { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.STARTED, libraries: {}, } @@ -199,7 +199,7 @@ describe("Reconciliation - named contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1", + futureId: "Module#Contract1", failure: "Library SafeMath has been added", }, ]); @@ -219,7 +219,7 @@ describe("Reconciliation - named contract", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", + id: "Module#Example", status: ExecutionStatus.STARTED, contractName: "Contract", value: BigInt(2), @@ -228,7 +228,7 @@ describe("Reconciliation - named contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: "Value has been changed from 2 to 3", }, ]); @@ -248,7 +248,7 @@ describe("Reconciliation - named contract", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Example", + id: "Module#Example", status: ExecutionStatus.STARTED, contractName: "Contract", from: oneAddress, @@ -257,7 +257,7 @@ describe("Reconciliation - named contract", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Example", + futureId: "Module#Example", failure: `From account has been changed from ${oneAddress} to ${twoAddress}`, }, ]); diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileNamedLibraryDeployment.ts b/packages/core/test/reconciliation/futures/reconcileNamedLibraryDeployment.ts similarity index 79% rename from packages/core/test/new-api/reconciliation/futures/reconcileNamedLibraryDeployment.ts rename to packages/core/test/reconciliation/futures/reconcileNamedLibraryDeployment.ts index d9ba1d9f5..f0cdcdb4c 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileNamedLibraryDeployment.ts +++ b/packages/core/test/reconciliation/futures/reconcileNamedLibraryDeployment.ts @@ -1,14 +1,14 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -24,12 +24,12 @@ describe("Reconciliation - named library", () => { const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -59,8 +59,8 @@ describe("Reconciliation - named library", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Submodule:SafeMath", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Submodule#SafeMath", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "SafeMath", result: { @@ -70,8 +70,8 @@ describe("Reconciliation - named library", () => { }, { ...exampleDeploymentState, - id: "Submodule:MainLibrary", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Submodule#MainLibrary", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "MainLibrary", libraries: { @@ -93,8 +93,8 @@ describe("Reconciliation - named library", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Library", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Module#Library", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "LibraryUnchanged", }) @@ -102,7 +102,7 @@ describe("Reconciliation - named library", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Library", + futureId: "Module#Library", failure: "Contract name has been changed from LibraryUnchanged to LibraryChanged", }, @@ -125,8 +125,8 @@ describe("Reconciliation - named library", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:SafeMath", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Module#SafeMath", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "SafeMath", result: { @@ -136,8 +136,8 @@ describe("Reconciliation - named library", () => { }, { ...exampleDeploymentState, - id: "Module:MainLibrary", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Module#MainLibrary", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "MainLibrary", libraries: { @@ -149,7 +149,7 @@ describe("Reconciliation - named library", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:MainLibrary", + futureId: "Module#MainLibrary", failure: "Library Unchanged has been removed", }, ]); @@ -166,8 +166,8 @@ describe("Reconciliation - named library", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Library", - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, + id: "Module#Library", + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "Library", from: oneAddress, @@ -176,7 +176,7 @@ describe("Reconciliation - named library", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Library", + futureId: "Module#Library", failure: `From account has been changed from ${oneAddress} to ${twoAddress}`, }, ]); diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileNamedStaticCall.ts b/packages/core/test/reconciliation/futures/reconcileNamedStaticCall.ts similarity index 72% rename from packages/core/test/new-api/reconciliation/futures/reconcileNamedStaticCall.ts rename to packages/core/test/reconciliation/futures/reconcileNamedStaticCall.ts index 06f5f8abf..691ec4c33 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileNamedStaticCall.ts +++ b/packages/core/test/reconciliation/futures/reconcileNamedStaticCall.ts @@ -1,15 +1,15 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, StaticCallExecutionState, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -26,12 +26,12 @@ describe("Reconciliation - named static call", () => { const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -42,15 +42,16 @@ describe("Reconciliation - named static call", () => { const exampleStaticCallState: StaticCallExecutionState = { id: "Example", type: ExecutionSateType.STATIC_CALL_EXECUTION_STATE, - futureType: FutureType.NAMED_STATIC_CALL, + futureType: FutureType.STATIC_CALL, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], contractAddress: exampleAddress, - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", functionName: "function", args: [], + nameOrIndex: 0, from: exampleAccounts[0], }; @@ -74,7 +75,7 @@ describe("Reconciliation - named static call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Submodule:Contract1", + id: "Submodule#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -83,8 +84,8 @@ describe("Reconciliation - named static call", () => { }, { ...exampleStaticCallState, - id: "Submodule:Contract1#function1", - futureType: FutureType.NAMED_STATIC_CALL, + id: "Submodule#Contract1.function1", + futureType: FutureType.STATIC_CALL, status: ExecutionStatus.SUCCESS, contractAddress: exampleAddress, functionName: "function1", @@ -98,7 +99,7 @@ describe("Reconciliation - named static call", () => { const moduleDefinition = buildModule("Module", (m) => { const contract1 = m.contract("Contract1"); - m.staticCall(contract1, "function1", [], { id: "config" }); + m.staticCall(contract1, "function1", [], 0, { id: "config" }); return { contract1 }; }); @@ -108,7 +109,7 @@ describe("Reconciliation - named static call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -117,7 +118,7 @@ describe("Reconciliation - named static call", () => { }, { ...exampleStaticCallState, - id: "Module:Contract1#config", + id: "Module#config", status: ExecutionStatus.STARTED, functionName: "function1", contractAddress: exampleAddress, @@ -127,9 +128,9 @@ describe("Reconciliation - named static call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#config", + futureId: "Module#config", failure: - "Contract address has been changed from 0x1F98431c8aD98523631AE4a59f267346ea31F984 to 0xBA12222222228d8Ba445958a75a0704d566BF2C8 (future Module:Contract1)", + "Contract address has been changed from 0x1F98431c8aD98523631AE4a59f267346ea31F984 to 0xBA12222222228d8Ba445958a75a0704d566BF2C8 (future Module#Contract1)", }, ]); }); @@ -138,7 +139,7 @@ describe("Reconciliation - named static call", () => { const moduleDefinition = buildModule("Module", (m) => { const contract1 = m.contract("Contract1"); - m.staticCall(contract1, "functionChanged", [], { id: "config" }); + m.staticCall(contract1, "functionChanged", [], 0, { id: "config" }); return { contract1 }; }); @@ -148,7 +149,7 @@ describe("Reconciliation - named static call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -157,8 +158,8 @@ describe("Reconciliation - named static call", () => { }, { ...exampleStaticCallState, - id: "Module:Contract1#config", - futureType: FutureType.NAMED_STATIC_CALL, + id: "Module#config", + futureType: FutureType.STATIC_CALL, status: ExecutionStatus.STARTED, contractAddress: exampleAddress, functionName: "functionUnchanged", @@ -168,7 +169,7 @@ describe("Reconciliation - named static call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#config", + futureId: "Module#config", failure: "Function name has been changed from functionUnchanged to functionChanged", }, @@ -181,7 +182,7 @@ describe("Reconciliation - named static call", () => { const contract1 = m.contract("Contract1"); - m.staticCall(contract1, "function1", [{ ticker }], {}); + m.staticCall(contract1, "function1", [{ ticker }], 0, {}); return { contract1 }; }); @@ -191,7 +192,7 @@ describe("Reconciliation - named static call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -200,8 +201,8 @@ describe("Reconciliation - named static call", () => { }, { ...exampleStaticCallState, - id: "Module:Contract1#function1", - futureType: FutureType.NAMED_STATIC_CALL, + id: "Module#Contract1.function1", + futureType: FutureType.STATIC_CALL, status: ExecutionStatus.STARTED, contractAddress: exampleAddress, functionName: "function1", @@ -212,7 +213,7 @@ describe("Reconciliation - named static call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#function1", + futureId: "Module#Contract1.function1", failure: "Argument at index 0 has been changed", }, ]); @@ -222,7 +223,7 @@ describe("Reconciliation - named static call", () => { const moduleDefinition = buildModule("Module", (m) => { const contract1 = m.contract("Contract1"); - m.staticCall(contract1, "function1", [], { + m.staticCall(contract1, "function1", [], 0, { id: "config", from: twoAddress, }); @@ -235,7 +236,7 @@ describe("Reconciliation - named static call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -244,8 +245,8 @@ describe("Reconciliation - named static call", () => { }, { ...exampleStaticCallState, - id: "Module:Contract1#config", - futureType: FutureType.NAMED_STATIC_CALL, + id: "Module#config", + futureType: FutureType.STATIC_CALL, status: ExecutionStatus.STARTED, contractAddress: exampleAddress, functionName: "function1", @@ -256,21 +257,62 @@ describe("Reconciliation - named static call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1#config", + futureId: "Module#config", failure: `From account has been changed from ${oneAddress} to ${twoAddress}`, }, ]); }); + it("should find changes to the argument unreconciliable", async () => { + const moduleDefinition = buildModule("Module", (m) => { + const contract = m.contract("Contract"); + + m.staticCall(contract, "function", [], "argChanged"); + + return { contract }; + }); + + const reconiliationResult = await reconcile( + moduleDefinition, + createDeploymentState( + { + ...exampleDeploymentState, + id: "Module#Contract", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, + status: ExecutionStatus.SUCCESS, + result: { + type: ExecutionResultType.SUCCESS, + address: exampleAddress, + }, + contractName: "Contract", + }, + { + ...exampleStaticCallState, + id: "Module#Contract.function", + status: ExecutionStatus.STARTED, + nameOrIndex: "argUnchanged", + } + ) + ); + + assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ + { + futureId: "Module#Contract.function", + failure: + "Argument name or index has been changed from argUnchanged to argChanged", + }, + ]); + }); + it("should not reconcile the use of the result of a static call that has changed", async () => { const moduleDefinition = buildModule("Module", (m) => { const contract1 = m.contract("Contract1"); - const resultArg1 = m.staticCall(contract1, "function1", ["first"], { - id: "first-call", + const resultArg1 = m.staticCall(contract1, "function1", ["first"], 0, { + id: "first_call", }); - const resultArg2 = m.staticCall(contract1, "function1", ["second"], { - id: "second-call", + const resultArg2 = m.staticCall(contract1, "function1", ["second"], 0, { + id: "second_call", after: [resultArg1], }); @@ -289,7 +331,7 @@ describe("Reconciliation - named static call", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -298,10 +340,10 @@ describe("Reconciliation - named static call", () => { }, { ...exampleStaticCallState, - id: "Module:first-call", - futureType: FutureType.NAMED_STATIC_CALL, + id: "Module#first_call", + futureType: FutureType.STATIC_CALL, status: ExecutionStatus.SUCCESS, - dependencies: new Set(["Module:Contract1"]), + dependencies: new Set(["Module#Contract1"]), contractAddress: exampleAddress, functionName: "function1", args: ["first"], @@ -312,13 +354,10 @@ describe("Reconciliation - named static call", () => { }, { ...exampleStaticCallState, - id: "Module:Contract1#second-call", - futureType: FutureType.NAMED_STATIC_CALL, + id: "Module#second_call", + futureType: FutureType.STATIC_CALL, status: ExecutionStatus.SUCCESS, - dependencies: new Set([ - "Module:Contract1", - "Module:Contract1#first-call", - ]), + dependencies: new Set(["Module#Contract1", "Module#first_call"]), contractAddress: exampleAddress, functionName: "function1", args: ["second"], @@ -329,12 +368,9 @@ describe("Reconciliation - named static call", () => { }, { ...exampleDeploymentState, - id: "Module:Contract2", + id: "Module#Contract2", status: ExecutionStatus.STARTED, - dependencies: new Set([ - "Module:Contract1#first-call", - "Module:Contract1#second-call", - ]), + dependencies: new Set(["Module#first_call", "Module#second_call"]), contractName: "Contract2", constructorArgs: ["first"], result: { @@ -347,7 +383,7 @@ describe("Reconciliation - named static call", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract2", + futureId: "Module#Contract2", failure: "Argument at index 0 has been changed", }, ]); diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileReadEventArgument.ts b/packages/core/test/reconciliation/futures/reconcileReadEventArgument.ts similarity index 81% rename from packages/core/test/new-api/reconciliation/futures/reconcileReadEventArgument.ts rename to packages/core/test/reconciliation/futures/reconcileReadEventArgument.ts index 6dc09587e..ffb6b4b28 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileReadEventArgument.ts +++ b/packages/core/test/reconciliation/futures/reconcileReadEventArgument.ts @@ -1,15 +1,15 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; -import { ExecutionResultType } from "../../../../src/new-api/internal/new-execution/types/execution-result"; +import { buildModule } from "../../../src/build-module"; +import { ExecutionResultType } from "../../../src/internal/execution/types/execution-result"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, ReadEventArgumentExecutionState, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -29,9 +29,9 @@ describe("Reconciliation - read event argument", () => { strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", eventName: "event1", - argumentName: "argument1", + nameOrIndex: "argument1", eventIndex: 0, emitterAddress: exampleAddress, txToReadFrom: txId, @@ -41,12 +41,12 @@ describe("Reconciliation - read event argument", () => { const exampleDeploymentState: DeploymentExecutionState = { id: "Example", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "./artifact.json", + artifactId: "./artifact.json", contractName: "Contract1", value: BigInt("0"), constructorArgs: [], @@ -74,8 +74,8 @@ describe("Reconciliation - read event argument", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Submodule:Contract", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Submodule#Contract", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract", result: { @@ -85,10 +85,10 @@ describe("Reconciliation - read event argument", () => { }, { ...exampleReadArgState, - id: "Submodule:Contract#EventName1#arg1#0", + id: "Submodule#Contract.EventName1.arg1.0", status: ExecutionStatus.STARTED, eventName: "EventName1", - argumentName: "arg1", + nameOrIndex: "arg1", } ) ); @@ -110,8 +110,8 @@ describe("Reconciliation - read event argument", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract", result: { @@ -121,7 +121,7 @@ describe("Reconciliation - read event argument", () => { }, { ...exampleReadArgState, - id: "Module:ReadEvent", + id: "Module#ReadEvent", status: ExecutionStatus.STARTED, eventName: "eventUnchanged", } @@ -130,7 +130,7 @@ describe("Reconciliation - read event argument", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:ReadEvent", + futureId: "Module#ReadEvent", failure: "Event name has been changed from eventUnchanged to EventChanged", }, @@ -153,8 +153,8 @@ describe("Reconciliation - read event argument", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -164,18 +164,18 @@ describe("Reconciliation - read event argument", () => { }, { ...exampleReadArgState, - id: "Module:ReadEvent", + id: "Module#ReadEvent", status: ExecutionStatus.STARTED, - argumentName: "argUnchanged", + nameOrIndex: "argUnchanged", } ) ); assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:ReadEvent", + futureId: "Module#ReadEvent", failure: - "Argument name has been changed from argUnchanged to argChanged", + "Argument name or index has been changed from argUnchanged to argChanged", }, ]); }); @@ -197,8 +197,8 @@ describe("Reconciliation - read event argument", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -208,7 +208,7 @@ describe("Reconciliation - read event argument", () => { }, { ...exampleReadArgState, - id: "Module:ReadEvent", + id: "Module#ReadEvent", status: ExecutionStatus.STARTED, eventIndex: 1, } @@ -217,7 +217,7 @@ describe("Reconciliation - read event argument", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:ReadEvent", + futureId: "Module#ReadEvent", failure: "Event index has been changed from 1 to 3", }, ]); @@ -241,8 +241,8 @@ describe("Reconciliation - read event argument", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract1", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract1", result: { @@ -252,8 +252,8 @@ describe("Reconciliation - read event argument", () => { }, { ...exampleDeploymentState, - id: "Module:Contract2", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract2", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract2", result: { @@ -263,7 +263,7 @@ describe("Reconciliation - read event argument", () => { }, { ...exampleReadArgState, - id: "Module:ReadEvent", + id: "Module#ReadEvent", status: ExecutionStatus.STARTED, emitterAddress: exampleAddress, } @@ -272,9 +272,9 @@ describe("Reconciliation - read event argument", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:ReadEvent", + futureId: "Module#ReadEvent", failure: - "Emitter has been changed from 0x1F98431c8aD98523631AE4a59f267346ea31F984 to 0xBA12222222228d8Ba445958a75a0704d566BF2C8 (future Module:Contract2)", + "Emitter has been changed from 0x1F98431c8aD98523631AE4a59f267346ea31F984 to 0xBA12222222228d8Ba445958a75a0704d566BF2C8 (future Module#Contract2)", }, ]); }); @@ -306,7 +306,7 @@ describe("Reconciliation - read event argument", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", + id: "Module#Contract1", status: ExecutionStatus.SUCCESS, result: { type: ExecutionResultType.SUCCESS, @@ -315,29 +315,29 @@ describe("Reconciliation - read event argument", () => { }, { ...exampleReadArgState, - id: "Module:ReadEvent1", + id: "Module#ReadEvent1", status: ExecutionStatus.SUCCESS, - dependencies: new Set(["Module:Contract1"]), + dependencies: new Set(["Module#Contract1"]), eventName: "event1", - argumentName: "argument1", + nameOrIndex: "argument1", emitterAddress: exampleAddress, result: "first", }, { ...exampleReadArgState, - id: "Module:ReadEvent2", + id: "Module#ReadEvent2", status: ExecutionStatus.SUCCESS, - dependencies: new Set(["Module:Contract1"]), + dependencies: new Set(["Module#Contract1"]), eventName: "event2", - argumentName: "argument2", + nameOrIndex: "argument2", emitterAddress: exampleAddress, result: "second", }, { ...exampleDeploymentState, - id: "Module:Contract2", + id: "Module#Contract2", status: ExecutionStatus.STARTED, - dependencies: new Set(["Module:ReadEvent1", "Module:ReadEvent2"]), + dependencies: new Set(["Module#ReadEvent1", "Module#ReadEvent2"]), contractName: "Contract2", result: { type: ExecutionResultType.SUCCESS, @@ -350,7 +350,7 @@ describe("Reconciliation - read event argument", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract2", + futureId: "Module#Contract2", failure: "Argument at index 0 has been changed", }, ]); diff --git a/packages/core/test/new-api/reconciliation/futures/reconcileSendData.ts b/packages/core/test/reconciliation/futures/reconcileSendData.ts similarity index 88% rename from packages/core/test/new-api/reconciliation/futures/reconcileSendData.ts rename to packages/core/test/reconciliation/futures/reconcileSendData.ts index 400331307..06dca8e5c 100644 --- a/packages/core/test/new-api/reconciliation/futures/reconcileSendData.ts +++ b/packages/core/test/reconciliation/futures/reconcileSendData.ts @@ -1,13 +1,13 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../../../src/new-api/build-module"; +import { buildModule } from "../../../src/build-module"; import { ExecutionSateType, ExecutionStatus, SendDataExecutionState, -} from "../../../../src/new-api/internal/new-execution/types/execution-state"; -import { FutureType } from "../../../../src/new-api/types/module"; +} from "../../../src/internal/execution/types/execution-state"; +import { FutureType } from "../../../src/types/module"; import { exampleAccounts } from "../../helpers"; import { assertSuccessReconciliation, @@ -50,7 +50,7 @@ describe("Reconciliation - send data", () => { moduleDefinition, createDeploymentState({ ...exampleSendState, - id: "Submodule:test_send", + id: "Submodule#test_send", status: ExecutionStatus.STARTED, }) ); @@ -67,7 +67,7 @@ describe("Reconciliation - send data", () => { moduleDefinition, createDeploymentState({ ...exampleSendState, - id: "Module:test_send", + id: "Module#test_send", status: ExecutionStatus.STARTED, data: "0x", }) @@ -85,7 +85,7 @@ describe("Reconciliation - send data", () => { moduleDefinition, createDeploymentState({ ...exampleSendState, - id: "Module:test_send", + id: "Module#test_send", status: ExecutionStatus.STARTED, to: exampleAddress, }) @@ -93,7 +93,7 @@ describe("Reconciliation - send data", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:test_send", + futureId: "Module#test_send", failure: 'Address "to" has been changed from 0x1F98431c8aD98523631AE4a59f267346ea31F984 to 0xBA12222222228d8Ba445958a75a0704d566BF2C8', }, @@ -111,7 +111,7 @@ describe("Reconciliation - send data", () => { moduleDefinition, createDeploymentState({ ...exampleSendState, - id: "Module:test_send", + id: "Module#test_send", status: ExecutionStatus.STARTED, data: "unchanged_data", }) @@ -119,7 +119,7 @@ describe("Reconciliation - send data", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:test_send", + futureId: "Module#test_send", failure: "Data has been changed from unchanged_data to changed_data", }, ]); @@ -136,7 +136,7 @@ describe("Reconciliation - send data", () => { moduleDefinition, createDeploymentState({ ...exampleSendState, - id: "Module:test_send", + id: "Module#test_send", status: ExecutionStatus.STARTED, value: 2n, }) @@ -144,7 +144,7 @@ describe("Reconciliation - send data", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:test_send", + futureId: "Module#test_send", failure: "Value has been changed from 2 to 3", }, ]); @@ -163,7 +163,7 @@ describe("Reconciliation - send data", () => { moduleDefinition, createDeploymentState({ ...exampleSendState, - id: "Module:test_send", + id: "Module#test_send", status: ExecutionStatus.STARTED, from: exampleAddress, }) @@ -171,7 +171,7 @@ describe("Reconciliation - send data", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:test_send", + futureId: "Module#test_send", failure: `From account has been changed from ${exampleAddress} to ${differentAddress}`, }, ]); diff --git a/packages/core/test/new-api/reconciliation/helpers.ts b/packages/core/test/reconciliation/helpers.ts similarity index 80% rename from packages/core/test/new-api/reconciliation/helpers.ts rename to packages/core/test/reconciliation/helpers.ts index 4db7366de..fc2dd54d8 100644 --- a/packages/core/test/new-api/reconciliation/helpers.ts +++ b/packages/core/test/reconciliation/helpers.ts @@ -5,15 +5,15 @@ import { ArtifactResolver, BuildInfo, DeploymentParameters, -} from "../../../src"; -import { DeploymentLoader } from "../../../src/new-api/internal/deployment-loader/types"; -import { DeploymentState } from "../../../src/new-api/internal/new-execution/types/deployment-state"; -import { ExecutionState } from "../../../src/new-api/internal/new-execution/types/execution-state"; -import { JournalMessage } from "../../../src/new-api/internal/new-execution/types/messages"; -import { getDefaultSender } from "../../../src/new-api/internal/new-execution/utils/get-default-sender"; -import { Reconciler } from "../../../src/new-api/internal/reconciliation/reconciler"; -import { ReconciliationResult } from "../../../src/new-api/internal/reconciliation/types"; -import { IgnitionModule } from "../../../src/new-api/types/module"; +} from "../../src"; +import { DeploymentLoader } from "../../src/internal/deployment-loader/types"; +import { DeploymentState } from "../../src/internal/execution/types/deployment-state"; +import { ExecutionState } from "../../src/internal/execution/types/execution-state"; +import { JournalMessage } from "../../src/internal/execution/types/messages"; +import { getDefaultSender } from "../../src/internal/execution/utils/get-default-sender"; +import { Reconciler } from "../../src/internal/reconciliation/reconciler"; +import { ReconciliationResult } from "../../src/internal/reconciliation/types"; +import { IgnitionModule } from "../../src/types/module"; import { exampleAccounts } from "../helpers"; export const oneAddress = "0x1111111111111111111111111111111111111111"; @@ -37,7 +37,7 @@ class MockDeploymentLoader implements DeploymentLoader { unknown > {} - public async loadArtifact(_artifactFutureId: string): Promise { + public async loadArtifact(_artifactId: string): Promise { return mockArtifact; } @@ -56,7 +56,10 @@ class MockDeploymentLoader implements DeploymentLoader { throw new Error("Method not implemented."); } - public storeBuildInfo(_buildInfo: BuildInfo): Promise { + public storeBuildInfo( + _futureId: string, + _buildInfo: BuildInfo + ): Promise { throw new Error("Method not implemented."); } @@ -66,6 +69,10 @@ class MockDeploymentLoader implements DeploymentLoader { ): Promise { throw new Error("Method not implemented."); } + + public emitDeploymentBatchEvent(_batches: string[][]): void { + throw new Error("Method not implemented."); + } } class MockArtifactResolver implements ArtifactResolver { diff --git a/packages/core/test/new-api/reconciliation/reconciler.ts b/packages/core/test/reconciliation/reconciler.ts similarity index 83% rename from packages/core/test/new-api/reconciliation/reconciler.ts rename to packages/core/test/reconciliation/reconciler.ts index 45b5e82f9..437da1646 100644 --- a/packages/core/test/new-api/reconciliation/reconciler.ts +++ b/packages/core/test/reconciliation/reconciler.ts @@ -1,14 +1,15 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../../src/new-api/build-module"; +import { buildModule } from "../../src/build-module"; import { DeploymentExecutionState, ExecutionSateType, ExecutionStatus, -} from "../../../src/new-api/internal/new-execution/types/execution-state"; -import { getDefaultSender } from "../../../src/new-api/internal/new-execution/utils/get-default-sender"; -import { FutureType } from "../../../src/new-api/types/module"; +} from "../../src/internal/execution/types/execution-state"; +import { getDefaultSender } from "../../src/internal/execution/utils/get-default-sender"; +import { Reconciler } from "../../src/internal/reconciliation/reconciler"; +import { FutureType } from "../../src/types/module"; import { exampleAccounts } from "../helpers"; import { @@ -22,14 +23,14 @@ import { describe("Reconciliation", () => { const exampleDeploymentState: DeploymentExecutionState = { - id: "Module1:Contract1", + id: "Module1#Contract1", type: ExecutionSateType.DEPLOYMENT_EXECUTION_STATE, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, strategy: "basic", status: ExecutionStatus.STARTED, dependencies: new Set(), networkInteractions: [], - artifactFutureId: "Example", + artifactId: "Example", contractName: "Contract1", value: 0n, constructorArgs: [], @@ -90,14 +91,14 @@ describe("Reconciliation", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module1:ContractMissed", // This future is not in the module + id: "Module1#ContractMissed", // This future is not in the module status: ExecutionStatus.STARTED, }) ); assert.deepStrictEqual( reconiliationResult.missingExecutedFutures, - ["Module1:ContractMissed"], + ["Module1#ContractMissed"], "Expected one missing previous executed future" ); }); @@ -112,9 +113,9 @@ describe("Reconciliation", () => { const reconiliationResult = await reconcile(moduleDefinition, { chainId: 123, executionStates: { - "Module1:Example": { + "Module1#Example": { ...exampleDeploymentState, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, }, }, @@ -122,61 +123,49 @@ describe("Reconciliation", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module1:Example", + futureId: "Module1#Example", failure: - "Future with id Module1:Example has changed from NAMED_CONTRACT_DEPLOYMENT to NAMED_LIBRARY_DEPLOYMENT", + "Future with id Module1#Example has changed from NAMED_ARTIFACT_CONTRACT_DEPLOYMENT to NAMED_ARTIFACT_LIBRARY_DEPLOYMENT", }, ]); }); - it("should flag as unreconsiliable a future that timed out on the previous run", async () => { - const moduleDefinition = buildModule("Module1", (m) => { - const contract1 = m.contract("Contract1"); - - return { contract1 }; - }); - - const reconiliationResult = await reconcile(moduleDefinition, { + it("should flag as PreviousRunError a future that timed out on the previous run", async () => { + const reconiliationResult = Reconciler.checkForPreviousRunErrors({ chainId: 123, executionStates: { - "Module1:Example": { + "Module1#Example": { ...exampleDeploymentState, status: ExecutionStatus.TIMEOUT, }, }, }); - assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ + assert.deepStrictEqual(reconiliationResult, [ { - futureId: "Module1:Contract1", + futureId: "Module1#Contract1", failure: - "The previous run of the future Module1:Contract1 timed out, and will need wiped before running again", + "The previous run of the future Module1#Contract1 timed out, and will need wiped before running again", }, ]); }); - it("should flag as unreconsiliable a future that failed on the previous run", async () => { - const moduleDefinition = buildModule("Module1", (m) => { - const contract1 = m.contract("Contract1"); - - return { contract1 }; - }); - - const reconiliationResult = await reconcile(moduleDefinition, { + it("should flag as PreviousRunError a future that failed on the previous run", async () => { + const reconiliationResult = Reconciler.checkForPreviousRunErrors({ chainId: 123, executionStates: { - "Module1:Example": { + "Module1#Example": { ...exampleDeploymentState, status: ExecutionStatus.FAILED, }, }, }); - assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ + assert.deepStrictEqual(reconiliationResult, [ { - futureId: "Module1:Contract1", + futureId: "Module1#Contract1", failure: - "The previous run of the future Module1:Contract1 failed, and will need wiped before running again", + "The previous run of the future Module1#Contract1 failed, and will need wiped before running again", }, ]); }); @@ -192,9 +181,9 @@ describe("Reconciliation", () => { const reconiliationResult = await reconcile(moduleDefinition, { chainId: 123, executionStates: { - "Module1:Contract1": { + "Module1#Contract1": { ...exampleDeploymentState, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, from: getDefaultSender(exampleAccounts), }, @@ -217,7 +206,7 @@ describe("Reconciliation", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, from: exampleAccounts[3], }) @@ -225,7 +214,7 @@ describe("Reconciliation", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module1:Contract1", + futureId: "Module1#Contract1", failure: `From account has been changed from ${exampleAccounts[3]} to ${exampleAccounts[2]}`, }, ]); @@ -251,24 +240,24 @@ describe("Reconciliation", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract1", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract1", }, { ...exampleDeploymentState, - id: "Module:Contract2", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract2", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract2", }, { ...exampleDeploymentState, - id: "Module:Contract3", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract3", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, - dependencies: new Set(["Module:Contract2", "Module:Contract2"]), + dependencies: new Set(["Module#Contract2", "Module#Contract2"]), contractName: "Contract3", } ) @@ -291,24 +280,24 @@ describe("Reconciliation", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract1", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract1", }, { ...exampleDeploymentState, - id: "Module:Contract2", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract2", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract2", }, { ...exampleDeploymentState, - id: "Module:Contract3", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract3", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, - dependencies: new Set(["Module:Contract1", "Module:Contract2"]), + dependencies: new Set(["Module#Contract1", "Module#Contract2"]), contractName: "Contract3", } ) @@ -330,15 +319,15 @@ describe("Reconciliation", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract1", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, contractName: "Contract1", }, { ...exampleDeploymentState, - id: "Module:Contract2", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract2", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, contractName: "Contract2", dependencies: new Set(), // no deps on last run @@ -362,15 +351,15 @@ describe("Reconciliation", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:Contract1", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract1", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, // Could still be in flight contractName: "Contract1", }, { ...exampleDeploymentState, - id: "Module:Contract2", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract2", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, dependencies: new Set(), // no deps on last run contractName: "Contract2", @@ -380,9 +369,9 @@ describe("Reconciliation", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract2", + futureId: "Module#Contract2", failure: - "A dependency from Module:Contract2 to Module:Contract1 has been added, and both futures had already started executing, so this change is incompatible", + "A dependency from Module#Contract2 to Module#Contract1 has been added, and both futures had already started executing, so this change is incompatible", }, ]); }); @@ -404,18 +393,18 @@ describe("Reconciliation", () => { createDeploymentState( { ...exampleDeploymentState, - id: "Module:ContractOriginal", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#ContractOriginal", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.SUCCESS, dependencies: new Set(), // no deps on last run contractName: "ContractOriginal", }, { ...exampleDeploymentState, - id: "Module:Contract2", - futureType: FutureType.NAMED_CONTRACT_DEPLOYMENT, + id: "Module#Contract2", + futureType: FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, status: ExecutionStatus.STARTED, - dependencies: new Set("Module:ContractOriginal"), // no deps on last run + dependencies: new Set("Module#ContractOriginal"), // no deps on last run contractName: "Contract2", constructorArgs: [exampleAddress], } @@ -424,9 +413,9 @@ describe("Reconciliation", () => { assert.deepStrictEqual(reconiliationResult.reconciliationFailures, [ { - futureId: "Module:Contract2", + futureId: "Module#Contract2", failure: - "A dependency from Module:Contract2 to Module:ContractNew has been added. The former has started executing before the latter started executing, so this change is incompatible.", + "A dependency from Module#Contract2 to Module#ContractNew has been added. The former has started executing before the latter started executing, so this change is incompatible.", }, ]); }); @@ -450,15 +439,15 @@ describe("Reconciliation", () => { }; const storedArtifactMap = { - "Module:Contract1": moduleArtifactMap.Contract1, + "Module#Contract1": moduleArtifactMap.Contract1, }; const reconciliationResult = await reconcile( moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Contract1", - artifactFutureId: "Module:Contract1", + id: "Module#Contract1", + artifactId: "Module#Contract1", }), new ArtifactMapDeploymentLoader(storedArtifactMap), new ArtifactMapResolver(moduleArtifactMap) @@ -484,7 +473,7 @@ describe("Reconciliation", () => { }; const storedArtifactMap = { - "Module:Contract1": { + "Module#Contract1": { abi: [], bytecode: "0xbbbbbb", contractName: "Contract1", @@ -496,8 +485,8 @@ describe("Reconciliation", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Contract1", - artifactFutureId: "Module:Contract1", + id: "Module#Contract1", + artifactId: "Module#Contract1", }), new ArtifactMapDeploymentLoader(storedArtifactMap), new ArtifactMapResolver(moduleArtifactMap) @@ -505,7 +494,7 @@ describe("Reconciliation", () => { assert.deepStrictEqual(reconciliationResult.reconciliationFailures, [ { - futureId: "Module:Contract1", + futureId: "Module#Contract1", failure: "Artifact bytecodes have been changed", }, ]); @@ -532,7 +521,7 @@ describe("Reconciliation", () => { }); const storedArtifactMap = { - "Module:Contract1": { + "Module#Contract1": { abi: [], bytecode: mainnetWethBytecode, contractName: "Contract1", @@ -553,8 +542,8 @@ describe("Reconciliation", () => { moduleDefinition, createDeploymentState({ ...exampleDeploymentState, - id: "Module:Contract1", - artifactFutureId: "Module:Contract1", + id: "Module#Contract1", + artifactId: "Module#Contract1", }), new ArtifactMapDeploymentLoader(storedArtifactMap), new ArtifactMapResolver(moduleArtifactMap) diff --git a/packages/core/test/new-api/send.ts b/packages/core/test/send.ts similarity index 86% rename from packages/core/test/new-api/send.ts rename to packages/core/test/send.ts index f09e13c98..483b767ba 100644 --- a/packages/core/test/new-api/send.ts +++ b/packages/core/test/send.ts @@ -1,21 +1,21 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { buildModule } from "../../src/new-api/build-module"; +import { buildModule } from "../src/build-module"; import { AccountRuntimeValueImplementation, ModuleParameterRuntimeValueImplementation, SendDataFutureImplementation, -} from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; -import { FutureType } from "../../src/new-api/types/module"; +} from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; +import { FutureType } from "../src/types/module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; describe("send", () => { it("should be able to setup a send", () => { const moduleWithASingleContract = buildModule("Module1", (m) => { - m.send("test send", "0xtest", 0n, "test-data"); + m.send("test_send", "0xtest", 0n, "test-data"); return {}; }); @@ -33,7 +33,7 @@ describe("send", () => { assert.equal(moduleWithASingleContract.submodules.size, 0); const sendFuture = [...moduleWithASingleContract.futures].find( - ({ id }) => id === "Module1:test send" + ({ id }) => id === "Module1#test_send" ); if (!(sendFuture instanceof SendDataFutureImplementation)) { @@ -46,7 +46,7 @@ describe("send", () => { it("should be able to pass one contract as the 'to' arg for a send", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.contract("Example"); - m.send("test send", example, 0n, ""); + m.send("test_send", example, 0n, ""); return { example }; }); @@ -54,11 +54,11 @@ describe("send", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const sendFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:test send" + ({ id }) => id === "Module1#test_send" ); if (!(sendFuture instanceof SendDataFutureImplementation)) { @@ -72,7 +72,7 @@ describe("send", () => { it("should be able to pass one contract as an after dependency of a send", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.contract("Example"); - m.send("test send", "0xtest", 0n, "", { after: [example] }); + m.send("test_send", "0xtest", 0n, "", { after: [example] }); return { example }; }); @@ -80,11 +80,11 @@ describe("send", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const sendFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:test send" + ({ id }) => id === "Module1#test_send" ); if (!(sendFuture instanceof SendDataFutureImplementation)) { @@ -97,7 +97,7 @@ describe("send", () => { it("should be able to pass a value", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - m.send("test send", "0xtest", 42n, ""); + m.send("test_send", "0xtest", 42n, ""); return {}; }); @@ -105,7 +105,7 @@ describe("send", () => { assert.isDefined(moduleWithDependentContracts); const sendFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:test send" + ({ id }) => id === "Module1#test_send" ); if (!(sendFuture instanceof SendDataFutureImplementation)) { @@ -117,7 +117,7 @@ describe("send", () => { it("Should be able to pass a ModuleParameterRuntimeValue as a value option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - m.send("test send", "0xtest", m.getParameter("value"), ""); + m.send("test_send", "0xtest", m.getParameter("value"), ""); return {}; }); @@ -125,7 +125,7 @@ describe("send", () => { assert.isDefined(moduleWithDependentContracts); const sendFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:test send" + ({ id }) => id === "Module1#test_send" ); if (!(sendFuture instanceof SendDataFutureImplementation)) { @@ -140,7 +140,7 @@ describe("send", () => { it("should be able to pass a string as from option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - m.send("test send", "0xtest", 0n, "", { from: "0x2" }); + m.send("test_send", "0xtest", 0n, "", { from: "0x2" }); return {}; }); @@ -148,7 +148,7 @@ describe("send", () => { assert.isDefined(moduleWithDependentContracts); const sendFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:test send" + ({ id }) => id === "Module1#test_send" ); if (!(sendFuture instanceof SendDataFutureImplementation)) { @@ -160,7 +160,7 @@ describe("send", () => { it("Should be able to pass an AccountRuntimeValue as from option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { - m.send("test send", "0xtest", 0n, "", { from: m.getAccount(1) }); + m.send("test_send", "0xtest", 0n, "", { from: m.getAccount(1) }); return {}; }); @@ -168,7 +168,7 @@ describe("send", () => { assert.isDefined(moduleWithDependentContracts); const sendFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:test send" + ({ id }) => id === "Module1#test_send" ); if (!(sendFuture instanceof SendDataFutureImplementation)) { @@ -190,11 +190,11 @@ describe("send", () => { return {}; }); - const futureC = Array.from(module.futures).find((f) => f.id === "Module:C"); + const futureC = Array.from(module.futures).find((f) => f.id === "Module#C"); assertInstanceOf(futureC, SendDataFutureImplementation); const futureC2 = Array.from(module.futures).find( - (f) => f.id === "Module:C2" + (f) => f.id === "Module#C2" ); assertInstanceOf(futureC2, SendDataFutureImplementation); @@ -210,8 +210,8 @@ describe("send", () => { describe("passing id", () => { it("should be able to call the same function twice by passing an id", () => { const moduleWithSameCallTwice = buildModule("Module1", (m) => { - m.send("test send", "0xtest", 0n, "test", { id: "first" }); - m.send("test send", "0xtest", 0n, "test", { id: "second" }); + m.send("first", "0xtest", 0n, "test"); + m.send("second", "0xtest", 0n, "test"); return {}; }); @@ -219,11 +219,11 @@ describe("send", () => { assert.equal(moduleWithSameCallTwice.id, "Module1"); const sendFuture = [...moduleWithSameCallTwice.futures].find( - ({ id }) => id === "Module1:first" + ({ id }) => id === "Module1#first" ); const sendFuture2 = [...moduleWithSameCallTwice.futures].find( - ({ id }) => id === "Module1:second" + ({ id }) => id === "Module1#second" ); assert.isDefined(sendFuture); @@ -234,12 +234,12 @@ describe("send", () => { assert.throws( () => buildModule("Module1", (m) => { - m.send("test send", "0xtest", 0n, "test"); - m.send("test send", "0xtest", 0n, "test"); + m.send("test_send", "0xtest", 0n, "test"); + m.send("test_send", "0xtest", 0n, "test"); return {}; }), - /Duplicated id Module1:test send found in module Module1/ + /Duplicated id Module1#test_send found in module Module1/ ); }); @@ -247,11 +247,11 @@ describe("send", () => { assert.throws( () => buildModule("Module1", (m) => { - m.send("test send", "0xtest", 0n, "test", { id: "first" }); - m.send("test send", "0xtest", 0n, "test", { id: "first" }); + m.send("first", "0xtest", 0n, "test"); + m.send("first", "0xtest", 0n, "test"); return {}; }), - /Duplicated id Module1:first found in module Module1/ + /Duplicated id Module1#first found in module Module1/ ); }); }); @@ -314,12 +314,12 @@ describe("send", () => { }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateSendData"); + let vm: typeof import("../src/internal/validation/stageTwo/validateSendData"); let validateSendData: typeof vm.validateSendData; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateSendData" + "../src/internal/validation/stageTwo/validateSendData" ); validateSendData = vm.validateSendData; diff --git a/packages/core/test/new-api/staticCall.ts b/packages/core/test/staticCall.ts similarity index 75% rename from packages/core/test/new-api/staticCall.ts rename to packages/core/test/staticCall.ts index 68d83dbc8..6d24f7846 100644 --- a/packages/core/test/new-api/staticCall.ts +++ b/packages/core/test/staticCall.ts @@ -1,16 +1,16 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; +import { Artifact } from "../src"; +import { buildModule } from "../src/build-module"; import { AccountRuntimeValueImplementation, ModuleParameterRuntimeValueImplementation, NamedContractCallFutureImplementation, NamedStaticCallFutureImplementation, -} from "../../src/new-api/internal/module"; -import { getFuturesFromModule } from "../../src/new-api/internal/utils/get-futures-from-module"; -import { FutureType } from "../../src/new-api/types/module"; +} from "../src/internal/module"; +import { getFuturesFromModule } from "../src/internal/utils/get-futures-from-module"; +import { FutureType } from "../src/types/module"; import { assertInstanceOf, setupMockArtifactResolver } from "./helpers"; @@ -30,18 +30,18 @@ describe("static call", () => { assert.equal(moduleWithASingleContract.id, "Module1"); assert.equal( moduleWithASingleContract.results.contract1.id, - "Module1:Contract1" + "Module1#Contract1" ); // 1 contract future & 1 call future assert.equal(moduleWithASingleContract.futures.size, 2); assert.equal( [...moduleWithASingleContract.futures][0].type, - FutureType.NAMED_CONTRACT_DEPLOYMENT + FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT ); assert.equal( [...moduleWithASingleContract.futures][1].type, - FutureType.NAMED_STATIC_CALL + FutureType.STATIC_CALL ); // No submodules @@ -61,15 +61,15 @@ describe("static call", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedStaticCallFutureImplementation)) { @@ -86,7 +86,7 @@ describe("static call", () => { const example = m.contract("Example"); const another = m.contract("Another"); - m.staticCall(example, "test", [], { after: [another] }); + m.staticCall(example, "test", [], 0, { after: [another] }); return { example, another }; }); @@ -94,15 +94,15 @@ describe("static call", () => { assert.isDefined(moduleWithDependentContracts); const exampleFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example" + ({ id }) => id === "Module1#Example" ); const anotherFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Another" + ({ id }) => id === "Module1#Another" ); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedStaticCallFutureImplementation)) { @@ -128,11 +128,11 @@ describe("static call", () => { assert.isDefined(moduleWithASingleContract); const staticCallFuture = [...moduleWithASingleContract.futures].find( - ({ id }) => id === "Module1:Contract1#test" + ({ id }) => id === "Module1#Contract1.test" ); const callFuture = [...moduleWithASingleContract.futures].find( - ({ id }) => id === "Module1:Contract1#test2" + ({ id }) => id === "Module1#Contract1.test2" ); if (!(callFuture instanceof NamedContractCallFutureImplementation)) { @@ -143,11 +143,43 @@ describe("static call", () => { assert(callFuture.dependencies.has(staticCallFuture!)); }); + it("should be able to use a string or number to index its result", () => { + const moduleWithASingleContract = buildModule("Module1", (m) => { + const contract1 = m.contract("Contract1"); + + m.staticCall(contract1, "test", [], "testName"); + m.staticCall(contract1, "test2", [], 2); + + return { contract1 }; + }); + + assert.isDefined(moduleWithASingleContract); + + const staticCallFuture = [...moduleWithASingleContract.futures].find( + ({ id }) => id === "Module1#Contract1.test" + ); + + const staticCallFuture2 = [...moduleWithASingleContract.futures].find( + ({ id }) => id === "Module1#Contract1.test2" + ); + + if (!(staticCallFuture instanceof NamedStaticCallFutureImplementation)) { + assert.fail("Not a named static contract deployment"); + } + + if (!(staticCallFuture2 instanceof NamedStaticCallFutureImplementation)) { + assert.fail("Not a named static contract deployment"); + } + + assert.equal(staticCallFuture.nameOrIndex, "testName"); + assert.equal(staticCallFuture2.nameOrIndex, 2); + }); + it("should be able to pass a string as from option", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.contract("Example"); - m.staticCall(example, "test", [], { from: "0x2" }); + m.staticCall(example, "test", [], 0, { from: "0x2" }); return { example }; }); @@ -155,7 +187,7 @@ describe("static call", () => { assert.isDefined(moduleWithDependentContracts); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedStaticCallFutureImplementation)) { @@ -169,7 +201,7 @@ describe("static call", () => { const moduleWithDependentContracts = buildModule("Module1", (m) => { const example = m.contract("Example"); - m.staticCall(example, "test", [], { from: m.getAccount(1) }); + m.staticCall(example, "test", [], 0, { from: m.getAccount(1) }); return { example }; }); @@ -177,7 +209,7 @@ describe("static call", () => { assert.isDefined(moduleWithDependentContracts); const callFuture = [...moduleWithDependentContracts.futures].find( - ({ id }) => id === "Module1:Example#test" + ({ id }) => id === "Module1#Example.test" ); if (!(callFuture instanceof NamedStaticCallFutureImplementation)) { @@ -198,7 +230,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -214,7 +246,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -230,7 +262,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -246,7 +278,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -262,7 +294,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -279,7 +311,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -297,7 +329,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -318,7 +350,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -340,7 +372,7 @@ describe("static call", () => { }); const future = [...module.futures].find( - ({ type }) => type === FutureType.NAMED_STATIC_CALL + ({ type }) => type === FutureType.STATIC_CALL ); assertInstanceOf(future, NamedStaticCallFutureImplementation); @@ -357,8 +389,8 @@ describe("static call", () => { const moduleWithSameCallTwice = buildModule("Module1", (m) => { const sameContract1 = m.contract("Example"); - m.staticCall(sameContract1, "test", [], { id: "first" }); - m.staticCall(sameContract1, "test", [], { id: "second" }); + m.staticCall(sameContract1, "test", [], 0, { id: "first" }); + m.staticCall(sameContract1, "test", [], 0, { id: "second" }); return { sameContract1 }; }); @@ -366,11 +398,11 @@ describe("static call", () => { assert.equal(moduleWithSameCallTwice.id, "Module1"); const callFuture = [...moduleWithSameCallTwice.futures].find( - ({ id }) => id === "Module1:Example#first" + ({ id }) => id === "Module1#first" ); const callFuture2 = [...moduleWithSameCallTwice.futures].find( - ({ id }) => id === "Module1:Example#second" + ({ id }) => id === "Module1#second" ); assert.isDefined(callFuture); @@ -387,7 +419,7 @@ describe("static call", () => { return { sameContract1 }; }), - /Duplicated id Module1:SameContract#test found in module Module1/ + /Duplicated id Module1#SameContract.test found in module Module1/ ); }); @@ -396,11 +428,11 @@ describe("static call", () => { () => buildModule("Module1", (m) => { const sameContract1 = m.contract("SameContract"); - m.staticCall(sameContract1, "test", [], { id: "first" }); - m.staticCall(sameContract1, "test", [], { id: "first" }); + m.staticCall(sameContract1, "test", [], 0, { id: "first" }); + m.staticCall(sameContract1, "test", [], 0, { id: "first" }); return { sameContract1 }; }), - /Duplicated id Module1:SameContract#first found in module Module1/ + /Duplicated id Module1#first found in module Module1/ ); }); }); @@ -412,7 +444,7 @@ describe("static call", () => { () => buildModule("Module1", (m) => { const another = m.contract("Another", []); - m.staticCall(another, "test", [], { from: 1 as any }); + m.staticCall(another, "test", [], 0, { from: 1 as any }); return { another }; }), @@ -420,6 +452,19 @@ describe("static call", () => { ); }); + it("should not validate a nameOrIndex that is not a number or string", () => { + assert.throws( + () => + buildModule("Module1", (m) => { + const another = m.contract("Another", []); + m.staticCall(another, "test", [], {} as any); + + return { another }; + }), + /Invalid nameOrIndex given/ + ); + }); + it("should not validate a non-contract", () => { assert.throws( () => @@ -434,15 +479,29 @@ describe("static call", () => { /Invalid contract given/ ); }); + + it("should not validate a library", () => { + assert.throws( + () => + buildModule("Module1", (m) => { + const another = m.library("Another"); + + m.staticCall(another as any, "test"); + + return { another }; + }), + /Invalid contract given/ + ); + }); }); describe("stage one", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageOne/validateNamedStaticCall"); + let vm: typeof import("../src/internal/validation/stageOne/validateNamedStaticCall"); let validateNamedStaticCall: typeof vm.validateNamedStaticCall; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageOne/validateNamedStaticCall" + "../src/internal/validation/stageOne/validateNamedStaticCall" ); validateNamedStaticCall = vm.validateNamedStaticCall; @@ -457,7 +516,7 @@ describe("static call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( @@ -478,14 +537,14 @@ describe("static call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.staticCall(another, "test"); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( @@ -517,14 +576,14 @@ describe("static call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.staticCall(another, "inc", [1, 2]); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( @@ -574,14 +633,14 @@ describe("static call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.staticCall(another, "inc(bool,uint256)", [1, 2, 3]); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( @@ -613,14 +672,14 @@ describe("static call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); m.staticCall(another, "inc", [1]); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( @@ -628,15 +687,93 @@ describe("static call", () => { /Function inc in contract Another is not 'pure' or 'view' and cannot be statically called/ ); }); + + it("should not validate a nameOrIndex that is invalid (nonexistent name)", async () => { + const fakeArtifact: Artifact = { + abi: [ + { + inputs: [], + name: "inc", + outputs: [ + { + internalType: "bool", + name: "b", + type: "bool", + }, + ], + stateMutability: "pure", + type: "function", + }, + ], + contractName: "", + bytecode: "", + linkReferences: {}, + }; + + const module = buildModule("Module1", (m) => { + const another = m.contract("Another", fakeArtifact, []); + m.staticCall(another, "inc", [], "a"); + + return { another }; + }); + + const future = getFuturesFromModule(module).find( + (v) => v.type === FutureType.STATIC_CALL + ); + + await assert.isRejected( + validateNamedStaticCall(future as any, setupMockArtifactResolver()), + /Function inc of contract Another has no return value named a/ + ); + }); + + it("should not validate a nameOrIndex that is invalid (out of range)", async () => { + const fakeArtifact: Artifact = { + abi: [ + { + inputs: [], + name: "inc", + outputs: [ + { + internalType: "bool", + name: "b", + type: "bool", + }, + ], + stateMutability: "pure", + type: "function", + }, + ], + contractName: "", + bytecode: "", + linkReferences: {}, + }; + + const module = buildModule("Module1", (m) => { + const another = m.contract("Another", fakeArtifact, []); + m.staticCall(another, "inc", [], 2); + + return { another }; + }); + + const future = getFuturesFromModule(module).find( + (v) => v.type === FutureType.STATIC_CALL + ); + + await assert.isRejected( + validateNamedStaticCall(future as any, setupMockArtifactResolver()), + /Function inc of contract Another has only 1 return values, but value 2 was requested/ + ); + }); }); describe("stage two", () => { - let vm: typeof import("../../src/new-api/internal/validation/stageTwo/validateNamedStaticCall"); + let vm: typeof import("../src/internal/validation/stageTwo/validateNamedStaticCall"); let validateNamedStaticCall: typeof vm.validateNamedStaticCall; before(async () => { vm = await import( - "../../src/new-api/internal/validation/stageTwo/validateNamedStaticCall" + "../src/internal/validation/stageTwo/validateNamedStaticCall" ); validateNamedStaticCall = vm.validateNamedStaticCall; @@ -659,7 +796,7 @@ describe("static call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( @@ -704,7 +841,7 @@ describe("static call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isFulfilled( @@ -736,7 +873,7 @@ describe("static call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( @@ -783,7 +920,7 @@ describe("static call", () => { }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isFulfilled( @@ -819,15 +956,15 @@ describe("static call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); const account = m.getAccount(-1); - m.staticCall(another, "inc", [1], { from: account }); + m.staticCall(another, "inc", [1], 0, { from: account }); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( @@ -864,15 +1001,15 @@ describe("static call", () => { }; const module = buildModule("Module1", (m) => { - const another = m.contractFromArtifact("Another", fakeArtifact, []); + const another = m.contract("Another", fakeArtifact, []); const account = m.getAccount(1); - m.staticCall(another, "inc", [1], { from: account }); + m.staticCall(another, "inc", [1], 0, { from: account }); return { another }; }); const future = getFuturesFromModule(module).find( - (v) => v.type === FutureType.NAMED_STATIC_CALL + (v) => v.type === FutureType.STATIC_CALL ); await assert.isRejected( diff --git a/packages/core/test/new-api/stored-deployment-serializer.ts b/packages/core/test/stored-deployment-serializer.ts similarity index 74% rename from packages/core/test/new-api/stored-deployment-serializer.ts rename to packages/core/test/stored-deployment-serializer.ts index f9299c979..afb56e39f 100644 --- a/packages/core/test/new-api/stored-deployment-serializer.ts +++ b/packages/core/test/stored-deployment-serializer.ts @@ -1,31 +1,25 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; +import { Artifact } from "../src"; +import { buildModule } from "../src/build-module"; +import { + IgnitionModuleDeserializer, + IgnitionModuleSerializer, +} from "../src/ignition-module-serializer"; import { ArtifactContractDeploymentFutureImplementation, ArtifactLibraryDeploymentFutureImplementation, NamedContractDeploymentFutureImplementation, NamedLibraryDeploymentFutureImplementation, -} from "../../src/new-api/internal/module"; -import { - StoredDeploymentDeserializer, - StoredDeploymentSerializer, -} from "../../src/new-api/stored-deployment-serializer"; +} from "../src/internal/module"; import { ContractFuture, IgnitionModule, IgnitionModuleResult, -} from "../../src/new-api/types/module"; -import { StoredDeployment } from "../../src/new-api/types/serialized-deployment"; +} from "../src/types/module"; describe("stored deployment serializer", () => { - const details = { - networkName: "hardhat", - chainId: 31117, - }; - describe("contract", () => { it("should serialize a contract deployment", () => { const module = buildModule("Module1", (m) => { @@ -34,10 +28,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a contract deployments with dependency", () => { @@ -49,10 +40,7 @@ describe("stored deployment serializer", () => { return { contract1, contract2, contract3 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a contract deployment with module parameter value", () => { @@ -63,10 +51,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); @@ -80,39 +65,28 @@ describe("stored deployment serializer", () => { it("should serialize a contractFromArtifact deployment", () => { const module = buildModule("Module1", (m) => { - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, []); + const contract1 = m.contract("Contract1", fakeArtifact, []); return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a contractFromArtifact deployment with dependency", () => { const module = buildModule("Module1", (m) => { - const contract1 = m.contractFromArtifact("Contract1", fakeArtifact, []); + const contract1 = m.contract("Contract1", fakeArtifact, []); - const contract2 = m.contractFromArtifact("Contract2", fakeArtifact, [ - contract1, - ]); + const contract2 = m.contract("Contract2", fakeArtifact, [contract1]); - const contract3 = m.contractFromArtifact( - "Contract3", - fakeArtifact, - [], - { after: [contract2] } - ); + const contract3 = m.contract("Contract3", fakeArtifact, [], { + after: [contract2], + }); return { contract1, contract2, contract3 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); @@ -124,10 +98,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a contractAt with a future address", () => { @@ -139,10 +110,7 @@ describe("stored deployment serializer", () => { return { contract1, contract2 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a contractAt with dependency", () => { @@ -155,10 +123,7 @@ describe("stored deployment serializer", () => { return { contract1, contract2 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); @@ -172,67 +137,37 @@ describe("stored deployment serializer", () => { it("should serialize a contractAt", () => { const module = buildModule("Module1", (m) => { - const contract1 = m.contractAtFromArtifact( - "Contract1", - "0x0", - fakeArtifact - ); + const contract1 = m.contractAt("Contract1", "0x0", fakeArtifact); return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a contractAt with a future address", () => { const module = buildModule("Module1", (m) => { - const contract1 = m.contractAtFromArtifact( - "Contract1", - "0x0", - fakeArtifact - ); + const contract1 = m.contractAt("Contract1", "0x0", fakeArtifact); const call = m.staticCall(contract1, "getAddress"); - const contract2 = m.contractAtFromArtifact( - "Contract2", - call, - fakeArtifact - ); + const contract2 = m.contractAt("Contract2", call, fakeArtifact); return { contract1, contract2 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a contractAt with dependency", () => { const module = buildModule("Module1", (m) => { - const contract1 = m.contractAtFromArtifact( - "Contract1", - "0x0", - fakeArtifact - ); - const contract2 = m.contractAtFromArtifact( - "Contract2", - "0x0", - fakeArtifact, - { - after: [contract1], - } - ); + const contract1 = m.contractAt("Contract1", "0x0", fakeArtifact); + const contract2 = m.contractAt("Contract2", "0x0", fakeArtifact, { + after: [contract1], + }); return { contract1, contract2 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); @@ -251,10 +186,7 @@ describe("stored deployment serializer", () => { return { library1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a library deployment with dependency", () => { @@ -268,10 +200,7 @@ describe("stored deployment serializer", () => { }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a libraries passed in as libraries", () => { @@ -284,22 +213,17 @@ describe("stored deployment serializer", () => { }, }); - const contract3 = m.contractFromArtifact( - "Contract3", - fakeArtifact, - [], - { - libraries: { - Lib1: library1, - }, - } - ); + const contract3 = m.contract("Contract3", fakeArtifact, [], { + libraries: { + Lib1: library1, + }, + }); const library4 = m.library("Library4", { libraries: { Lib1: library1 }, }); - const library5 = m.libraryFromArtifact("Library5", fakeArtifact, { + const library5 = m.library("Library5", fakeArtifact, { libraries: { Lib1: library1 }, }); @@ -312,10 +236,7 @@ describe("stored deployment serializer", () => { }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); @@ -329,32 +250,26 @@ describe("stored deployment serializer", () => { it("should serialize a libraryFromArtifact deployment", () => { const module = buildModule("Module1", (m) => { - const library1 = m.libraryFromArtifact("Contract1", fakeArtifact); + const library1 = m.library("Contract1", fakeArtifact); return { library1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a libraryFromArtifact deployment with dependency", () => { const module = buildModule("Module1", (m) => { - const library1 = m.libraryFromArtifact("Library1", fakeArtifact); + const library1 = m.library("Library1", fakeArtifact); - const library2 = m.libraryFromArtifact("Library2", fakeArtifact, { + const library2 = m.library("Library2", fakeArtifact, { after: [library1], }); return { library1, library2 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); @@ -368,10 +283,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a call with dependencies", () => { @@ -385,10 +297,7 @@ describe("stored deployment serializer", () => { return { contract1, contract2 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); @@ -402,10 +311,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a static call with dependencies", () => { @@ -414,15 +320,12 @@ describe("stored deployment serializer", () => { const contract2 = m.contract("Contract2"); m.staticCall(contract2, "lock", [contract1]); - m.staticCall(contract2, "unlock", [], { after: [contract1] }); + m.staticCall(contract2, "unlock", [], 0, { after: [contract1] }); return { contract1, contract2 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("Should serialize readEventArgument", () => { @@ -430,7 +333,7 @@ describe("stored deployment serializer", () => { const contract1 = m.contract("Contract1"); const emitter = m.contract("Emitter"); - m.readEventArgument(contract1, "EventName", "argumentName", { + m.readEventArgument(contract1, "EventName", "nameOrIndex", { id: "customId", emitter, eventIndex: 123, @@ -439,10 +342,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); @@ -460,10 +360,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize contract dependencies over the useModule barrier", () => { @@ -482,10 +379,7 @@ describe("stored deployment serializer", () => { return { contract1, contract2, contract3 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should serialize a diamond useModule", () => { @@ -514,24 +408,19 @@ describe("stored deployment serializer", () => { return { leftContract, rightContract }; }); - const deployment = { - details, - module, - }; + assertSerializableModuleIn(module); - assertSerializableModuleIn(deployment); - - const reserialized = StoredDeploymentDeserializer.deserialize( + const reserialized = IgnitionModuleDeserializer.deserialize( JSON.parse( JSON.stringify( - StoredDeploymentSerializer.serialize(deployment), + IgnitionModuleSerializer.serialize(module), sortedKeysJsonStringifyReplacer ) ) ); - const lc = reserialized.module.results.leftContract; - const rc = reserialized.module.results.rightContract; + const lc = reserialized.results.leftContract; + const rc = reserialized.results.rightContract; assert.equal(lc, rc); }); @@ -545,10 +434,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("Should support arrays as arguments", () => { @@ -558,10 +444,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("Should support objects as arguments", () => { @@ -571,10 +454,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("Should support futures as arguments", () => { @@ -585,10 +465,7 @@ describe("stored deployment serializer", () => { return { contract1, contract2 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should support nested futures as arguments", () => { @@ -613,10 +490,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should support AccountRuntimeValues as from", () => { @@ -627,10 +501,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should support nested AccountRuntimeValues as arguments", () => { @@ -641,10 +512,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should support ModuleParameterRuntimeValue as arguments", () => { @@ -655,10 +523,7 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); it("should support nested ModuleParameterRuntimeValue as arguments", () => { @@ -669,29 +534,28 @@ describe("stored deployment serializer", () => { return { contract1 }; }); - assertSerializableModuleIn({ - details, - module, - }); + assertSerializableModuleIn(module); }); }); }); -function assertSerializableModuleIn(deployment: StoredDeployment) { +function assertSerializableModuleIn( + module: IgnitionModule> +) { const serialized = JSON.stringify( - StoredDeploymentSerializer.serialize(deployment), + IgnitionModuleSerializer.serialize(module), // This is not actually needed, but we use it to be able to compare the // serialized string, which can be easier to debug. sortedKeysJsonStringifyReplacer, 2 ); - const deserialized = StoredDeploymentDeserializer.deserialize( + const deserialized = IgnitionModuleDeserializer.deserialize( JSON.parse(serialized) ); const reserialized = JSON.stringify( - StoredDeploymentSerializer.serialize(deserialized), + IgnitionModuleSerializer.serialize(deserialized), sortedKeysJsonStringifyReplacer, 2 ); @@ -703,16 +567,16 @@ function assertSerializableModuleIn(deployment: StoredDeployment) { ); assert.deepEqual( - deployment, + module, deserialized, "Module not the same across serialization/deserialization" ); // Invariants - const ignitionModule = StoredDeploymentDeserializer.deserialize( + const ignitionModule = IgnitionModuleDeserializer.deserialize( JSON.parse(reserialized) - ).module; + ); assert( Object.values(ignitionModule.results).every((result) => diff --git a/packages/core/test/new-api/types/deployment-loader.ts b/packages/core/test/types/deployment-loader.ts similarity index 66% rename from packages/core/test/new-api/types/deployment-loader.ts rename to packages/core/test/types/deployment-loader.ts index 4cee095fc..b270d5458 100644 --- a/packages/core/test/new-api/types/deployment-loader.ts +++ b/packages/core/test/types/deployment-loader.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { EphemeralDeploymentLoader } from "../../../src/new-api/internal/deployment-loader/ephemeral-deployment-loader"; -import { FileDeploymentLoader } from "../../../src/new-api/internal/deployment-loader/file-deployment-loader"; -import { DeploymentLoader } from "../../../src/new-api/internal/deployment-loader/types"; -import { ExactInterface } from "../../helpers/exact-interface"; +import { EphemeralDeploymentLoader } from "../../src/internal/deployment-loader/ephemeral-deployment-loader"; +import { FileDeploymentLoader } from "../../src/internal/deployment-loader/file-deployment-loader"; +import { DeploymentLoader } from "../../src/internal/deployment-loader/types"; import { setupMockArtifactResolver } from "../helpers"; +import { ExactInterface } from "../helpers/exact-interface"; describe("DeploymentLoaderImpls", function () { describe("file-deployment-loader", () => { @@ -13,7 +13,7 @@ describe("DeploymentLoaderImpls", function () { const _implementation: ExactInterface< DeploymentLoader, FileDeploymentLoader - > = new FileDeploymentLoader("./example", true); + > = new FileDeploymentLoader("./example"); assert.isDefined(_implementation); }); @@ -24,7 +24,7 @@ describe("DeploymentLoaderImpls", function () { const _implementation: ExactInterface< DeploymentLoader, EphemeralDeploymentLoader - > = new EphemeralDeploymentLoader(setupMockArtifactResolver(), true); + > = new EphemeralDeploymentLoader(setupMockArtifactResolver()); assert.isDefined(_implementation); }); diff --git a/packages/core/test/new-api/types/module.ts b/packages/core/test/types/module.ts similarity index 97% rename from packages/core/test/new-api/types/module.ts rename to packages/core/test/types/module.ts index d77a8165c..3adbad465 100644 --- a/packages/core/test/new-api/types/module.ts +++ b/packages/core/test/types/module.ts @@ -5,7 +5,7 @@ import { IgnitionModule, RuntimeValue, RuntimeValueType, -} from "../../../src/new-api/types/module"; +} from "../../src/types/module"; type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ( k: infer I diff --git a/packages/core/test/new-api/useModule.ts b/packages/core/test/useModule.ts similarity index 95% rename from packages/core/test/new-api/useModule.ts rename to packages/core/test/useModule.ts index e6cfda56e..5b57757f0 100644 --- a/packages/core/test/new-api/useModule.ts +++ b/packages/core/test/useModule.ts @@ -1,9 +1,9 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { Artifact, DeploymentResultType } from "../../src"; -import { buildModule } from "../../src/new-api/build-module"; -import { validateStageTwo } from "../../src/new-api/internal/validation/validateStageTwo"; +import { Artifact, DeploymentResultType } from "../src"; +import { buildModule } from "../src/build-module"; +import { validateStageTwo } from "../src/internal/validation/validateStageTwo"; import { setupMockArtifactResolver } from "./helpers"; @@ -211,7 +211,7 @@ describe("useModule", () => { assert.deepStrictEqual(result, { type: DeploymentResultType.VALIDATION_ERROR, errors: { - "Submodule1:Contract1": [ + "Submodule1#Contract1": [ "Module parameter 'param1' requires a value but was given none", ], }, diff --git a/packages/core/test/new-api/utils/adjacency-list.ts b/packages/core/test/utils/adjacency-list.ts similarity index 92% rename from packages/core/test/new-api/utils/adjacency-list.ts rename to packages/core/test/utils/adjacency-list.ts index 0920c6dd5..28aa832b1 100644 --- a/packages/core/test/new-api/utils/adjacency-list.ts +++ b/packages/core/test/utils/adjacency-list.ts @@ -1,7 +1,7 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { AdjacencyList } from "../../../src/new-api/internal/utils/adjacency-list"; +import { AdjacencyList } from "../../src/internal/utils/adjacency-list"; describe("adjacency list", () => { it("should provide a topological sort", () => { diff --git a/packages/core/test/utils/future-id-builders.ts b/packages/core/test/utils/future-id-builders.ts new file mode 100644 index 000000000..74dcfaa9a --- /dev/null +++ b/packages/core/test/utils/future-id-builders.ts @@ -0,0 +1,92 @@ +import { assert } from "chai"; + +import { + toCallFutureId, + toDeploymentFutureId, + toReadEventArgumentFutureId, + toSendDataFutureId, +} from "../../src/internal/utils/future-id-builders"; + +describe("future id rules", () => { + describe("contract, library, contractAt ids", () => { + it("the fallback id should be built based on the contract or library name", () => { + assert.equal( + toDeploymentFutureId("MyModule", undefined, "MyContract"), + "MyModule#MyContract" + ); + }); + + it("namespaces to the module a user provided id", () => { + assert.equal( + toDeploymentFutureId("MyModule", "MyId", "MyContract"), + "MyModule#MyId" + ); + }); + }); + + describe("call ids", () => { + it("the fallback id should be built based on the contractName and function name", () => { + assert.equal( + toCallFutureId("MyModule", undefined, "MyContract", "MyFunction"), + "MyModule#MyContract.MyFunction" + ); + }); + + it("namespaces the user provided id to the module", () => { + assert.equal( + toCallFutureId("MyModule", "MyId", "MyContract", "MyFunction"), + "MyModule#MyId" + ); + }); + }); + + describe("read event argument ids", () => { + it("the fallback id should be built based on the contractName, event name, arg name and index", () => { + assert.equal( + toReadEventArgumentFutureId( + "MyModule", + undefined, + "MyContract", + "MyFunction", + "MyArg", + 2 + ), + "MyModule#MyContract.MyFunction.MyArg.2" + ); + }); + + it("the fallback id should be built even when the arg is an index", () => { + assert.equal( + toReadEventArgumentFutureId( + "MyModule", + undefined, + "MyContract", + "MyFunction", + 3, + 2 + ), + "MyModule#MyContract.MyFunction.3.2" + ); + }); + + it("namespaces the user provided id to the module", () => { + assert.equal( + toReadEventArgumentFutureId( + "MyModule", + "MyId", + "MyContract", + "MyFunction", + "MyArg", + 2 + ), + "MyModule#MyId" + ); + }); + }); + + describe("send data ids", () => { + it("namespaces the user provided id to the module", () => { + assert.equal(toSendDataFutureId("MyModule", "MyId"), "MyModule#MyId"); + }); + }); +}); diff --git a/packages/core/test/new-api/utils/replace-within-arg.ts b/packages/core/test/utils/replace-within-arg.ts similarity index 97% rename from packages/core/test/new-api/utils/replace-within-arg.ts rename to packages/core/test/utils/replace-within-arg.ts index 9641a10d8..e714d700a 100644 --- a/packages/core/test/new-api/utils/replace-within-arg.ts +++ b/packages/core/test/utils/replace-within-arg.ts @@ -1,13 +1,13 @@ /* eslint-disable import/no-unused-modules */ import { assert } from "chai"; -import { ArgumentType, SolidityParameterType } from "../../../src"; +import { ArgumentType, SolidityParameterType } from "../../src"; import { AccountRuntimeValueImplementation, ModuleParameterRuntimeValueImplementation, NamedContractAtFutureImplementation, -} from "../../../src/new-api/internal/module"; -import { replaceWithinArg } from "../../../src/new-api/internal/utils/replace-within-arg"; +} from "../../src/internal/module"; +import { replaceWithinArg } from "../../src/internal/utils/replace-within-arg"; describe("Arg resolution", () => { const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; diff --git a/packages/core/test/validations/id-rules.ts b/packages/core/test/validations/id-rules.ts new file mode 100644 index 000000000..b2428735d --- /dev/null +++ b/packages/core/test/validations/id-rules.ts @@ -0,0 +1,308 @@ +import { assert } from "chai"; + +import { buildModule } from "../../src/build-module"; +import { fakeArtifact } from "../helpers"; + +describe("id rules", () => { + const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; + + describe("constrain module ids", () => { + it("should not allow non-alphanumerics in module ids", () => { + assert.throws(() => { + buildModule("MyModule:v2", (m) => { + const myContract = m.contract("MyContract"); + + return { myContract }; + }); + }, /The moduleId "MyModule:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + }); + + // Windows is not going to allow these characters in filenames + describe("constrain user provided ids", () => { + it("should not allow non-alphanumerics in contract ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract", [], { + id: "MyContract:v2", + }); + + return { myContract }; + }); + }, /The id "MyContract:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in contractFromArtifact ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract( + "MyContractFromArtifact", + fakeArtifact, + [], + { + id: "MyContractFromArtifact:v2", + } + ); + + return { myContract }; + }); + }, /The id "MyContractFromArtifact:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in library ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const library = m.library("MyLibrary", { + id: "MyLibrary:v2", + }); + + return { library }; + }); + }, /The id "MyLibrary:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in libraryFromArtifact ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myLibraryFromArtifact = m.library( + "MyLibraryFromArtifact", + fakeArtifact, + { + id: "MyLibraryFromArtifact:v2", + } + ); + + return { myLibraryFromArtifact }; + }); + }, /The id "MyLibraryFromArtifact:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in call ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.call(myContract, "config", [], { + id: "MyCall:v2", + }); + + return { myContract }; + }); + }, /The id "MyCall:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in static call ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.staticCall(myContract, "config", [], 0, { + id: "MyStaticCall:v2", + }); + + return { myContract }; + }); + }, /The id "MyStaticCall:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in contractAt ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContractAt = m.contractAt("MyContract", exampleAddress, { + id: "MyContractAt:v2", + }); + + return { myContractAt }; + }); + }, /The id "MyContractAt:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in contractAtFromArtifact ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContractAt = m.contractAt( + "MyContract", + exampleAddress, + fakeArtifact, + { + id: "MyContractAt:v2", + } + ); + + return { myContractAt }; + }); + }, /The id "MyContractAt:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in readEventArgument ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.readEventArgument(myContract, "MyEvent", "ArgName", { + id: "MyReadEventArgument:v2", + }); + + return { myContract }; + }); + }, /The id "MyReadEventArgument:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + + it("should not allow non-alphanumerics in send id", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + m.send("MySend:v2", exampleAddress, 2n); + + return {}; + }); + }, /The id "MySend:v2" contains banned characters, ids can only contain alphanumerics or underscores/); + }); + }); + + describe("constrain contract names", () => { + it("should not allow non-alphanumerics in contract name", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract:v2"); + + return { myContract }; + }); + }, /The contract "MyContract:v2" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs/); + }); + + it("should not allow non-alphanumerics in contractFromArtifact contract name", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract:v2", fakeArtifact); + + return { myContract }; + }); + }, /The contract "MyContract:v2" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs/); + }); + + it("should not allow non-alphanumerics in library contract names", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const library = m.library("MyLibrary:v2"); + + return { library }; + }); + }, /The contract "MyLibrary:v2" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs/); + }); + + it("should not allow non-alphanumerics in libraryFromArtifact contract names", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myLibraryFromArtifact = m.library( + "MyLibraryFromArtifact:v2", + fakeArtifact + ); + + return { myLibraryFromArtifact }; + }); + }, /The contract "MyLibraryFromArtifact:v2" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs/); + }); + + it("should not allow non-alphanumerics in contractAt contract names", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContractAt = m.contractAt("MyContract:v2", exampleAddress); + + return { myContractAt }; + }); + }, /The contract "MyContract:v2" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs/); + }); + + it("should not allow non-alphanumerics in contractAtFromArtifact contract names", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContractAt = m.contractAt( + "MyContractAt:v2", + exampleAddress, + fakeArtifact + ); + + return { myContractAt }; + }); + }, /The contract "MyContractAt:v2" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs/); + }); + }); + + describe("constrain function names", () => { + it("should not allow non-alphanumerics in call function names", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.call(myContract, "config:v2"); + + return { myContract }; + }); + }, /The function name "config:v2" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs/); + }); + + it("should not allow non-alphanumerics in static call ids", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.staticCall(myContract, "config:v2"); + + return { myContract }; + }); + }, /The function name "config:v2" contains banned characters, contract names can only contain alphanumerics, underscores or dollar signs/); + }); + + it("should allow ethers style function specification", () => { + assert.doesNotThrow(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.staticCall(myContract, "config(uint256,bool)"); + + return { myContract }; + }); + }); + }); + }); + + describe("constrain event names", () => { + it("should not allow non-alphanumerics in readEventArgument event names", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.readEventArgument(myContract, "MyEvent:v2", "MyArg"); + + return { myContract }; + }); + }, /The event "MyEvent:v2" contains banned characters, event names can only contain alphanumerics, underscores or dollar signs/); + }); + + it("should allow ethers sytle event specification", () => { + assert.doesNotThrow(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.readEventArgument(myContract, "MyEvent(bool,bool)", "MyArg"); + + return { myContract }; + }); + }); + }); + }); + + describe("constrain argument names", () => { + it("should not allow non-alphanumerics in readEventArgument argument names", () => { + assert.throws(() => { + buildModule("MyModule", (m) => { + const myContract = m.contract("MyContract"); + + m.readEventArgument(myContract, "MyEvent", "MyArg:v2"); + + return { myContract }; + }); + }, /The argument "MyArg:v2" contains banned characters, argument names can only contain alphanumerics, underscores or dollar signs/); + }); + }); +}); diff --git a/packages/core/test/new-api/wipe.ts b/packages/core/test/wipe.ts similarity index 81% rename from packages/core/test/new-api/wipe.ts rename to packages/core/test/wipe.ts index 6861c625a..90a017950 100644 --- a/packages/core/test/new-api/wipe.ts +++ b/packages/core/test/wipe.ts @@ -1,17 +1,17 @@ import { assert } from "chai"; -import { ArtifactResolver } from "../../src"; -import { EphemeralDeploymentLoader } from "../../src/new-api/internal/deployment-loader/ephemeral-deployment-loader"; +import { ArtifactResolver } from "../src"; +import { EphemeralDeploymentLoader } from "../src/internal/deployment-loader/ephemeral-deployment-loader"; import { applyNewMessage, initializeDeploymentState, -} from "../../src/new-api/internal/new-execution/deployment-state-helpers"; +} from "../src/internal/execution/deployment-state-helpers"; import { DeploymentExecutionStateInitializeMessage, JournalMessageType, -} from "../../src/new-api/internal/new-execution/types/messages"; -import { Wiper } from "../../src/new-api/internal/wiper"; -import { FutureType } from "../../src/new-api/types/module"; +} from "../src/internal/execution/types/messages"; +import { Wiper } from "../src/internal/wiper"; +import { FutureType } from "../src/types/module"; describe("wipe", () => { const exampleAddress = "0x1F98431c8aD98523631AE4a59f267346ea31F984"; @@ -28,8 +28,8 @@ describe("wipe", () => { const contract1InitMessage: DeploymentExecutionStateInitializeMessage = { type: JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, futureId: contract1Id, - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, - artifactFutureId: contract1Id, + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, + artifactId: contract1Id, constructorArgs: [], contractName: "Contract1", dependencies: [], @@ -43,8 +43,8 @@ describe("wipe", () => { const contract2InitMessage: DeploymentExecutionStateInitializeMessage = { type: JournalMessageType.DEPLOYMENT_EXECUTION_STATE_INITIALIZE, futureId: contract1Id, - futureType: FutureType.NAMED_LIBRARY_DEPLOYMENT, - artifactFutureId: contract2Id, + futureType: FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, + artifactId: contract2Id, constructorArgs: [], contractName: "Contract1", dependencies: [contract1Id], @@ -56,8 +56,7 @@ describe("wipe", () => { it("should allow wiping of future", async () => { const deploymentLoader = new EphemeralDeploymentLoader( - mockArtifactResolver, - false + mockArtifactResolver ); let deploymentState = await initializeDeploymentState( @@ -82,8 +81,7 @@ describe("wipe", () => { it("should error if the deployment hasn't been initialized", async () => { const deploymentLoader = new EphemeralDeploymentLoader( - mockArtifactResolver, - false + mockArtifactResolver ); const wiper = new Wiper(deploymentLoader); @@ -95,8 +93,7 @@ describe("wipe", () => { it("should error if the future id doesn't exist", async () => { const deploymentLoader = new EphemeralDeploymentLoader( - mockArtifactResolver, - false + mockArtifactResolver ); await initializeDeploymentState(123, deploymentLoader); @@ -110,8 +107,7 @@ describe("wipe", () => { it("should error if other futures are depenent on the future being wiped", async () => { const deploymentLoader = new EphemeralDeploymentLoader( - mockArtifactResolver, - false + mockArtifactResolver ); let deploymentState = await initializeDeploymentState( diff --git a/packages/hardhat-plugin/CHANGELOG.md b/packages/hardhat-plugin/CHANGELOG.md index 53cc3e6dd..7f612ed68 100644 --- a/packages/hardhat-plugin/CHANGELOG.md +++ b/packages/hardhat-plugin/CHANGELOG.md @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## 0.4.0 - 2023-09-15 + +### Added + +- Advanced cli UI for deploy ([#401](https://github.com/NomicFoundation/ignition/pull/401)) +- Store artifact debug files as part of deployment directory ([#473](https://github.com/NomicFoundation/ignition/pull/473)) + +### Changed + +- Changed npm package name to `@nomicfoundation/hardhat-ignition` +- rename the `plan` task to `visualize` ([#471](https://github.com/NomicFoundation/ignition/pull/471)) +- Constrain module ids and action ids to better support storing deployments on windows ([#466](https://github.com/NomicFoundation/ignition/pull/466)) +- Rename `use-verbose` flag on `deploy` task to `simple-text-ui` ([#444](https://github.com/NomicFoundation/ignition/pull/444)) + +### Fixed + +- Fix batch completion on non-automining chains ([#467](https://github.com/NomicFoundation/ignition/pull/467)) + ## 0.3.0 - 2023-08-30 ### Added diff --git a/packages/hardhat-plugin/README.md b/packages/hardhat-plugin/README.md index a6557f3c9..0793fbe54 100644 --- a/packages/hardhat-plugin/README.md +++ b/packages/hardhat-plugin/README.md @@ -1,4 +1,4 @@ -[![npm](https://img.shields.io/npm/v/@ignored/hardhat-ignition.svg)](https://www.npmjs.com/package/@ignored/hardhat-ignition) [![hardhat](https://hardhat.org/buidler-plugin-badge.svg?1)](https://hardhat.org) +[![npm](https://img.shields.io/npm/v/@nomicfoundation/hardhat-ignition.svg)](https://www.npmjs.com/package/@nomicfoundation/hardhat-ignition) [![hardhat](https://hardhat.org/buidler-plugin-badge.svg?1)](https://hardhat.org) # hardhat-ignition @@ -11,24 +11,24 @@ This plugin brings **Ignition** to your **Hardhat** project, allowing you to orc ## Installation ```bash -npm install --save-dev @ignored/hardhat-ignition +npm install --save-dev @nomicfoundation/hardhat-ignition ``` And add the following statement to your `hardhat.config.js`: ```js -require("@ignored/hardhat-ignition"); +require("@nomicfoundation/hardhat-ignition"); ``` Or, if you are using TypeScript, add this to your `hardhat.config.ts`: ```js -import "@ignored/hardhat-ignition"; +import "@nomicfoundation/hardhat-ignition"; ``` ## Tasks -This plugin provides the `deploy` and `plan` tasks. +This plugin provides the `deploy` and `visualize` tasks. ## Usage diff --git a/packages/hardhat-plugin/package.json b/packages/hardhat-plugin/package.json index 634eaee81..c3f4399fc 100644 --- a/packages/hardhat-plugin/package.json +++ b/packages/hardhat-plugin/package.json @@ -1,6 +1,6 @@ { - "name": "@ignored/hardhat-ignition", - "version": "0.3.0", + "name": "@nomicfoundation/hardhat-ignition", + "version": "0.4.0", "license": "MIT", "author": "Nomic Foundation", "homepage": "https://hardhat.org", @@ -31,8 +31,8 @@ "prepack": "npm run build" }, "devDependencies": { - "@ignored/ignition-core": "^0.3.0", - "@ignored/ignition-ui": "^0.3.0", + "@nomicfoundation/ignition-core": "^0.4.0", + "@nomicfoundation/ignition-ui": "^0.4.0", "@istanbuljs/nyc-config-typescript": "1.0.2", "@nomicfoundation/hardhat-ethers": "^3.0.4", "@types/chai": "^4.2.22", @@ -42,6 +42,7 @@ "@types/dompurify": "2.4.0", "@types/fs-extra": "^9.0.13", "@types/lodash": "4.14.189", + "@types/lodash.flattendeep": "^4.4.7", "@types/mermaid": "^9.1.0", "@types/mocha": "^9.0.0", "@types/ndjson": "2.0.1", @@ -71,8 +72,8 @@ "typescript": "^4.7.4" }, "peerDependencies": { - "@ignored/ignition-core": "^0.3.0", - "@ignored/ignition-ui": "^0.3.0", + "@nomicfoundation/ignition-core": "^0.4.0", + "@nomicfoundation/ignition-ui": "^0.4.0", "@nomicfoundation/hardhat-ethers": "^3.0.4", "hardhat": "^2.14.0" }, @@ -82,6 +83,7 @@ "fs-extra": "^10.0.0", "ink": "3.2.0", "ink-spinner": "4.0.3", + "lodash.flattendeep": "^4.4.0", "ndjson": "2.0.0", "prompts": "^2.4.2", "react": "18.2.0", diff --git a/packages/hardhat-plugin/src/hardhat-artifact-resolver.ts.ts b/packages/hardhat-plugin/src/hardhat-artifact-resolver.ts similarity index 93% rename from packages/hardhat-plugin/src/hardhat-artifact-resolver.ts.ts rename to packages/hardhat-plugin/src/hardhat-artifact-resolver.ts index f57b8e671..317843709 100644 --- a/packages/hardhat-plugin/src/hardhat-artifact-resolver.ts.ts +++ b/packages/hardhat-plugin/src/hardhat-artifact-resolver.ts @@ -1,4 +1,8 @@ -import { Artifact, ArtifactResolver, BuildInfo } from "@ignored/ignition-core"; +import { + Artifact, + ArtifactResolver, + BuildInfo, +} from "@nomicfoundation/ignition-core"; import fs from "fs"; import { HardhatRuntimeEnvironment } from "hardhat/types"; import path from "path"; diff --git a/packages/hardhat-plugin/src/ignition-helper.ts b/packages/hardhat-plugin/src/ignition-helper.ts index e4c954e88..a08cb1d8f 100644 --- a/packages/hardhat-plugin/src/ignition-helper.ts +++ b/packages/hardhat-plugin/src/ignition-helper.ts @@ -11,14 +11,14 @@ import { IgnitionModule, IgnitionModuleResult, isContractFuture, - NamedContractAtFuture, - NamedContractDeploymentFuture, + NamedArtifactContractAtFuture, + NamedArtifactContractDeploymentFuture, SuccessfulDeploymentResult, -} from "@ignored/ignition-core"; +} from "@nomicfoundation/ignition-core"; import { HardhatPluginError } from "hardhat/plugins"; import { HardhatRuntimeEnvironment } from "hardhat/types"; -import { HardhatArtifactResolver } from "./hardhat-artifact-resolver.ts"; +import { HardhatArtifactResolver } from "./hardhat-artifact-resolver"; import { errorDeploymentResultToExceptionMessage } from "./utils/error-deployment-result-to-exception-message"; export type DeployedContract = { @@ -84,7 +84,6 @@ export class IgnitionHelper { ignitionModule, deploymentParameters: parameters, accounts, - verbose: false, }); if (result.type !== DeploymentResultType.SUCCESSFUL_DEPLOYMENT) { @@ -134,7 +133,7 @@ export class IgnitionHelper { ): Promise { if (!isContractFuture(future)) { throw new HardhatPluginError( - "@ignored/hardhat-ignition", + "@nomicfoundation/hardhat-ignition", `Expected contract future but got ${future.id} with type ${future.type} instead` ); } @@ -158,8 +157,8 @@ export type IgnitionModuleResultsTToEthersContracts< IgnitionModuleResultsT extends IgnitionModuleResult > = { [contract in keyof IgnitionModuleResultsT]: IgnitionModuleResultsT[contract] extends - | NamedContractDeploymentFuture - | NamedContractAtFuture + | NamedArtifactContractDeploymentFuture + | NamedArtifactContractAtFuture ? TypeChainEthersContractByName : Contract; }; diff --git a/packages/hardhat-plugin/src/index.ts b/packages/hardhat-plugin/src/index.ts index 387d8785d..bfc270c74 100644 --- a/packages/hardhat-plugin/src/index.ts +++ b/packages/hardhat-plugin/src/index.ts @@ -1,31 +1,28 @@ +import "@nomicfoundation/hardhat-ethers"; import { deploy, DeploymentParameters, - DeploymentResult, - DeploymentResultType, - IgnitionModuleResult, - plan, - SuccessfulDeploymentResult, + IgnitionModuleSerializer, wipe, -} from "@ignored/ignition-core"; -import "@nomicfoundation/hardhat-ethers"; +} from "@nomicfoundation/ignition-core"; import { existsSync, readdirSync, readJSONSync } from "fs-extra"; import { extendConfig, extendEnvironment, task } from "hardhat/config"; import { lazyObject } from "hardhat/plugins"; import path from "path"; import Prompt from "prompts"; -import { HardhatArtifactResolver } from "./hardhat-artifact-resolver.ts"; +import { HardhatArtifactResolver } from "./hardhat-artifact-resolver"; import { IgnitionHelper } from "./ignition-helper"; import { loadModule } from "./load-module"; -import { writePlan } from "./plan/write-plan"; -import { errorDeploymentResultToExceptionMessage } from "./utils/error-deployment-result-to-exception-message"; +import { UiEventHandler } from "./ui/UiEventHandler"; +import { VerboseEventHandler } from "./ui/VerboseEventHandler"; import { open } from "./utils/open"; +import { writeVisualization } from "./visualization/write-visualization"; import "./type-extensions"; // eslint-disable-next-line import/no-unused-modules -export { buildModule } from "@ignored/ignition-core"; +export { buildModule } from "@nomicfoundation/ignition-core"; /* ignition config defaults */ const IGNITION_DIR = "ignition"; @@ -65,19 +62,22 @@ task("deploy") ) .addOptionalParam("id", "set the deployment id") .addFlag("force", "restart the deployment ignoring previous history") - .addFlag("logs", "output journal logs to the terminal") + .addFlag( + "simpleTextUi", + "use a simple text based UI instead of the default UI" + ) .setAction( async ( { moduleNameOrPath, parameters: parametersInput, - logs, + simpleTextUi, id: givenDeploymentId, }: { moduleNameOrPath: string; parameters?: string; force: boolean; - logs: boolean; + simpleTextUi: boolean; id: string; }, hre @@ -139,22 +139,31 @@ task("deploy") const artifactResolver = new HardhatArtifactResolver(hre); - const result = await deploy({ - config: hre.config.ignition, - provider: hre.network.provider, - artifactResolver, - deploymentDir, - ignitionModule: userModule, - deploymentParameters: parameters ?? {}, - accounts, - verbose: logs, - }); - - displayDeploymentResult(result); + const executionEventListener = simpleTextUi + ? new VerboseEventHandler() + : new UiEventHandler(parameters); + + try { + await deploy({ + config: hre.config.ignition, + provider: hre.network.provider, + executionEventListener, + artifactResolver, + deploymentDir, + ignitionModule: userModule, + deploymentParameters: parameters ?? {}, + accounts, + }); + } catch (e) { + if (executionEventListener instanceof UiEventHandler) { + executionEventListener.unmountCli(); + } + throw e; + } } ); -task("plan") +task("visualize") .addFlag("quiet", "Disables logging output path to terminal") .addPositionalParam("moduleNameOrPath") .setAction( @@ -177,35 +186,24 @@ task("plan") process.exit(0); } - const chainId = Number( - await hre.network.provider.request({ - method: "eth_chainId", - }) - ); + const serializedIgnitionModule = + IgnitionModuleSerializer.serialize(userModule); - const artifactResolver = new HardhatArtifactResolver(hre); - - const serializedModule = await plan({ - artifactResolver, - storedDeployment: { - details: { - networkName: hre.network.name, - chainId, - }, - module: userModule, - }, - }); - - await writePlan(serializedModule, { cacheDir: hre.config.paths.cache }); + await writeVisualization( + { module: serializedIgnitionModule }, + { + cacheDir: hre.config.paths.cache, + } + ); if (!quiet) { const indexFile = path.join( hre.config.paths.cache, - "plan", + "visualization", "index.html" ); - console.log(`Plan written to ${indexFile}`); + console.log(`Deployment visualization written to ${indexFile}`); open(indexFile); } @@ -321,29 +319,3 @@ function resolveParametersString(paramString: string): DeploymentParameters { process.exit(0); } } - -function displayDeploymentResult( - result: DeploymentResult> -): void { - switch (result.type) { - case DeploymentResultType.VALIDATION_ERROR: - case DeploymentResultType.RECONCILIATION_ERROR: - case DeploymentResultType.EXECUTION_ERROR: - return console.log(errorDeploymentResultToExceptionMessage(result)); - case DeploymentResultType.SUCCESSFUL_DEPLOYMENT: - return _displaySuccessfulDeployment(result); - } -} - -function _displaySuccessfulDeployment( - result: SuccessfulDeploymentResult> -): void { - console.log("Deployment complete"); - console.log(""); - - for (const [futureId, { contractName, address }] of Object.entries( - result.contracts - )) { - console.log(`${contractName} (${futureId}) - ${address}`); - } -} diff --git a/packages/hardhat-plugin/src/load-module.ts b/packages/hardhat-plugin/src/load-module.ts index 5e8d5fe91..d49aa718b 100644 --- a/packages/hardhat-plugin/src/load-module.ts +++ b/packages/hardhat-plugin/src/load-module.ts @@ -1,4 +1,4 @@ -import { IgnitionError, IgnitionModule } from "@ignored/ignition-core"; +import { IgnitionError, IgnitionModule } from "@nomicfoundation/ignition-core"; import setupDebug from "debug"; import { existsSync, pathExistsSync } from "fs-extra"; import path from "path"; diff --git a/packages/hardhat-plugin/src/type-extensions.ts b/packages/hardhat-plugin/src/type-extensions.ts index cc1eb7550..117961123 100644 --- a/packages/hardhat-plugin/src/type-extensions.ts +++ b/packages/hardhat-plugin/src/type-extensions.ts @@ -2,7 +2,7 @@ import "hardhat/types/config"; import "hardhat/types/runtime"; -import { DeployConfig } from "@ignored/ignition-core"; +import { DeployConfig } from "@nomicfoundation/ignition-core"; import { IgnitionHelper } from "./ignition-helper"; diff --git a/packages/hardhat-plugin/src/ui/UiEventHandler.tsx b/packages/hardhat-plugin/src/ui/UiEventHandler.tsx new file mode 100644 index 000000000..e7f7d100a --- /dev/null +++ b/packages/hardhat-plugin/src/ui/UiEventHandler.tsx @@ -0,0 +1,479 @@ +import { + BatchInitializeEvent, + BeginNextBatchEvent, + CallExecutionStateCompleteEvent, + CallExecutionStateInitializeEvent, + ContractAtExecutionStateInitializeEvent, + DeploymentCompleteEvent, + DeploymentExecutionStateCompleteEvent, + DeploymentExecutionStateInitializeEvent, + DeploymentParameters, + DeploymentResult, + DeploymentResultType, + DeploymentStartEvent, + ExecutionEventListener, + ExecutionEventResult, + ExecutionEventResultType, + IgnitionError, + IgnitionModuleResult, + NetworkInteractionRequestEvent, + OnchainInteractionBumpFeesEvent, + OnchainInteractionDroppedEvent, + OnchainInteractionReplacedByUserEvent, + OnchainInteractionTimeoutEvent, + ReadEventArgExecutionStateInitializeEvent, + RunStartEvent, + SendDataExecutionStateCompleteEvent, + SendDataExecutionStateInitializeEvent, + SetModuleIdEvent, + StaticCallCompleteEvent, + StaticCallExecutionStateCompleteEvent, + StaticCallExecutionStateInitializeEvent, + TransactionConfirmEvent, + TransactionSendEvent, + WipeApplyEvent, +} from "@nomicfoundation/ignition-core"; +import { render } from "ink"; + +import { IgnitionUi } from "./components"; +import { + UiBatches, + UiFuture, + UiFutureErrored, + UiFutureHeld, + UiFutureStatusType, + UiFutureSuccess, + UiState, + UiStateDeploymentStatus, +} from "./types"; + +interface RenderState { + rerender: null | ((node: React.ReactNode) => void); + unmount: null | (() => void); + waitUntilExit: null | (() => Promise); + clear: null | (() => void); +} + +export class UiEventHandler implements ExecutionEventListener { + private _renderState: RenderState = { + rerender: null, + unmount: null, + waitUntilExit: null, + clear: null, + }; + + private _uiState: UiState = { + status: UiStateDeploymentStatus.UNSTARTED, + chainId: null, + moduleName: null, + batches: [], + result: null, + }; + + constructor(private _deploymentParams: DeploymentParameters = {}) {} + + public get state(): UiState { + return this._uiState; + } + + public set state(uiState: UiState) { + this._uiState = uiState; + + this._renderToCli(); + } + + public runStart(event: RunStartEvent): void { + this.state = { + ...this.state, + chainId: event.chainId, + }; + } + + public wipeApply(event: WipeApplyEvent): void { + const batches: UiBatches = []; + + for (const batch of this.state.batches) { + const futureBatch: UiFuture[] = []; + + for (const future of batch) { + if (future.futureId === event.futureId) { + continue; + } else { + futureBatch.push(future); + } + } + + batches.push(futureBatch); + } + + this.state = { + ...this.state, + batches, + }; + } + + public deploymentExecutionStateInitialize( + event: DeploymentExecutionStateInitializeEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: { + type: UiFutureStatusType.PENDING, + }, + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public deploymentExecutionStateComplete( + event: DeploymentExecutionStateCompleteEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: this._getFutureStatusFromEventResult(event.result), + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public callExecutionStateInitialize( + event: CallExecutionStateInitializeEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: { + type: UiFutureStatusType.PENDING, + }, + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public callExecutionStateComplete( + event: CallExecutionStateCompleteEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: this._getFutureStatusFromEventResult(event.result), + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public staticCallExecutionStateInitialize( + event: StaticCallExecutionStateInitializeEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: { + type: UiFutureStatusType.PENDING, + }, + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public staticCallExecutionStateComplete( + event: StaticCallExecutionStateCompleteEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: this._getFutureStatusFromEventResult(event.result), + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public sendDataExecutionStateInitialize( + event: SendDataExecutionStateInitializeEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: { + type: UiFutureStatusType.PENDING, + }, + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public sendDataExecutionStateComplete( + event: SendDataExecutionStateCompleteEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: this._getFutureStatusFromEventResult(event.result), + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public contractAtExecutionStateInitialize( + event: ContractAtExecutionStateInitializeEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: { + type: UiFutureStatusType.SUCCESS, + }, + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public readEventArgumentExecutionStateInitialize( + event: ReadEventArgExecutionStateInitializeEvent + ): void { + const updatedFuture: UiFuture = { + futureId: event.futureId, + status: { + type: UiFutureStatusType.SUCCESS, + }, + }; + + this.state = { + ...this.state, + batches: this._applyUpdateToBatchFuture(updatedFuture), + }; + } + + public batchInitialize(event: BatchInitializeEvent): void { + const batches: UiBatches = []; + + for (const batch of event.batches) { + const futureBatch: UiFuture[] = []; + + for (const futureId of batch) { + futureBatch.push({ + futureId, + status: { + type: UiFutureStatusType.UNSTARTED, + }, + }); + } + + batches.push(futureBatch); + } + + this.state = { + ...this.state, + batches, + }; + } + + public networkInteractionRequest( + _event: NetworkInteractionRequestEvent + ): void {} + + public transactionSend(_event: TransactionSendEvent): void {} + + public transactionConfirm(_event: TransactionConfirmEvent): void {} + + public staticCallComplete(_event: StaticCallCompleteEvent): void {} + + public onchainInteractionBumpFees( + _event: OnchainInteractionBumpFeesEvent + ): void {} + + public onchainInteractionDropped( + _event: OnchainInteractionDroppedEvent + ): void {} + + public onchainInteractionReplacedByUser( + _event: OnchainInteractionReplacedByUserEvent + ): void {} + + public onchainInteractionTimeout( + _event: OnchainInteractionTimeoutEvent + ): void {} + + public deploymentStart(event: DeploymentStartEvent): void { + this.state = { + ...this.state, + status: UiStateDeploymentStatus.DEPLOYING, + moduleName: event.moduleName, + }; + } + + public beginNextBatch(_event: BeginNextBatchEvent): void {} + + public deploymentComplete(event: DeploymentCompleteEvent): void { + this.state = { + ...this.state, + status: UiStateDeploymentStatus.COMPLETE, + result: event.result, + batches: this._applyResultToBatches(this.state.batches, event.result), + }; + } + + public setModuleId(event: SetModuleIdEvent): void { + this.state = { + ...this.state, + moduleName: event.moduleName, + }; + } + + public unmountCli(): void { + if ( + this._renderState.unmount === null || + this._renderState.waitUntilExit === null || + this._renderState.clear === null + ) { + throw new IgnitionError("Cannot unmount with no unmount function"); + } + + this._renderState.clear(); + this._renderState.unmount(); + } + + private _renderToCli(): void { + if (this._renderState.rerender === null) { + const { rerender, unmount, waitUntilExit, clear } = render( + , + { patchConsole: false } + ); + + this._renderState.rerender = rerender; + this._renderState.unmount = unmount; + this._renderState.waitUntilExit = waitUntilExit; + this._renderState.clear = clear; + + return; + } + + this._renderState.rerender( + + ); + } + + private _applyUpdateToBatchFuture(updatedFuture: UiFuture): UiBatches { + const batches: UiBatches = []; + + for (const batch of this.state.batches) { + const futureBatch: UiFuture[] = []; + + for (const future of batch) { + if (future.futureId === updatedFuture.futureId) { + futureBatch.push(updatedFuture); + } else { + futureBatch.push(future); + } + } + + batches.push(futureBatch); + } + + return batches; + } + + private _getFutureStatusFromEventResult( + result: ExecutionEventResult + ): UiFutureSuccess | UiFutureErrored | UiFutureHeld { + switch (result.type) { + case ExecutionEventResultType.SUCCESS: { + return { + type: UiFutureStatusType.SUCCESS, + result: result.result, + }; + } + case ExecutionEventResultType.ERROR: { + return { + type: UiFutureStatusType.ERRORED, + message: result.error, + }; + } + case ExecutionEventResultType.HELD: { + return { + type: UiFutureStatusType.HELD, + heldId: result.heldId, + reason: result.reason, + }; + } + } + } + + private _applyResultToBatches( + batches: UiBatches, + result: DeploymentResult> + ): UiBatches { + const newBatches: UiBatches = []; + + for (const oldBatch of batches) { + const newBatch = []; + for (const future of oldBatch) { + const updatedFuture = this._hasUpdatedResult(future.futureId, result); + + newBatch.push(updatedFuture ?? future); + } + + newBatches.push(newBatch); + } + + return newBatches; + } + + private _hasUpdatedResult( + futureId: string, + result: DeploymentResult> + ): UiFuture | null { + if (result.type !== DeploymentResultType.EXECUTION_ERROR) { + return null; + } + + const failed = result.failed.find((f) => f.futureId === futureId); + + if (failed !== undefined) { + const f: UiFuture = { + futureId, + status: { + type: UiFutureStatusType.ERRORED, + message: failed.error, + }, + }; + + return f; + } + + const timedout = result.timedOut.find((f) => f.futureId === futureId); + + if (timedout !== undefined) { + const f: UiFuture = { + futureId, + status: { + type: UiFutureStatusType.PENDING, + }, + }; + + return f; + } + + return null; + } +} diff --git a/packages/hardhat-plugin/src/ui/VerboseEventHandler.ts b/packages/hardhat-plugin/src/ui/VerboseEventHandler.ts new file mode 100644 index 000000000..4414cb27d --- /dev/null +++ b/packages/hardhat-plugin/src/ui/VerboseEventHandler.ts @@ -0,0 +1,257 @@ +import { + BatchInitializeEvent, + BeginNextBatchEvent, + CallExecutionStateCompleteEvent, + CallExecutionStateInitializeEvent, + ContractAtExecutionStateInitializeEvent, + DeploymentCompleteEvent, + DeploymentExecutionStateCompleteEvent, + DeploymentExecutionStateInitializeEvent, + DeploymentStartEvent, + ExecutionEventListener, + ExecutionEventNetworkInteractionType, + ExecutionEventResultType, + NetworkInteractionRequestEvent, + OnchainInteractionBumpFeesEvent, + OnchainInteractionDroppedEvent, + OnchainInteractionReplacedByUserEvent, + OnchainInteractionTimeoutEvent, + ReadEventArgExecutionStateInitializeEvent, + RunStartEvent, + SendDataExecutionStateCompleteEvent, + SendDataExecutionStateInitializeEvent, + SetModuleIdEvent, + StaticCallCompleteEvent, + StaticCallExecutionStateCompleteEvent, + StaticCallExecutionStateInitializeEvent, + TransactionConfirmEvent, + TransactionSendEvent, + WipeApplyEvent, +} from "@nomicfoundation/ignition-core"; + +export class VerboseEventHandler implements ExecutionEventListener { + public runStart(event: RunStartEvent): void { + console.log(`Deployment started for chainId: ${event.chainId}`); + } + + public wipeApply(event: WipeApplyEvent): void { + console.log(`Removing the execution of future ${event.futureId}`); + } + + public deploymentExecutionStateInitialize( + event: DeploymentExecutionStateInitializeEvent + ): void { + console.log(`Starting to execute the deployment future ${event.futureId}`); + } + + public deploymentExecutionStateComplete( + event: DeploymentExecutionStateCompleteEvent + ): void { + switch (event.result.type) { + case ExecutionEventResultType.SUCCESS: { + return console.log( + `Successfully completed the execution of deployment future ${ + event.futureId + } with address ${event.result.result ?? "undefined"}` + ); + } + case ExecutionEventResultType.ERROR: { + return console.log( + `Execution of future ${event.futureId} failed with reason: ${event.result.error}` + ); + } + case ExecutionEventResultType.HELD: { + return console.log( + `Execution of future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}` + ); + } + } + } + + public callExecutionStateInitialize( + event: CallExecutionStateInitializeEvent + ): void { + console.log(`Starting to execute the call future ${event.futureId}`); + } + + public callExecutionStateComplete( + event: CallExecutionStateCompleteEvent + ): void { + switch (event.result.type) { + case ExecutionEventResultType.SUCCESS: { + return console.log( + `Successfully completed the execution of call future ${event.futureId}` + ); + } + case ExecutionEventResultType.ERROR: { + return console.log( + `Execution of call future ${event.futureId} failed with reason: ${event.result.error}` + ); + } + case ExecutionEventResultType.HELD: { + return console.log( + `Execution of call future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}` + ); + } + } + } + + public staticCallExecutionStateInitialize( + event: StaticCallExecutionStateInitializeEvent + ): void { + console.log(`Starting to execute the static call future ${event.futureId}`); + } + + public staticCallExecutionStateComplete( + event: StaticCallExecutionStateCompleteEvent + ): void { + switch (event.result.type) { + case ExecutionEventResultType.SUCCESS: { + return console.log( + `Successfully completed the execution of static call future ${ + event.futureId + } with result ${event.result.result ?? "undefined"}` + ); + } + case ExecutionEventResultType.ERROR: { + return console.log( + `Execution of static call future ${event.futureId} failed with reason: ${event.result.error}` + ); + } + case ExecutionEventResultType.HELD: { + return console.log( + `Execution of static call future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}` + ); + } + } + } + + public sendDataExecutionStateInitialize( + event: SendDataExecutionStateInitializeEvent + ): void { + console.log(`Started to execute the send data future ${event.futureId}`); + } + + public sendDataExecutionStateComplete( + event: SendDataExecutionStateCompleteEvent + ): void { + switch (event.result.type) { + case ExecutionEventResultType.SUCCESS: { + return console.log( + `Successfully completed the execution of send data future ${ + event.futureId + } in tx ${event.result.result ?? "undefined"}` + ); + } + case ExecutionEventResultType.ERROR: { + return console.log( + `Execution of future ${event.futureId} failed with reason: ${event.result.error}` + ); + } + case ExecutionEventResultType.HELD: { + return console.log( + `Execution of send future ${event.futureId}/${event.result.heldId} held with reason: ${event.result.reason}` + ); + } + } + } + + public contractAtExecutionStateInitialize( + event: ContractAtExecutionStateInitializeEvent + ): void { + console.log(`Executed contract at future ${event.futureId}`); + } + + public readEventArgumentExecutionStateInitialize( + event: ReadEventArgExecutionStateInitializeEvent + ): void { + console.log( + `Executed read event argument future ${event.futureId} with result ${ + event.result.result ?? "undefined" + }` + ); + } + + public networkInteractionRequest( + event: NetworkInteractionRequestEvent + ): void { + if ( + event.networkInteractionType === + ExecutionEventNetworkInteractionType.ONCHAIN_INTERACTION + ) { + console.log( + `New onchain interaction requested for future ${event.futureId}` + ); + } else { + console.log(`New static call requested for future ${event.futureId}`); + } + } + + public transactionSend(event: TransactionSendEvent): void { + console.log( + `Transaction ${event.hash} sent for onchain interaction of future ${event.futureId}` + ); + } + + public transactionConfirm(event: TransactionConfirmEvent): void { + console.log(`Transaction ${event.hash} confirmed`); + } + + public staticCallComplete(event: StaticCallCompleteEvent): void { + console.log(`Static call completed for future ${event.futureId}`); + } + + public onchainInteractionBumpFees( + event: OnchainInteractionBumpFeesEvent + ): void { + console.log( + `A transaction with higher fees will be sent for onchain interaction of future ${event.futureId}` + ); + } + + public onchainInteractionDropped( + event: OnchainInteractionDroppedEvent + ): void { + console.log( + `Transactions for onchain interaction of future ${event.futureId} has been dropped and will be resent` + ); + } + + public onchainInteractionReplacedByUser( + event: OnchainInteractionReplacedByUserEvent + ): void { + console.log( + `Transactions for onchain interaction of future ${event.futureId} has been replaced by the user and the onchain interaction exection will start again` + ); + } + + public onchainInteractionTimeout( + event: OnchainInteractionTimeoutEvent + ): void { + console.log( + `Onchain interaction of future ${event.futureId} failed due to being resent too many times and not having confirmed` + ); + } + + public batchInitialize(event: BatchInitializeEvent): void { + console.log( + `Starting execution for batches: ${JSON.stringify(event.batches)}` + ); + } + + public deploymentStart(_event: DeploymentStartEvent): void { + console.log(`Starting execution for new deployment`); + } + + public beginNextBatch(_event: BeginNextBatchEvent): void { + console.log(`Starting execution for next batch`); + } + + public deploymentComplete(_event: DeploymentCompleteEvent): void { + console.log(`Deployment complete`); + } + + public setModuleId(event: SetModuleIdEvent): void { + console.log(`Starting validation for module: ${event.moduleName}`); + } +} diff --git a/packages/hardhat-plugin/src/ui/components/StartingPanel.tsx b/packages/hardhat-plugin/src/ui/components/StartingPanel.tsx new file mode 100644 index 000000000..0a1b24797 --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/StartingPanel.tsx @@ -0,0 +1,12 @@ +import { Box, Text } from "ink"; +import Spinner from "ink-spinner"; + +export const StartingPanel = () => { + return ( + + + Ignition starting + + + ); +}; diff --git a/packages/hardhat-plugin/src/ui/components/execution/AddressResults.tsx b/packages/hardhat-plugin/src/ui/components/execution/AddressResults.tsx new file mode 100644 index 000000000..451c2629f --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/AddressResults.tsx @@ -0,0 +1,34 @@ +import { + IgnitionModuleResult, + SuccessfulDeploymentResult, +} from "@nomicfoundation/ignition-core"; +import { Box, Spacer, Text } from "ink"; + +import { NetworkInfo } from "./NetworkInfo"; + +export const AddressResults = ({ + contracts, + chainId, +}: { + contracts: SuccessfulDeploymentResult< + string, + IgnitionModuleResult + >["contracts"]; + chainId: number; +}) => { + return ( + + + Deployed Addresses + + + + + {Object.values(contracts).map((contract) => ( + + {contract.id} {`->`} {contract.address} + + ))} + + ); +}; diff --git a/packages/hardhat-plugin/src/ui/components/execution/BatchExecution.tsx b/packages/hardhat-plugin/src/ui/components/execution/BatchExecution.tsx new file mode 100644 index 000000000..16b028c46 --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/BatchExecution.tsx @@ -0,0 +1,160 @@ +import { Box, Text } from "ink"; +import Spinner from "ink-spinner"; + +import { + UiFuture, + UiFutureStatusType, + UiState, + UiStateDeploymentStatus, +} from "../../types"; + +import { Divider } from "./Divider"; + +export const BatchExecution = ({ state }: { state: UiState }) => { + const isComplete = state.status === UiStateDeploymentStatus.COMPLETE; + + return ( + <> + + + + {isComplete ? ( + Execution complete + ) : ( + + Executing + + )} + + + {state.batches + .filter((batch, i) => isBatchDisplayable(batch, i)) + .map((batch, i) => ( + + ))} + + ); +}; + +const Batch = ({ batch, index }: { batch: UiFuture[]; index: number }) => { + const borderColor = resolveBatchBorderColor(batch); + + return ( + + + #{index} + + + {batch.map((future, i) => ( + + ))} + + ); +}; + +const Future = ({ future }: { future: UiFuture }) => { + const { borderColor, borderStyle, textColor } = resolveFutureColors(future); + + return ( + + + {future.futureId} + + ); +}; + +const StatusBadge = ({ future }: { future: UiFuture }) => { + let badge: any = " "; + switch (future.status.type) { + case UiFutureStatusType.UNSTARTED: + badge = ; + break; + case UiFutureStatusType.SUCCESS: + badge = ; + break; + case UiFutureStatusType.PENDING: + badge = 🔶; + break; + case UiFutureStatusType.ERRORED: + badge = ; + break; + case UiFutureStatusType.HELD: + badge = 🔶; + break; + } + + return ( + <> + + {badge} + + + ); +}; + +function resolveBatchBorderColor(futures: UiFuture[]) { + if (futures.some((v) => v.status.type === UiFutureStatusType.UNSTARTED)) { + return "lightgray"; + } + + if (futures.some((v) => v.status.type === UiFutureStatusType.ERRORED)) { + return "red"; + } + + if (futures.some((v) => v.status.type === UiFutureStatusType.PENDING)) { + return "yellow"; + } + + if (futures.every((v) => v.status.type === UiFutureStatusType.SUCCESS)) { + return "green"; + } + + return "lightgray"; +} + +function resolveFutureColors(future: UiFuture): { + borderColor: string; + borderStyle: "single" | "classic" | "bold" | "singleDouble"; + textColor: string; +} { + switch (future.status.type) { + case UiFutureStatusType.UNSTARTED: + return { + borderColor: "lightgray", + borderStyle: "singleDouble", + textColor: "white", + }; + case UiFutureStatusType.SUCCESS: + return { + borderColor: "greenBright", + borderStyle: "single", + textColor: "white", + }; + case UiFutureStatusType.PENDING: + return { + borderColor: "yellow", + borderStyle: "bold", + textColor: "white", + }; + case UiFutureStatusType.ERRORED: + return { + borderColor: "redBright", + borderStyle: "bold", + textColor: "white", + }; + case UiFutureStatusType.HELD: + return { + borderColor: "yellow", + borderStyle: "bold", + textColor: "white", + }; + } +} + +function isBatchDisplayable(batch: UiFuture[], index: number): boolean { + if (index === 0) { + return true; + } + + return batch.some((v) => v.status.type !== UiFutureStatusType.UNSTARTED); +} diff --git a/packages/hardhat-plugin/src/ui/components/execution/DeployParameters.tsx b/packages/hardhat-plugin/src/ui/components/execution/DeployParameters.tsx new file mode 100644 index 000000000..941908b0e --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/DeployParameters.tsx @@ -0,0 +1,60 @@ +import type { + DeploymentParameters, + ModuleParameters, +} from "@nomicfoundation/ignition-core"; + +import { Newline, Text } from "ink"; + +export const DeployParameters = ({ + deployParams, +}: { + deployParams?: DeploymentParameters; +}) => { + if (deployParams === undefined) { + return null; + } + + const entries = Object.entries(deployParams); + + if (entries.length === 0) { + return null; + } + + const params = entries.map(([moduleId, moduleParams]) => { + return ( + + + Module: {moduleId} + + + + + + ); + }); + + return ( + + Deployment parameters: + + {...params} + + ); +}; + +const ModuleParams = ({ moduleParams }: { moduleParams: ModuleParameters }) => { + const entries = Object.entries(moduleParams); + + const params = entries.map(([paramId, paramValue]) => { + return ( + + + {paramId}: {JSON.stringify(paramValue)} + + + + ); + }); + + return {...params}; +}; diff --git a/packages/hardhat-plugin/src/ui/components/execution/Divider.tsx b/packages/hardhat-plugin/src/ui/components/execution/Divider.tsx new file mode 100644 index 000000000..b4a26f474 --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/Divider.tsx @@ -0,0 +1,15 @@ +import { Box, Text } from "ink"; + +export const Divider = () => { + return ( + + + + {Array.from({ length: 400 }) + .map((_i) => "─") + .join("")} + + + + ); +}; diff --git a/packages/hardhat-plugin/src/ui/components/execution/ExecutionPanel.tsx b/packages/hardhat-plugin/src/ui/components/execution/ExecutionPanel.tsx new file mode 100644 index 000000000..da877c56b --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/ExecutionPanel.tsx @@ -0,0 +1,34 @@ +import type { DeploymentParameters } from "@nomicfoundation/ignition-core"; + +import { Box } from "ink"; + +import { UiState } from "../../types"; + +import { BatchExecution } from "./BatchExecution"; +import { FinalStatus } from "./FinalStatus"; +import { SummarySection } from "./SummarySection"; +import { viewEverythingExecutedAlready } from "./views"; + +export const ExecutionPanel = ({ + state, + deployParams, +}: { + state: UiState; + deployParams?: DeploymentParameters; +}) => { + if (viewEverythingExecutedAlready(state)) { + return ( + + + + ); + } + + return ( + + + + + + ); +}; diff --git a/packages/hardhat-plugin/src/ui/components/execution/FinalStatus.tsx b/packages/hardhat-plugin/src/ui/components/execution/FinalStatus.tsx new file mode 100644 index 000000000..c64935741 --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/FinalStatus.tsx @@ -0,0 +1,221 @@ +import { + DeploymentResultType, + ExecutionErrorDeploymentResult, + IgnitionModuleResult, + PreviousRunErrorDeploymentResult, + ReconciliationErrorDeploymentResult, + SuccessfulDeploymentResult, + ValidationErrorDeploymentResult, +} from "@nomicfoundation/ignition-core"; +import { Box, Newline, Text } from "ink"; + +import { UiState } from "../../types"; + +import { AddressResults } from "./AddressResults"; +import { Divider } from "./Divider"; + +export const FinalStatus = ({ state }: { state: UiState }) => { + if (state.result === null) { + return null; + } + + switch (state.result.type) { + case DeploymentResultType.VALIDATION_ERROR: { + return ( + + ); + } + case DeploymentResultType.RECONCILIATION_ERROR: { + return ( + + ); + } + case DeploymentResultType.EXECUTION_ERROR: { + return ( + + ); + } + case DeploymentResultType.PREVIOUS_RUN_ERROR: { + return ( + + ); + } + case DeploymentResultType.SUCCESSFUL_DEPLOYMENT: { + return ( + + ); + } + } +}; + +const SuccessfulResult: React.FC<{ + moduleName: string; + chainId: number; + result: SuccessfulDeploymentResult>; +}> = ({ moduleName, chainId, result }) => { + return ( + + + + + 🚀 Deployment Complete for module{" "} + {moduleName} + + + + + + + ); +}; + +const ErrorResult: React.FC<{ + moduleName: string; + chainId: number; + message: string; + result: ReconciliationErrorDeploymentResult | ValidationErrorDeploymentResult; +}> = ({ moduleName, message, result }) => { + return ( + + + + + ⛔ {message} {moduleName} + + + + + + {Object.entries(result.errors).map(([futureId, futureErrors]) => ( + + {futureId} errors: + + {futureErrors.map((error, i) => ( + + {" "} + - {error} + + + ))} + + ))} + + + + + ); +}; + +const ExecutionErrorResult: React.FC<{ + moduleName: string; + chainId: number; + result: ExecutionErrorDeploymentResult; +}> = ({ moduleName, result }) => { + return ( + + + + + ⛔ Execution failed for module {moduleName} + + + + + + {result.timedOut.length > 0 && ( + + + Timed Out: + + + {result.timedOut.map(({ futureId, networkInteractionId }) => ( + + - {futureId}/{networkInteractionId} + + ))} + + )} + + {result.failed.length > 0 && ( + + + Failed: + + + + {result.failed.map(({ futureId, networkInteractionId, error }) => ( + + - {futureId}/{networkInteractionId}: {error} + + ))} + + )} + + + + + ); +}; + +const PreviousRunErrorResult: React.FC<{ + moduleName: string; + chainId: number; + result: PreviousRunErrorDeploymentResult; +}> = ({ moduleName, result }) => { + return ( + + + + + ⛔ Deployment cancelled due to failed or timed out futures on a previous + run of module {moduleName}. + + + + + + + These futures will need to be rerun; use the `wipe` task to reset + them: + + + {Object.entries(result.errors).map(([futureId, futureErrors]) => ( + + {futureId} + {futureErrors.map((error, i) => ( + + {" "} + - {error} + + + ))} + + ))} + + + + + ); +}; diff --git a/packages/hardhat-plugin/src/ui/components/execution/NetworkInfo.tsx b/packages/hardhat-plugin/src/ui/components/execution/NetworkInfo.tsx new file mode 100644 index 000000000..a7eb0ba35 --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/NetworkInfo.tsx @@ -0,0 +1,11 @@ +import { Text } from "ink"; + +export const NetworkInfo = ({ + networkInfo: { chainId }, +}: { + networkInfo: { + chainId: number; + }; +}) => { + return Chain ID: {chainId}; +}; diff --git a/packages/hardhat-plugin/src/ui/components/execution/SummarySection.tsx b/packages/hardhat-plugin/src/ui/components/execution/SummarySection.tsx new file mode 100644 index 000000000..fbcd01e37 --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/SummarySection.tsx @@ -0,0 +1,28 @@ +import { DeploymentParameters } from "@nomicfoundation/ignition-core"; +import { Box, Spacer, Text } from "ink"; + +import { UiState } from "../../types"; + +import { DeployParameters } from "./DeployParameters"; +import { NetworkInfo } from "./NetworkInfo"; + +export const SummarySection = ({ + state: { chainId, moduleName }, + deployParams, +}: { + state: UiState; + deployParams?: DeploymentParameters; +}) => { + return ( + + + + Deploying module {moduleName} + + + + + + + ); +}; diff --git a/packages/hardhat-plugin/src/ui/components/execution/views.ts b/packages/hardhat-plugin/src/ui/components/execution/views.ts new file mode 100644 index 000000000..3dd1ca256 --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/execution/views.ts @@ -0,0 +1,16 @@ +import { UiState, UiStateDeploymentStatus } from "../../types"; + +/** + * Determine whether any on-chain executions happened in this + * run. An execution that requires on-chain updates in this + * run will have batches, a lack of batches indicates nothing + * to execute or execution happened on a previous run. + * @param state the deploy state + * @returns whether on-chain executions happened in this run + */ +export function viewEverythingExecutedAlready(state: UiState): boolean { + return ( + state.status !== UiStateDeploymentStatus.UNSTARTED && + state.batches.length === 0 + ); +} diff --git a/packages/hardhat-plugin/src/ui/components/index.tsx b/packages/hardhat-plugin/src/ui/components/index.tsx new file mode 100644 index 000000000..930a0ece7 --- /dev/null +++ b/packages/hardhat-plugin/src/ui/components/index.tsx @@ -0,0 +1,20 @@ +import type { DeploymentParameters } from "@nomicfoundation/ignition-core"; + +import { UiState, UiStateDeploymentStatus } from "../types"; + +import { StartingPanel } from "./StartingPanel"; +import { ExecutionPanel } from "./execution/ExecutionPanel"; + +export const IgnitionUi = ({ + state, + deployParams, +}: { + state: UiState; + deployParams?: DeploymentParameters; +}) => { + if (state.status === UiStateDeploymentStatus.UNSTARTED) { + return ; + } + + return ; +}; diff --git a/packages/hardhat-plugin/src/ui/types.ts b/packages/hardhat-plugin/src/ui/types.ts new file mode 100644 index 000000000..a45c2470d --- /dev/null +++ b/packages/hardhat-plugin/src/ui/types.ts @@ -0,0 +1,68 @@ +import { + DeploymentResult, + IgnitionModuleResult, +} from "@nomicfoundation/ignition-core"; + +export enum UiFutureStatusType { + UNSTARTED = "UNSTARTED", + SUCCESS = "SUCCESS", + PENDING = "PENDING", + ERRORED = "ERRORED", + HELD = "HELD", +} + +export enum UiStateDeploymentStatus { + UNSTARTED = "UNSTARTED", + DEPLOYING = "DEPLOYING", + COMPLETE = "COMPLETE", +} + +export interface UiFutureUnstarted { + type: UiFutureStatusType.UNSTARTED; +} + +export interface UiFutureSuccess { + type: UiFutureStatusType.SUCCESS; + result?: string; +} + +export interface UiFuturePending { + type: UiFutureStatusType.PENDING; +} + +export interface UiFutureErrored { + type: UiFutureStatusType.ERRORED; + message: string; +} + +export interface UiFutureHeld { + type: UiFutureStatusType.HELD; + heldId: number; + reason: string; +} + +export type UiFutureStatus = + | UiFutureUnstarted + | UiFutureSuccess + | UiFuturePending + | UiFutureErrored + | UiFutureHeld; + +export interface UiFuture { + status: UiFutureStatus; + futureId: string; +} + +export type UiBatches = UiFuture[][]; + +export interface UiState { + status: UiStateDeploymentStatus; + chainId: number | null; + moduleName: string | null; + batches: UiBatches; + result: DeploymentResult> | null; +} + +export interface AddressMap { + [label: string]: string; +} diff --git a/packages/hardhat-plugin/src/utils/error-deployment-result-to-exception-message.ts b/packages/hardhat-plugin/src/utils/error-deployment-result-to-exception-message.ts index a0e5eed05..db02b53b1 100644 --- a/packages/hardhat-plugin/src/utils/error-deployment-result-to-exception-message.ts +++ b/packages/hardhat-plugin/src/utils/error-deployment-result-to-exception-message.ts @@ -1,9 +1,10 @@ import { DeploymentResultType, ExecutionErrorDeploymentResult, + PreviousRunErrorDeploymentResult, ReconciliationErrorDeploymentResult, ValidationErrorDeploymentResult, -} from "@ignored/ignition-core"; +} from "@nomicfoundation/ignition-core"; import { HardhatPluginError } from "hardhat/plugins"; /** @@ -18,6 +19,7 @@ export function errorDeploymentResultToExceptionMessage( | ValidationErrorDeploymentResult | ReconciliationErrorDeploymentResult | ExecutionErrorDeploymentResult + | PreviousRunErrorDeploymentResult ): string { switch (result.type) { case DeploymentResultType.VALIDATION_ERROR: @@ -26,6 +28,8 @@ export function errorDeploymentResultToExceptionMessage( return _convertReconciliationError(result); case DeploymentResultType.EXECUTION_ERROR: return _convertExecutionError(result); + case DeploymentResultType.PREVIOUS_RUN_ERROR: + return _convertPreviousRunError(result); } } @@ -59,11 +63,13 @@ function _convertExecutionError(result: ExecutionErrorDeploymentResult) { const messageDetails = { timeouts: result.timedOut.length > 0, failures: result.failed.length > 0, + held: result.held.length > 0, }; if (messageDetails.timeouts) { const timeoutList = result.timedOut.map( - ({ futureId, executionId }) => ` * ${futureId}/${executionId}` + ({ futureId, networkInteractionId }) => + ` * ${futureId}/${networkInteractionId}` ); sections.push(`Timed out:\n\n${timeoutList.join("\n")}`); @@ -71,13 +77,21 @@ function _convertExecutionError(result: ExecutionErrorDeploymentResult) { if (messageDetails.failures) { const errorList = result.failed.map( - ({ futureId, executionId, error }) => - ` * ${futureId}/${executionId}: ${error}` + ({ futureId, networkInteractionId, error }) => + ` * ${futureId}/${networkInteractionId}: ${error}` ); sections.push(`Failures:\n\n${errorList.join("\n")}`); } + if (messageDetails.held) { + const reasonList = result.held.map( + ({ futureId, heldId, reason }) => ` * ${futureId}/${heldId}: ${reason}` + ); + + sections.push(`Held:\n\n${reasonList.join("\n")}`); + } + return `The deployment wasn't successful, there were ${_toText( messageDetails )}: @@ -85,23 +99,43 @@ function _convertExecutionError(result: ExecutionErrorDeploymentResult) { ${sections.join("\n\n")}`; } +function _convertPreviousRunError(result: PreviousRunErrorDeploymentResult) { + const errorsList = Object.entries(result.errors).flatMap( + ([futureId, errors]) => errors.map((err) => ` * ${futureId}: ${err}`) + ); + + return `The deployment wasn't run because of the following errors in a previous run: + +${errorsList.join("\n")}`; +} + function _toText({ timeouts, failures, + held, }: { timeouts: boolean; failures: boolean; + held: boolean; }): string { - if (timeouts && failures) { + if (timeouts && failures && held) { + return "timeouts, failures and holds"; + } else if (timeouts && failures) { return "timeouts and failures"; + } else if (failures && held) { + return "failures and holds"; + } else if (timeouts && held) { + return "timeouts and holds"; } else if (timeouts) { return "timeouts"; } else if (failures) { return "failures"; + } else if (held) { + return "holds"; } throw new HardhatPluginError( - "@ignored/hardhat-ignition", + "@nomicfoundation/hardhat-ignition", "Invariant violated: neither timeouts or failures" ); } diff --git a/packages/hardhat-plugin/src/plan/write-plan.ts b/packages/hardhat-plugin/src/visualization/write-visualization.ts similarity index 50% rename from packages/hardhat-plugin/src/plan/write-plan.ts rename to packages/hardhat-plugin/src/visualization/write-visualization.ts index 3896a8f05..183dbc1b1 100644 --- a/packages/hardhat-plugin/src/plan/write-plan.ts +++ b/packages/hardhat-plugin/src/visualization/write-visualization.ts @@ -1,13 +1,13 @@ -import { SerializedStoredDeployment } from "@ignored/ignition-core"; +import { SerializedIgnitionModule } from "@nomicfoundation/ignition-core"; import { ensureDir, pathExists, readFile, writeFile } from "fs-extra"; import path from "path"; -export async function writePlan( - serializedStoredDeployment: SerializedStoredDeployment, +export async function writeVisualization( + visualizationPayload: { module: SerializedIgnitionModule }, { cacheDir }: { cacheDir: string } ) { const templateDir = path.join( - require.resolve("@ignored/ignition-ui/package.json"), + require.resolve("@nomicfoundation/ignition-ui/package.json"), "../dist" ); @@ -18,14 +18,14 @@ export async function writePlan( process.exit(1); } - const planDir = path.join(cacheDir, "plan"); + const visualizationDir = path.join(cacheDir, "visualization"); - await ensureDir(planDir); + await ensureDir(visualizationDir); const indexHtml = await readFile(path.join(templateDir, "index.html")); const updatedHtml = indexHtml .toString() - .replace('{"unloaded":true}', JSON.stringify(serializedStoredDeployment)); + .replace('{"unloaded":true}', JSON.stringify(visualizationPayload)); - await writeFile(path.join(planDir, "index.html"), updatedHtml); + await writeFile(path.join(visualizationDir, "index.html"), updatedHtml); } diff --git a/packages/hardhat-plugin/test/calls.ts b/packages/hardhat-plugin/test/calls.ts index 577be49d1..f12a24e2b 100644 --- a/packages/hardhat-plugin/test/calls.ts +++ b/packages/hardhat-plugin/test/calls.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("calls", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should be able to call contracts", async function () { const moduleDefinition = buildModule("SetAddressModule", (m) => { diff --git a/packages/hardhat-plugin/test/config.ts b/packages/hardhat-plugin/test/config.ts index 36029f1ff..88e42c5b0 100644 --- a/packages/hardhat-plugin/test/config.ts +++ b/packages/hardhat-plugin/test/config.ts @@ -1,6 +1,6 @@ /* eslint-disable import/no-unused-modules */ -import { DeployConfig, buildModule } from "@ignored/ignition-core"; +import { DeployConfig, buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { KeyListOf } from "./type-helper"; diff --git a/packages/hardhat-plugin/test/contracts.ts b/packages/hardhat-plugin/test/contracts.ts index ca4f2f9c0..205b1e319 100644 --- a/packages/hardhat-plugin/test/contracts.ts +++ b/packages/hardhat-plugin/test/contracts.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("contract deploys", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should be able to deploy a contract", async function () { const moduleDefinition = buildModule("FooModule", (m) => { @@ -76,9 +76,7 @@ describe("contract deploys", () => { const artifact = await this.hre.artifacts.readArtifact("Greeter"); const moduleDefinition = buildModule("ArtifactModule", (m) => { - const greeter = m.contractFromArtifact("Greeter", artifact, [ - "Hello World", - ]); + const greeter = m.contract("Greeter", artifact, ["Hello World"]); return { greeter }; }); diff --git a/packages/hardhat-plugin/test/error-handling.ts b/packages/hardhat-plugin/test/error-handling.ts index db23cc3e6..1ef33498b 100644 --- a/packages/hardhat-plugin/test/error-handling.ts +++ b/packages/hardhat-plugin/test/error-handling.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("module error handling", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should error on passing async callback", async function () { assert.throws( diff --git a/packages/hardhat-plugin/test/events.ts b/packages/hardhat-plugin/test/events.ts index b1453ea19..c61ff3ef1 100644 --- a/packages/hardhat-plugin/test/events.ts +++ b/packages/hardhat-plugin/test/events.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("events", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should be able to use the output of a readEvent in a contract at", async function () { const moduleDefinition = buildModule("FooModule", (m) => { @@ -48,7 +48,7 @@ describe("events", () => { "fooAddress" ); - const foo = m.contractAtFromArtifact("Foo", newAddress, artifact); + const foo = m.contractAt("Foo", newAddress, artifact); return { fooFactory, foo }; }); @@ -58,4 +58,49 @@ describe("events", () => { assert.equal(await result.fooFactory.isDeployed(), true); assert.equal(await result.foo.x(), Number(1)); }); + + it("should be able to read an event from a SendDataFuture", async function () { + const moduleDefinition = buildModule("FooModule", (m) => { + const sendEmitter = m.contract("SendDataEmitter"); + + const send = m.send("send_data_event", sendEmitter); + + const output = m.readEventArgument(send, "SendDataEvent", "arg", { + emitter: sendEmitter, + }); + + m.call(sendEmitter, "validateEmitted", [output]); + + return { sendEmitter }; + }); + + const result = await this.deploy(moduleDefinition); + + assert.equal(await result.sendEmitter.wasEmitted(), true); + }); + + it("should be able to use the output of a readEvent with an indexed tuple result", async function () { + const moduleDefinition = buildModule("FooModule", (m) => { + const tupleContract = m.contract("TupleEmitter"); + + const tupleCall = m.call(tupleContract, "emitTuple"); + + const arg1 = m.readEventArgument(tupleCall, "TupleEvent", "arg1", { + id: "arg1", + }); + const arg2 = m.readEventArgument(tupleCall, "TupleEvent", 1, { + id: "arg2", + }); + + m.call(tupleContract, "verifyArg1", [arg1], { id: "call1" }); + m.call(tupleContract, "verifyArg2", [arg2], { id: "call2" }); + + return { tupleContract }; + }); + + const result = await this.deploy(moduleDefinition); + + assert.equal(await result.tupleContract.arg1Captured(), true); + assert.equal(await result.tupleContract.arg2Captured(), true); + }); }); diff --git a/packages/hardhat-plugin/test/execution/deploy-contract-at-from-artifact.ts b/packages/hardhat-plugin/test/execution/deploy-contract-at-from-artifact.ts index 4079b17be..5e81e72ce 100644 --- a/packages/hardhat-plugin/test/execution/deploy-contract-at-from-artifact.ts +++ b/packages/hardhat-plugin/test/execution/deploy-contract-at-from-artifact.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -14,8 +14,7 @@ import { * with a passed in artifact. */ describe.skip("execution - deploy contractAt from artifact", function () { - // TODO: rename back to minimal api once execution switched over - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should deploy a contract that is callable", async function () { // Arrange @@ -39,7 +38,7 @@ describe.skip("execution - deploy contractAt from artifact", function () { const fooArtifact = await this.hre.artifacts.readArtifact("Foo"); const contractAtModuleDefinition = buildModule("FooModule", (m) => { - const atFoo = m.contractAtFromArtifact("AtFoo", fooAddress, fooArtifact); + const atFoo = m.contractAt("AtFoo", fooAddress, fooArtifact); return { atFoo }; }); diff --git a/packages/hardhat-plugin/test/execution/deploy-contract-at.ts b/packages/hardhat-plugin/test/execution/deploy-contract-at.ts index d71a0c4f0..8d8e24872 100644 --- a/packages/hardhat-plugin/test/execution/deploy-contract-at.ts +++ b/packages/hardhat-plugin/test/execution/deploy-contract-at.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -13,8 +13,7 @@ import { * First deploy a working contract, then reuse it from a subsequent module. */ describe("execution - deploy contract at", function () { - // TODO: rename back to minimal api once execution switched over - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it.skip("should deploy a contract that is callable", async function () { const moduleDefinition = buildModule("FooModule", (m) => { diff --git a/packages/hardhat-plugin/test/execution/deploy-contract-from-artifact.ts b/packages/hardhat-plugin/test/execution/deploy-contract-from-artifact.ts index 12cb7daf7..84fd82a59 100644 --- a/packages/hardhat-plugin/test/execution/deploy-contract-from-artifact.ts +++ b/packages/hardhat-plugin/test/execution/deploy-contract-from-artifact.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { waitForPendingTxs } from "../helpers"; @@ -11,14 +11,13 @@ import { mineBlock } from "./helpers"; * Deploy a contract from an artifact. */ describe("execution - deploy contract from artifact", function () { - // TODO: rename back to minimal api once execution switched over - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should deploy a contract that is callable", async function () { const fooArtifact = await this.hre.artifacts.readArtifact("Foo"); const moduleDefinition = buildModule("FooModule", (m) => { - const foo = m.contractFromArtifact("Foo", fooArtifact); + const foo = m.contract("Foo", fooArtifact); return { foo }; }); diff --git a/packages/hardhat-plugin/test/execution/deploy-contract.ts b/packages/hardhat-plugin/test/execution/deploy-contract.ts index a6467571b..a2e69bfe7 100644 --- a/packages/hardhat-plugin/test/execution/deploy-contract.ts +++ b/packages/hardhat-plugin/test/execution/deploy-contract.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { waitForPendingTxs } from "../helpers"; @@ -13,8 +13,7 @@ import { mineBlock } from "./helpers"; * Deploy a single contract with non-problematic network */ describe("execution - deploy contract", function () { - // TODO: rename back to minimal api once execution switched over - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should deploy a contract that is callable", async function () { const moduleDefinition = buildModule("FooModule", (m) => { diff --git a/packages/hardhat-plugin/test/execution/multiple-batch-contract-deploy.ts b/packages/hardhat-plugin/test/execution/multiple-batch-contract-deploy.ts index f4a4c98fa..14ac3a8c5 100644 --- a/packages/hardhat-plugin/test/execution/multiple-batch-contract-deploy.ts +++ b/packages/hardhat-plugin/test/execution/multiple-batch-contract-deploy.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "../use-ignition-project"; @@ -12,8 +12,7 @@ import { sleep } from "./helpers"; * The intent here is to test batching. */ describe("execution - multiple batch contract deploy", function () { - // TODO: rename back to minimal api once execution switched over - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should deploy over multiple batches", async function () { const moduleDefinition = buildModule("FooModule", (m) => { diff --git a/packages/hardhat-plugin/test/execution/nonce-checks/error-on-pending-user-transactions.ts b/packages/hardhat-plugin/test/execution/nonce-checks/error-on-pending-user-transactions.ts index 0c72f426a..1d77b324a 100644 --- a/packages/hardhat-plugin/test/execution/nonce-checks/error-on-pending-user-transactions.ts +++ b/packages/hardhat-plugin/test/execution/nonce-checks/error-on-pending-user-transactions.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { waitForPendingTxs } from "../../helpers"; @@ -16,7 +16,7 @@ import { mineBlock } from "../helpers"; */ describe("execution - error on pending user transactions", () => { useFileIgnitionProject( - "minimal-new-api", + "minimal", "error-on-rerun-with-replaced-pending-user-transaction" ); diff --git a/packages/hardhat-plugin/test/execution/nonce-checks/error-on-rerun-with-replaced-pending-user-transaction.ts b/packages/hardhat-plugin/test/execution/nonce-checks/error-on-rerun-with-replaced-pending-user-transaction.ts index 5fbde58b9..07815222c 100644 --- a/packages/hardhat-plugin/test/execution/nonce-checks/error-on-rerun-with-replaced-pending-user-transaction.ts +++ b/packages/hardhat-plugin/test/execution/nonce-checks/error-on-rerun-with-replaced-pending-user-transaction.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -15,7 +15,7 @@ import { */ describe("execution - error on rerun with replaced pending user transaction", () => { useFileIgnitionProject( - "minimal-new-api", + "minimal", "error-on-rerun-with-replaced-pending-user-transaction" ); diff --git a/packages/hardhat-plugin/test/execution/nonce-checks/error-on-transaction-dropped.ts b/packages/hardhat-plugin/test/execution/nonce-checks/error-on-transaction-dropped.ts index 2430a1c85..8b02d1e4d 100644 --- a/packages/hardhat-plugin/test/execution/nonce-checks/error-on-transaction-dropped.ts +++ b/packages/hardhat-plugin/test/execution/nonce-checks/error-on-transaction-dropped.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -12,7 +12,7 @@ import { * before it is confirmed, then we halt and display an error. */ describe("execution - error on transaction dropped", () => { - useFileIgnitionProject("minimal-new-api", "error-on-transaction-dropped"); + useFileIgnitionProject("minimal", "error-on-transaction-dropped"); it.skip("should error on the drop being detected", async function () { // Setup a module with two contract deploys (foo1 and foo2) over 2 batches diff --git a/packages/hardhat-plugin/test/execution/nonce-checks/error-on-user-transaction-sent.ts b/packages/hardhat-plugin/test/execution/nonce-checks/error-on-user-transaction-sent.ts index d3851599a..47d350193 100644 --- a/packages/hardhat-plugin/test/execution/nonce-checks/error-on-user-transaction-sent.ts +++ b/packages/hardhat-plugin/test/execution/nonce-checks/error-on-user-transaction-sent.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -13,7 +13,7 @@ import { * we should error and halt immediately */ describe("execution - error on user transaction sent", () => { - useFileIgnitionProject("minimal-new-api", "error-on-user-transaction-sent"); + useFileIgnitionProject("minimal", "error-on-user-transaction-sent"); it.skip("should error on the drop being detected", async function () { const moduleDefinition = buildModule("FooModule", (m) => { diff --git a/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-dropped-ignition-transaction.ts b/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-dropped-ignition-transaction.ts index 93fc7a21c..2163ac8c0 100644 --- a/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-dropped-ignition-transaction.ts +++ b/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-dropped-ignition-transaction.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -14,10 +14,7 @@ import { clearPendingTransactionsFromMemoryPool, mineBlock } from "../helpers"; * the transaction should be resubmitted. */ describe("execution - rerun with dropped ignition transactions", () => { - useFileIgnitionProject( - "minimal-new-api", - "rerun-with-dropped-ignition-transactions" - ); + useFileIgnitionProject("minimal", "rerun-with-dropped-ignition-transactions"); it.skip("should deploy successfully on second run", async function () { const moduleDefinition = buildModule("FooModule", (m) => { diff --git a/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-now-complete-ignition-transactions.ts b/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-now-complete-ignition-transactions.ts index 2153ff2be..c3000d7a2 100644 --- a/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-now-complete-ignition-transactions.ts +++ b/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-now-complete-ignition-transactions.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -15,7 +15,7 @@ import { mineBlock } from "../helpers"; */ describe("execution - rerun with now complete ignition transactions", () => { useFileIgnitionProject( - "minimal-new-api", + "minimal", "rerun-with-now-complete-ignition-transactions" ); diff --git a/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-pending-ignition-transactions.ts b/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-pending-ignition-transactions.ts index 55a7f154e..5b633cb79 100644 --- a/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-pending-ignition-transactions.ts +++ b/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-pending-ignition-transactions.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -13,10 +13,7 @@ import { * up where the first run left off and without any other user transactions. */ describe("execution - rerun with pending ignition transactions", () => { - useFileIgnitionProject( - "minimal-new-api", - "rerun-with-pending-ignition-transactions" - ); + useFileIgnitionProject("minimal", "rerun-with-pending-ignition-transactions"); it.skip("should complete the run on the second attempt", async function () { const moduleDefinition = buildModule("FooModule", (m) => { diff --git a/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-replaced-confirmed-user-transaction.ts b/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-replaced-confirmed-user-transaction.ts index 79644a2b2..3a49397d5 100644 --- a/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-replaced-confirmed-user-transaction.ts +++ b/packages/hardhat-plugin/test/execution/nonce-checks/rerun-with-replaced-confirmed-user-transaction.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -17,7 +17,7 @@ import { mineBlock, sleep } from "../helpers"; */ describe("execution - rerun with replaced confirmed user transaction", () => { useFileIgnitionProject( - "minimal-new-api", + "minimal", "rerun-with-replaced-confirmed-user-transaction" ); diff --git a/packages/hardhat-plugin/test/execution/timeouts/deploy-run-times-out.ts b/packages/hardhat-plugin/test/execution/timeouts/deploy-run-times-out.ts index 121fb91a0..51c26d7bc 100644 --- a/packages/hardhat-plugin/test/execution/timeouts/deploy-run-times-out.ts +++ b/packages/hardhat-plugin/test/execution/timeouts/deploy-run-times-out.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -13,7 +13,7 @@ import { * TODO: Needs to be updated to deal with fee bumps */ describe.skip("execution - deploy run times out", () => { - useFileIgnitionProject("minimal-new-api", "deploy-run-times-out", {}); + useFileIgnitionProject("minimal", "deploy-run-times-out", {}); it("should error naming timed out transactions", async function () { // Setup a module with a contract deploy on accounts[2] diff --git a/packages/hardhat-plugin/test/execution/timeouts/rerun-a-deploy-that-timed-out.ts b/packages/hardhat-plugin/test/execution/timeouts/rerun-a-deploy-that-timed-out.ts index a74b57e53..10d055234 100644 --- a/packages/hardhat-plugin/test/execution/timeouts/rerun-a-deploy-that-timed-out.ts +++ b/packages/hardhat-plugin/test/execution/timeouts/rerun-a-deploy-that-timed-out.ts @@ -1,5 +1,5 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { @@ -13,7 +13,7 @@ import { * TODO: Needs to be updated to deal with fee bumps */ describe.skip("execution - rerun a deploy that timed out", () => { - useFileIgnitionProject("minimal-new-api", "rerun-a-deploy-that-timed-out"); + useFileIgnitionProject("minimal", "rerun-a-deploy-that-timed-out"); it("should error naming timed out transactions", async function () { // Setup a module with a contract deploy on accounts[2] diff --git a/packages/hardhat-plugin/test/existing-contract.ts b/packages/hardhat-plugin/test/existing-contract.ts index 1041c43f8..890762fee 100644 --- a/packages/hardhat-plugin/test/existing-contract.ts +++ b/packages/hardhat-plugin/test/existing-contract.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("existing contract", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should be able to use an existing contract", async function () { await this.hre.run("compile", { quiet: true }); @@ -31,8 +31,8 @@ describe("existing contract", () => { await firstResult.usesContract.getAddress(); const secondModuleDefinition = buildModule("SecondModule", (m) => { - const bar = m.contractAtFromArtifact("Bar", barAddress, barArtifact); - const usesContract = m.contractAtFromArtifact( + const bar = m.contractAt("Bar", barAddress, barArtifact); + const usesContract = m.contractAt( "UsesContract", usesContractAddress, usesContractArtifact diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/Contracts.sol b/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/Contracts.sol deleted file mode 100644 index 03e094119..000000000 --- a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/Contracts.sol +++ /dev/null @@ -1,140 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; -pragma experimental ABIEncoderV2; - -contract Foo { - bool public isFoo = true; - uint256 public x = 1; - - function inc() public { - x++; - } - - function incByPositiveNumber(uint256 n) public { - require(n > 0, "n must be positive"); - x += n; - } - - function incTwoNumbers(uint256 first, uint256 second) public { - x += first; - x += second; - } -} - -contract Bar { - bool public isBar = true; -} - -contract UsesContract { - address public contractAddress; - - constructor(address _contract) { - contractAddress = _contract; - } - - function setAddress(address _contract) public { - contractAddress = _contract; - } -} - -contract Greeter { - string private _greeting; - - constructor(string memory greeting) { - _greeting = greeting; - } - - function getGreeting() public view returns (string memory) { - return _greeting; - } -} - -contract PassingValue { - constructor() payable {} - - function deposit() public payable {} -} - -contract CaptureArraysContract { - bool public arraysCaptured; - - constructor() { - arraysCaptured = false; - } - - function recordArrays( - uint256[] memory first, - string[] memory second, - bool[] memory third - ) public returns (uint256 output) { - arraysCaptured = true; - - require(first.length == 3, "Wrong number of args on first arg"); - require(first[0] == 1, "First value is wrong"); - require(first[1] == 2, "Second value is wrong"); - require(first[2] == 3, "Third value is wrong"); - - require(second.length == 3, "Wrong number of args on second arg"); - require( - keccak256(abi.encodePacked(second[0])) == - keccak256(abi.encodePacked("a")), - "First value is wrong" - ); - require( - keccak256(abi.encodePacked(second[1])) == - keccak256(abi.encodePacked("b")), - "Second value is wrong" - ); - require( - keccak256(abi.encodePacked(second[2])) == - keccak256(abi.encodePacked("c")), - "Third value is wrong" - ); - - require(third.length == 3, "Wrong number of args on third arg"); - require(third[0] == true, "First value is wrong"); - require(third[1] == false, "Second value is wrong"); - require(third[2] == true, "Third value is wrong"); - - return 1; - } -} - -contract CaptureComplexObjectContract { - bool public complexArgCaptured; - - constructor() { - complexArgCaptured = false; - } - - struct SubComplex { - string sub; - } - - struct Complex { - bool firstBool; - uint256[] secondArray; - SubComplex thirdSubcomplex; - } - - function testComplexObject( - Complex memory complexArg - ) public returns (uint256 output) { - complexArgCaptured = true; - - require(complexArg.firstBool, "bad first bool"); - - require(complexArg.secondArray.length == 3, "bad second array"); - require(complexArg.secondArray[0] == 1, "First value is wrong"); - require(complexArg.secondArray[1] == 2, "Second value is wrong"); - require(complexArg.secondArray[2] == 3, "Third value is wrong"); - - require( - keccak256(abi.encodePacked(complexArg.thirdSubcomplex.sub)) == - keccak256(abi.encodePacked("sub")), - "The complex sub object property is wrong" - ); - - return 1; - } -} diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/Trace.sol b/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/Trace.sol deleted file mode 100644 index 1687a1d48..000000000 --- a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/Trace.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; - -contract Trace { - string[] public entries; - - constructor(string memory firstEntry) { - entries = [firstEntry]; - } - - function addEntry(string memory entry) public { - entries.push(entry); - } -} diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/WithLibrary.sol b/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/WithLibrary.sol deleted file mode 100644 index 3a1f0acd2..000000000 --- a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/WithLibrary.sol +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0 -pragma solidity >=0.7.0 <0.9.0; - -library RubbishMath { - function add(uint16 left, uint16 right) public pure returns (uint16) { - return left + right; - } -} - -contract DependsOnLib { - function addThreeNumbers( - uint16 first, - uint16 second, - uint16 third - ) public pure returns (uint16) { - return RubbishMath.add(first, RubbishMath.add(second, third)); - } -} - -library LibDependsOnLib { - function add(uint16 left, uint16 right) public pure returns (uint16) { - return RubbishMath.add(left, right); - } -} - -contract DependsOnLibThatDependsOnLib { - function addThreeNumbers( - uint16 first, - uint16 second, - uint16 third - ) public pure returns (uint16) { - return LibDependsOnLib.add(first, LibDependsOnLib.add(second, third)); - } -} diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/hardhat.config.js b/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/hardhat.config.js deleted file mode 100644 index 791b28f33..000000000 --- a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/hardhat.config.js +++ /dev/null @@ -1,12 +0,0 @@ -require("../../../src/index"); - -module.exports = { - solidity: "0.8.19", - networks: { - hardhat: { - mining: { - auto: false, - }, - }, - }, -}; diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/ignition/MyModule.js b/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/ignition/MyModule.js deleted file mode 100644 index cb7a2935d..000000000 --- a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/ignition/MyModule.js +++ /dev/null @@ -1,13 +0,0 @@ -// eslint-disable-next-line import/no-unused-modules -const { buildModule } = require("@ignored/ignition-core"); - -module.exports = buildModule("MyModule", (m) => { - const bar = m.contract("Bar"); - const usesContract = m.contract("UsesContract", [ - "0x0000000000000000000000000000000000000000", - ]); - - m.call(usesContract, "setAddress", [bar]); - - return { bar, usesContract }; -}); diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/Contracts.sol b/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/Contracts.sol index 03e094119..d4559d1af 100644 --- a/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/Contracts.sol +++ b/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/Contracts.sol @@ -3,138 +3,206 @@ pragma solidity >=0.7.0 <0.9.0; pragma experimental ABIEncoderV2; contract Foo { - bool public isFoo = true; - uint256 public x = 1; - - function inc() public { - x++; - } - - function incByPositiveNumber(uint256 n) public { - require(n > 0, "n must be positive"); - x += n; - } - - function incTwoNumbers(uint256 first, uint256 second) public { - x += first; - x += second; - } + bool public isFoo = true; + uint256 public x = 1; + + function inc() public { + x++; + } + + function incByPositiveNumber(uint256 n) public { + require(n > 0, "n must be positive"); + x += n; + } + + function incTwoNumbers(uint256 first, uint256 second) public { + x += first; + x += second; + } } contract Bar { - bool public isBar = true; + bool public isBar = true; } contract UsesContract { - address public contractAddress; + address public contractAddress; - constructor(address _contract) { - contractAddress = _contract; - } + constructor(address _contract) { + contractAddress = _contract; + } - function setAddress(address _contract) public { - contractAddress = _contract; - } + function setAddress(address _contract) public { + contractAddress = _contract; + } } contract Greeter { - string private _greeting; + string private _greeting; - constructor(string memory greeting) { - _greeting = greeting; - } + constructor(string memory greeting) { + _greeting = greeting; + } - function getGreeting() public view returns (string memory) { - return _greeting; - } + function getGreeting() public view returns (string memory) { + return _greeting; + } } contract PassingValue { - constructor() payable {} + constructor() payable {} - function deposit() public payable {} + function deposit() public payable {} +} + +contract TupleReturn { + bool public arg1Captured; + bool public arg2Captured; + + function getTuple() public pure returns (bool arg1, uint256 arg2) { + return (true, 1234); + } + + function verifyArg1(bool arg) public returns (uint256 output) { + arg1Captured = true; + + require(arg == true, "arg1 is wrong"); + + return 1; + } + + function verifyArg2(uint256 arg) public returns (uint256 output) { + arg2Captured = true; + + require(arg == 1234, "arg2 is wrong"); + + return 1; + } +} + +contract TupleEmitter { + bool public arg1Captured; + bool public arg2Captured; + + event TupleEvent(bool arg1, uint256 arg2); + + function emitTuple() public { + emit TupleEvent(true, 1234); + } + + function verifyArg1(bool arg) public returns (uint256 output) { + arg1Captured = true; + + require(arg == true, "arg1 is wrong"); + + return 1; + } + + function verifyArg2(uint256 arg) public returns (uint256 output) { + arg2Captured = true; + + require(arg == 1234, "arg2 is wrong"); + + return 1; + } } contract CaptureArraysContract { - bool public arraysCaptured; - - constructor() { - arraysCaptured = false; - } - - function recordArrays( - uint256[] memory first, - string[] memory second, - bool[] memory third - ) public returns (uint256 output) { - arraysCaptured = true; - - require(first.length == 3, "Wrong number of args on first arg"); - require(first[0] == 1, "First value is wrong"); - require(first[1] == 2, "Second value is wrong"); - require(first[2] == 3, "Third value is wrong"); - - require(second.length == 3, "Wrong number of args on second arg"); - require( - keccak256(abi.encodePacked(second[0])) == - keccak256(abi.encodePacked("a")), - "First value is wrong" - ); - require( - keccak256(abi.encodePacked(second[1])) == - keccak256(abi.encodePacked("b")), - "Second value is wrong" - ); - require( - keccak256(abi.encodePacked(second[2])) == - keccak256(abi.encodePacked("c")), - "Third value is wrong" - ); - - require(third.length == 3, "Wrong number of args on third arg"); - require(third[0] == true, "First value is wrong"); - require(third[1] == false, "Second value is wrong"); - require(third[2] == true, "Third value is wrong"); - - return 1; - } + bool public arraysCaptured; + + constructor() { + arraysCaptured = false; + } + + function recordArrays( + uint256[] memory first, + string[] memory second, + bool[] memory third + ) public returns (uint256 output) { + arraysCaptured = true; + + require(first.length == 3, "Wrong number of args on first arg"); + require(first[0] == 1, "First value is wrong"); + require(first[1] == 2, "Second value is wrong"); + require(first[2] == 3, "Third value is wrong"); + + require(second.length == 3, "Wrong number of args on second arg"); + require( + keccak256(abi.encodePacked(second[0])) == + keccak256(abi.encodePacked("a")), + "First value is wrong" + ); + require( + keccak256(abi.encodePacked(second[1])) == + keccak256(abi.encodePacked("b")), + "Second value is wrong" + ); + require( + keccak256(abi.encodePacked(second[2])) == + keccak256(abi.encodePacked("c")), + "Third value is wrong" + ); + + require(third.length == 3, "Wrong number of args on third arg"); + require(third[0] == true, "First value is wrong"); + require(third[1] == false, "Second value is wrong"); + require(third[2] == true, "Third value is wrong"); + + return 1; + } } contract CaptureComplexObjectContract { - bool public complexArgCaptured; - - constructor() { - complexArgCaptured = false; - } - - struct SubComplex { - string sub; - } - - struct Complex { - bool firstBool; - uint256[] secondArray; - SubComplex thirdSubcomplex; - } - - function testComplexObject( - Complex memory complexArg - ) public returns (uint256 output) { - complexArgCaptured = true; - - require(complexArg.firstBool, "bad first bool"); - - require(complexArg.secondArray.length == 3, "bad second array"); - require(complexArg.secondArray[0] == 1, "First value is wrong"); - require(complexArg.secondArray[1] == 2, "Second value is wrong"); - require(complexArg.secondArray[2] == 3, "Third value is wrong"); - - require( - keccak256(abi.encodePacked(complexArg.thirdSubcomplex.sub)) == - keccak256(abi.encodePacked("sub")), - "The complex sub object property is wrong" - ); - - return 1; - } + bool public complexArgCaptured; + + constructor() { + complexArgCaptured = false; + } + + struct SubComplex { + string sub; + } + + struct Complex { + bool firstBool; + uint256[] secondArray; + SubComplex thirdSubcomplex; + } + + function testComplexObject( + Complex memory complexArg + ) public returns (uint256 output) { + complexArgCaptured = true; + + require(complexArg.firstBool, "bad first bool"); + + require(complexArg.secondArray.length == 3, "bad second array"); + require(complexArg.secondArray[0] == 1, "First value is wrong"); + require(complexArg.secondArray[1] == 2, "Second value is wrong"); + require(complexArg.secondArray[2] == 3, "Third value is wrong"); + + require( + keccak256(abi.encodePacked(complexArg.thirdSubcomplex.sub)) == + keccak256(abi.encodePacked("sub")), + "The complex sub object property is wrong" + ); + + return 1; + } +} + +contract SendDataEmitter { + event SendDataEvent(bool arg); + + bool public wasEmitted; + + receive() external payable { + emit SendDataEvent(true); + } + + function validateEmitted(bool arg) public { + wasEmitted = true; + + require(arg == true, "arg is wrong"); + } } diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/Factory.sol b/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/Factory.sol similarity index 100% rename from packages/hardhat-plugin/test/fixture-projects/minimal-new-api/contracts/Factory.sol rename to packages/hardhat-plugin/test/fixture-projects/minimal/contracts/Factory.sol diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/WithLibrary.sol b/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/WithLibrary.sol index 903f589c6..3a1f0acd2 100644 --- a/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/WithLibrary.sol +++ b/packages/hardhat-plugin/test/fixture-projects/minimal/contracts/WithLibrary.sol @@ -2,17 +2,33 @@ pragma solidity >=0.7.0 <0.9.0; library RubbishMath { - function add(uint16 left, uint16 right) public pure returns (uint16) { - return left + right; - } + function add(uint16 left, uint16 right) public pure returns (uint16) { + return left + right; + } } contract DependsOnLib { - function addThreeNumbers( - uint16 first, - uint16 second, - uint16 third - ) public pure returns (uint16) { - return RubbishMath.add(first, RubbishMath.add(second, third)); - } + function addThreeNumbers( + uint16 first, + uint16 second, + uint16 third + ) public pure returns (uint16) { + return RubbishMath.add(first, RubbishMath.add(second, third)); + } +} + +library LibDependsOnLib { + function add(uint16 left, uint16 right) public pure returns (uint16) { + return RubbishMath.add(left, right); + } +} + +contract DependsOnLibThatDependsOnLib { + function addThreeNumbers( + uint16 first, + uint16 second, + uint16 third + ) public pure returns (uint16) { + return LibDependsOnLib.add(first, LibDependsOnLib.add(second, third)); + } } diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal/hardhat.config.js b/packages/hardhat-plugin/test/fixture-projects/minimal/hardhat.config.js index 39a079dae..791b28f33 100644 --- a/packages/hardhat-plugin/test/fixture-projects/minimal/hardhat.config.js +++ b/packages/hardhat-plugin/test/fixture-projects/minimal/hardhat.config.js @@ -1,6 +1,7 @@ require("../../../src/index"); module.exports = { + solidity: "0.8.19", networks: { hardhat: { mining: { diff --git a/packages/hardhat-plugin/test/fixture-projects/minimal/ignition/MyModule.js b/packages/hardhat-plugin/test/fixture-projects/minimal/ignition/MyModule.js index 3a4fc78c5..f00a750bd 100644 --- a/packages/hardhat-plugin/test/fixture-projects/minimal/ignition/MyModule.js +++ b/packages/hardhat-plugin/test/fixture-projects/minimal/ignition/MyModule.js @@ -1,15 +1,13 @@ // eslint-disable-next-line import/no-unused-modules -const { buildModule } = require("@ignored/ignition-core"); +const { buildModule } = require("@nomicfoundation/ignition-core"); module.exports = buildModule("MyModule", (m) => { const bar = m.contract("Bar"); - const usesContract = m.contract("UsesContract", { - args: ["0x0000000000000000000000000000000000000000"], - }); + const usesContract = m.contract("UsesContract", [ + "0x0000000000000000000000000000000000000000", + ]); - m.call(usesContract, "setAddress", { - args: [bar], - }); + m.call(usesContract, "setAddress", [bar]); return { bar, usesContract }; }); diff --git a/packages/hardhat-plugin/test/fixture-projects/with-config/ignition/MyModule.js b/packages/hardhat-plugin/test/fixture-projects/with-config/ignition/MyModule.js index 3a4fc78c5..9f13f90ac 100644 --- a/packages/hardhat-plugin/test/fixture-projects/with-config/ignition/MyModule.js +++ b/packages/hardhat-plugin/test/fixture-projects/with-config/ignition/MyModule.js @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-unused-modules -const { buildModule } = require("@ignored/ignition-core"); +const { buildModule } = require("@nomicfoundation/ignition-core"); module.exports = buildModule("MyModule", (m) => { const bar = m.contract("Bar"); diff --git a/packages/hardhat-plugin/test/fixture-projects/with-invalid-config/ignition/MyModule.js b/packages/hardhat-plugin/test/fixture-projects/with-invalid-config/ignition/MyModule.js index 3a4fc78c5..9f13f90ac 100644 --- a/packages/hardhat-plugin/test/fixture-projects/with-invalid-config/ignition/MyModule.js +++ b/packages/hardhat-plugin/test/fixture-projects/with-invalid-config/ignition/MyModule.js @@ -1,5 +1,5 @@ // eslint-disable-next-line import/no-unused-modules -const { buildModule } = require("@ignored/ignition-core"); +const { buildModule } = require("@nomicfoundation/ignition-core"); module.exports = buildModule("MyModule", (m) => { const bar = m.contract("Bar"); diff --git a/packages/hardhat-plugin/test/libraries.ts b/packages/hardhat-plugin/test/libraries.ts index b667d9c40..146036bda 100644 --- a/packages/hardhat-plugin/test/libraries.ts +++ b/packages/hardhat-plugin/test/libraries.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("libraries", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should be able to deploy a contract that depends on a hardhat library", async function () { const moduleDefinition = buildModule("WithLibModule", (m) => { @@ -41,7 +41,7 @@ describe("libraries", () => { ); const moduleDefinition = buildModule("ArtifactLibraryModule", (m) => { - const rubbishMath = m.libraryFromArtifact("RubbishMath", libraryArtifact); + const rubbishMath = m.library("RubbishMath", libraryArtifact); const dependsOnLib = m.contract("DependsOnLib", [], { libraries: { RubbishMath: rubbishMath, diff --git a/packages/hardhat-plugin/test/params.ts b/packages/hardhat-plugin/test/params.ts index d4641a5bd..6c3325406 100644 --- a/packages/hardhat-plugin/test/params.ts +++ b/packages/hardhat-plugin/test/params.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("module parameters", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should be able to retrieve a default number", async function () { const moduleDefinition = buildModule("WithDefaultModule", (m) => { @@ -85,7 +85,7 @@ describe("module parameters", () => { }); describe("params validation", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should throw if no parameters object provided", async function () { await this.hre.run("compile", { quiet: true }); diff --git a/packages/hardhat-plugin/test/plan/index.ts b/packages/hardhat-plugin/test/plan/index.ts index a940464e0..4ee8812cb 100644 --- a/packages/hardhat-plugin/test/plan/index.ts +++ b/packages/hardhat-plugin/test/plan/index.ts @@ -5,21 +5,20 @@ import path from "path"; import { useEphemeralIgnitionProject } from "../use-ignition-project"; -describe("plan", () => { - // TODO: rename back to minimal api once execution switched over - useEphemeralIgnitionProject("minimal-new-api"); +describe("visualize", () => { + useEphemeralIgnitionProject("minimal"); - it("should create a plan", async function () { - const planPath = path.resolve("../minimal-new-api/cache/plan"); - emptyDirSync(planPath); + it("should create a visualization", async function () { + const visualizationPath = path.resolve("../minimal/cache/visualization"); + emptyDirSync(visualizationPath); await this.hre.run("compile", { quiet: true }); - await this.hre.run("plan", { + await this.hre.run("visualize", { quiet: true, moduleNameOrPath: "MyModule.js", }); - const files = await readdir(planPath); + const files = await readdir(visualizationPath); assert(files.includes("index.html")); }); diff --git a/packages/hardhat-plugin/test/static-calls.ts b/packages/hardhat-plugin/test/static-calls.ts index 0b0dc3e0f..8c34694a6 100644 --- a/packages/hardhat-plugin/test/static-calls.ts +++ b/packages/hardhat-plugin/test/static-calls.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("static calls", () => { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); it("should be able to use the output of a static call in a contract at", async function () { const moduleDefinition = buildModule("FooModule", (m) => { @@ -15,7 +15,7 @@ describe("static calls", () => { const createCall = m.call(fooFactory, "create", []); - const newAddress = m.staticCall(fooFactory, "deployed", [], { + const newAddress = m.staticCall(fooFactory, "deployed", [], 0, { after: [createCall], }); @@ -40,11 +40,11 @@ describe("static calls", () => { const createCall = m.call(fooFactory, "create", []); - const newAddress = m.staticCall(fooFactory, "deployed", [], { + const newAddress = m.staticCall(fooFactory, "deployed", [], 0, { after: [createCall], }); - const foo = m.contractAtFromArtifact("Foo", newAddress, artifact); + const foo = m.contractAt("Foo", newAddress, artifact); return { fooFactory, foo }; }); @@ -63,7 +63,7 @@ describe("static calls", () => { const createCall = m.call(fooFactory, "create", []); - const newAddress = m.staticCall(fooFactory, "allDeployed", [0], { + const newAddress = m.staticCall(fooFactory, "allDeployed", [0], 0, { after: [createCall], }); @@ -86,9 +86,15 @@ describe("static calls", () => { const createCall = m.call(fooFactory, "create", []); - const newAddress = m.staticCall(fooFactory, "getDeployed(uint256)", [0], { - after: [createCall], - }); + const newAddress = m.staticCall( + fooFactory, + "getDeployed(uint256)", + [0], + 0, + { + after: [createCall], + } + ); const foo = m.contractAt("Foo", newAddress); @@ -101,6 +107,29 @@ describe("static calls", () => { assert.equal(await result.foo.x(), Number(1)); }); + it("should be able to use the output of a static call with an indexed tuple result", async function () { + const moduleDefinition = buildModule("FooModule", (m) => { + const tupleContract = m.contract("TupleReturn"); + + const arg1 = m.staticCall(tupleContract, "getTuple", [], "arg1", { + id: "arg1", + }); + const arg2 = m.staticCall(tupleContract, "getTuple", [], "arg2", { + id: "arg2", + }); + + m.call(tupleContract, "verifyArg1", [arg1], { id: "call1" }); + m.call(tupleContract, "verifyArg2", [arg2], { id: "call2" }); + + return { tupleContract }; + }); + + const result = await this.deploy(moduleDefinition); + + assert.equal(await result.tupleContract.arg1Captured(), true); + assert.equal(await result.tupleContract.arg2Captured(), true); + }); + it("should not be able to use the output of a non-address static call in a contract at", async function () { const moduleDefinition = buildModule("FooModule", (m) => { const account1 = m.getAccount(1); @@ -109,7 +138,7 @@ describe("static calls", () => { const createCall = m.call(fooFactory, "create", []); - const nonAddress = m.staticCall(fooFactory, "nonAddressResult", [], { + const nonAddress = m.staticCall(fooFactory, "nonAddressResult", [], 0, { after: [createCall], }); @@ -120,7 +149,7 @@ describe("static calls", () => { await assert.isRejected( this.deploy(moduleDefinition), - /Future 'FooModule:FooFactory#nonAddressResult' must be a valid address/ + /Future 'FooModule#FooFactory.nonAddressResult' must be a valid address/ ); }); @@ -134,18 +163,18 @@ describe("static calls", () => { const createCall = m.call(fooFactory, "create", []); - const nonAddress = m.staticCall(fooFactory, "nonAddressResult", [], { + const nonAddress = m.staticCall(fooFactory, "nonAddressResult", [], 0, { after: [createCall], }); - const foo = m.contractAtFromArtifact("Foo", nonAddress, artifact); + const foo = m.contractAt("Foo", nonAddress, artifact); return { fooFactory, foo }; }); await assert.isRejected( this.deploy(moduleDefinition), - /Future 'FooModule:FooFactory#nonAddressResult' must be a valid address/ + /Future 'FooModule#FooFactory.nonAddressResult' must be a valid address/ ); }); }); diff --git a/packages/hardhat-plugin/test/use-ignition-project.ts b/packages/hardhat-plugin/test/use-ignition-project.ts index c01222061..5dafa5564 100644 --- a/packages/hardhat-plugin/test/use-ignition-project.ts +++ b/packages/hardhat-plugin/test/use-ignition-project.ts @@ -1,4 +1,4 @@ -import { DeployConfig, IgnitionModule } from "@ignored/ignition-core"; +import { DeployConfig, IgnitionModule } from "@nomicfoundation/ignition-core"; import { Contract } from "ethers"; import { ensureDirSync, removeSync } from "fs-extra"; import { resetHardhatContext } from "hardhat/plugins-testing"; @@ -67,7 +67,7 @@ export function useFileIgnitionProject( const hre = require("hardhat"); const deploymentDir = path.join( - path.resolve(__dirname, "./fixture-projects/minimal-new-api/"), + path.resolve(__dirname, "./fixture-projects/minimal/"), "deployments", deploymentId ); diff --git a/packages/hardhat-plugin/test/use-module.ts b/packages/hardhat-plugin/test/use-module.ts index acceed119..586047e6f 100644 --- a/packages/hardhat-plugin/test/use-module.ts +++ b/packages/hardhat-plugin/test/use-module.ts @@ -1,11 +1,11 @@ /* eslint-disable import/no-unused-modules */ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { useEphemeralIgnitionProject } from "./use-ignition-project"; describe("useModule", function () { - useEphemeralIgnitionProject("minimal-new-api"); + useEphemeralIgnitionProject("minimal"); describe("returning futures from module usage", () => { it("using useModule", async function () { @@ -43,7 +43,7 @@ describe("useModule", function () { const secondCall = m.call(trace, "addEntry", ["second"]); m.call(trace, "addEntry", ["third"], { - id: "third-add-entry", + id: "third_add_entry", after: [secondCall], }); diff --git a/packages/hardhat-plugin/test/utils/error-deployment-result-to-exception-message.ts b/packages/hardhat-plugin/test/utils/error-deployment-result-to-exception-message.ts index 0770d26bd..5af59e692 100644 --- a/packages/hardhat-plugin/test/utils/error-deployment-result-to-exception-message.ts +++ b/packages/hardhat-plugin/test/utils/error-deployment-result-to-exception-message.ts @@ -3,7 +3,7 @@ import { ExecutionErrorDeploymentResult, ReconciliationErrorDeploymentResult, ValidationErrorDeploymentResult, -} from "@ignored/ignition-core"; +} from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { errorDeploymentResultToExceptionMessage } from "../../src/utils/error-deployment-result-to-exception-message"; @@ -63,9 +63,10 @@ describe("display error deployment result", () => { type: DeploymentResultType.EXECUTION_ERROR, started: [], timedOut: [ - { futureId: "MyModule:MyContract", executionId: 1 }, - { futureId: "MyModule:AnotherContract", executionId: 3 }, + { futureId: "MyModule:MyContract", networkInteractionId: 1 }, + { futureId: "MyModule:AnotherContract", networkInteractionId: 3 }, ], + held: [], failed: [], successful: [], }; @@ -81,20 +82,53 @@ Timed out: ); }); + it("should display an execution error with holds", () => { + const result: ExecutionErrorDeploymentResult = { + type: DeploymentResultType.EXECUTION_ERROR, + started: [], + timedOut: [], + held: [ + { + futureId: "MyModule:MyContract", + heldId: 1, + reason: "Vote is not complete", + }, + { + futureId: "MyModule:AnotherContract", + heldId: 3, + reason: "Server timed out", + }, + ], + failed: [], + successful: [], + }; + + assert.equal( + errorDeploymentResultToExceptionMessage(result), + `The deployment wasn't successful, there were holds: + +Held: + + * MyModule:MyContract/1: Vote is not complete + * MyModule:AnotherContract/3: Server timed out` + ); + }); + it("should display an execution error with execution failures", () => { const result: ExecutionErrorDeploymentResult = { type: DeploymentResultType.EXECUTION_ERROR, started: [], timedOut: [], + held: [], failed: [ { futureId: "MyModule:MyContract", - executionId: 1, + networkInteractionId: 1, error: "Reverted with reason x", }, { futureId: "MyModule:AnotherContract", - executionId: 3, + networkInteractionId: 3, error: "Reverted with reason y", }, ], @@ -117,18 +151,19 @@ Failures: type: DeploymentResultType.EXECUTION_ERROR, started: [], timedOut: [ - { futureId: "MyModule:FirstContract", executionId: 1 }, - { futureId: "MyModule:SecondContract", executionId: 3 }, + { futureId: "MyModule:FirstContract", networkInteractionId: 1 }, + { futureId: "MyModule:SecondContract", networkInteractionId: 3 }, ], + held: [], failed: [ { futureId: "MyModule:ThirdContract", - executionId: 1, + networkInteractionId: 1, error: "Reverted with reason x", }, { futureId: "MyModule:FourthContract", - executionId: 3, + networkInteractionId: 3, error: "Reverted with reason y", }, ], diff --git a/packages/ui/CHANGELOG.md b/packages/ui/CHANGELOG.md index 83385f50e..015829aa3 100644 --- a/packages/ui/CHANGELOG.md +++ b/packages/ui/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## 0.4.0 - 2023-09-15 + +### Changed + +- Now published on the `@nomicfoundation` namespace + ## 0.1.0 - 2023-07-27 ### Added diff --git a/packages/ui/README.md b/packages/ui/README.md index 109f5a7c2..d8fe4f7b8 100644 --- a/packages/ui/README.md +++ b/packages/ui/README.md @@ -1,6 +1,6 @@ -# Ignition Plan UI +# Ignition Visualize UI -The website used in Ignitions plan task for visualising a deployment. +The website used in Ignitions `visualize` task for visualising a deployment. ## Development diff --git a/packages/ui/examples/ComplexModule.js b/packages/ui/examples/ComplexModule.js index 3b3d2bc73..4a972e1b6 100644 --- a/packages/ui/examples/ComplexModule.js +++ b/packages/ui/examples/ComplexModule.js @@ -1,4 +1,4 @@ -import { buildModule } from "@ignored/ignition-core"; +import { buildModule } from "@nomicfoundation/ignition-core"; const fakeArtifact = ["fake artifact"]; diff --git a/packages/ui/package.json b/packages/ui/package.json index c91d48211..309d45732 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { - "name": "@ignored/ignition-ui", - "version": "0.3.0", + "name": "@nomicfoundation/ignition-ui", + "version": "0.4.0", "type": "module", "scripts": { "predev": "npm run regenerate-deployment-example", @@ -14,7 +14,7 @@ "prepack": "npm run build" }, "dependencies": { - "@ignored/ignition-core": "^0.3.0", + "@nomicfoundation/ignition-core": "^0.4.0", "mermaid": "10.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", diff --git a/packages/ui/scripts/generate-example-deployment-json.js b/packages/ui/scripts/generate-example-deployment-json.js index 22964c8eb..b619aa148 100644 --- a/packages/ui/scripts/generate-example-deployment-json.js +++ b/packages/ui/scripts/generate-example-deployment-json.js @@ -1,42 +1,22 @@ -import { - ModuleConstructor, - StoredDeploymentSerializer, -} from "@ignored/ignition-core"; +import { IgnitionModuleSerializer } from "@nomicfoundation/ignition-core"; import { writeFile } from "node:fs/promises"; -import moduleDefinition from "../examples/ComplexModule.js"; +import complexModule from "../examples/ComplexModule.js"; const main = async () => { - await writeDeploymentJsonFor({ - details: { - chainId: 999, - networkName: "Hardhat", - }, - moduleDefinition: moduleDefinition, - }); + await writeDeploymentJsonFor(complexModule); }; -async function writeDeploymentJsonFor(deployment) { - const serializedDeployment = serializeDeployment(deployment); +async function writeDeploymentJsonFor(ignitionModule) { + const serializedIgnitionModule = + IgnitionModuleSerializer.serialize(ignitionModule); console.log("Deployment written to ./public/deployment.json"); await writeFile( "./public/deployment.json", - JSON.stringify(serializedDeployment, undefined, 2) + JSON.stringify({ module: serializedIgnitionModule }, undefined, 2) ); } -function serializeDeployment(deployment) { - const constructor = new ModuleConstructor(deployment.details.chainId, []); - const module = constructor.construct(deployment.moduleDefinition); - - const serializedModule = StoredDeploymentSerializer.serialize({ - details: deployment.details, - module, - }); - - return serializedModule; -} - main(); diff --git a/packages/ui/src/components/mermaid.tsx b/packages/ui/src/components/mermaid.tsx index cf9c8431e..ea5aa75d5 100644 --- a/packages/ui/src/components/mermaid.tsx +++ b/packages/ui/src/components/mermaid.tsx @@ -1,22 +1,25 @@ import React, { useEffect, useMemo } from "react"; import styled from "styled-components"; -import { StoredDeployment } from "@ignored/ignition-core/ui-helpers"; +import { + IgnitionModule, + IgnitionModuleResult, +} from "@nomicfoundation/ignition-core/ui-helpers"; import mermaid from "mermaid"; import { toMermaid } from "../utils/to-mermaid"; export const Mermaid: React.FC<{ - deployment: StoredDeployment; -}> = ({ deployment }) => { + ignitionModule: IgnitionModule>; +}> = ({ ignitionModule }) => { const diagram = useMemo(() => { - const d = toMermaid(deployment); + const d = toMermaid(ignitionModule); // NOTE: this is explicitly added to aid troubleshooting // eslint-disable-next-line @typescript-eslint/no-explicit-any (window as any).diagram = d; return d; - }, [deployment]); + }, [ignitionModule]); useEffect(() => { mermaid.initialize({}); diff --git a/packages/ui/src/components/summary-header.tsx b/packages/ui/src/components/summary-header.tsx index 914237601..d4b5676ab 100644 --- a/packages/ui/src/components/summary-header.tsx +++ b/packages/ui/src/components/summary-header.tsx @@ -1,24 +1,18 @@ import React from "react"; import styled from "styled-components"; -export const SummaryHeader: React.FC<{ - networkName: string; - chainId: number; -}> = ({ networkName, chainId }) => { +export const SummaryHeader: React.FC = () => { return (
Summary
- - Network: {networkName} ({chainId}) -
); }; const Header = styled.div` display: grid; - grid-template-columns: auto 1fr auto; + grid-template-columns: auto 1fr; p { font-weight: bold; @@ -28,7 +22,3 @@ const Header = styled.div` const Title = styled.h2` place-self: center; `; - -const NetworkText = styled.p` - place-self: center; -`; diff --git a/packages/ui/src/main.tsx b/packages/ui/src/main.tsx index 96668463c..1bcf46e48 100644 --- a/packages/ui/src/main.tsx +++ b/packages/ui/src/main.tsx @@ -1,13 +1,20 @@ import React from "react"; -import type { StoredDeployment } from "@ignored/ignition-core/ui-helpers"; -import { StoredDeploymentDeserializer } from "@ignored/ignition-core/ui-helpers"; +import { + IgnitionModule, + IgnitionModuleDeserializer, + IgnitionModuleResult, +} from "@nomicfoundation/ignition-core/ui-helpers"; import ReactDOM from "react-dom/client"; import { RouterProvider, createHashRouter } from "react-router-dom"; import { FutureDetails } from "./pages/future-details/future-details"; -import { PlanOverview } from "./pages/plan-overview/plan-overview"; +import { VisualizationOverview } from "./pages/visualization-overview/visualization-overview"; -const loadDeploymentFromEmbeddedDiv = (): StoredDeployment | null => { +const loadDeploymentFromEmbeddedDiv = (): IgnitionModule< + string, + string, + IgnitionModuleResult +> | null => { const scriptTag = document.getElementById("deployment"); if (scriptTag === null || scriptTag.textContent === null) { @@ -20,13 +27,13 @@ const loadDeploymentFromEmbeddedDiv = (): StoredDeployment | null => { return null; } - return StoredDeploymentDeserializer.deserialize(data); + return IgnitionModuleDeserializer.deserialize(data.module); }; const loadDeploymentFromDevFile = async () => { const response = await fetch("./deployment.json"); const data = await response.json(); - return StoredDeploymentDeserializer.deserialize(data); + return IgnitionModuleDeserializer.deserialize(data.module); }; const loadDeploymentData = () => { @@ -35,16 +42,16 @@ const loadDeploymentData = () => { const main = async () => { try { - const deployment = await loadDeploymentData(); + const ignitionModule = await loadDeploymentData(); const router = createHashRouter([ { path: "/", - element: , + element: , }, { path: "/future/:futureId", - element: , + element: , }, ]); diff --git a/packages/ui/src/pages/future-details/components/future-summary.tsx b/packages/ui/src/pages/future-details/components/future-summary.tsx index d5d525a8a..3ffbd30e8 100644 --- a/packages/ui/src/pages/future-details/components/future-summary.tsx +++ b/packages/ui/src/pages/future-details/components/future-summary.tsx @@ -1,17 +1,15 @@ import { Future, FutureType, - StoredDeployment, isFuture, -} from "@ignored/ignition-core/ui-helpers"; +} from "@nomicfoundation/ignition-core/ui-helpers"; import { PageTitle, Panel } from "../../../components/shared"; import { SummaryHeader } from "../../../components/summary-header"; import { argumentTypeToString } from "../../../utils/argumentTypeToString"; export const FutureSummary: React.FC<{ - deployment: StoredDeployment; future: Future; -}> = ({ deployment, future }) => { +}> = ({ future }) => { const title = resolveTitleFor(future); return ( @@ -21,10 +19,7 @@ export const FutureSummary: React.FC<{ - +
@@ -36,19 +31,19 @@ export const FutureSummary: React.FC<{ function resolveTitleFor(future: Future): string { switch (future.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: return `Contract deploy - ${future.contractName}`; - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: return `Contract deploy from Artifact - ${future.contractName}`; - case FutureType.NAMED_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: return `Library deploy - ${future.contractName}`; - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: return `Library deploy from Artifact - ${future.contractName}`; - case FutureType.NAMED_CONTRACT_CALL: + case FutureType.CONTRACT_CALL: return `Call - ${future.contract.contractName}/${future.functionName}`; - case FutureType.NAMED_STATIC_CALL: + case FutureType.STATIC_CALL: return `Static call - ${future.contract.contractName}/${future.functionName}`; - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: return `Existing contract - ${future.contractName} (${ typeof future.address === "string" ? future.address @@ -56,7 +51,7 @@ function resolveTitleFor(future: Future): string { ? future.address.id : argumentTypeToString(future.address) })`; - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: return `Existing contract from Artifact - ${future.contractName} (${ typeof future.address === "string" ? future.address @@ -73,7 +68,7 @@ function resolveTitleFor(future: Future): string { const FutureDetailsSection: React.FC<{ future: Future }> = ({ future }) => { switch (future.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: return (

Contract - {future.contractName}

@@ -87,7 +82,7 @@ const FutureDetailsSection: React.FC<{ future: Future }> = ({ future }) => {
); - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: return (

Contract - {future.contractName}

@@ -101,19 +96,19 @@ const FutureDetailsSection: React.FC<{ future: Future }> = ({ future }) => {
); - case FutureType.NAMED_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: return (

Library - {future.contractName}

); - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: return (

Library - {future.contractName}

); - case FutureType.NAMED_CONTRACT_CALL: + case FutureType.CONTRACT_CALL: return (

Contract - {future.contract.contractName}

@@ -126,7 +121,7 @@ const FutureDetailsSection: React.FC<{ future: Future }> = ({ future }) => {
); - case FutureType.NAMED_STATIC_CALL: + case FutureType.STATIC_CALL: return (

Contract - {future.contract.contractName}

@@ -139,7 +134,7 @@ const FutureDetailsSection: React.FC<{ future: Future }> = ({ future }) => {
); - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: return (

Contract - {future.contractName}

@@ -154,7 +149,7 @@ const FutureDetailsSection: React.FC<{ future: Future }> = ({ future }) => {
); - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: return (

Contract - {future.contractName}

@@ -177,7 +172,7 @@ const FutureDetailsSection: React.FC<{ future: Future }> = ({ future }) => { ) : null}

Event - {future.eventName}

Event index - {future.eventIndex}

-

Argument - {future.argumentName}

+

Argument - {future.nameOrIndex}

); case FutureType.SEND_DATA: diff --git a/packages/ui/src/pages/future-details/future-details.tsx b/packages/ui/src/pages/future-details/future-details.tsx index 78ccd86e6..5b0a22027 100644 --- a/packages/ui/src/pages/future-details/future-details.tsx +++ b/packages/ui/src/pages/future-details/future-details.tsx @@ -1,18 +1,21 @@ -import { StoredDeployment } from "@ignored/ignition-core"; +import { + IgnitionModule, + IgnitionModuleResult, +} from "@nomicfoundation/ignition-core/ui-helpers"; import React, { useMemo } from "react"; import { useParams } from "react-router-dom"; import { Page } from "../../components/shared"; import { getFutureById } from "../../queries/futures"; import { FutureSummary } from "./components/future-summary"; -export const FutureDetails: React.FC<{ deployment: StoredDeployment }> = ({ - deployment, -}) => { +export const FutureDetails: React.FC<{ + ignitionModule: IgnitionModule>; +}> = ({ ignitionModule }) => { const { futureId } = useParams(); const future = useMemo( - () => getFutureById(deployment, futureId), - [deployment, futureId] + () => getFutureById(ignitionModule, futureId), + [ignitionModule, futureId] ); if (future === undefined) { @@ -25,7 +28,7 @@ export const FutureDetails: React.FC<{ deployment: StoredDeployment }> = ({ return ( - + ); }; diff --git a/packages/ui/src/pages/plan-overview/plan-overview.tsx b/packages/ui/src/pages/plan-overview/plan-overview.tsx deleted file mode 100644 index 16a6c7acc..000000000 --- a/packages/ui/src/pages/plan-overview/plan-overview.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import { StoredDeployment } from "@ignored/ignition-core/ui-helpers"; -import React from "react"; -import { Page, PageTitle, Panel } from "../../components/shared"; -import { PlanDetails } from "./components/plan-details"; -import { PlanSummary } from "./components/plan-summary"; - -export const PlanOverview: React.FC<{ deployment: StoredDeployment }> = ({ - deployment, -}) => { - return ( - -
- Ignition - {deployment.module.id} -
- - - - - - - - -
- ); -}; diff --git a/packages/ui/src/pages/plan-overview/components/action.tsx b/packages/ui/src/pages/visualization-overview/components/action.tsx similarity index 76% rename from packages/ui/src/pages/plan-overview/components/action.tsx rename to packages/ui/src/pages/visualization-overview/components/action.tsx index 9e932ae43..848173066 100644 --- a/packages/ui/src/pages/plan-overview/components/action.tsx +++ b/packages/ui/src/pages/visualization-overview/components/action.tsx @@ -2,7 +2,7 @@ import { Future, FutureType, isFuture, -} from "@ignored/ignition-core/ui-helpers"; +} from "@nomicfoundation/ignition-core/ui-helpers"; import React, { useCallback } from "react"; import { useNavigate } from "react-router-dom"; import styled, { css } from "styled-components"; @@ -16,7 +16,7 @@ export const Action: React.FC<{ const displayText = toDisplayText(future); const navigateToFuture = useCallback(() => { - return navigate(`/future/${future.id}`); + return navigate(`/future/${encodeURIComponent(future.id)}`); }, [future.id, navigate]); return ( @@ -28,19 +28,19 @@ export const Action: React.FC<{ function toDisplayText(future: Future): string { switch (future.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: return `Contract deploy ${future.contractName}`; - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: return `Deploy contract ${future.contractName} from artifact`; - case FutureType.NAMED_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: return `Library deploy ${future.contractName}`; - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: return `Library deploy ${future.contractName} from artifact`; - case FutureType.NAMED_CONTRACT_CALL: + case FutureType.CONTRACT_CALL: return `Call ${future.contract.contractName}/${future.functionName}`; - case FutureType.NAMED_STATIC_CALL: + case FutureType.STATIC_CALL: return `Static call ${future.contract.contractName}/${future.functionName}`; - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: return `Existing contract ${future.contractName} (${ typeof future.address === "string" ? future.address @@ -48,7 +48,7 @@ function toDisplayText(future: Future): string { ? future.address.id : argumentTypeToString(future.address) })`; - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: return `Existing contract ${future.contractName} from artifact (${ typeof future.address === "string" ? future.address @@ -57,7 +57,7 @@ function toDisplayText(future: Future): string { : argumentTypeToString(future.address) })`; case FutureType.READ_EVENT_ARGUMENT: - return `Read event from future ${future.futureToReadFrom.id} (event ${future.eventName} argument ${future.argumentName})`; + return `Read event from future ${future.futureToReadFrom.id} (event ${future.eventName} argument ${future.nameOrIndex})`; case FutureType.SEND_DATA: return `Send data to ${ typeof future.to === "string" @@ -85,10 +85,10 @@ const ActionBtn = styled.div<{ futureType: FutureType }>` ${(props) => [ - FutureType.NAMED_CONTRACT_DEPLOYMENT, - FutureType.ARTIFACT_CONTRACT_DEPLOYMENT, - FutureType.NAMED_LIBRARY_DEPLOYMENT, - FutureType.ARTIFACT_LIBRARY_DEPLOYMENT, + FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT, + FutureType.CONTRACT_DEPLOYMENT, + FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT, + FutureType.LIBRARY_DEPLOYMENT, ].includes(props.futureType) && css` background: green; @@ -96,7 +96,7 @@ const ActionBtn = styled.div<{ futureType: FutureType }>` `} ${(props) => - [FutureType.NAMED_CONTRACT_CALL, FutureType.NAMED_STATIC_CALL].includes( + [FutureType.CONTRACT_CALL, FutureType.STATIC_CALL].includes( props.futureType ) && css` diff --git a/packages/ui/src/pages/plan-overview/components/plan-details.tsx b/packages/ui/src/pages/visualization-overview/components/visualization-details.tsx similarity index 57% rename from packages/ui/src/pages/plan-overview/components/plan-details.tsx rename to packages/ui/src/pages/visualization-overview/components/visualization-details.tsx index 64117d9ff..f3e6213dd 100644 --- a/packages/ui/src/pages/plan-overview/components/plan-details.tsx +++ b/packages/ui/src/pages/visualization-overview/components/visualization-details.tsx @@ -1,24 +1,27 @@ -import { StoredDeployment } from "@ignored/ignition-core/ui-helpers"; +import { + IgnitionModule, + IgnitionModuleResult, +} from "@nomicfoundation/ignition-core/ui-helpers"; import { useMemo } from "react"; import styled from "styled-components"; import { Mermaid } from "../../../components/mermaid"; import { getAllFuturesForModule } from "../../../queries/futures"; import { Action } from "./action"; -export const PlanDetails: React.FC<{ deployment: StoredDeployment }> = ({ - deployment, -}) => { +export const VisualizationDetails: React.FC<{ + ignitionModule: IgnitionModule>; +}> = ({ ignitionModule }) => { const futures = useMemo( - () => getAllFuturesForModule(deployment.module), - [deployment] + () => getAllFuturesForModule(ignitionModule), + [ignitionModule] ); return (
-

Plan

+

Visualization

- +

Actions

diff --git a/packages/ui/src/pages/plan-overview/components/plan-summary.tsx b/packages/ui/src/pages/visualization-overview/components/visualization-summary.tsx similarity index 74% rename from packages/ui/src/pages/plan-overview/components/plan-summary.tsx rename to packages/ui/src/pages/visualization-overview/components/visualization-summary.tsx index 721ad50f8..6f16006f9 100644 --- a/packages/ui/src/pages/plan-overview/components/plan-summary.tsx +++ b/packages/ui/src/pages/visualization-overview/components/visualization-summary.tsx @@ -1,4 +1,7 @@ -import { StoredDeployment } from "@ignored/ignition-core/ui-helpers"; +import { + IgnitionModule, + IgnitionModuleResult, +} from "@nomicfoundation/ignition-core/ui-helpers"; import React, { useMemo } from "react"; import styled from "styled-components"; import { SummaryHeader } from "../../../components/summary-header"; @@ -7,28 +10,24 @@ import { getAllDeployFuturesFor, } from "../../../queries/futures"; -export const PlanSummary: React.FC<{ deployment: StoredDeployment }> = ({ - deployment, -}) => { - const { details } = deployment; +export const VisualizationSummary: React.FC<{ + ignitionModule: IgnitionModule>; +}> = ({ ignitionModule }) => { const deployFutures = useMemo( - () => getAllDeployFuturesFor(deployment), - [deployment] + () => getAllDeployFuturesFor(ignitionModule), + [ignitionModule] ); const callFutures = useMemo( - () => getAllCallFuturesFor(deployment), - [deployment] + () => getAllCallFuturesFor(ignitionModule), + [ignitionModule] ); return (
- +

- The successful completion of the plan will send{" "} + The successful completion of the deployment will send{" "} {deployFutures.length + callFutures.length} transactions:

diff --git a/packages/ui/src/pages/visualization-overview/visualization-overview.tsx b/packages/ui/src/pages/visualization-overview/visualization-overview.tsx new file mode 100644 index 000000000..0f2116ced --- /dev/null +++ b/packages/ui/src/pages/visualization-overview/visualization-overview.tsx @@ -0,0 +1,28 @@ +import { + IgnitionModule, + IgnitionModuleResult, +} from "@nomicfoundation/ignition-core/ui-helpers"; +import React from "react"; +import { Page, PageTitle, Panel } from "../../components/shared"; +import { VisualizationDetails } from "./components/visualization-details"; +import { VisualizationSummary } from "./components/visualization-summary"; + +export const VisualizationOverview: React.FC<{ + ignitionModule: IgnitionModule>; +}> = ({ ignitionModule }) => { + return ( + +
+ Ignition - {ignitionModule.id} +
+ + + + + + + + +
+ ); +}; diff --git a/packages/ui/src/queries/futures.ts b/packages/ui/src/queries/futures.ts index e1fb165e7..897ed0dfe 100644 --- a/packages/ui/src/queries/futures.ts +++ b/packages/ui/src/queries/futures.ts @@ -2,20 +2,21 @@ import { DeploymentFuture, FunctionCallFuture, Future, - StoredDeployment, + IgnitionModule, + IgnitionModuleResult, isDeploymentFuture, isFunctionCallFuture, -} from "@ignored/ignition-core/ui-helpers"; +} from "@nomicfoundation/ignition-core/ui-helpers"; export function getFutureById( - deployment: StoredDeployment, + ignitionModule: IgnitionModule>, futureId: string | undefined ): Future | undefined { if (futureId === undefined) { return undefined; } - const f = getAllFuturesForModule(deployment.module).find( + const f = getAllFuturesForModule(ignitionModule).find( (f) => f.id === futureId ); @@ -30,7 +31,7 @@ export function getFutureById( export function getAllFuturesForModule({ futures, submodules, -}: StoredDeployment["module"]): Future[] { +}: IgnitionModule>): Future[] { return Array.from(futures).concat( Array.from(submodules.values()).flatMap((submodule) => getAllFuturesForModule(submodule) @@ -46,16 +47,16 @@ export function getAllFuturesForModule({ * - artifact library deploys */ export function getAllDeployFuturesFor( - deployment: StoredDeployment + ignitionModule: IgnitionModule> ): DeploymentFuture[] { - return getAllFuturesForModule(deployment.module).filter(isDeploymentFuture); + return getAllFuturesForModule(ignitionModule).filter(isDeploymentFuture); } /** * Get all calls in a module and its submodules */ export function getAllCallFuturesFor( - deployment: StoredDeployment + ignitionModule: IgnitionModule> ): FunctionCallFuture[] { - return getAllFuturesForModule(deployment.module).filter(isFunctionCallFuture); + return getAllFuturesForModule(ignitionModule).filter(isFunctionCallFuture); } diff --git a/packages/ui/src/utils/argumentTypeToString.tsx b/packages/ui/src/utils/argumentTypeToString.tsx index 3a4a3334d..fbfb67fbb 100644 --- a/packages/ui/src/utils/argumentTypeToString.tsx +++ b/packages/ui/src/utils/argumentTypeToString.tsx @@ -3,7 +3,7 @@ import { RuntimeValueType, isFuture, isRuntimeValue, -} from "@ignored/ignition-core/ui-helpers"; +} from "@nomicfoundation/ignition-core/ui-helpers"; export function argumentTypeToString(argument: ArgumentType): string { return JSON.stringify( diff --git a/packages/ui/src/utils/to-mermaid.ts b/packages/ui/src/utils/to-mermaid.ts index 3bd01161f..a9695da87 100644 --- a/packages/ui/src/utils/to-mermaid.ts +++ b/packages/ui/src/utils/to-mermaid.ts @@ -3,14 +3,15 @@ import { FutureType, IgnitionModule, IgnitionModuleResult, - StoredDeployment, isFuture, -} from "@ignored/ignition-core/ui-helpers"; +} from "@nomicfoundation/ignition-core/ui-helpers"; import { getAllFuturesForModule } from "../queries/futures.js"; import { argumentTypeToString } from "./argumentTypeToString.js"; -export function toMermaid(deployment: StoredDeployment) { - const modules = recursivelyListModulesAndSubmodulesFor(deployment.module); +export function toMermaid( + ignitionModule: IgnitionModule> +) { + const modules = recursivelyListModulesAndSubmodulesFor(ignitionModule); const subgraphSections = modules .map((m) => prettyPrintModule(m, " ")) @@ -18,7 +19,7 @@ export function toMermaid(deployment: StoredDeployment) { const futureDependencies = [ ...new Set( - getAllFuturesForModule(deployment.module) + getAllFuturesForModule(ignitionModule) .flatMap((f) => Array.from(f.dependencies).map((d) => [ toEscapedId(f.id), @@ -43,7 +44,7 @@ export function toMermaid(deployment: StoredDeployment) { ].join("\n"); return `flowchart BT\n\n${toEscapedId( - deployment.module.id + ignitionModule.id )}:::startModule\n\n${subgraphSections}${ futureDependencies === "" ? "" : "\n\n" + futureDependencies }${ @@ -74,19 +75,19 @@ function prettyPrintModule( function toLabel(f: Future): string { switch (f.type) { - case FutureType.NAMED_CONTRACT_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_CONTRACT_DEPLOYMENT: return `Deploy ${f.contractName}`; - case FutureType.ARTIFACT_CONTRACT_DEPLOYMENT: + case FutureType.CONTRACT_DEPLOYMENT: return `Deploy from artifact ${f.contractName}`; - case FutureType.NAMED_LIBRARY_DEPLOYMENT: + case FutureType.NAMED_ARTIFACT_LIBRARY_DEPLOYMENT: return `Deploy library ${f.contractName}`; - case FutureType.ARTIFACT_LIBRARY_DEPLOYMENT: + case FutureType.LIBRARY_DEPLOYMENT: return `Deploy library from artifact ${f.contractName}`; - case FutureType.NAMED_CONTRACT_CALL: + case FutureType.CONTRACT_CALL: return `Call ${f.contract.contractName}/${f.functionName}`; - case FutureType.NAMED_STATIC_CALL: + case FutureType.STATIC_CALL: return `Static call ${f.contract.contractName}/${f.functionName}`; - case FutureType.NAMED_CONTRACT_AT: + case FutureType.NAMED_ARTIFACT_CONTRACT_AT: return `Existing contract ${f.contractName} (${ typeof f.address === "string" ? f.address @@ -94,7 +95,7 @@ function toLabel(f: Future): string { ? f.address.id : argumentTypeToString(f.address) })`; - case FutureType.ARTIFACT_CONTRACT_AT: + case FutureType.CONTRACT_AT: return `Existing contract from artifact ${f.contractName} (${ typeof f.address === "string" ? f.address @@ -103,7 +104,7 @@ function toLabel(f: Future): string { : argumentTypeToString(f.address) })`; case FutureType.READ_EVENT_ARGUMENT: - return `Read event from future ${f.futureToReadFrom.id} (event ${f.eventName} argument ${f.argumentName})`; + return `Read event from future ${f.futureToReadFrom.id} (event ${f.eventName} argument ${f.nameOrIndex})`; case FutureType.SEND_DATA: return `Send data to ${ typeof f.to === "string" diff --git a/packages/ui/test/to-mermaid.ts b/packages/ui/test/to-mermaid.ts index 13f816b20..6695dd4fa 100644 --- a/packages/ui/test/to-mermaid.ts +++ b/packages/ui/test/to-mermaid.ts @@ -1,4 +1,8 @@ -import { Artifact, IgnitionModule, buildModule } from "@ignored/ignition-core"; +import { + Artifact, + IgnitionModule, + buildModule, +} from "@nomicfoundation/ignition-core"; import { assert } from "chai"; import { toMermaid } from "../src/utils/to-mermaid.js"; @@ -19,7 +23,7 @@ describe("to-mermaid", () => { subgraph Module direction BT - Module:Contract1["Deploy Contract1"] + Module#Contract1["Deploy Contract1"] end classDef startModule stroke-width:4px`; @@ -28,7 +32,7 @@ describe("to-mermaid", () => { }); it("should render a module with a space in the name", () => { - const moduleDefinition = buildModule("Test registrar", (m) => { + const moduleDefinition = buildModule("Test_registrar", (m) => { const p = m.getParameter("p", 123); const contract1 = m.contract("Contract1", [{ arr: [p] }]); @@ -40,10 +44,10 @@ describe("to-mermaid", () => { Test_registrar:::startModule - subgraph Test registrar + subgraph Test_registrar direction BT - Test_registrar:Contract1["Deploy Contract1"] + Test_registrar#Contract1["Deploy Contract1"] end classDef startModule stroke-width:4px`; @@ -83,21 +87,21 @@ describe("to-mermaid", () => { subgraph Module direction BT - Module:Contract3["Deploy Contract3"] + Module#Contract3["Deploy Contract3"] end subgraph Submodule1 direction BT - Submodule1:Contract1["Deploy Contract1"] + Submodule1#Contract1["Deploy Contract1"] end subgraph Submodule2 direction BT - Submodule2:Contract2["Deploy Contract2"] + Submodule2#Contract2["Deploy Contract2"] end - Module:Contract3 --> Submodule1:Contract1 - Module:Contract3 --> Submodule2:Contract2 + Module#Contract3 --> Submodule1#Contract1 + Module#Contract3 --> Submodule2#Contract2 Module -.-> Submodule1 Module -.-> Submodule2 @@ -121,21 +125,12 @@ describe("to-mermaid", () => { const moduleDefinition = buildModule("Module", (m) => { const basic = m.contract("BasicContract"); const library = m.library("BasicLibrary"); - const libFromArtifact = m.libraryFromArtifact( - "BasicLibrary", - libArtifact, - { - id: "BasicLibrary2", - } - ); - const withLib = m.contractFromArtifact( - "ContractWithLibrary", - withLibArtifact, - [], - { - libraries: { BasicLibrary: library }, - } - ); + const libFromArtifact = m.library("BasicLibrary", libArtifact, { + id: "BasicLibrary2", + }); + const withLib = m.contract("ContractWithLibrary", withLibArtifact, [], { + libraries: { BasicLibrary: library }, + }); const call = m.call(basic, "basicFunction", [40]); const eventArg = m.readEventArgument(call, "BasicEvent", "eventArg"); @@ -144,14 +139,14 @@ describe("to-mermaid", () => { const duplicate = m.contractAt("BasicContract", basic, { id: "BasicContract2", }); - const duplicateWithLib = m.contractAtFromArtifact( + const duplicateWithLib = m.contractAt( "ContractWithLibrary", withLib, withLibArtifact, { id: "ContractWithLibrary2" } ); - m.send("test-send", duplicate, 123n); + m.send("test_send", duplicate, 123n); return { basic, @@ -171,26 +166,26 @@ describe("to-mermaid", () => { subgraph Module direction BT - Module:BasicContract["Deploy BasicContract"] - Module:BasicLibrary["Deploy library BasicLibrary"] - Module:BasicLibrary2["Deploy library from artifact BasicLibrary"] - Module:ContractWithLibrary["Deploy from artifact ContractWithLibrary"] - Module:BasicContract#basicFunction["Call BasicContract/basicFunction"] - Module:BasicContract#BasicEvent#eventArg#0["Read event from future Module:BasicContract#basicFunction (event BasicEvent argument eventArg)"] - Module:ContractWithLibrary#readonlyFunction["Static call ContractWithLibrary/readonlyFunction"] - Module:BasicContract2["Existing contract BasicContract (Module:BasicContract)"] - Module:ContractWithLibrary2["Existing contract from artifact ContractWithLibrary (Module:ContractWithLibrary)"] - Module:test-send["Send data to Module:BasicContract2"] + Module#BasicContract["Deploy BasicContract"] + Module#BasicLibrary["Deploy library BasicLibrary"] + Module#BasicLibrary2["Deploy library from artifact BasicLibrary"] + Module#ContractWithLibrary["Deploy from artifact ContractWithLibrary"] + Module#BasicContract.basicFunction["Call BasicContract/basicFunction"] + Module#BasicContract.BasicEvent.eventArg.0["Read event from future Module#BasicContract.basicFunction (event BasicEvent argument eventArg)"] + Module#ContractWithLibrary.readonlyFunction["Static call ContractWithLibrary/readonlyFunction"] + Module#BasicContract2["Existing contract BasicContract (Module#BasicContract)"] + Module#ContractWithLibrary2["Existing contract from artifact ContractWithLibrary (Module#ContractWithLibrary)"] + Module#test_send["Send data to Module#BasicContract2"] end - Module:ContractWithLibrary --> Module:BasicLibrary - Module:BasicContract#basicFunction --> Module:BasicContract - Module:BasicContract#BasicEvent#eventArg#0 --> Module:BasicContract#basicFunction - Module:ContractWithLibrary#readonlyFunction --> Module:ContractWithLibrary - Module:ContractWithLibrary#readonlyFunction --> Module:BasicContract#BasicEvent#eventArg#0 - Module:BasicContract2 --> Module:BasicContract - Module:ContractWithLibrary2 --> Module:ContractWithLibrary - Module:test-send --> Module:BasicContract2 + Module#ContractWithLibrary --> Module#BasicLibrary + Module#BasicContract.basicFunction --> Module#BasicContract + Module#BasicContract.BasicEvent.eventArg.0 --> Module#BasicContract.basicFunction + Module#ContractWithLibrary.readonlyFunction --> Module#ContractWithLibrary + Module#ContractWithLibrary.readonlyFunction --> Module#BasicContract.BasicEvent.eventArg.0 + Module#BasicContract2 --> Module#BasicContract + Module#ContractWithLibrary2 --> Module#ContractWithLibrary + Module#test_send --> Module#BasicContract2 classDef startModule stroke-width:4px`; @@ -215,13 +210,13 @@ describe("to-mermaid", () => { subgraph Module direction BT - Module:ens["Deploy ens"] - Module:ens#setAddr_bytes32_address_["Call ens/setAddr(bytes32,address)"] - Module:ens#getAddr_bytes32_address_["Static call ens/getAddr(bytes32,address)"] + Module#ens["Deploy ens"] + Module#ens.setAddr_bytes32_address_["Call ens/setAddr(bytes32,address)"] + Module#ens.getAddr_bytes32_address_["Static call ens/getAddr(bytes32,address)"] end - Module:ens#setAddr_bytes32_address_ --> Module:ens - Module:ens#getAddr_bytes32_address_ --> Module:ens + Module#ens.setAddr_bytes32_address_ --> Module#ens + Module#ens.getAddr_bytes32_address_ --> Module#ens classDef startModule stroke-width:4px`; @@ -230,15 +225,7 @@ describe("to-mermaid", () => { }); function assertDiagram(ignitionModule: IgnitionModule, expectedResult: string) { - const details = { - networkName: "hardhat", - chainId: 31117, - }; - - const result = toMermaid({ - details, - module: ignitionModule, - }); + const result = toMermaid(ignitionModule); assert.equal(result, expectedResult); } diff --git a/packages/ui/vite.config.ts b/packages/ui/vite.config.ts index 31e35cae0..533d4623c 100644 --- a/packages/ui/vite.config.ts +++ b/packages/ui/vite.config.ts @@ -6,7 +6,7 @@ import { viteSingleFile } from "vite-plugin-singlefile"; export default defineConfig({ plugins: [react(), viteSingleFile()], optimizeDeps: { - include: ["@ignored/ignition-core/ui-helpers"], + include: ["@nomicfoundation/ignition-core/ui-helpers"], }, build: { commonjsOptions: {