@waves/js-test-env
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -7,2 +7,3 @@ /** | ||
import { WithTxType } from '@waves/waves-transactions/dist/general'; | ||
export declare let context: any; | ||
/** | ||
@@ -183,4 +184,4 @@ * Creates alias transaction or signs already formed one. Creates alias for address. | ||
/** | ||
* Generates test accounts with balances. Sends waves to generated accounts from master seed. Saves account seeds to global.env.accounts | ||
* E.g.: setupAccounts({foo:1000}). Now global.env.accounts['foo'] contains seed phrase for account and this account has | ||
* Generates test accounts with balances. Sends waves to generated accounts from master seed. Saves account seeds to context.env.accounts | ||
* E.g.: setupAccounts({foo:1000}). Now context.env.accounts['foo'] contains seed phrase for account and this account has | ||
* 1000 wavelets | ||
@@ -187,0 +188,0 @@ * By default uses current environment node and seed as masterSeed |
74
index.js
@@ -9,12 +9,16 @@ "use strict"; | ||
const ride_js_1 = require("@waves/ride-js"); | ||
if (global === undefined) | ||
global = window; | ||
const withDefaults = (options = {}) => ({ | ||
timeout: options.timeout || 20000, | ||
apiBase: options.apiBase || global.env.API_BASE | ||
}); | ||
const currentAddress = () => wt.libs.crypto.address(global.env.SEED, global.env.CHAIN_ID); | ||
const injectEnv = (f) => (po, seed) => f(Object.assign({ chainId: global.env.CHAIN_ID, additionalFee: seed === undefined && global.env.isScripted ? 400000 : undefined }, po), seed === null | ||
? null | ||
: seed || global.env.SEED); | ||
exports.context = global; | ||
function withDefaults(options = {}) { | ||
return { | ||
timeout: options.timeout || 20000, | ||
apiBase: options.apiBase || exports.context.env.API_BASE | ||
}; | ||
} | ||
function currentAddress() { return wt.libs.crypto.address(exports.context.env.SEED, exports.context.env.CHAIN_ID); } | ||
; | ||
function injectEnv(f) { | ||
return (po, seed) => f(Object.assign({ chainId: exports.context.env.CHAIN_ID, additionalFee: seed === undefined && exports.context.env.isScripted ? 400000 : undefined }, po), seed === null | ||
? null | ||
: seed || exports.context.env.SEED); | ||
} | ||
/// TRANSACTION CREATORS | ||
@@ -164,3 +168,3 @@ /** | ||
async function currentHeight(apiBase) { | ||
return wt.nodeInteraction.currentHeight(apiBase || global.env.API_BASE); | ||
return wt.nodeInteraction.currentHeight(apiBase || exports.context.env.API_BASE); | ||
} | ||
@@ -181,3 +185,3 @@ exports.currentHeight = currentHeight; | ||
async function balance(address, apiBase) { | ||
return wt.nodeInteraction.balance(address || currentAddress(), apiBase || global.env.API_BASE); | ||
return wt.nodeInteraction.balance(address || currentAddress(), apiBase || exports.context.env.API_BASE); | ||
} | ||
@@ -190,3 +194,3 @@ exports.balance = balance; | ||
async function assetBalance(assetId, address, apiBase) { | ||
return wt.nodeInteraction.assetBalance(assetId, address || currentAddress(), apiBase || global.env.API_BASE); | ||
return wt.nodeInteraction.assetBalance(assetId, address || currentAddress(), apiBase || exports.context.env.API_BASE); | ||
} | ||
@@ -199,3 +203,3 @@ exports.assetBalance = assetBalance; | ||
async function balanceDetails(address, apiBase) { | ||
return wt.nodeInteraction.balanceDetails(address || currentAddress(), apiBase || global.env.API_BASE); | ||
return wt.nodeInteraction.balanceDetails(address || currentAddress(), apiBase || exports.context.env.API_BASE); | ||
} | ||
@@ -208,3 +212,3 @@ exports.balanceDetails = balanceDetails; | ||
async function accountData(address, apiBase) { | ||
return wt.nodeInteraction.accountData(address || currentAddress(), apiBase || global.env.API_BASE); | ||
return wt.nodeInteraction.accountData(address || currentAddress(), apiBase || exports.context.env.API_BASE); | ||
} | ||
@@ -217,3 +221,3 @@ exports.accountData = accountData; | ||
async function accountDataByKey(key, address, apiBase) { | ||
return wt.nodeInteraction.accountDataByKey(key, address || currentAddress(), apiBase || global.env.API_BASE); | ||
return wt.nodeInteraction.accountDataByKey(key, address || currentAddress(), apiBase || exports.context.env.API_BASE); | ||
} | ||
@@ -226,3 +230,3 @@ exports.accountDataByKey = accountDataByKey; | ||
async function stateChanges(invokeScriptTxId, apiBase) { | ||
return wt.nodeInteraction.stateChanges(invokeScriptTxId, apiBase || global.env.API_BASE); | ||
return wt.nodeInteraction.stateChanges(invokeScriptTxId, apiBase || exports.context.env.API_BASE); | ||
} | ||
@@ -235,3 +239,3 @@ exports.stateChanges = stateChanges; | ||
async function broadcast(tx, apiBase) { | ||
return wt.nodeInteraction.broadcast(tx, apiBase || global.env.API_BASE); | ||
return wt.nodeInteraction.broadcast(tx, apiBase || exports.context.env.API_BASE); | ||
} | ||
@@ -244,6 +248,6 @@ exports.broadcast = broadcast; | ||
function file(name) { | ||
if (typeof global.env.file !== 'function') { | ||
if (typeof exports.context.env.file !== 'function') { | ||
throw new Error('File content API is not available. Please provide it to the console'); | ||
} | ||
return global.env.file(name); | ||
return exports.context.env.file(name); | ||
} | ||
@@ -255,3 +259,3 @@ exports.file = file; | ||
async function contract() { | ||
return global.env.file(); | ||
return exports.context.env.file(); | ||
} | ||
@@ -264,3 +268,3 @@ exports.contract = contract; | ||
function keyPair(seed) { | ||
return wt.libs.crypto.keyPair(seed || global.env.SEED); | ||
return wt.libs.crypto.keyPair(seed || exports.context.env.SEED); | ||
} | ||
@@ -273,3 +277,3 @@ exports.keyPair = keyPair; | ||
function publicKey(seed) { | ||
return wt.libs.crypto.keyPair(seed || global.env.SEED).public; | ||
return wt.libs.crypto.keyPair(seed || exports.context.env.SEED).public; | ||
} | ||
@@ -282,3 +286,3 @@ exports.publicKey = publicKey; | ||
function privateKey(seed) { | ||
return wt.libs.crypto.keyPair(seed || global.env.SEED).private; | ||
return wt.libs.crypto.keyPair(seed || exports.context.env.SEED).private; | ||
} | ||
@@ -291,3 +295,3 @@ exports.privateKey = privateKey; | ||
function address(seed, chainId) { | ||
return wt.libs.crypto.address(seed || global.env.SEED, chainId || global.env.CHAIN_ID); | ||
return wt.libs.crypto.address(seed || exports.context.env.SEED, chainId || exports.context.env.CHAIN_ID); | ||
} | ||
@@ -310,8 +314,8 @@ exports.address = address; | ||
function signBytes(bytes, seed) { | ||
return wt.libs.crypto.signBytes(bytes, seed || global.env.SEED); | ||
return wt.libs.crypto.signBytes(bytes, seed || exports.context.env.SEED); | ||
} | ||
exports.signBytes = signBytes; | ||
/** | ||
* Generates test accounts with balances. Sends waves to generated accounts from master seed. Saves account seeds to global.env.accounts | ||
* E.g.: setupAccounts({foo:1000}). Now global.env.accounts['foo'] contains seed phrase for account and this account has | ||
* Generates test accounts with balances. Sends waves to generated accounts from master seed. Saves account seeds to context.env.accounts | ||
* E.g.: setupAccounts({foo:1000}). Now context.env.accounts['foo'] contains seed phrase for account and this account has | ||
* 1000 wavelets | ||
@@ -324,10 +328,10 @@ * By default uses current environment node and seed as masterSeed | ||
const nonce = (options && options.nonce) || getNonce(); | ||
const masterSeed = (options && options.masterSeed) || global.env.SEED; | ||
global.console.log(`Generating accounts with nonce: ${nonce}`); | ||
const masterSeed = (options && options.masterSeed) || exports.context.env.SEED; | ||
exports.context.console.log(`Generating accounts with nonce: ${nonce}`); | ||
const transfers = []; | ||
Object.entries(balances).forEach(([name, balance]) => { | ||
const seed = name + '#' + nonce; | ||
const addr = address(seed, global.env.CHAIN_ID); | ||
global.env.accounts[name] = seed; | ||
global.console.log(`Account generated: ${seed} - ${addr}`); | ||
const addr = address(seed, exports.context.env.CHAIN_ID); | ||
exports.context.env.accounts[name] = seed; | ||
exports.context.console.log(`Account generated: ${seed} - ${addr}`); | ||
transfers.push({ | ||
@@ -341,5 +345,5 @@ recipient: addr, | ||
await waitForTx(mtt.id); | ||
global.console.log(`Accounts successfully funded`); | ||
return Object.assign({}, global.env.accounts); | ||
exports.context.console.log(`Accounts successfully funded`); | ||
return Object.assign({}, exports.context.env.accounts); | ||
} | ||
exports.setupAccounts = setupAccounts; |
{ | ||
"name": "@waves/js-test-env", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "test": "echo \"Error: no test specified\" && exit 1", |
20715
521