Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Update test env to use new nearlib
Browse files Browse the repository at this point in the history
  • Loading branch information
ilblackdragon committed Jun 8, 2019
1 parent 1722f14 commit 7c1cbdd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion blank_project/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

async function initContract() {
// Initializing connection to the NEAR DevNet.
window.near = await nearlib.dev.connect(nearConfig);
window.near = await nearlib.connect(nearConfig);

// Initializing our contract APIs by contract name and configuration.
window.contract = await near.loadContract(nearConfig.contractName, {
Expand Down
20 changes: 7 additions & 13 deletions test_environment.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const NodeEnvironment = require('jest-environment-node');
const dev = require('nearlib/dev');
const fs = require('fs');
const nearlib = require('nearlib');

const fs = require('fs');

class LocalTestEnvironment extends NodeEnvironment {
constructor(config) {
Expand All @@ -11,7 +9,6 @@ class LocalTestEnvironment extends NodeEnvironment {

async setup() {
this.global.nearlib = require('nearlib');
this.global.nearlib.dev = require('nearlib/dev');
this.global.window = {};
let config = require('./get-config')();
this.global.testSettings = config;
Expand All @@ -21,18 +18,15 @@ class LocalTestEnvironment extends NodeEnvironment {
});
config.deps = Object.assign(config.deps || {}, {
storage: this.createFakeStorage(),
keyStore: new nearlib.InMemoryKeyStore(),
keyStore: new nearlib.keyStores.InMemoryKeyStore(),
});
const near = await dev.connect(config);

const keyWithRandomSeed = await nearlib.KeyPair.fromRandomSeed();
await config.deps.createAccount(config.contractName, keyWithRandomSeed.getPublicKey());
config.deps.keyStore.setKey(config.contractName, keyWithRandomSeed);
const near = await nearlib.connect(config);

// deploy contract
const masterAccount = near.account('test.near');
const randomKey = await nearlib.KeyPair.fromRandom('ed25519');
const data = [...fs.readFileSync('./out/main.wasm')];
await near.waitForTransactionResult(
await near.deployContract(config.contractName, data));
await masterAccount.createAndDeployContract(config.contractName, randomKey.getPublicKey(), data, 1000000);
config.deps.keyStore.setKey(config.networkId, config.contractName, randomKey);

await super.setup();
}
Expand Down

0 comments on commit 7c1cbdd

Please sign in to comment.