create-near-app 6.3.1 → 6.4.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.
- package/README.md +7 -7
- package/dist/app.js +1 -2
- package/dist/make.js +3 -25
- package/dist/messages.js +5 -9
- package/dist/tracking.js +1 -2
- package/dist/types.js +2 -3
- package/dist/user-input.js +9 -39
- package/package.json +1 -1
- package/templates/contracts/rs/Cargo.toml +17 -8
- package/templates/contracts/rs/README.md +23 -84
- package/templates/contracts/rs/rust-toolchain.toml +2 -2
- package/templates/contracts/rs/src/lib.rs +10 -17
- package/templates/contracts/rs/tests/test_basics.rs +32 -0
- package/templates/contracts/ts/README.md +15 -12
- package/templates/contracts/ts/ava.config.cjs +15 -0
- package/templates/contracts/ts/package.json +9 -5
- package/templates/{sandbox-tests/sandbox-ts/src → contracts/ts/sandbox-ts}/main.ava.ts +6 -7
- package/templates/contracts/ts/src/contract.ts +1 -1
- package/templates/contracts/ts/tsconfig.json +7 -2
- package/templates/frontend/next-app/README.md +10 -1
- package/templates/frontend/next-app/next.config.js +1 -1
- package/templates/frontend/next-app/package.json +16 -21
- package/templates/frontend/next-app/src/app/hello-components/page.js +9 -10
- package/templates/frontend/next-app/src/app/hello-near/page.js +18 -12
- package/templates/frontend/next-app/src/app/layout.js +25 -5
- package/templates/frontend/next-app/src/components/navigation.js +8 -7
- package/templates/frontend/next-app/src/components/vm-component.js +7 -8
- package/templates/frontend/next-app/src/config.js +8 -6
- package/templates/frontend/next-app/src/wallets/near-wallet.js +144 -0
- package/templates/frontend/next-page/README.md +10 -1
- package/templates/frontend/next-page/next.config.js +1 -1
- package/templates/frontend/next-page/package.json +10 -12
- package/templates/frontend/next-page/src/components/cards.js +1 -1
- package/templates/frontend/next-page/src/components/navigation.js +8 -6
- package/templates/frontend/next-page/src/components/vm-component.js +4 -5
- package/templates/frontend/next-page/src/config.js +8 -6
- package/templates/frontend/next-page/src/layout.js +22 -6
- package/templates/frontend/next-page/src/pages/_app.js +3 -3
- package/templates/frontend/next-page/src/pages/_document.js +2 -2
- package/templates/frontend/next-page/src/pages/hello-components/index.js +14 -15
- package/templates/frontend/next-page/src/pages/hello-near/index.js +23 -21
- package/templates/frontend/next-page/src/pages/index.js +4 -4
- package/templates/frontend/next-page/src/wallets/near-wallet.js +143 -0
- package/templates/frontend/next-page/yarn.lock +8439 -0
- package/templates/contracts/rs/.cargo/config +0 -2
- package/templates/contracts/rs/build.sh +0 -3
- package/templates/contracts/rs/deploy.sh +0 -2
- package/templates/contracts/rs/test-rs.sh +0 -9
- package/templates/contracts/rs/test-ts.sh +0 -10
- package/templates/contracts/ts/package-lock.json +0 -5966
- package/templates/frontend/next-app/src/wallets/wallet-selector.js +0 -120
- package/templates/frontend/next-page/package-lock.json +0 -14642
- package/templates/frontend/next-page/src/wallets/wallet-selector.js +0 -120
- package/templates/frontend/vanilla/.babelrc +0 -7
- package/templates/frontend/vanilla/.gitpod.yml +0 -6
- package/templates/frontend/vanilla/README.md +0 -100
- package/templates/frontend/vanilla/package.json +0 -43
- package/templates/frontend/vanilla/src/assets/favicon.ico +0 -0
- package/templates/frontend/vanilla/src/assets/global.css +0 -202
- package/templates/frontend/vanilla/src/assets/logo-black.svg +0 -1
- package/templates/frontend/vanilla/src/assets/logo-white.svg +0 -1
- package/templates/frontend/vanilla/src/components.html +0 -61
- package/templates/frontend/vanilla/src/components.js +0 -59
- package/templates/frontend/vanilla/src/hello-near.html +0 -80
- package/templates/frontend/vanilla/src/hello.js +0 -61
- package/templates/frontend/vanilla/src/index.html +0 -65
- package/templates/frontend/vanilla/src/near-wallet.js +0 -108
- package/templates/frontend/vanilla/webpack.config.js +0 -79
- package/templates/sandbox-tests/sandbox-rs/Cargo.toml +0 -14
- package/templates/sandbox-tests/sandbox-rs/src/tests.rs +0 -65
- package/templates/sandbox-tests/sandbox-ts/ava.config.cjs +0 -9
- package/templates/sandbox-tests/sandbox-ts/package-lock.json +0 -5014
- package/templates/sandbox-tests/sandbox-ts/package.json +0 -17
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<link rel="icon" href="assets/favicon.ico" />
|
|
8
|
-
<link href="assets/global.css" rel="stylesheet">
|
|
9
|
-
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
|
10
|
-
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
|
11
|
-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
|
|
12
|
-
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
|
|
13
|
-
crossorigin="anonymous"></script>
|
|
14
|
-
<title>Welcome to NEAR</title>
|
|
15
|
-
</head>
|
|
16
|
-
|
|
17
|
-
<body>
|
|
18
|
-
<nav class="navbar">
|
|
19
|
-
<div class="container-fluid navbar-expand-lg">
|
|
20
|
-
<a href="/"><img src="./assets/logo-black.svg" alt="Near" height="40" class="d-inline-block align-text-top" /></a>
|
|
21
|
-
<div class='navbar-nav pt-1'>
|
|
22
|
-
<button class="btn btn-secondary" id="sign-in-button"> Login </button>
|
|
23
|
-
<button class="btn btn-secondary" id="sign-out-button"> Logout <span data-behavior="account-id"></span></button>
|
|
24
|
-
</div>
|
|
25
|
-
</div>
|
|
26
|
-
</nav>
|
|
27
|
-
|
|
28
|
-
<div class="container">
|
|
29
|
-
|
|
30
|
-
<div class="alert alert-info mx-auto mt-3" role="alert">
|
|
31
|
-
Interacting with the contract: hello.near-examples.testnet
|
|
32
|
-
</div>
|
|
33
|
-
|
|
34
|
-
<div class="row my-5 pt-5 flex-1">
|
|
35
|
-
<div class="col-8">
|
|
36
|
-
<h1> The contract says: <span class="greeting" id="displayGreeting"></span> </h1>
|
|
37
|
-
</div>
|
|
38
|
-
<div class="col-4">
|
|
39
|
-
<div id="signed-out" class="small">
|
|
40
|
-
Please login to change the greeting
|
|
41
|
-
</div>
|
|
42
|
-
<div id="signed-in">
|
|
43
|
-
<form class="change">
|
|
44
|
-
<div className="input-group">
|
|
45
|
-
<input placeholder="Store a new greeting" id="greeting" />
|
|
46
|
-
<button class="btn btn-primary">
|
|
47
|
-
<span>Save</span>
|
|
48
|
-
<div class="loader"></div>
|
|
49
|
-
</button>
|
|
50
|
-
</div>
|
|
51
|
-
</form>
|
|
52
|
-
</div>
|
|
53
|
-
</div>
|
|
54
|
-
</div>
|
|
55
|
-
|
|
56
|
-
<div class="row pt-5">
|
|
57
|
-
<div class="col-6">
|
|
58
|
-
<a href="/components.html">
|
|
59
|
-
<h3>
|
|
60
|
-
Web3 Components <span>-></span>
|
|
61
|
-
</h3>
|
|
62
|
-
<p class="small">See how Web3 components can help you to create multi-chain apps.</p>
|
|
63
|
-
</a>
|
|
64
|
-
</div>
|
|
65
|
-
<div class="col-6">
|
|
66
|
-
<a href="https://docs.near.org/develop/integrate/quickstart-frontend" target="_blank">
|
|
67
|
-
<h3>
|
|
68
|
-
NEAR Docs <span>-></span>
|
|
69
|
-
</h3>
|
|
70
|
-
<p class="small">Learn how this application works, and what you can build on NEAR.</p>
|
|
71
|
-
</a>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
|
|
75
|
-
</div>
|
|
76
|
-
|
|
77
|
-
<script src="hello.js" type="module"></script>
|
|
78
|
-
</body>
|
|
79
|
-
|
|
80
|
-
</html>
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Wallet } from './near-wallet';
|
|
2
|
-
|
|
3
|
-
const HELLO_NEAR = 'hello.near-examples.testnet';
|
|
4
|
-
|
|
5
|
-
// When creating the wallet you can optionally ask to create an access key
|
|
6
|
-
// Having the key enables to call non-payable methods without interrupting the user to sign
|
|
7
|
-
const wallet = new Wallet({ network: 'testnet' });
|
|
8
|
-
|
|
9
|
-
// Setup on page load
|
|
10
|
-
window.onload = async () => {
|
|
11
|
-
let isSignedIn = await wallet.startUp();
|
|
12
|
-
isSignedIn ? signedInUI() : signedOutUI();
|
|
13
|
-
getGreeting();
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// Button clicks
|
|
17
|
-
document.querySelector('form').onsubmit = setGreeting;
|
|
18
|
-
document.querySelector('#sign-in-button').onclick = () => { wallet.signIn(); };
|
|
19
|
-
document.querySelector('#sign-out-button').onclick = () => { wallet.signOut(); };
|
|
20
|
-
|
|
21
|
-
async function setGreeting(event) {
|
|
22
|
-
event.preventDefault();
|
|
23
|
-
|
|
24
|
-
// handle UI
|
|
25
|
-
document.querySelector('#signed-in').classList.add('please-wait');
|
|
26
|
-
|
|
27
|
-
// use the wallet to send the greeting to the Smart Contract
|
|
28
|
-
const { greeting } = event.target.elements;
|
|
29
|
-
await wallet.callMethod({ method: 'set_greeting', args: { greeting: greeting.value }, contractId: HELLO_NEAR });
|
|
30
|
-
|
|
31
|
-
// query the new greeting
|
|
32
|
-
await getGreeting();
|
|
33
|
-
|
|
34
|
-
// handle UI
|
|
35
|
-
document.querySelector('#signed-in').classList.remove('please-wait');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function getGreeting() {
|
|
39
|
-
// use the wallet to query the Smart Contract
|
|
40
|
-
const currentGreeting = await wallet.viewMethod({ method: 'get_greeting', contractId: HELLO_NEAR });
|
|
41
|
-
|
|
42
|
-
// Display it
|
|
43
|
-
document.querySelector('#displayGreeting').innerText = currentGreeting;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// UI: Hide signed-in elements
|
|
47
|
-
function signedOutUI() { hide('#signed-in'); hide('#sign-out-button'); }
|
|
48
|
-
|
|
49
|
-
// UI: Hide signed-out elements
|
|
50
|
-
function signedInUI() {
|
|
51
|
-
hide('#signed-out');
|
|
52
|
-
hide('#sign-in-button');
|
|
53
|
-
|
|
54
|
-
document.querySelectorAll('[data-behavior=account-id]').forEach(el => {
|
|
55
|
-
el.innerText = wallet.accountId;
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function hide(id) {
|
|
60
|
-
document.querySelectorAll(id).forEach(el => el.style.display = 'none');
|
|
61
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
-
<link rel="icon" href="assets/favicon.ico" />
|
|
8
|
-
<link href="assets/global.css" rel="stylesheet">
|
|
9
|
-
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
|
|
10
|
-
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
|
11
|
-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
|
|
12
|
-
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
|
|
13
|
-
crossorigin="anonymous"></script>
|
|
14
|
-
<title>Welcome to NEAR</title>
|
|
15
|
-
</head>
|
|
16
|
-
|
|
17
|
-
<body>
|
|
18
|
-
<nav class="navbar">
|
|
19
|
-
<div class="container-fluid navbar-expand-lg">
|
|
20
|
-
<a href="/"><img src="./assets/logo-black.svg" alt="Near" height="40" class="d-inline-block align-text-top" /></a>
|
|
21
|
-
<div class='navbar-nav pt-1'>
|
|
22
|
-
</div>
|
|
23
|
-
</div>
|
|
24
|
-
</nav>
|
|
25
|
-
|
|
26
|
-
<div class="container">
|
|
27
|
-
|
|
28
|
-
<div class="alert alert-info mx-auto mt-3 text-left" role="alert">
|
|
29
|
-
For educational purposes only. To build production ready apps use the Next.js template.
|
|
30
|
-
</div>
|
|
31
|
-
|
|
32
|
-
<h1 class="mt-5 pt-5"> Welcome to Near </h1>
|
|
33
|
-
|
|
34
|
-
<div class="row pt-5 mt-5">
|
|
35
|
-
<div class="col-6">
|
|
36
|
-
<a href="/hello-near.html" className={styles.card} rel="noopener noreferrer">
|
|
37
|
-
<h3>
|
|
38
|
-
NEAR Integration <span>-></span>
|
|
39
|
-
</h3>
|
|
40
|
-
<p class="small">Discover how simple it is to interact with a NEAR smart contract.</p>
|
|
41
|
-
</a>
|
|
42
|
-
</div>
|
|
43
|
-
<div class="col-6">
|
|
44
|
-
<a href="/components.html">
|
|
45
|
-
<h3>
|
|
46
|
-
Web3 Components <span>-></span>
|
|
47
|
-
</h3>
|
|
48
|
-
<p class="small">See how Web3 components can help you to create multi-chain apps.</p>
|
|
49
|
-
</a>
|
|
50
|
-
</div>
|
|
51
|
-
<div class="col-6 mt-md-3">
|
|
52
|
-
<a href="https://docs.near.org/develop/integrate/quickstart-frontend" target="_blank">
|
|
53
|
-
<h3>
|
|
54
|
-
NEAR Docs <span>-></span>
|
|
55
|
-
</h3>
|
|
56
|
-
<p class="small">Learn how this application works, and what you can build on NEAR.</p>
|
|
57
|
-
</a>
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
|
|
61
|
-
</div>
|
|
62
|
-
|
|
63
|
-
</body>
|
|
64
|
-
|
|
65
|
-
</html>
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/* A helper file that simplifies using the wallet selector */
|
|
2
|
-
|
|
3
|
-
// near api js
|
|
4
|
-
import { providers } from 'near-api-js';
|
|
5
|
-
|
|
6
|
-
// wallet selector
|
|
7
|
-
import '@near-wallet-selector/modal-ui/styles.css';
|
|
8
|
-
import { setupModal } from '@near-wallet-selector/modal-ui';
|
|
9
|
-
import { setupWalletSelector } from '@near-wallet-selector/core';
|
|
10
|
-
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet';
|
|
11
|
-
|
|
12
|
-
const THIRTY_TGAS = '30000000000000';
|
|
13
|
-
const NO_DEPOSIT = '0';
|
|
14
|
-
|
|
15
|
-
// Wallet that simplifies using the wallet selector
|
|
16
|
-
export class Wallet {
|
|
17
|
-
selector;
|
|
18
|
-
wallet;
|
|
19
|
-
network;
|
|
20
|
-
createAccessKeyFor;
|
|
21
|
-
|
|
22
|
-
constructor({ createAccessKeyFor = undefined, network = 'mainnet' }) {
|
|
23
|
-
// Login to a wallet passing a contractId will create a local
|
|
24
|
-
// key, so the user skips signing non-payable transactions.
|
|
25
|
-
// Omitting the accountId will result in the user being
|
|
26
|
-
// asked to sign all transactions.
|
|
27
|
-
this.createAccessKeyFor = createAccessKeyFor;
|
|
28
|
-
this.network = network;
|
|
29
|
-
this.selector = setupWalletSelector({
|
|
30
|
-
network: this.network,
|
|
31
|
-
modules: [setupMyNearWallet()],
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// To be called when the website loads
|
|
36
|
-
async startUp() {
|
|
37
|
-
const walletSelector = await this.selector;
|
|
38
|
-
const isSignedIn = walletSelector.isSignedIn();
|
|
39
|
-
|
|
40
|
-
if (isSignedIn) {
|
|
41
|
-
this.wallet = await walletSelector.wallet();
|
|
42
|
-
this.accountId = walletSelector.store.getState().accounts[0].accountId;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return isSignedIn;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Sign-in method
|
|
49
|
-
async signIn() {
|
|
50
|
-
const description = 'Please select a wallet to sign in.';
|
|
51
|
-
const modal = setupModal(await this.selector, { contractId: this.createAccessKeyFor, description });
|
|
52
|
-
modal.show();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Sign-out method
|
|
56
|
-
async signOut() {
|
|
57
|
-
await this.wallet.signOut();
|
|
58
|
-
this.wallet = this.accountId = this.createAccessKeyFor = null;
|
|
59
|
-
window.location.replace(window.location.origin + window.location.pathname);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Make a read-only call to retrieve information from the network
|
|
63
|
-
async viewMethod({ contractId, method, args = {} }) {
|
|
64
|
-
const walletSelector = await this.selector;
|
|
65
|
-
const { network } = walletSelector.options;
|
|
66
|
-
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });
|
|
67
|
-
|
|
68
|
-
let res = await provider.query({
|
|
69
|
-
request_type: 'call_function',
|
|
70
|
-
account_id: contractId,
|
|
71
|
-
method_name: method,
|
|
72
|
-
args_base64: Buffer.from(JSON.stringify(args)).toString('base64'),
|
|
73
|
-
finality: 'optimistic',
|
|
74
|
-
});
|
|
75
|
-
return JSON.parse(Buffer.from(res.result).toString());
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Call a method that changes the contract's state
|
|
79
|
-
async callMethod({ contractId, method, args = {}, gas = THIRTY_TGAS, deposit = NO_DEPOSIT }) {
|
|
80
|
-
// Sign a transaction with the "FunctionCall" action
|
|
81
|
-
return await this.wallet.signAndSendTransaction({
|
|
82
|
-
signerId: this.accountId,
|
|
83
|
-
receiverId: contractId,
|
|
84
|
-
actions: [
|
|
85
|
-
{
|
|
86
|
-
type: 'FunctionCall',
|
|
87
|
-
params: {
|
|
88
|
-
methodName: method,
|
|
89
|
-
args,
|
|
90
|
-
gas,
|
|
91
|
-
deposit,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
],
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Get transaction result from the network
|
|
99
|
-
async getTransactionResult(txhash) {
|
|
100
|
-
const walletSelector = await this.selector;
|
|
101
|
-
const { network } = walletSelector.options;
|
|
102
|
-
const provider = new providers.JsonRpcProvider({ url: network.nodeUrl });
|
|
103
|
-
|
|
104
|
-
// Retrieve transaction result from the network
|
|
105
|
-
const transaction = await provider.txStatus(txhash, 'unnused');
|
|
106
|
-
return providers.getTransactionLastResult(transaction);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const webpack = require('webpack')
|
|
3
|
-
|
|
4
|
-
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
|
5
|
-
const CopyWebpackPlugin = require('copy-webpack-plugin');
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
mode: 'development',
|
|
9
|
-
entry: {
|
|
10
|
-
hello: './src/hello.js',
|
|
11
|
-
components: './src/components.js',
|
|
12
|
-
'near-wallet': './src/near-wallet.js',
|
|
13
|
-
},
|
|
14
|
-
devtool: 'inline-source-map',
|
|
15
|
-
devServer: {
|
|
16
|
-
static: './dist',
|
|
17
|
-
},
|
|
18
|
-
output: {
|
|
19
|
-
filename: '[name].js',
|
|
20
|
-
path: path.resolve(__dirname, 'dist'),
|
|
21
|
-
clean: true,
|
|
22
|
-
},
|
|
23
|
-
resolve: {
|
|
24
|
-
fallback: {
|
|
25
|
-
https: require.resolve("https-browserify"),
|
|
26
|
-
http: require.resolve("stream-http"),
|
|
27
|
-
crypto: require.resolve("crypto-browserify"),
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
module: {
|
|
31
|
-
rules: [
|
|
32
|
-
{
|
|
33
|
-
test: /\.(js)$/,
|
|
34
|
-
exclude: /node_modules/,
|
|
35
|
-
use: ['babel-loader']
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
test: /\.css$/i,
|
|
39
|
-
use: ['style-loader', 'css-loader'],
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
test: /\.(png|svg|jpg|jpeg|gif)$/i,
|
|
43
|
-
type: 'asset/resource',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
test: /\.m?js/,
|
|
47
|
-
resolve: {
|
|
48
|
-
fullySpecified: false
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
plugins: [
|
|
54
|
-
new CopyWebpackPlugin({
|
|
55
|
-
patterns: [{ from: 'src/assets', to: 'assets' }]
|
|
56
|
-
}),
|
|
57
|
-
new HtmlWebpackPlugin({
|
|
58
|
-
filename: 'index.html',
|
|
59
|
-
template: './src/index.html',
|
|
60
|
-
chunks: ['index'],
|
|
61
|
-
}),
|
|
62
|
-
new HtmlWebpackPlugin({
|
|
63
|
-
filename: 'hello-near.html',
|
|
64
|
-
template: './src/hello-near.html',
|
|
65
|
-
chunks: ['index'],
|
|
66
|
-
}),
|
|
67
|
-
new HtmlWebpackPlugin({
|
|
68
|
-
filename: 'components.html',
|
|
69
|
-
template: './src/components.html',
|
|
70
|
-
chunks: ['components'],
|
|
71
|
-
}),
|
|
72
|
-
new webpack.ProvidePlugin({
|
|
73
|
-
process: 'process/browser',
|
|
74
|
-
}),
|
|
75
|
-
new webpack.ProvidePlugin({
|
|
76
|
-
Buffer: ['buffer', 'Buffer'],
|
|
77
|
-
}),
|
|
78
|
-
]
|
|
79
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "sandbox"
|
|
3
|
-
version = "1.0.0"
|
|
4
|
-
publish = false
|
|
5
|
-
edition = "2021"
|
|
6
|
-
|
|
7
|
-
[dev-dependencies]
|
|
8
|
-
tokio = { version = "1.18.1", features = ["full"] }
|
|
9
|
-
near-workspaces = "0.9.0"
|
|
10
|
-
serde_json = { version = "1.0", features = ["arbitrary_precision"] }
|
|
11
|
-
|
|
12
|
-
[[example]]
|
|
13
|
-
name = "sandbox"
|
|
14
|
-
path = "src/tests.rs"
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
use near_workspaces::{types::NearToken, Account, Contract};
|
|
2
|
-
use serde_json::json;
|
|
3
|
-
use std::{env, fs};
|
|
4
|
-
|
|
5
|
-
#[tokio::main]
|
|
6
|
-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
7
|
-
let wasm_arg: &str = &(env::args().nth(1).unwrap());
|
|
8
|
-
let wasm_filepath = fs::canonicalize(env::current_dir()?.join(wasm_arg))?;
|
|
9
|
-
|
|
10
|
-
let worker = near_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 account = worker.dev_create_account().await?;
|
|
16
|
-
let alice = account
|
|
17
|
-
.create_subaccount("alice")
|
|
18
|
-
.initial_balance(NearToken::from_near(30))
|
|
19
|
-
.transact()
|
|
20
|
-
.await?
|
|
21
|
-
.into_result()?;
|
|
22
|
-
|
|
23
|
-
// begin tests
|
|
24
|
-
test_default_message(&alice, &contract).await?;
|
|
25
|
-
test_changes_message(&alice, &contract).await?;
|
|
26
|
-
Ok(())
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async fn test_default_message(
|
|
30
|
-
user: &Account,
|
|
31
|
-
contract: &Contract,
|
|
32
|
-
) -> Result<(), Box<dyn std::error::Error>> {
|
|
33
|
-
let greeting: String = user
|
|
34
|
-
.call(contract.id(), "get_greeting")
|
|
35
|
-
.args_json(json!({}))
|
|
36
|
-
.transact()
|
|
37
|
-
.await?
|
|
38
|
-
.json()?;
|
|
39
|
-
|
|
40
|
-
assert_eq!(greeting, "Hello".to_string());
|
|
41
|
-
println!(" Passed ✅ gets default greeting");
|
|
42
|
-
Ok(())
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async fn test_changes_message(
|
|
46
|
-
user: &Account,
|
|
47
|
-
contract: &Contract,
|
|
48
|
-
) -> Result<(), Box<dyn std::error::Error>> {
|
|
49
|
-
user.call(contract.id(), "set_greeting")
|
|
50
|
-
.args_json(json!({"greeting": "Howdy"}))
|
|
51
|
-
.transact()
|
|
52
|
-
.await?
|
|
53
|
-
.into_result()?;
|
|
54
|
-
|
|
55
|
-
let greeting: String = user
|
|
56
|
-
.call(contract.id(), "get_greeting")
|
|
57
|
-
.args_json(json!({}))
|
|
58
|
-
.transact()
|
|
59
|
-
.await?
|
|
60
|
-
.json()?;
|
|
61
|
-
|
|
62
|
-
assert_eq!(greeting, "Howdy".to_string());
|
|
63
|
-
println!(" Passed ✅ changes greeting");
|
|
64
|
-
Ok(())
|
|
65
|
-
}
|