Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Update install docs and package.json bin file (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Jul 7, 2022
1 parent 459d2e6 commit 268f825
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 60 deletions.
8 changes: 4 additions & 4 deletions cadence/contracts/FlowManager.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mapper>(from: self.accountManagerStorage)
Expand Down
4 changes: 2 additions & 2 deletions docs/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/cli/commands/make.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand All @@ -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);

Expand Down
94 changes: 47 additions & 47 deletions src/generated/contracts/FlowManager.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<Mapper>(from: self.accountManagerStorage)
Expand All @@ -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.<string, string>} 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.<string, string>} addressMap - contract name as a key and address where it's deployed as value
* @param Array<*> args - list of arguments
* param Array<string> - 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.<string, string>} 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.<string, string>} addressMap - contract name as a key and address where it's deployed as value
* @param Array<*> args - list of arguments
* param Array<string> - list of signers
*/
export const deployFlowManager = async (props) => {
const { addressMap = {} } = props;
const code = await FlowManagerTemplate(addressMap);
const name = "FlowManager"

return deployContract({ code, name, ...props })
}

0 comments on commit 268f825

Please sign in to comment.