-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from near/feat-issue-390/update-template
Feat issue 390/update template
- Loading branch information
Showing
6 changed files
with
150 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
.near-credentials/workspaces/testnet/templateprojectmaster.testnet.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"account_id":"","public_key":"","private_key":""} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Worker } from 'near-workspaces'; | ||
import test from 'ava'; | ||
import process from "process"; | ||
|
||
test.beforeEach(async t => { | ||
// Init the worker and start a Sandbox server | ||
const worker = await Worker.init({network: 'testnet'}); | ||
|
||
// Prepare sandbox for tests, create accounts, deploy contracts, etc. | ||
const root = worker.rootAccount; | ||
// Deploy the clean-state contract. | ||
const counter = await root.devDeploy('./build/contract.wasm', {initialBalance: "6 N"}); | ||
|
||
// Test users | ||
const ali = await root.createSubAccount('ali', {initialBalance : "1 N"}); | ||
const bob = await root.createSubAccount('bob', {initialBalance : "1 N"}); | ||
|
||
// Save state for test runs | ||
t.context.worker = worker; | ||
t.context.accounts = { root, counter, ali, bob }; | ||
}); | ||
|
||
// If the environment is reused, use test.after to replace test.afterEach | ||
test.afterEach(async t => { | ||
const { root, counter, ali, bob } = t.context.accounts; | ||
const masterAcc = process.env.TESTNET_MASTER_ACCOUNT_ID; | ||
await root.delete(masterAcc); | ||
await counter.delete(masterAcc); | ||
await ali.delete(masterAcc); | ||
await bob.delete(masterAcc); | ||
await t.context.worker.tearDown().catch(error => { | ||
console.log('Failed to tear down the worker:', error); | ||
}); | ||
}); | ||
|
||
test('Initial count is 0, Increase works, Decrease works', async t => { | ||
const { counter, ali, bob } = t.context.accounts; | ||
let result = await counter.view('getCount', {}); | ||
t.is(result, 0); | ||
|
||
await ali.call(counter, 'increase', {}); | ||
|
||
result = await counter.view('getCount', {}); | ||
t.is(result, 1); | ||
|
||
await bob.call(counter, 'increase', { n: 4 }); | ||
result = await counter.view('getCount', {}); | ||
t.is(result, 5); | ||
|
||
await ali.call(counter, 'decrease', {}); | ||
|
||
result = await counter.view('getCount', {}); | ||
t.is(result, 4); | ||
|
||
await bob.call(counter, 'decrease', { n: 5 }); | ||
result = await counter.view('getCount', {}); | ||
t.is(result, -1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,13 @@ | |
"type": "module", | ||
"scripts": { | ||
"build": "near-sdk-js build", | ||
"test": "ava" | ||
"test": "yarn test:template && yarn test:testnetdeploy", | ||
"test:template": "ava ./__tests__/test-template.ava.js", | ||
"test:testnetdeploy": "ava ./__tests__/test-testnet-dev-deploy.ava.js", | ||
"testci": "yarn testci:template && yarn testci:testnetdeploy", | ||
"testci:template": "ava ./__tests__/test-template.ava.js", | ||
"testci:testnetdeploy": "TESTNET_MASTER_ACCOUNT_ID='templateprojectmaster.testnet' ava ./__tests__/test-testnet-dev-deploy.ava.js", | ||
"test:clidevdeploy": "bash scripts/near_cli_deploy.sh" | ||
}, | ||
"author": "Near Inc <[email protected]>", | ||
"license": "Apache-2.0", | ||
|
@@ -16,6 +22,7 @@ | |
}, | ||
"devDependencies": { | ||
"ava": "^4.2.0", | ||
"near-workspaces": "^3.3.0" | ||
"near-workspaces": "^3.3.0", | ||
"near-cli": "^4.0.13" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# generate random account | ||
uuid=$(uuidgen | tr 'A-Z' 'a-z') | ||
CONTRACT="devcontract-"${uuid:0:10}".testnet" | ||
echo $CONTRACT | ||
USER="devuser-"${uuid:0:10}".testnet" | ||
echo $USER | ||
BENEFICIARY="templateprojectmaster.testnet" | ||
|
||
near create-account $CONTRACT --useFaucet | ||
near deploy $CONTRACT ./build/contract.wasm | ||
near create-account $USER --useFaucet | ||
near view $CONTRACT getCount '' | ||
near call $CONTRACT increase '{ "n": 1 }' --accountId $USER | ||
near view $CONTRACT getCount '' | ||
near call $CONTRACT decrease '{ "n": 2 }' --accountId $USER | ||
near view $CONTRACT getCount '' | ||
|
||
echo y | near delete $CONTRACT $BENEFICIARY | ||
echo y | near delete $USER $BENEFICIARY |