Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status examples merged #76

Merged
merged 1 commit into from
Jun 2, 2022
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
2 changes: 0 additions & 2 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ jobs:
run: cd examples/non-fungible-token && yarn && yarn build && yarn test && rm -rf node_modules && rm -rf build && cd ../..
- name: status-message
run: cd examples/status-message && yarn && yarn build && yarn test && rm -rf node_modules && rm -rf build && cd ../..
- name: status-message-collections
run: cd examples/status-message-collections && yarn && yarn build && yarn test && rm -rf node_modules && rm -rf build && cd ../..
- name: clean-state
run: cd examples/clean-state && yarn && yarn build && yarn test && rm -rf node_modules && rm -rf build && cd ../..
- name: template
Expand Down
2 changes: 0 additions & 2 deletions examples/status-message-collections/.gitignore

This file was deleted.

18 changes: 0 additions & 18 deletions examples/status-message-collections/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions examples/status-message-collections/ava.config.cjs

This file was deleted.

6 changes: 0 additions & 6 deletions examples/status-message-collections/babel.config.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/status-message-collections/package.json

This file was deleted.

10 changes: 4 additions & 6 deletions examples/status-message/README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Status message contract in JavaScript

This is an equivalent JavaScript implementation of the status message example. Every user can store a message on chain. Every user can view everyone's message.
This is an equivalent JavaScript implementation of the status message example. Every user can store a message on chain. Every user can view everyone's message. Logic is implemented two times with the use of collections and without them.

## Build the contract

First ensure JSVM contract is build and deployed locally, follow [Local Installation](https://github.com/near/near-sdk-js#local-installation). Then run:
```
npm i
npm run build
```

Result contract bytecode file will be in `build/status-message.base64`. Intermediate JavaScript file can be found in `build/status-message.js`. You'll only need the `base64` file to deploy contract to chain. The intermediate JavaScript file is for curious user and near-sdk-js developers to understand what code generation happened under the hood.
Result contract bytecode files will be stored in `build/status-message.base64` and `build/status-message-collections.base64`. Intermediate JavaScript file can be found in `build/` folder. You'll only need the `base64` file to deploy contract to chain. The intermediate JavaScript file is for curious user and near-sdk-js developers to understand what code generation happened under the hood.

## Test the contract with workspaces-js
## Test the contracts with workspaces-js
```
npm run test
```
Expand Down Expand Up @@ -75,4 +73,4 @@ near js view status-message.test.near get_status --args '["alice.test.near"]' --
near call jsvm.test.near call_js_contract --accountId bob.test.near --base64 --args $(node encode_call.js status-message.test.near get_status '["alice.test.near"]')

</p>
</details>
</details>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test.beforeEach(async t => {

// Deploy status-message JS contract
const statusMessage = await root.createSubAccount('status-message');
let contract_base64 = (await readFile('build/contract.base64')).toString();
let contract_base64 = (await readFile('build/status-message-collections.base64')).toString();
await statusMessage.call(jsvm, 'deploy_js_contract', Buffer.from(contract_base64, 'base64'), {attachedDeposit: '400000000000000000000000'});
await statusMessage.call(jsvm, 'call_js_contract', encodeCall(statusMessage.accountId, 'init', []), {attachedDeposit: '400000000000000000000000'});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test.before(async t => {

// Deploy status-message JS contract
const statusMessage = await root.createSubAccount('status-message');
let contract_base64 = (await readFile('build/contract.base64')).toString();
let contract_base64 = (await readFile('build/status-message.base64')).toString();
await statusMessage.call(jsvm, 'deploy_js_contract', Buffer.from(contract_base64, 'base64'), {attachedDeposit: '400000000000000000000000'});
await statusMessage.call(jsvm, 'call_js_contract', encodeCall(statusMessage.accountId, 'init', []), {attachedDeposit: '400000000000000000000000'});

Expand Down
4 changes: 3 additions & 1 deletion examples/status-message/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"type": "module",
"scripts": {
"build": "near-sdk build",
"build": "yarn build:simple && yarn build:collections",
"build:simple": "near-sdk build src/status-message.js build/status-message.base64",
"build:collections": "near-sdk build src/status-message-collections.js build/status-message-collections.base64",
"test": "ava"
},
"author": "Near Inc <hello@nearprotocol.com>",
Expand Down
Loading