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

feat: adding near-sandbox with new runner to start server #68

Closed
wants to merge 15 commits into from
200 changes: 197 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,8 @@
"description": "Compiles NEAR Protocol example of setting and retrieving a status message per NEAR account",
"scripts": {
"build": "cargo build --target wasm32-unknown-unknown --release",
"postbuild": "cp target/wasm32-unknown-unknown/release/status_message.wasm ./res/"
"postbuild": "cp target/wasm32-unknown-unknown/release/status_message.wasm ./res/",
"test": "node test.js"
},
"repository": {
"type": "git",
Expand All @@ -26,5 +27,7 @@
"borsh": "^0.4.0",
"near-api-js": "near/near-api-js#bace1ee"
},
"devDependencies": {}
"devDependencies": {
"near-sandbox": "^0.0.3"
}
}
7 changes: 6 additions & 1 deletion test.js
Expand Up @@ -2,6 +2,7 @@ const nearAPI = require("near-api-js");
const BN = require("bn.js");
const fs = require("fs").promises;
const assert = require("assert").strict;
const {runServer} = require("near-sandbox/runner")

function getConfig(env) {
switch (env) {
Expand Down Expand Up @@ -29,6 +30,7 @@ let keyStore;
let near;

async function initNear() {
const server = await runServer();
config = getConfig(process.env.NEAR_ENV || "sandbox");
const keyFile = require(config.keyPath);
masterKey = nearAPI.utils.KeyPair.fromString(
Expand All @@ -46,6 +48,7 @@ async function initNear() {
});
masterAccount = new nearAPI.Account(near.connection, config.masterAccount);
console.log("Finish init NEAR");
return server;
}

async function createContractUser(
Expand Down Expand Up @@ -95,7 +98,7 @@ async function initTest() {

async function test() {
// 1. Creates testing accounts and deploys a contract
await initNear();
const server = await initNear();
const { aliceUseContract, bobUseContract } = await initTest();

// 2. Performs a `set_status` transaction signed by Alice and then calls `get_status` to confirm `set_status` worked
Expand All @@ -121,6 +124,8 @@ async function test() {
account_id: "alice.test.near",
});
assert.equal(alice_message, "hello");

server.close();
}

test();