Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/src/api/apollo/generated
**/src/api/apollo/generated
*.hbs
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "flow-playground",
"private": true,
"engines": {
"node": ">=16.0.0 <17.0.0"
},
"scripts": {
"start": "webpack-dev-server -d source-map --config webpack.config.js",
"build": "webpack --mode=production",
Expand Down
64 changes: 36 additions & 28 deletions src/templates/js/config/README.md.hbs
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
#
{{projectTitle}}

## Description
{{projectDescription}}

## Readme
{{projectReadme}}

## About Playground Export This project was generated from Playground living
here: [{{projectLink}}]({{projectLink}}) We have added some basics tests, which
you can run using Node, Flow Emulator and Flow JS Testing Framework. ##
Installation ### Node *(optional if you have it installed already)* Please
follow instructions on NodeJS download page and install latest version of NodeJS
software: https://nodejs.org/en/download/ ### Flow Emulator *(optional if you
have it installed already)* Flow Emulator is bundled with Flow CLI. You can find
instructions on how to install it on Flow Docs site:
https://docs.onflow.org/flow-cli/ ### Flow JS Testing Framework All the
necessary files will be installed if you run `npm install` inside `test` folder.
For documentations on how to use the framework you can consult package
repository
[https://github.com/onflow/flow-js-testing](https://github.com/onflow/flow-js-testing)
### Next Step When all the above tools would be installed you will need to init
Flow Emulator with `flow init` command from within `test` folder. This will
create `flow.json` file in the folder, which is necessary for emulator to
operate properly. Then you can proceed running the tests. We encourage you to
run "Create Accounts" suit first, followed by "Deployment" and then transactions
and scripts. ### Afterword Good luck and happy hacking! :)
# {{projectTitle}}

## Description
{{ projectDescription }}

## Readme
{{ projectReadme }}

## About Playground Export
This project was generated from Playground living here:
[{{projectLink}}]({{projectLink}})

We have added some basics tests, which you can run using Node, Flow Emulator and Flow JS Testing Framework.

## Installation
### Node *(optional if you have it installed already)*
Please follow instructions on NodeJS download page and install latest version of NodeJS software:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add something about node v17?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added node 16 to the package.json engines

https://nodejs.org/en/download/

### Flow Emulator *(optional if you have it installed already)*
Flow Emulator is bundled with Flow CLI. You can find instructions on how to install it on Flow Docs site:
https://docs.onflow.org/flow-cli/

### Flow JS Testing Framework
All the necessary files will be installed if you run `npm install` inside `test` folder. For documentations on how to use
the framework you can consult package repository [https://github.com/onflow/flow-js-testing](https://github.com/onflow/flow-js-testing)

### Next Step
When all the above tools would be installed you will need to init Flow Emulator with `flow init` command from within
`test` folder. This will create `flow.json` file in the folder, which is necessary for emulator to operate properly.

Then you can proceed running the tests. We encourage you to run "Create Accounts" suit first, followed by "Deployment" and then
transactions and scripts.

### Afterword
Good luck and happy hacking! :)
13 changes: 12 additions & 1 deletion src/templates/js/config/babel.config.hbs
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
{ "presets": [ [ "@babel/preset-env", { "targets": { "node": "current" } } ] ] }
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "current"
}
}
]
]
}
7 changes: 5 additions & 2 deletions src/templates/js/config/jest.config.js.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
module.exports = { "testEnvironment": "node", "verbose": true,
"coveragePathIgnorePatterns": ["/node_modules/"], };
module.exports = {
"testEnvironment": "node",
"verbose": true,
"coveragePathIgnorePatterns": ["/node_modules/"],
};
26 changes: 21 additions & 5 deletions src/templates/js/config/package.json.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
{ "name": "{{name}}", "version": "0.0.0", "main": "index.js", "license": "MIT",
"scripts": { "init-flow": "flow init", "start-emulator": "flow emulator -v" },
"dependencies": { "@babel/core": "^7.12.10", "@babel/preset-env": "^7.12.11",
"@onflow/types": "^0.0.4", "babel-jest": "^26.6.3", "flow-js-testing": "~0.1.7",
"jest": "^26.6.3" }, "devDependencies": { "prettier": "^2.2.1" } }
{
"name": "{{name}}",
"version": "0.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"init-flow": "flow init",
"start-emulator": "flow emulator -v"
},
"dependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@onflow/types": "^0.0.4",
"babel-jest": "^26.6.3",
"flow-js-testing": "~0.1.7",
"jest": "^26.6.3"
},
"devDependencies": {
"prettier": "^2.2.1"
}
}
15 changes: 8 additions & 7 deletions src/templates/js/partials/addSigners.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{{#if signers~}}
// Set transaction signers const signers = [
{{#each signers~}}
{{this}},
{{/each}}
]
{{/if}}
{{#if signers ~}}
// Set transaction signers
const signers = [
{{#each signers ~}}
{{this}},
{{/each}}
]
{{/if}}
27 changes: 13 additions & 14 deletions src/templates/js/partials/addressMap.hbs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{{#if imports~}}
// Generate addressMap from import statements
{{#each imports~}}
const
{{name}}
= await getContractAddress("{{name}}")
{{/each}}

const addressMap = {
{{#each imports~}}
{{name}},
{{/each}}
}
{{/if}}
{{#if imports ~}}
// Generate addressMap from import statements
{{#each imports ~}}
const {{name}} = await getContractAddress("{{name}}")
{{/each}}

const addressMap = {
{{#each imports ~}}
{{name}},
{{/each}}
}
{{/if}}

22 changes: 12 additions & 10 deletions src/templates/js/partials/codeReplacement.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{{#if accounts~}}
// pass corrected addressed to getAccount calls code =
code.replace(/(?:getAccount\(\s*)(0x.*)(?:\s*\))/g, (_, match) => { const
accounts = {
{{#each accounts}}
"{{this}}" :
{{getNameByAddress this}},
{{/each}}
} const name = accounts[match] return `getAccount(${name})`; });
{{/if}}
{{#if accounts ~}}
// pass corrected addressed to getAccount calls
code = code.replace(/(?:getAccount\(\s*)(0x.*)(?:\s*\))/g, (_, match) => {
const accounts = {
{{#each accounts}}
"{{this}}" : {{getNameByAddress this}},
{{/each}}
}
const name = accounts[match]
return `getAccount(${name})`;
});
{{/if}}
14 changes: 6 additions & 8 deletions src/templates/js/partials/getAccounts.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{{#if accounts~}}
// Import participating accounts
{{#each accounts~}}
const
{{this}}
= await getAccountAddress("{{this}}")
{{/each}}
{{/if}}
{{#if accounts ~}}
// Import participating accounts
{{#each accounts ~}}
const {{this}} = await getAccountAddress("{{this}}")
{{/each}}
{{/if}}
2 changes: 1 addition & 1 deletion src/templates/js/partials/quoteWrap.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{#if wrap}}"{{/if}}{{item}}{{#if wrap}}"{{/if}}
{{#if wrap}}"{{/if}}{{item}}{{#if wrap}}"{{/if}}
81 changes: 52 additions & 29 deletions src/templates/js/testSuit.hbs
Original file line number Diff line number Diff line change
@@ -1,29 +1,52 @@
import path from "path"; import * as types from "@onflow/types"; import { init,
sendTransaction, deployContractByName, getTransactionCode, } from
"flow-js-testing/dist"; import { getScriptCode } from
"flow-js-testing/dist/utils/file"; import { executeScript } from
"flow-js-testing/dist/utils/interaction"; import { getContractAddress } from
"flow-js-testing/dist/utils/contract"; import { getAccountAddress } from
"flow-js-testing/dist/utils/create-account"; const basePath =
path.resolve(__dirname, "../{{cadenceFolder}}"); beforeAll(() => {
init(basePath); }); describe("Replicate Playground Accounts", () => {
test("Create Accounts", async ()=>{ // Playground project support 4 accounts,
but nothing stops you from creating more by following the example laid out below
const Alice = await getAccountAddress("Alice") const Bob = await
getAccountAddress("Bob") const Charlie = await getAccountAddress("Charlie")
const Dave = await getAccountAddress("Dave") console.log("Four Playground
accounts were created with following addresses"); console.log("Alice:", Alice)
console.log("Bob:", Bob) console.log("Charlie:", Charlie) console.log("Dave:",
Dave) }) }) describe("Deployment", () => {
{{#each contractsUnitTests}}
{{{this}}}
{{/each}}
}) describe("Transactions", () => {
{{#each transactionsUnitTests}}
{{{this}}}
{{/each}}
}) describe("Scripts", () => {
{{#each scriptsUnitTests}}
{{{this}}}
{{/each}}
})
import path from "path";
import * as types from "@onflow/types";
import {
init,
sendTransaction,
deployContractByName,
getTransactionCode,
} from "flow-js-testing/dist";
import { getScriptCode } from "flow-js-testing/dist/utils/file";
import { executeScript } from "flow-js-testing/dist/utils/interaction";
import { getContractAddress } from "flow-js-testing/dist/utils/contract";
import { getAccountAddress } from "flow-js-testing/dist/utils/create-account";

const basePath = path.resolve(__dirname, "../{{cadenceFolder}}");

beforeAll(() => {
init(basePath);
});

describe("Replicate Playground Accounts", () => {
test("Create Accounts", async ()=>{
// Playground project support 4 accounts, but nothing stops you from creating more by following the example laid out below
const Alice = await getAccountAddress("Alice")
const Bob = await getAccountAddress("Bob")
const Charlie = await getAccountAddress("Charlie")
const Dave = await getAccountAddress("Dave")

console.log("Four Playground accounts were created with following addresses");
console.log("Alice:", Alice)
console.log("Bob:", Bob)
console.log("Charlie:", Charlie)
console.log("Dave:", Dave)
})
})

describe("Deployment", () => {
{{#each contractsUnitTests}}
{{{this}}}
{{/each}}
})

describe("Transactions", () => {
{{#each transactionsUnitTests}}
{{{this}}}
{{/each}}
})

describe("Scripts", () => {
{{#each scriptsUnitTests}}
{{{this}}}
{{/each}}
})