UNPKG

create-tezos-smart-contract

Version:

Node.js toolset to write, test and deploy Tezos smart contracts

57 lines (56 loc) 2.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupJestEnv = void 0; const console_1 = require("../../console"); const bundle_1 = require("../bundle"); const config_1 = require("../config"); const types_1 = require("./types"); const setupJestEnv = async () => { const { TEZOS_NETWORK, DEPLOYED_CONTRACTS, } = process.env; const cwd = (0, console_1.getCWD)(); const bundle = new bundle_1.ContractsBundle(cwd); const config = await bundle.readConfigFile(); // Start to configure Sandbox, then will switch to Testnet if --tezosToolchainNetwork=testnet was passed in command ENV let network = config_1.ToolchainNetworks.SANDBOX; let signer = config.networks.sandbox.defaultSignerSK; let rpcNode = `http://${config.sandbox.host}:${config.sandbox.port}`; if (TEZOS_NETWORK) { if (TEZOS_NETWORK === config_1.ToolchainNetworks.TESTNET) { network = config_1.ToolchainNetworks.TESTNET; rpcNode = `${config.networks.testnet.host}:${config.networks.testnet.port}`; if (config.networks.testnet.faucet && (0, types_1.isFaucet)(config.networks.testnet.faucet)) { signer = config.networks.testnet.faucet; } else { throw new Error('ERROR: When running tests in testnet, a Faucet is mandatory.\nPlease get a Faucet account from https://faucet.tzalpha.net and add it in testnet config in config.json'); } } else if (TEZOS_NETWORK !== config_1.ToolchainNetworks.SANDBOX) { throw new Error(`ERROR: The specified network "${TEZOS_NETWORK}" is not available. Please use either sandbox or testnet.`); } } let deployedContracts = undefined; if (DEPLOYED_CONTRACTS) { const contractNames = await bundle.getContractsFiles(); deployedContracts = {}; const pairs = DEPLOYED_CONTRACTS.split(';'); for (const pair of pairs) { const tokens = pair.split(':'); if (tokens.length !== 2) { throw new Error(`Contracts argument is in the wrong format: "${pair}" is not in the form "filename.ext:contractAddress!"`); } if (!contractNames.find(x => x === tokens[0])) { throw new Error(`Contracts argument specifies a contract which is not part of this repository: "${tokens[0]}"`); } deployedContracts[tokens[0]] = tokens[1]; } } return { tezosRPCNode: rpcNode, tezosToolchainNetwork: network, tezosDefaultSigner: signer, tezosCWD: cwd, tezosDeployedContracts: deployedContracts, }; }; exports.setupJestEnv = setupJestEnv;