@waves/js-test-env
Advanced tools
Comparing version 0.7.0-beta.0 to 0.7.0-beta.3
@@ -1,116 +0,8 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const wt = tslib_1.__importStar(require("@waves/waves-transactions")); | ||
const ride_js_1 = require("@waves/ride-js"); | ||
const chai_1 = tslib_1.__importDefault(require("chai")); | ||
const chai_as_promised_1 = tslib_1.__importDefault(require("chai-as-promised")); | ||
chai_1.default.use(chai_as_promised_1.default); | ||
const NO_SEED_MSG = `Seed is undefined. Please check that you have seed in your config file or web ide settings`; | ||
function addEnvFunctionsToGlobal(global, options) { | ||
function withDefaults(options = {}) { | ||
return { | ||
timeout: options.timeout || global.env.timeout || 20000, | ||
apiBase: options.apiBase || global.env.API_BASE | ||
}; | ||
} | ||
const envSeed = () => global.env.SEED || (() => { | ||
throw new Error(NO_SEED_MSG); | ||
})(); | ||
function currentAddress() { | ||
return wt.libs.crypto.address(envSeed(), global.env.CHAIN_ID); | ||
} | ||
function injectEnv(f) { | ||
return (po, seed) => f(Object.assign({ chainId: global.env.CHAIN_ID, additionalFee: global.env.defaultAdditionalFee }, po), seed === null ? null : seed || envSeed()); | ||
} | ||
global.wavesCrypto = wt.libs.crypto; | ||
global.chai = chai_1.default; | ||
global.expect = chai_1.default.expect; | ||
global.alias = injectEnv(wt.alias); | ||
global.burn = injectEnv(wt.burn); | ||
global.cancelLease = injectEnv(wt.cancelLease); | ||
global.cancelOrder = injectEnv(wt.cancelOrder); | ||
global.data = injectEnv(wt.data); | ||
global.issue = injectEnv(wt.issue); | ||
global.reissue = injectEnv(wt.reissue); | ||
global.lease = injectEnv(wt.lease); | ||
global.massTransfer = injectEnv(wt.massTransfer); | ||
global.order = injectEnv(wt.order); | ||
global.transfer = injectEnv(wt.transfer); | ||
global.setScript = injectEnv(wt.setScript); | ||
global.setAssetScript = injectEnv(wt.setAssetScript); | ||
global.invokeScript = injectEnv(wt.invokeScript); | ||
global.sponsorship = injectEnv(wt.sponsorship); | ||
global.signTx = injectEnv(wt.signTx); | ||
global.waitForTx = async (txId, options) => wt.nodeInteraction.waitForTx(txId, withDefaults(options)); | ||
global.waitForTxWithNConfirmations = async (txId, confirmations, options) => wt.nodeInteraction.waitForTxWithNConfirmations(txId, confirmations, withDefaults(options)); | ||
global.waitNBlocks = (blocksCount, options) => wt.nodeInteraction.waitNBlocks(blocksCount, withDefaults(options)); | ||
global.currentHeight = (apiBase) => wt.nodeInteraction.currentHeight(apiBase || global.env.API_BASE); | ||
global.waitForHeight = (target, options) => wt.nodeInteraction.waitForHeight(target, withDefaults(options)); | ||
global.balance = (address, apiBase) => wt.nodeInteraction.balance(address || currentAddress(), apiBase || global.env.API_BASE); | ||
global.assetBalance = (assetId, address, apiBase) => wt.nodeInteraction.assetBalance(assetId, address || currentAddress(), apiBase || global.env.API_BASE); | ||
global.balanceDetails = (address, apiBase) => wt.nodeInteraction.balanceDetails(address || currentAddress(), apiBase || global.env.API_BASE); | ||
global.accountData = (address, apiBase) => wt.nodeInteraction.accountData(address || currentAddress(), apiBase || global.env.API_BASE); | ||
global.accountDataByKey = (key, address, apiBase) => wt.nodeInteraction.accountDataByKey(key, address || currentAddress(), apiBase || global.env.API_BASE); | ||
global.stateChanges = (invokeScriptTxId, apiBase) => wt.nodeInteraction.stateChanges(invokeScriptTxId, apiBase || global.env.API_BASE); | ||
global.broadcast = (tx, apiBase) => options && options.broadcastWrapper | ||
? options.broadcastWrapper(wt.nodeInteraction.broadcast)(tx, apiBase || global.env.API_BASE) | ||
: wt.nodeInteraction.broadcast(tx, apiBase || global.env.API_BASE); | ||
global.file = (name) => { | ||
if (typeof global.env.file !== 'function') { | ||
throw new Error('File content API is not available. Please provide it to the console'); | ||
} | ||
return global.env.file(name); | ||
}; | ||
global.contract = () => global.env.file(); | ||
global.keyPair = (seed) => wt.libs.crypto.keyPair(seed || envSeed()); | ||
global.publicKey = (seed) => wt.libs.crypto.keyPair(seed || envSeed()).publicKey; | ||
global.privateKey = (seed) => wt.libs.crypto.keyPair(seed || envSeed()).privateKey; | ||
global.address = (seed, chainId) => wt.libs.crypto.address(seed || envSeed(), chainId || global.env.CHAIN_ID); | ||
global.compile = (code) => { | ||
const info = ride_js_1.scriptInfo(code); | ||
if ('error' in info) | ||
throw new Error(info.error); | ||
const libraries = info.imports.reduce((acc, libname) => { | ||
try { | ||
acc[libname] = global.file(libname); | ||
} | ||
catch (e) { } | ||
return acc; | ||
}, {}); | ||
const resultOrError = ride_js_1.compile(code, libraries); | ||
if ('error' in resultOrError) | ||
throw new Error(resultOrError.error); | ||
return resultOrError.result.base64; | ||
}; | ||
global.signBytes = (bytes, seed) => wt.libs.crypto.signBytes(bytes, seed || envSeed()); | ||
global.setupAccounts = async (balances, options) => { | ||
if (!global.accounts) | ||
global.accounts = {}; | ||
const getNonce = () => [].map.call(wt.libs.crypto.randomBytes(4), (n) => n.toString(16)) | ||
.join(''); | ||
const nonce = (options && options.nonce) || getNonce(); | ||
const masterSeed = (options && options.masterSeed) || envSeed(); | ||
global.console.log(`Generating accounts with nonce: ${nonce}`); | ||
const transfers = []; | ||
Object.entries(balances).forEach(([name, balance]) => { | ||
const seed = name + '#' + nonce; | ||
const addr = wt.libs.crypto.address(seed, global.env.CHAIN_ID); | ||
global.accounts[name] = seed; | ||
global.console.log(`Account generated: ${seed} - ${addr}`); | ||
transfers.push({ | ||
recipient: addr, | ||
amount: balance | ||
}); | ||
}); | ||
const totalAmount = transfers.reduce((acc, { amount }) => acc + +amount, 0); | ||
if (totalAmount > 0) { | ||
const mtt = global.massTransfer({ transfers }, masterSeed); | ||
await global.broadcast(mtt); | ||
await global.waitForTx(mtt.id); | ||
global.console.log(`Accounts successfully funded`); | ||
} | ||
return Object.assign({}, global.env.accounts); | ||
}; | ||
} | ||
exports.addEnvFunctionsToGlobal = addEnvFunctionsToGlobal; | ||
import augment from './augment'; | ||
augment(global); | ||
(global as any).env = { | ||
API_BASE: 'https://nodes-testnet.wavesnodes.com', | ||
SEED: 'default seed', | ||
CHAIN_ID: 'T' | ||
}; |
{ | ||
"name": "@waves/js-test-env", | ||
"version": "0.4.0", | ||
"version": "0.7.0-beta.0", | ||
"description": "", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"buildDocs": "node ./scripts/buildDocs.js", | ||
"deploy": "tsc && cp package.json dist/package.json && cp src/augmentedGlobal.d.ts dist/augmentedGlobal.d.ts && cd dist && npm publish -tag beta" | ||
"compileAugment": "tsc src/augment.ts --esModuleInterop --declaration --outDir dist", | ||
"copyIndex": "cp src/index.d.ts dist/index.d.ts && cp src/index.js dist/index.js", | ||
"copyPackageJson": "node ./scripts/copyPackageJson", | ||
"build": "npm run compileAugment && npm run copyIndex && npm run copyPackageJson" | ||
}, | ||
@@ -16,2 +19,5 @@ "repository": { | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"author": "", | ||
@@ -24,4 +30,4 @@ "license": "ISC", | ||
"dependencies": { | ||
"@waves/ride-js": "^0.17.7", | ||
"@waves/waves-transactions": "^3.12.2", | ||
"@waves/ride-js": "^1.1.0", | ||
"@waves/waves-transactions": "^3.18.0", | ||
"chai": "^4.2.0", | ||
@@ -36,6 +42,6 @@ "chai-as-promised": "^7.1.1", | ||
"tslint": "^5.17.0", | ||
"typedoc": "^0.14.2", | ||
"typedoc": "^0.15.0", | ||
"typedoc-plugin-external-module-name": "^2.1.0", | ||
"typescript": "^3.5.1" | ||
} | ||
} | ||
} |
{ | ||
"name": "@waves/js-test-env", | ||
"version": "0.7.0-beta.0", | ||
"version": "0.7.0-beta.3", | ||
"description": "", | ||
@@ -10,3 +10,6 @@ "main": "dist/index.js", | ||
"buildDocs": "node ./scripts/buildDocs.js", | ||
"prepublishOnly": "tsc && cp src/augmentedGlobal.d.ts dist/augmentedGlobal.d.ts" | ||
"compileAugment": "tsc src/augment.ts --esModuleInterop --declaration --outDir dist", | ||
"copyIndex": "cp src/index.d.ts dist/index.d.ts && cp src/index.js dist/index.js", | ||
"copyPackageJson": "node ./scripts/copyPackageJson", | ||
"build": "npm run compileAugment && npm run copyIndex && npm run copyPackageJson" | ||
}, | ||
@@ -27,4 +30,4 @@ "repository": { | ||
"dependencies": { | ||
"@waves/ride-js": "^1.1.0-beta.13", | ||
"@waves/waves-transactions": "^3.14.3", | ||
"@waves/ride-js": "^1.1.0", | ||
"@waves/waves-transactions": "^3.18.0", | ||
"chai": "^4.2.0", | ||
@@ -31,0 +34,0 @@ "chai-as-promised": "^7.1.1", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3177
4
7
2
Updated@waves/ride-js@^1.1.0