From 268f8257ea9e4a7ad0b343e6c8604e329f8c7803 Mon Sep 17 00:00:00 2001 From: Jordan Ribbink Date: Thu, 7 Jul 2022 12:27:43 -0700 Subject: [PATCH] Update install docs and package.json bin file (#133) --- cadence/contracts/FlowManager.cdc | 8 +-- docs/generator.md | 4 +- docs/install.md | 8 ++- package.json | 4 +- src/cli/commands/make.js | 10 +-- src/generated/contracts/FlowManager.js | 94 +++++++++++++------------- 6 files changed, 68 insertions(+), 60 deletions(-) diff --git a/cadence/contracts/FlowManager.cdc b/cadence/contracts/FlowManager.cdc index f1d6734f..7420f943 100644 --- a/cadence/contracts/FlowManager.cdc +++ b/cadence/contracts/FlowManager.cdc @@ -93,11 +93,11 @@ pub contract FlowManager { 0x05: "Eve" } - self.accountManagerStorage = /storage/testSuitAccountManager - self.contractManagerStorage = /storage/testSuitContractManager + self.accountManagerStorage = /storage/testSuiteAccountManager + self.contractManagerStorage = /storage/testSuiteContractManager - self.accountManagerPath = /public/testSuitAccountManager - self.contractManagerPath = /public/testSuitContractManager + self.accountManagerPath = /public/testSuiteAccountManager + self.contractManagerPath = /public/testSuiteContractManager // Destroy previously stored values self.account.load(from: self.accountManagerStorage) diff --git a/docs/generator.md b/docs/generator.md index fdaef17b..396342db 100644 --- a/docs/generator.md +++ b/docs/generator.md @@ -19,9 +19,9 @@ Then it will install dependencies. After the installation is finished, the utili > it would be executed and also could affect your `package.json` file. That's why we advise you to use new empty folder > to contain your Cadence related tests. -### Generate New Test Suit +### Generate New Test Suite -Create a test suit file for your project with all necessary imports and setup for describe blocks. +Create a test suite file for your project with all necessary imports and setup for describe blocks. You can start writing your asserts and expectations right away: ```shell diff --git a/docs/install.md b/docs/install.md index 97ab6912..07621535 100644 --- a/docs/install.md +++ b/docs/install.md @@ -15,6 +15,12 @@ Create new folder and move into it: mkdir test && cd ./test ``` +Install `@onflow/flow-js-testing` + +```shell +npm install @onflow/flow-js-testing +``` + Generate complete setup via `init` call: ```shell @@ -46,7 +52,7 @@ npm init Then install all necessary packages by running following command: ```shell -npm install flow-js-testing jest @babel/core @babel/preset-env babel-jest +npm install @onflow/flow-js-testing jest @babel/core @babel/preset-env babel-jest ``` If your project _is_ JavaScript based, then run the above command from the folder that contains your project's `package.json` file. diff --git a/package.json b/package.json index 285ac870..f7f51990 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "type": "git", "url": "https://github.com/onflow/flow-js-testing" }, - "bin": "./bin/index.js", + "bin": { + "flow-js-testing": "./bin/index.js" + }, "scripts": { "build": "microbundle", "generate-code": "node_modules/.bin/flow-generate -i ./cadence -o ./src/generated", diff --git a/src/cli/commands/make.js b/src/cli/commands/make.js index 01a92401..3a7ed3e2 100644 --- a/src/cli/commands/make.js +++ b/src/cli/commands/make.js @@ -36,7 +36,7 @@ const hashedTimestamp = () => { const command = { command: "make [name]", aliases: ["new"], - describe: "Generate test suit", + describe: "Generate test suite", builder: (yargs) => { return yargs .positional("name", { @@ -45,20 +45,20 @@ const command = { .option("clear", { alias: "c", type: "boolean", - description: "Exclude comments from test suit code", + description: "Exclude comments from test suite code", }) .option("base-path", { alias: "b", type: "string", - description: "Exclude comments from test suit code", + description: "Exclude comments from test suite code", }); }, handler: (args) => { - const name = args.name || `test-suit${hashedTimestamp()}`; + const name = args.name || `test-suite${hashedTimestamp()}`; const basePath = args.basePath || "../cadence"; const clear = args.clear; - console.log(`\n🔧 Generating test suit "${name}"`); + console.log(`\n🔧 Generating test suite "${name}"`); const content = testTemplate(name, basePath, !clear); writeFile(`./${name}.test.js`, content); diff --git a/src/generated/contracts/FlowManager.js b/src/generated/contracts/FlowManager.js index 179eb2bc..3bfa4426 100644 --- a/src/generated/contracts/FlowManager.js +++ b/src/generated/contracts/FlowManager.js @@ -1,13 +1,13 @@ -/** pragma type contract **/ - -import { - getEnvironment, - replaceImportAddresses, - reportMissingImports, - deployContract, -} from 'flow-cadut' - -export const CODE = ` +/** pragma type contract **/ + +import { + getEnvironment, + replaceImportAddresses, + reportMissingImports, + deployContract, +} from 'flow-cadut' + +export const CODE = ` pub contract FlowManager { /// Account Manager @@ -103,11 +103,11 @@ export const CODE = ` 0x05: "Eve" } - self.accountManagerStorage = /storage/testSuitAccountManager - self.contractManagerStorage = /storage/testSuitContractManager + self.accountManagerStorage = /storage/testSuiteAccountManager + self.contractManagerStorage = /storage/testSuiteContractManager - self.accountManagerPath = /public/testSuitAccountManager - self.contractManagerPath = /public/testSuitContractManager + self.accountManagerPath = /public/testSuiteAccountManager + self.contractManagerPath = /public/testSuiteContractManager // Destroy previously stored values self.account.load(from: self.accountManagerStorage) @@ -120,37 +120,37 @@ export const CODE = ` self.account.link<&Mapper>(self.contractManagerPath, target: self.contractManagerStorage) } } - -`; - -/** -* Method to generate cadence code for FlowManager transaction -* @param {Object.} addressMap - contract name as a key and address where it's deployed as value -*/ -export const FlowManagerTemplate = async (addressMap = {}) => { - const envMap = await getEnvironment(); - const fullMap = { - ...envMap, - ...addressMap, - }; - - // If there are any missing imports in fullMap it will be reported via console - reportMissingImports(CODE, fullMap, `FlowManager =>`) - - return replaceImportAddresses(CODE, fullMap); -}; - - -/** -* Deploys FlowManager transaction to the network -* @param {Object.} addressMap - contract name as a key and address where it's deployed as value -* @param Array<*> args - list of arguments -* param Array - list of signers -*/ -export const deployFlowManager = async (props) => { - const { addressMap = {} } = props; - const code = await FlowManagerTemplate(addressMap); - const name = "FlowManager" - - return deployContract({ code, name, ...props }) + +`; + +/** +* Method to generate cadence code for FlowManager transaction +* @param {Object.} addressMap - contract name as a key and address where it's deployed as value +*/ +export const FlowManagerTemplate = async (addressMap = {}) => { + const envMap = await getEnvironment(); + const fullMap = { + ...envMap, + ...addressMap, + }; + + // If there are any missing imports in fullMap it will be reported via console + reportMissingImports(CODE, fullMap, `FlowManager =>`) + + return replaceImportAddresses(CODE, fullMap); +}; + + +/** +* Deploys FlowManager transaction to the network +* @param {Object.} addressMap - contract name as a key and address where it's deployed as value +* @param Array<*> args - list of arguments +* param Array - list of signers +*/ +export const deployFlowManager = async (props) => { + const { addressMap = {} } = props; + const code = await FlowManagerTemplate(addressMap); + const name = "FlowManager" + + return deployContract({ code, name, ...props }) } \ No newline at end of file