create-near-app 2.0.1 → 3.0.0-pre.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/{common/contracts → contracts}/assemblyscript/README.md +1 -2
  2. package/{common/contracts → contracts}/assemblyscript/as-pect.config.js +0 -0
  3. package/{common/contracts → contracts}/assemblyscript/asconfig.json +0 -0
  4. package/{common/contracts → contracts}/assemblyscript/assembly/__tests__/as-pect.d.ts +0 -0
  5. package/contracts/assemblyscript/assembly/__tests__/main.spec.ts +11 -0
  6. package/{common/contracts → contracts}/assemblyscript/assembly/as_types.d.ts +0 -0
  7. package/contracts/assemblyscript/assembly/index.ts +23 -0
  8. package/{common/contracts → contracts}/assemblyscript/assembly/tsconfig.json +0 -0
  9. package/{common/contracts → contracts}/assemblyscript/package.json +2 -6
  10. package/{common/contracts → contracts}/rust/.cargo/config +0 -0
  11. package/{common/contracts → contracts}/rust/Cargo.toml +4 -5
  12. package/{common/contracts → contracts}/rust/README.md +1 -2
  13. package/contracts/rust/src/lib.rs +72 -0
  14. package/index.js +50 -73
  15. package/integration-tests/rs/Cargo.toml +22 -0
  16. package/integration-tests/rs/src/tests.rs +66 -0
  17. package/integration-tests/ts/ava.config.cjs +9 -0
  18. package/integration-tests/ts/package.json +16 -0
  19. package/integration-tests/ts/src/main.ava.ts +44 -0
  20. package/package.json +23 -24
  21. package/templates/react/README.md +2 -2
  22. package/templates/react/ava.config.cjs +9 -0
  23. package/templates/react/{src → frontend}/App.js +34 -29
  24. package/templates/react/{src → frontend}/__mocks__/fileMock.js +0 -0
  25. package/{common/frontend → templates/react/frontend/assets/css}/global.css +4 -3
  26. package/{common/frontend/assets → templates/react/frontend/assets/img}/favicon.ico +0 -0
  27. package/{common/frontend/assets → templates/react/frontend/assets/img}/logo-black.svg +0 -0
  28. package/{common/frontend/assets → templates/react/frontend/assets/img}/logo-white.svg +0 -0
  29. package/templates/react/{src → frontend/assets/js/near}/config.js +1 -1
  30. package/templates/{vue/src → react/frontend/assets/js/near}/utils.js +14 -4
  31. package/templates/react/{src → frontend}/index.html +3 -3
  32. package/templates/react/frontend/index.js +14 -0
  33. package/templates/react/near.gitignore +1 -1
  34. package/templates/react/package.json +29 -43
  35. package/templates/vanilla/README.md +2 -2
  36. package/templates/vanilla/frontend/assets/css/global.css +189 -0
  37. package/templates/vanilla/frontend/assets/img/favicon.ico +0 -0
  38. package/templates/vanilla/frontend/assets/img/logo-black.svg +1 -0
  39. package/templates/vanilla/frontend/assets/img/logo-white.svg +1 -0
  40. package/templates/vanilla/frontend/assets/js/index.js +74 -0
  41. package/templates/vanilla/{src → frontend/assets/js/near}/config.js +1 -1
  42. package/templates/{angular/src → vanilla/frontend/assets/js/near}/utils.js +14 -4
  43. package/templates/vanilla/{src → frontend}/index.html +22 -27
  44. package/templates/vanilla/near.gitignore +1 -1
  45. package/templates/vanilla/package.json +25 -31
  46. package/utils/rust-setup.js +1 -20
  47. package/utils/tracking.js +1 -2
  48. package/common/contracts/assemblyscript/assembly/__tests__/main.spec.ts +0 -9
  49. package/common/contracts/assemblyscript/assembly/index.ts +0 -34
  50. package/common/contracts/assemblyscript/compile.js +0 -50
  51. package/common/contracts/rust/Cargo.lock +0 -638
  52. package/common/contracts/rust/compile.js +0 -53
  53. package/common/contracts/rust/res/.gitkeep +0 -0
  54. package/common/contracts/rust/src/lib.rs +0 -121
  55. package/templates/angular/.gitpod.yml +0 -6
  56. package/templates/angular/README.md +0 -102
  57. package/templates/angular/angular.json +0 -126
  58. package/templates/angular/extra-webpack.config.ts +0 -7
  59. package/templates/angular/karma.conf.js +0 -40
  60. package/templates/angular/near.gitignore +0 -46
  61. package/templates/angular/neardev/shared-test/test.near.json +0 -1
  62. package/templates/angular/neardev/shared-test-staging/test.near.json +0 -1
  63. package/templates/angular/package.json +0 -63
  64. package/templates/angular/set-contract-name.js +0 -16
  65. package/templates/angular/src/app/app.component.html +0 -87
  66. package/templates/angular/src/app/app.component.spec.ts +0 -107
  67. package/templates/angular/src/app/app.component.ts +0 -88
  68. package/templates/angular/src/app/app.module.ts +0 -21
  69. package/templates/angular/src/app/components/notification/notification.component.html +0 -12
  70. package/templates/angular/src/app/components/notification/notification.component.spec.ts +0 -25
  71. package/templates/angular/src/app/components/notification/notification.component.ts +0 -23
  72. package/templates/angular/src/app/services/window.service.ts +0 -43
  73. package/templates/angular/src/config.d.ts +0 -13
  74. package/templates/angular/src/config.js +0 -62
  75. package/templates/angular/src/contract-name.js +0 -1
  76. package/templates/angular/src/environments/environment.prod.ts +0 -3
  77. package/templates/angular/src/environments/environment.ts +0 -16
  78. package/templates/angular/src/index.html +0 -15
  79. package/templates/angular/src/main.ts +0 -15
  80. package/templates/angular/src/polyfills.ts +0 -64
  81. package/templates/angular/src/styles.scss +0 -1
  82. package/templates/angular/src/test.ts +0 -25
  83. package/templates/angular/src/utils.d.ts +0 -3
  84. package/templates/angular/src/window.d.ts +0 -15
  85. package/templates/angular/tsconfig.app.json +0 -15
  86. package/templates/angular/tsconfig.json +0 -21
  87. package/templates/angular/tsconfig.spec.json +0 -18
  88. package/templates/angular/tslint.json +0 -149
  89. package/templates/react/babel.config.js +0 -3
  90. package/templates/react/neardev/shared-test-staging/test.near.json +0 -1
  91. package/templates/react/src/index.js +0 -13
  92. package/templates/react/src/jest.init.js +0 -1
  93. package/templates/react/src/main.test.js +0 -28
  94. package/templates/react/src/utils.js +0 -39
  95. package/templates/react/src/wallet/login/index.html +0 -28
  96. package/templates/vanilla/neardev/shared-test-staging/test.near.json +0 -1
  97. package/templates/vanilla/src/index.js +0 -113
  98. package/templates/vanilla/src/main.test.js +0 -15
  99. package/templates/vanilla/src/utils.js +0 -39
  100. package/templates/vanilla/src/wallet/login/index.html +0 -28
  101. package/templates/vue/.gitpod.yml +0 -6
  102. package/templates/vue/README.md +0 -101
  103. package/templates/vue/babel.config.js +0 -5
  104. package/templates/vue/copy-dev-account.js +0 -7
  105. package/templates/vue/jest.config.js +0 -7
  106. package/templates/vue/near.gitignore +0 -46
  107. package/templates/vue/neardev/shared-test/test.near.json +0 -1
  108. package/templates/vue/neardev/shared-test-staging/test.near.json +0 -1
  109. package/templates/vue/package.json +0 -86
  110. package/templates/vue/src/App.vue +0 -37
  111. package/templates/vue/src/components/Notification.vue +0 -38
  112. package/templates/vue/src/components/SignedIn.vue +0 -179
  113. package/templates/vue/src/components/SignedOut.vue +0 -34
  114. package/templates/vue/src/config.js +0 -63
  115. package/templates/vue/src/main.js +0 -16
  116. package/templates/vue/tests/unit/Notification.spec.js +0 -26
  117. package/templates/vue/tests/unit/SignedIn.spec.js +0 -24
  118. package/templates/vue/tests/unit/SignedOut.spec.js +0 -17
@@ -13,8 +13,7 @@ Before you compile this code, you will need to install [Node.js] ≥ 12
13
13
  Exploring The Code
14
14
  ==================
15
15
 
16
- 1. The main smart contract code lives in `assembly/index.ts`. You can compile
17
- it with the `./compile` script.
16
+ 1. The main smart contract code lives in `assembly/index.ts`.
18
17
  2. Tests: You can run smart contract tests with the `./test` script. This runs
19
18
  standard AssemblyScript tests using [as-pect].
20
19
 
@@ -0,0 +1,11 @@
1
+ import { set_greeting, get_greeting } from '..'
2
+
3
+ describe('Greeting ', () => {
4
+ it('should get the default greeting', () => {
5
+ expect(get_greeting()).toBe('Hello')
6
+ })
7
+ it('should change the greeting', () => {
8
+ set_greeting('howdy')
9
+ expect(get_greeting()).toBe('howdy')
10
+ })
11
+ })
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Example smart contract written in AssemblyScript
3
+ *
4
+ * Learn more about writing NEAR smart contracts with AssemblyScript:
5
+ * https://near-docs.io/develop/welcome
6
+ *
7
+ */
8
+
9
+ import { logging, storage } from 'near-sdk-as'
10
+
11
+ const DEFAULT_MESSAGE = 'Hello'
12
+
13
+ // Public method - returns the greeting saved, defaulting to DEFAULT_MESSAGE
14
+ export function get_greeting(): string {
15
+ return storage.getPrimitive<string>('message', DEFAULT_MESSAGE)
16
+ }
17
+
18
+ // Public method - accepts a greeting, such as 'howdy', and records it
19
+ export function set_greeting(message: string): void {
20
+ // Use logging.log to record logs permanently to the blockchain!
21
+ logging.log(`Saving greeting '${message}'`)
22
+ storage.set<string>('message', message)
23
+ }
@@ -1,17 +1,13 @@
1
1
  {
2
2
  "name": "greeter",
3
- "version": "0.0.1",
3
+ "version": "1.0.0",
4
4
  "license": "UNLICENSED",
5
5
  "private": true,
6
6
  "scripts": {
7
7
  "build": "asb",
8
- "build:debug": "asb --target debug",
9
8
  "test": "asp --nologo"
10
9
  },
11
10
  "dependencies": {
12
- "near-sdk-as": "3.1.0"
13
- },
14
- "devDependencies": {
15
- "shelljs": "^0.8.4"
11
+ "near-sdk-as": "^3.2.3"
16
12
  }
17
13
  }
@@ -1,23 +1,22 @@
1
1
  [package]
2
2
  name = "greeter"
3
- version = "0.1.0"
3
+ version = "1.0.0"
4
4
  authors = ["Near Inc <hello@near.org>"]
5
- edition = "2018"
5
+ edition = "2021"
6
6
 
7
7
  [lib]
8
8
  crate-type = ["cdylib", "rlib"]
9
9
 
10
10
  [dependencies]
11
- near-sdk = "3.1.0"
11
+ near-sdk = "4.0.0"
12
+ uint = { version = "0.9.3", default-features = false }
12
13
 
13
14
  [profile.release]
14
15
  codegen-units = 1
15
- # Tell `rustc` to optimize for small code size.
16
16
  opt-level = "z"
17
17
  lto = true
18
18
  debug = false
19
19
  panic = "abort"
20
- # Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801
21
20
  overflow-checks = true
22
21
 
23
22
  [workspace]
@@ -13,8 +13,7 @@ Before you compile this code, you will need to install Rust with [correct target
13
13
  Exploring The Code
14
14
  ==================
15
15
 
16
- 1. The main smart contract code lives in `src/lib.rs`. You can compile it with
17
- the `./compile` script.
16
+ 1. The main smart contract code lives in `src/lib.rs`.
18
17
  2. Tests: You can run smart contract tests with the `./test` script. This runs
19
18
  standard Rust tests using [cargo] with a `--nocapture` flag so that you
20
19
  can see any debug info you print to the console.
@@ -0,0 +1,72 @@
1
+ /*
2
+ * Example smart contract written in RUST
3
+ *
4
+ * Learn more about writing NEAR smart contracts with Rust:
5
+ * https://near-docs.io/develop/Contract
6
+ *
7
+ */
8
+
9
+ use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
10
+ use near_sdk::{log, near_bindgen};
11
+
12
+ // Define the default message
13
+ const DEFAULT_MESSAGE: &str = "Hello";
14
+
15
+ // Define the contract structure
16
+ #[near_bindgen]
17
+ #[derive(BorshDeserialize, BorshSerialize)]
18
+ pub struct Contract {
19
+ message: String,
20
+ }
21
+
22
+ // Define the default, which automatically initializes the contract
23
+ impl Default for Contract{
24
+ fn default() -> Self{
25
+ Self{message: DEFAULT_MESSAGE.to_string()}
26
+ }
27
+ }
28
+
29
+ // Implement the contract structure
30
+ #[near_bindgen]
31
+ impl Contract {
32
+ // Public method - returns the greeting saved, defaulting to DEFAULT_MESSAGE
33
+ pub fn get_greeting(&self) -> String {
34
+ return self.message.clone();
35
+ }
36
+
37
+ // Public method - accepts a greeting, such as "howdy", and records it
38
+ pub fn set_greeting(&mut self, message: String) {
39
+ // Use env::log to record logs permanently to the blockchain!
40
+ log!("Saving greeting {}", message);
41
+ self.message = message;
42
+ }
43
+ }
44
+
45
+ /*
46
+ * The rest of this file holds the inline tests for the code above
47
+ * Learn more about Rust tests: https://doc.rust-lang.org/book/ch11-01-writing-tests.html
48
+ */
49
+ #[cfg(test)]
50
+ mod tests {
51
+ use super::*;
52
+
53
+ #[test]
54
+ fn get_default_greeting() {
55
+ let contract = Contract::default();
56
+ // this test did not call set_greeting so should return the default "Hello" greeting
57
+ assert_eq!(
58
+ contract.get_greeting(),
59
+ "Hello".to_string()
60
+ );
61
+ }
62
+
63
+ #[test]
64
+ fn set_then_get_greeting() {
65
+ let mut contract = Contract::default();
66
+ contract.set_greeting("howdy".to_string());
67
+ assert_eq!(
68
+ contract.get_greeting(),
69
+ "howdy".to_string()
70
+ );
71
+ }
72
+ }
package/index.js CHANGED
@@ -1,26 +1,26 @@
1
1
  #!/usr/bin/env node
2
+ const fs = require('fs')
3
+ const os = require('os')
4
+ const path = require('path')
2
5
  const yargs = require('yargs')
3
- const { basename, resolve } = require('path')
6
+
4
7
  const replaceInFiles = require('replace-in-files')
5
- const ncp = require('ncp').ncp
6
- ncp.limit = 16
7
- const fs = require('fs')
8
8
  const spawn = require('cross-spawn')
9
9
  const chalk = require('chalk')
10
10
  const which = require('which')
11
- const sh = require('shelljs')
12
- const path = require('path')
11
+ const ncp = require('ncp').ncp
12
+ ncp.limit = 16
13
+
13
14
  const rustSetup = require('./utils/rust-setup')
14
- const mixpanel =require('./utils/tracking')
15
+ const mixpanel = require('./utils/tracking')
15
16
 
16
- const renameFile = async function(oldPath, newPath) {
17
+ const renameFile = async function (oldPath, newPath) {
17
18
  return new Promise((resolve, reject) => {
18
19
  fs.rename(oldPath, newPath, (err) => {
19
20
  if (err) {
20
21
  console.error(err)
21
22
  return reject(err)
22
23
  }
23
- console.log(`Renamed ${oldPath} to ${newPath}`)
24
24
  resolve()
25
25
  })
26
26
  })
@@ -28,7 +28,7 @@ const renameFile = async function(oldPath, newPath) {
28
28
 
29
29
  // Wrap `ncp` tool to wait for the copy to finish when using `await`
30
30
  // Allow passing `skip` variable to skip copying an array of filenames
31
- function copyDir (source, dest, { skip, veryVerbose } = {}) {
31
+ function copyDir(source, dest, { skip, veryVerbose } = {}) {
32
32
  return new Promise((resolve, reject) => {
33
33
  const copied = []
34
34
  const skipped = []
@@ -53,69 +53,50 @@ function copyDir (source, dest, { skip, veryVerbose } = {}) {
53
53
  })
54
54
  }
55
55
 
56
- const createProject = async function({ contract, frontend, projectDir, veryVerbose }) {
57
- if (frontend === 'angular') {
58
- console.log(chalk`{yellow Angular frontend is deprecated. You can choose vanilla, react or vue.}`)
56
+ const createProject = async function ({ contract, frontend, projectDir, veryVerbose }) {
57
+ if (os.platform() === 'win32') {
58
+ console.log('Sorry, create-near-app is not compatible with Windows. Please consider using Windows Subsystem for Linux.\n')
59
+ return
59
60
  }
60
- const templateDir = `/templates/${frontend}`
61
- const sourceTemplateDir = __dirname + templateDir
61
+ // track used options
62
62
  mixpanel.track(frontend, contract)
63
63
 
64
- console.log(`Copying files to new project directory (${projectDir}) from template source (${sourceTemplateDir}).`)
65
-
66
- await copyDir(sourceTemplateDir, projectDir, { veryVerbose, skip: [
67
- // our frontend templates are set up with symlinks for easy development,
68
- // developing right in these directories also results in build artifacts;
69
- // we don't want to copy these
70
- path.join(sourceTemplateDir, '.cache'),
71
- path.join(sourceTemplateDir, 'dist'),
72
- path.join(sourceTemplateDir, 'out'),
73
- path.join(sourceTemplateDir, 'node_modules'),
74
- path.join(sourceTemplateDir, 'yarn.lock'),
75
- path.join(sourceTemplateDir, 'package-lock.json'),
76
- path.join(sourceTemplateDir, 'contract'),
77
- ...sh.ls(`${__dirname}/common/frontend`).map(f => path.join('src', f))
78
- ]})
79
-
80
-
81
- // copy common files
82
- await copyDir(`${__dirname}/common/frontend`, `${projectDir}/src`)
83
- const contractSourceDir = `${__dirname}/common/contracts/${contract}`
84
- await copyDir(contractSourceDir, `${projectDir}/contract`, { veryVerbose, skip: [
85
- // as above, skip rapid-development build artifacts
86
- path.join(contractSourceDir, 'node_modules'),
87
- path.join(contractSourceDir, 'yarn.lock'),
88
- path.join(contractSourceDir, 'package-lock.json'),
89
- ]})
90
-
91
- // update package name
92
- let projectName = basename(resolve(projectDir))
93
- await replaceInFiles({
94
- files: [
95
- // NOTE: These can use globs if necessary later
96
- `${projectDir}/README.md`,
97
- `${projectDir}/package.json`,
98
- `${projectDir}/contract/README.md`,
99
- `${projectDir}/src/config.js`,
100
- `${projectDir}/src/App.vue`,
101
- `${projectDir}/angular.json`,
102
- `${projectDir}/karma.conf.js`,
103
- `${projectDir}/set-contract-name.js`,
104
- ],
105
- from: /near-blank-project/g,
106
- to: projectName
107
- })
64
+ console.log(chalk`Creating {bold ${projectDir}} with a contract in {bold ${contract}}, and a frontend using {bold ${frontend} js}.`)
65
+ console.log('Remember that you can change these settings using the --frontend and --contract flags. \n')
66
+
67
+ // skip rapid-development build artifacts and symlinks
68
+ const skip = ['.cache', 'dist', 'out', 'node_modules', 'yarn.lock', 'package-lock.json', 'contract', 'integration-tests']
69
+
70
+ // copy frontend
71
+ const sourceTemplateDir = __dirname + `/templates/${frontend}`
72
+ await copyDir(sourceTemplateDir, projectDir, { veryVerbose, skip: skip.map(f => path.join(sourceTemplateDir, f)) })
73
+
74
+ // copy tests
75
+ const sourceTestDir = __dirname + '/integration-tests'
76
+ await copyDir(sourceTestDir, `${projectDir}/integration-tests`, { veryVerbose, skip: skip.map(f => path.join(sourceTestDir, f)) })
77
+
78
+ // copy contract files
79
+ const contractSourceDir = `${__dirname}/contracts/${contract}`
80
+ await copyDir(contractSourceDir, `${projectDir}/contract`, { veryVerbose, skip: skip.map(f => path.join(contractSourceDir, f)) })
108
81
 
82
+ // changes in package.json for rust
109
83
  if (contract === 'rust') {
110
- await replaceInFiles({ files: `${projectDir}/src/**/*`, from: /getGreeting/g, to: 'get_greeting' })
111
- await replaceInFiles({ files: `${projectDir}/src/**/*`, from: /setGreeting/g, to: 'set_greeting' })
112
- await replaceInFiles({ files: `${projectDir}/src/**/*`, from: /{ accountId:/g, to: '{ account_id:' })
113
- await replaceInFiles({ files: `${projectDir}/package.json`, from: 'cd contract && npm run test', to: 'cd contract && cargo test -- --nocapture' })
114
- await replaceInFiles({ files: `${projectDir}/package.json`, from: 'watch contract -e ts', to: 'watch contract/src -e rs' })
84
+ await replaceInFiles({
85
+ files: `${projectDir}/package.json`,
86
+ from: 'cd contract && npm run build && mkdir -p ../out && rm -f ./out/main.wasm && cp ./build/release/greeter.wasm ../out/main.wasm',
87
+ to: 'mkdir -p out && cd contract && rustup target add wasm32-unknown-unknown && cargo build --all --target wasm32-unknown-unknown --release && rm -f ./out/main.wasm && cp ./target/wasm32-unknown-unknown/release/greeter.wasm ../out/main.wasm'
88
+ })
89
+ await replaceInFiles({
90
+ files: `${projectDir}/package.json`,
91
+ from: '"test:unit": "cd contract && npm i && npm run test"',
92
+ to: '"test:unit": "cd contract && cargo test"'
93
+ })
115
94
  }
116
95
 
96
+ // add .gitignore
117
97
  await renameFile(`${projectDir}/near.gitignore`, `${projectDir}/.gitignore`)
118
- console.log('Copying project files complete.\n')
98
+
99
+ console.log('Project created! Lets set it up.\n')
119
100
 
120
101
  const hasNpm = which.sync('npm', { nothrow: true })
121
102
  const hasYarn = which.sync('yarn', { nothrow: true })
@@ -141,6 +122,7 @@ const createProject = async function({ contract, frontend, projectDir, veryVerbo
141
122
 
142
123
  const runCommand = hasYarn ? 'yarn' : 'npm run'
143
124
 
125
+ // print success message
144
126
  console.log(chalk`
145
127
  Success! Created ${projectDir}
146
128
  Inside that directory, you can run several commands:
@@ -152,11 +134,6 @@ Inside that directory, you can run several commands:
152
134
  {bold ${runCommand} test}
153
135
  Starts the test runner.
154
136
 
155
- {bold ${runCommand} deploy}
156
- Deploys contract in permanent location (as configured in {bold src/config.js}).
157
- Also deploys web frontend using GitHub Pages.
158
- Consult with {bold README.md} for details on how to deploy and {bold package.json} for full list of commands.
159
-
160
137
  We suggest that you begin by typing:`)
161
138
 
162
139
  if (wasRustupInstalled) {
@@ -177,17 +154,17 @@ Happy hacking!`)
177
154
  const opts = yargs
178
155
  .strict()
179
156
  .usage('$0 <projectDir>', 'Create a new NEAR project')
180
- // BUG: does not work; https://github.com/yargs/yargs/issues/1331
157
+ // BUG: does not work; https://github.com/yargs/yargs/issues/1331
181
158
  .example('$0 new-app', 'Create a project called "new-app"')
182
159
  .option('frontend', {
183
160
  desc: 'template to use',
184
- choices: ['vanilla', 'react', 'vue', 'angular'],
161
+ choices: ['vanilla', 'react'],
185
162
  default: 'vanilla',
186
163
  })
187
164
  .option('contract', {
188
165
  desc: 'language for smart contract',
189
166
  choices: ['assemblyscript', 'rust'],
190
- default: 'assemblyscript'
167
+ default: 'rust'
191
168
  })
192
169
  .option('very-verbose', {
193
170
  desc: 'turn on very verbose logging',
@@ -0,0 +1,22 @@
1
+ [package]
2
+ name = "integration-tests"
3
+ version = "1.0.0"
4
+ publish = false
5
+ edition = "2018"
6
+
7
+ [dev-dependencies]
8
+ anyhow = "1.0"
9
+ borsh = "0.9"
10
+ maplit = "1.0"
11
+ near-units = "0.2.0"
12
+ # arbitrary_precision enabled for u128 types that workspaces requires for Balance types
13
+ serde_json = { version = "1.0", features = ["arbitrary_precision"] }
14
+ tokio = { version = "1.18.1", features = ["full"] }
15
+ tracing = "0.1"
16
+ tracing-subscriber = { version = "0.3.11", features = ["env-filter"] }
17
+ workspaces = "0.2.1"
18
+ pkg-config = "0.3.1"
19
+
20
+ [[example]]
21
+ name = "integration-tests"
22
+ path = "src/tests.rs"
@@ -0,0 +1,66 @@
1
+ use near_units::parse_near;
2
+ use serde_json::json;
3
+ use workspaces::prelude::*;
4
+ use workspaces::{network::Sandbox, Account, Contract, Worker};
5
+
6
+ const WASM_FILEPATH: &str = "../../out/main.wasm";
7
+
8
+ #[tokio::main]
9
+ async fn main() -> anyhow::Result<()> {
10
+ let worker = workspaces::sandbox().await?;
11
+ let wasm = std::fs::read(WASM_FILEPATH)?;
12
+ let contract = worker.dev_deploy(&wasm).await?;
13
+
14
+ // create accounts
15
+ let owner = worker.root_account();
16
+ let alice = owner
17
+ .create_subaccount(&worker, "alice")
18
+ .initial_balance(parse_near!("30 N"))
19
+ .transact()
20
+ .await?
21
+ .into_result()?;
22
+
23
+ // begin tests
24
+ test_default_message(&alice, &contract, &worker).await?;
25
+ test_changes_message(&alice, &contract, &worker).await?;
26
+ Ok(())
27
+ }
28
+
29
+ async fn test_default_message(
30
+ user: &Account,
31
+ contract: &Contract,
32
+ worker: &Worker<Sandbox>,
33
+ ) -> anyhow::Result<()> {
34
+ let message: String = user
35
+ .call(&worker, contract.id(), "get_greeting")
36
+ .args_json(json!({}))?
37
+ .transact()
38
+ .await?
39
+ .json()?;
40
+
41
+ assert_eq!(message, "Hello".to_string());
42
+ println!(" Passed ✅ gets default message");
43
+ Ok(())
44
+ }
45
+
46
+ async fn test_changes_message(
47
+ user: &Account,
48
+ contract: &Contract,
49
+ worker: &Worker<Sandbox>,
50
+ ) -> anyhow::Result<()> {
51
+ user.call(&worker, contract.id(), "set_greeting")
52
+ .args_json(json!({"message": "Howdy"}))?
53
+ .transact()
54
+ .await?;
55
+
56
+ let message: String = user
57
+ .call(&worker, contract.id(), "get_greeting")
58
+ .args_json(json!({}))?
59
+ .transact()
60
+ .await?
61
+ .json()?;
62
+
63
+ assert_eq!(message, "Howdy".to_string());
64
+ println!(" Passed ✅ changes message");
65
+ Ok(())
66
+ }
@@ -0,0 +1,9 @@
1
+ require("util").inspect.defaultOptions.depth = 5; // Increase AVA's printing depth
2
+
3
+ module.exports = {
4
+ timeout: "300000",
5
+ files: ["src/*.ava.ts"],
6
+ failWithoutAssertions: false,
7
+ extensions: ["ts"],
8
+ require: ["ts-node/register"],
9
+ };
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "ava-testing",
3
+ "version": "1.0.0",
4
+ "license": "(MIT AND Apache-2.0)",
5
+ "scripts": {
6
+ "test": "ava --verbose"
7
+ },
8
+ "devDependencies": {
9
+ "ava": "^4.2.0",
10
+ "near-workspaces": "^2.0.0",
11
+ "typescript": "^4.7.2",
12
+ "ts-node": "^10.8.0",
13
+ "@types/bn.js": "^5.1.0"
14
+ },
15
+ "dependencies": {}
16
+ }
@@ -0,0 +1,44 @@
1
+ import { Worker, NEAR, NearAccount } from 'near-workspaces'
2
+ import anyTest, { TestFn } from 'ava'
3
+
4
+ const test = anyTest as TestFn<{
5
+ worker: Worker;
6
+ accounts: Record<string, NearAccount>;
7
+ }>
8
+
9
+ test.beforeEach(async (t) => {
10
+ // Init the worker and start a Sandbox server
11
+ const worker = await Worker.init()
12
+
13
+ // deploy contract
14
+ const root = worker.rootAccount
15
+ const contract = await root.createAndDeploy(
16
+ root.getSubAccount('greeter').accountId,
17
+ './out/main.wasm',
18
+ { initialBalance: NEAR.parse('30 N').toJSON() }
19
+ )
20
+
21
+ // Save state for test runs, it is unique for each test
22
+ t.context.worker = worker
23
+ t.context.accounts = { root, contract }
24
+ })
25
+
26
+ test.afterEach(async (t) => {
27
+ // Stop Sandbox server
28
+ await t.context.worker.tearDown().catch((error) => {
29
+ console.log('Failed to stop the Sandbox:', error)
30
+ })
31
+ })
32
+
33
+ test('returns the default greeting', async (t) => {
34
+ const { contract } = t.context.accounts
35
+ const message: string = await contract.view('get_greeting', {})
36
+ t.is(message, 'Hello')
37
+ })
38
+
39
+ test('changes the message', async (t) => {
40
+ const { root, contract } = t.context.accounts
41
+ await root.call(contract, 'set_greeting', { message: 'Howdy' })
42
+ const message: string = await contract.view('get_greeting', {})
43
+ t.is(message, 'Howdy')
44
+ })
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "create-near-app",
3
- "version": "2.0.1",
3
+ "version": "3.0.0-pre.7.0",
4
4
  "description": "generate new near blank project with different type",
5
5
  "main": "index.js",
6
6
  "files": [
7
- "common",
7
+ "contracts",
8
8
  "templates",
9
- "utils"
9
+ "utils",
10
+ "integration-tests"
10
11
  ],
11
12
  "scripts": {
12
13
  "test": "node ./test/test-new-project.js",
@@ -23,7 +24,6 @@
23
24
  "assemblyscript",
24
25
  "rust",
25
26
  "react",
26
- "angular",
27
27
  "smart-contract",
28
28
  "blockchain"
29
29
  ],
@@ -32,37 +32,36 @@
32
32
  "create-near-app": "index.js"
33
33
  },
34
34
  "dependencies": {
35
- "chalk": "^4.0.0",
36
- "cross-spawn": "^7.0.1",
37
- "mixpanel": "^0.13.0",
35
+ "chalk": "^4.1.2",
36
+ "cross-spawn": "^7.0.3",
37
+ "mixpanel": "^0.15.0",
38
38
  "ncp": "^2.0.0",
39
- "os": "^0.1.1",
39
+ "os": "^0.1.2",
40
40
  "replace-in-files": "^3.0.0",
41
- "shelljs": "^0.8.3",
41
+ "shelljs": "^0.8.5",
42
42
  "which": "^2.0.2",
43
- "yargs": "^17.0.1"
43
+ "yargs": "^17.5.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@commitlint/cli": "^12.0.0",
47
- "@commitlint/config-conventional": "^12.0.0",
48
- "@release-it/conventional-changelog": "^2.0.0",
49
- "@typescript-eslint/eslint-plugin": "^4.6.1",
50
- "@typescript-eslint/parser": "^4.6.1",
46
+ "@commitlint/cli": "^17.0.1",
47
+ "@commitlint/config-conventional": "^17.0.0",
48
+ "@release-it/conventional-changelog": "^5.0.0",
49
+ "@typescript-eslint/eslint-plugin": "^5.26.0",
50
+ "@typescript-eslint/parser": "^5.26.0",
51
51
  "babel-eslint": "10.x",
52
- "eslint": "7.20.0",
53
- "eslint-config-react-app": "^6.0.0",
54
- "eslint-plugin-flowtype": "5.7.2",
52
+ "eslint": "8.16.0",
53
+ "eslint-config-react-app": "^7.0.1",
54
+ "eslint-plugin-flowtype": "8.0.3",
55
55
  "eslint-plugin-import": "2.x",
56
56
  "eslint-plugin-jsx-a11y": "6.x",
57
57
  "eslint-plugin-react": "7.x",
58
- "eslint-plugin-react-hooks": "4.2.0",
59
- "eslint-plugin-vue": "^7.0.0",
60
- "husky": "^6.0.0",
61
- "release-it": "^14.0.1",
62
- "typescript": "^4.0.2"
58
+ "eslint-plugin-react-hooks": "4.5.0",
59
+ "husky": "^8.0.1",
60
+ "release-it": "^15.0.0",
61
+ "typescript": "^4.7.2"
63
62
  },
64
63
  "engines": {
65
- "node": ">=12"
64
+ "node": ">=16"
66
65
  },
67
66
  "husky": {
68
67
  "hooks": {
@@ -24,8 +24,8 @@ Exploring The Code
24
24
 
25
25
  1. The "backend" code lives in the `/contract` folder. See the README there for
26
26
  more info.
27
- 2. The frontend code lives in the `/src` folder. `/src/index.html` is a great
28
- place to start exploring. Note that it loads in `/src/index.js`, where you
27
+ 2. The frontend code lives in the `/frontend` folder. `/frontend/index.html` is a great
28
+ place to start exploring. Note that it loads in `/frontend/assets/js/index.js`, where you
29
29
  can learn how the frontend connects to the NEAR blockchain.
30
30
  3. Tests: there are different kinds of tests for the frontend and the smart
31
31
  contract. See `contract/README` for info about how it's tested. The frontend
@@ -0,0 +1,9 @@
1
+ require("util").inspect.defaultOptions.depth = 5; // Increase AVA's printing depth
2
+
3
+ module.exports = {
4
+ timeout: "300000",
5
+ files: ["**/*.ava.ts"],
6
+ failWithoutAssertions: false,
7
+ extensions: ["ts"],
8
+ require: ["ts-node/register"],
9
+ };