How to use actualConfig method in stryker-parent

Best JavaScript code snippet using stryker-parent

cli.js

Source:cli.js Github

copy

Full Screen

1/* eslint-disable no-console */2/* eslint-disable no-use-before-define */3/* eslint-disable no-shadow */4const fs = require('fs');5const readline = require('readline');6const chalk = require('chalk');7const { Writable } = require('stream');8const feeTable = require('../js/constants').fee;9const { Wallet } = require('./src/utils/wallet');10const {11 depositTx, sendTx, depositOnTopTx, withdrawTx, forceWithdrawTx,12 showAccounts, transferTx, depositAndTransferTx, showExitsBatch, approveTx,13 showStateAccount, withdrawOffChainTx,14} = require('./src/utils/cli-utils');15const { error } = require('./helpers/list-errors');16const walletPathDefault = './wallet.json';17const configPathDefault = './config.json';18const noncePathDefault = './nonceJson.json';19const { version } = require('./package');20const { argv } = require('yargs') // eslint-disable-line21 .version(version)22 .usage(`23rollup-cli <command> <options>24createkeys command25=============26 rollup-cli createkeys <options>27 create new rollup wallet28 -w or --walletpath <path> (optional)29 Path to store wallet30 Default: [wallet.json]31 -m or --mnemonic <mnemonic>32 Mnemonic 12 words33printkeys command34=============35 rollup-cli printkeys <options>36 Print public keys37 You can choose:38 -w or --walletpath <path>39 Path of your wallet40 -c or --configpath <path>41 Path of your configuration file with wallet path42 Default: config.json43setparam command44=============45 rollup-cli setparam46 Set configuration file parameters47 --pm or --param <parameter>48 Parameter to set49 -v or --value <value of parameter>50 Value of the parameter51 -c or --configpath <parameter file> (optional)52 Path of your configuration file53 Default: config.json54offchainTx command55=============56 rollup-cli offchaintx <options>57 -t or --type [send | withdrawOffChain | depositOffChain]58 Defines which transaction should be done59 -a or --amount <amount>60 Amount to send61 --tk or --tokenid <token ID>62 -r or --recipient <recipient babyJub compressed publick key>63 -e or --fee <% fee>64 --ethaddr or --ethereumaddress <ethereum address>65 only used in deposit offchain transaction66 --no or --nonce <nonce TX> (optional)67 -c or --configpath <parameter file> (optional)68 Path of your configuration file69 Default: config.json70onchainTx command71=============72 rollup-cli onchaintx <options>73 --type or -t [deposit | depositontop | withdraw | forcewithdraw | transfer | depositandtransfer | approve]74 Defines which transaction should be done75 -l or --loadamount <amount>76 Amount to deposit within the rollup77 -a or --amount <amount>78 Amount to move inside rollup79 --tk or --tokenid <token ID>80 -n or --numexitbatch <num exit batch>81 -r or --recipient <recipient babyJub Compressed publick key>82 -c or --configpath <parameter file> (optional)83 Path of your configuration file84 Default: config.json85 --gaslimit or --gl <number>86 Gas limit at the time to send a transaction87 --gasmultiplier or --gm <number>88 GasPrice used = default gas price * gasmultiplier89info command90=============91 rollup-cli info <options>92 -t or --type [accounts | exits]93 get accounts information94 get batches where an account has been done an exit transaction 95 -f or --filter [babyjubjub | ethereum | tokenid]96 only used on account information97 --tk or --tokenid <token ID>98 filters by token id99 -c or --configpath <parameter file> (optional)100 Path of your configuration file101 Default: config.json102 `)103 .help('h')104 .alias('h', 'help')105 .alias('p', 'passphrase')106 .alias('w', 'walletpath')107 .alias('c', 'configpath')108 .alias('m', 'mnemonic')109 .alias('pm', 'param')110 .alias('v', 'value')111 .alias('t', 'type')112 .alias('r', 'recipient')113 .alias('e', 'fee')114 .alias('f', 'filter')115 .alias('a', 'amount')116 .alias('l', 'loadamount')117 .alias('tk', 'tokenid')118 .alias('ethaddr', 'ethereumaddress')119 .alias('n', 'numexitbatch')120 .alias('no', 'nonce')121 .alias('gl', 'gaslimit')122 .alias('gm', 'gasmultiplier')123 .epilogue('Rollup client cli tool');124let walletpath = (argv.walletpath) ? argv.walletpath : 'nowalletpath';125const mnemonic = (argv.mnemonic) ? argv.mnemonic : 'nomnemonic';126const param = (argv.param) ? argv.param : 'noparam';127const value = (argv.value) ? argv.value : 'novalue';128const configPath = (argv.configpath) ? argv.configpath : configPathDefault;129const type = (argv.type) ? argv.type : 'notype';130const recipient = (argv.recipient) ? argv.recipient : 'norecipient';131const amount = (argv.amount) ? argv.amount.toString() : -1;132const loadamount = (argv.loadamount) ? argv.loadamount.toString() : -1;133const tokenId = (argv.tokenid || argv.tokenid === 0) ? argv.tokenid : 'notokenid';134const ethAddr = (argv.ethereumaddress || argv.ethereumaddress === 0) ? argv.ethereumaddress : 'noethaddr';135const fee = argv.fee ? argv.fee.toString() : 'nofee';136const numExitBatch = argv.numexitbatch ? argv.numexitbatch.toString() : 'nonumexitbatch';137const filter = argv.filter ? argv.filter : 'nofilter';138const nonce = (argv.nonce || argv.nonce === 0) ? argv.nonce.toString() : undefined;139const gasLimit = (argv.gaslimit) ? argv.gaslimit : 5000000;140const gasMultiplier = (argv.gasmultiplier) ? argv.gasmultiplier : 1;141(async () => {142 try {143 let actualConfig = {};144 if (argv._[0].toUpperCase() === 'CREATEKEYS') {145 let encWallet;146 let wallet;147 const passphrase = await getPassword();148 console.log('repeat your password please');149 const passphrase2 = await getPassword();150 if (passphrase !== passphrase2) {151 throw new Error(error.PASSWORD_NOT_MATCH);152 }153 if (walletpath === 'nowalletpath') {154 walletpath = walletPathDefault;155 }156 if (mnemonic !== 'nomnemonic') {157 if (mnemonic.split(' ').length !== 12) {158 console.log('Invalid Mnemonic, enter the mnemonic between "" \n');159 throw new Error(error.INVALID_MNEMONIC);160 } else {161 console.log('creating rollup wallet from mnemonic...\n');162 wallet = await Wallet.fromMnemonic(mnemonic);163 encWallet = await wallet.toEncryptedJson(passphrase);164 printKeys(encWallet);165 }166 } else {167 console.log('creating new rollup wallet...\n');168 wallet = await Wallet.createRandom();169 encWallet = await wallet.toEncryptedJson(passphrase);170 printKeys(encWallet);171 }172 fs.writeFileSync(walletpath, JSON.stringify(encWallet, null, 1), 'utf-8');173 process.exit(0);174 } else if (argv._[0].toUpperCase() === 'SETPARAM') {175 if (fs.existsSync(configPath)) {176 actualConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));177 }178 if (param.toUpperCase() === 'PATHWALLET' && value !== 'novalue') {179 actualConfig.wallet = value;180 } else if (param.toUpperCase() === 'ABIROLLUPPATH' && value !== 'novalue') {181 actualConfig.abiRollupPath = value;182 } else if (param.toUpperCase() === 'URLOPERATOR' && value !== 'novalue') {183 actualConfig.urlOperator = value;184 } else if (param.toUpperCase() === 'NODEETH' && value !== 'novalue') {185 actualConfig.nodeEth = value;186 } else if (param.toUpperCase() === 'ADDRESSROLLUP' && value !== 'novalue') {187 actualConfig.addressRollup = value;188 } else if (param.toUpperCase() === 'CONTROLLERADDRESS' && value !== 'novalue') {189 actualConfig.controllerAddress = value;190 } else if (param.toUpperCase() === 'ADDRESSTOKENS' && value !== 'novalue') {191 actualConfig.addressTokens = value;192 } else if (param.toUpperCase() === 'ABIERC20PATH' && value !== 'novalue') {193 actualConfig.abiTokensPath = value;194 } else if (param === 'noparam') {195 console.log('Please provide a param\n');196 throw new Error(error.NO_PARAM);197 } else if (value === 'novalue') {198 console.log('Please provide a value\n\n');199 throw new Error(error.NO_VALUE);200 } else {201 console.log('Invalid param\n');202 throw new Error(error.INVALID_PARAM);203 }204 fs.writeFileSync(configPath, JSON.stringify(actualConfig, null, 1), 'utf-8');205 process.exit(0);206 } else if (argv._[0].toUpperCase() === 'PRINTKEYS') {207 if (walletpath === 'nowalletpath') {208 if (fs.existsSync(configPath)) {209 actualConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));210 if (actualConfig.wallet !== undefined) {211 walletpath = actualConfig.wallet;212 }213 }214 }215 if (walletpath === 'nowalletpath') {216 walletpath = walletPathDefault;217 }218 if (!fs.existsSync(walletpath)) {219 console.log('Please provide a valid path\n');220 throw new Error(error.INVALID_PATH);221 }222 const readWallet = JSON.parse(fs.readFileSync(walletpath, 'utf-8'));223 printKeys(readWallet);224 process.exit(0);225 } else if (argv._[0].toUpperCase() === 'OFFCHAINTX') {226 if (type === 'notype') {227 console.log('It is necessary to specify the type of action\n');228 throw new Error(error.NO_TYPE);229 } else {230 const passphrase = await getPassword();231 if (fs.existsSync(configPath)) {232 actualConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));233 } else {234 console.log('No params file was submitted\n');235 throw new Error(error.NO_PARAMS_FILE);236 }237 checkparamsOffchain(type, actualConfig);238 const wallet = JSON.parse(fs.readFileSync(actualConfig.wallet, 'utf-8'));239 const { urlOperator } = actualConfig;240 let { noncePath } = actualConfig;241 if (noncePath === undefined) {242 noncePath = noncePathDefault;243 }244 let actualNonce;245 if (fs.existsSync(noncePath)) {246 actualNonce = JSON.parse(fs.readFileSync(noncePath, 'utf8'));247 }248 if (type.toUpperCase() === 'SEND') {249 const res = await sendTx(urlOperator, recipient, amount, wallet, passphrase, tokenId,250 feeTable[fee], nonce, actualNonce);251 console.log(`Status: ${res.status}, Nonce: ${res.nonce}`);252 if (res.status.toString() === '200') {253 fs.writeFileSync(noncePath, JSON.stringify(res.nonceObject, null, 1), 'utf-8');254 }255 } else if (type.toUpperCase() === 'WITHDRAWOFFCHAIN') {256 const res = await withdrawOffChainTx(urlOperator, amount, wallet, passphrase, tokenId, feeTable[fee],257 nonce, actualNonce);258 console.log(`Status: ${res.status}, Nonce: ${res.nonce}`);259 if (res.status.toString() === '200') {260 fs.writeFileSync(noncePath, JSON.stringify(res.nonceObject, null, 1), 'utf-8');261 }262 } else if (type.toUpperCase() === 'DEPOSITOFFCHAIN') {263 checkparam(ethAddr, 'noethaddr', 'Ethereum address');264 const res = await sendTx(urlOperator, recipient, amount, wallet, passphrase, tokenId, feeTable[fee],265 nonce, actualNonce, ethAddr);266 console.log(`Status: ${res.status}, Nonce: ${res.nonce}`);267 if (res.status.toString() === '200') {268 fs.writeFileSync(noncePath, JSON.stringify(res.nonceObject, null, 1), 'utf-8');269 }270 } else {271 throw new Error(error.INVALID_TYPE);272 }273 }274 process.exit(0);275 } else if (argv._[0].toUpperCase() === 'ONCHAINTX') {276 if (type !== 'notype' && type.toUpperCase() !== 'DEPOSIT' && type.toUpperCase() !== 'DEPOSITONTOP' && type.toUpperCase() !== 'WITHDRAW'277 && type.toUpperCase() !== 'FORCEWITHDRAW' && type.toUpperCase() !== 'TRANSFER' && type.toUpperCase() !== 'DEPOSITANDTRANSFER'278 && type.toUpperCase() !== 'APPROVE') {279 throw new Error(error.INVALID_KEY_TYPE);280 } else if (type === 'notype') {281 console.log('It is necessary to specify the type of action\n');282 throw new Error(error.NO_TYPE);283 } else {284 const passphrase = await getPassword();285 if (fs.existsSync(configPath)) {286 actualConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));287 } else {288 console.log('No params file was submitted\n');289 throw new Error(error.NO_PARAMS_FILE);290 }291 checkparamsOnchain(type, actualConfig);292 const abi = JSON.parse(fs.readFileSync(actualConfig.abiRollupPath, 'utf-8'));293 const wallet = JSON.parse(fs.readFileSync(actualConfig.wallet, 'utf-8'));294 if (type.toUpperCase() === 'DEPOSIT') {295 const Tx = await depositTx(actualConfig.nodeEth, actualConfig.addressRollup, loadamount,296 tokenId, wallet, passphrase, actualConfig.controllerAddress, abi, gasLimit, gasMultiplier);297 console.log(JSON.stringify({ 'Transaction Hash': Tx.hash }));298 } else if (type.toUpperCase() === 'DEPOSITONTOP') {299 const Tx = await depositOnTopTx(actualConfig.nodeEth, actualConfig.addressRollup, loadamount,300 tokenId, recipient, wallet, passphrase, abi, gasLimit, gasMultiplier);301 console.log(JSON.stringify({ 'Transaction Hash': Tx.hash }));302 } else if (type.toUpperCase() === 'FORCEWITHDRAW') {303 const Tx = await forceWithdrawTx(actualConfig.nodeEth, actualConfig.addressRollup, tokenId, amount,304 wallet, passphrase, abi, gasLimit, gasMultiplier);305 console.log(JSON.stringify({ 'Transaction Hash': Tx.hash }));306 } else if (type.toUpperCase() === 'WITHDRAW') {307 const Tx = await withdrawTx(actualConfig.nodeEth, actualConfig.addressRollup, tokenId, wallet,308 passphrase, abi, actualConfig.urlOperator, numExitBatch, gasLimit, gasMultiplier);309 console.log(JSON.stringify({ 'Transaction Hash': Tx.hash }));310 } else if (type.toUpperCase() === 'TRANSFER') {311 const Tx = await transferTx(actualConfig.nodeEth, actualConfig.addressRollup, amount,312 tokenId, recipient, wallet, passphrase, abi, gasLimit, gasMultiplier);313 console.log(JSON.stringify({ 'Transaction Hash': Tx.hash }));314 } else if (type.toUpperCase() === 'DEPOSITANDTRANSFER') {315 const Tx = await depositAndTransferTx(actualConfig.nodeEth, actualConfig.addressRollup, loadamount, amount,316 tokenId, recipient, wallet, passphrase, actualConfig.controllerAddress, abi, gasLimit, gasMultiplier);317 console.log(JSON.stringify({ 'Transaction Hash': Tx.hash }));318 } else if (type.toUpperCase() === 'APPROVE') {319 const abiTokens = JSON.parse(fs.readFileSync(actualConfig.abiTokensPath, 'utf-8'));320 const Tx = await approveTx(actualConfig.nodeEth, actualConfig.addressTokens, amount, actualConfig.addressRollup,321 wallet, passphrase, abiTokens, gasLimit, gasMultiplier);322 console.log(JSON.stringify({ 'Transaction Hash': Tx.hash }));323 } else {324 throw new Error(error.INVALID_TYPE);325 }326 }327 process.exit(0);328 } else if (argv._[0].toUpperCase() === 'INFO') {329 if (type === 'notype') {330 console.log('It is necessary to specify the type of information to print\n');331 throw new Error(error.NO_TYPE);332 } else {333 if (fs.existsSync(configPath)) {334 actualConfig = JSON.parse(fs.readFileSync(configPath, 'utf8'));335 } else {336 console.log('No params file was submitted\n');337 throw new Error(error.NO_PARAMS_FILE);338 }339 checkParamsInfo(type, actualConfig);340 if (type.toUpperCase() === 'ACCOUNTS') {341 const wallet = JSON.parse(fs.readFileSync(actualConfig.wallet, 'utf-8'));342 const filters = {};343 if (filter.toUpperCase() === 'BABYJUBJUB') {344 filters.ax = wallet.babyjubWallet.public.ax;345 filters.ay = wallet.babyjubWallet.public.ay;346 const res = await showAccounts(actualConfig.urlOperator, filters);347 console.log(`Accounts found: \n ${JSON.stringify(res.data, null, 1)}`);348 } else if (filter.toUpperCase() === 'ETHEREUM') {349 if (wallet.ethWallet.address.startsWith('0x')) {350 filters.ethAddr = wallet.ethWallet.address;351 } else {352 filters.ethAddr = `0x${wallet.ethWallet.address}`;353 }354 const res = await showAccounts(actualConfig.urlOperator, filters);355 console.log(`Accounts found: \n ${JSON.stringify(res.data, null, 1)}`);356 } else if (filter.toUpperCase() === 'TOKENID') {357 checkparam(tokenId, 'notokenid', 'token ID');358 const { ax } = wallet.babyjubWallet.public;359 const { ay } = wallet.babyjubWallet.public;360 const res = await showStateAccount(actualConfig.urlOperator, tokenId, ax, ay);361 console.log(`Accounts found: \n ${JSON.stringify(res.data, null, 1)}`);362 } else {363 throw new Error(error.INVALID_FILTER);364 }365 } else if (type.toUpperCase() === 'EXITS') {366 const wallet = JSON.parse(fs.readFileSync(actualConfig.wallet, 'utf-8'));367 const { ax } = wallet.babyjubWallet.public;368 const { ay } = wallet.babyjubWallet.public;369 const res = await showExitsBatch(actualConfig.urlOperator, tokenId, ax, ay);370 console.log(`${chalk.yellow('Number exits batch found: ')}\n${res.data}`);371 }372 }373 process.exit(0);374 } else {375 throw new Error(error.INVALID_COMMAND);376 }377 } catch (err) {378 console.error(`${chalk.red('Error information: ')}`);379 console.log(err.message);380 const cliError = Object.keys(error)[err.message];381 if (cliError) console.log(Object.keys(error)[err.message]);382 process.exit(err.message);383 }384})();385function checkparamsOnchain(type, actualConfig) {386 switch (type.toUpperCase()) {387 case 'DEPOSIT':388 checkparam(loadamount, -1, 'loadamount');389 checkparam(tokenId, 'notokenid', 'token ID');390 checkparam(actualConfig.nodeEth, undefined, 'node (with setparam command)');391 checkparam(actualConfig.addressRollup, undefined, 'contract address (with setparam command)');392 checkparam(actualConfig.abiRollupPath, undefined, 'abi path (with setparam command)');393 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');394 break;395 case 'DEPOSITONTOP':396 checkparam(loadamount, -1, 'loadamount');397 checkparam(tokenId, 'notokenid', 'token ID');398 checkparam(actualConfig.nodeEth, undefined, 'node (with setparam command)');399 checkparam(actualConfig.addressRollup, undefined, 'contract address (with setparam command)');400 checkparam(actualConfig.abiRollupPath, undefined, 'abi path (with setparam command)');401 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');402 checkparam(recipient, 'norecipient', 'recipient');403 break;404 case 'WITHDRAW':405 checkparam(actualConfig.nodeEth, undefined, 'node (with setparam command)');406 checkparam(actualConfig.addressRollup, undefined, 'contract address (with setparam command)');407 checkparam(actualConfig.abiRollupPath, undefined, 'abi path (with setparam command)');408 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');409 checkparam(actualConfig.urlOperator, undefined, 'operator (with setparam command)');410 checkparam(numExitBatch, 'nonumexitbatch', 'num exit batch');411 checkparam(tokenId, 'notokenid', 'token ID');412 break;413 case 'FORCEWITHDRAW':414 checkparam(amount, -1, 'amount');415 checkparam(actualConfig.nodeEth, undefined, 'node (with setparam command)');416 checkparam(actualConfig.addressRollup, undefined, 'contract address (with setparam command)');417 checkparam(actualConfig.abiRollupPath, undefined, 'abi path (with setparam command)');418 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');419 checkparam(tokenId, 'notokenid', 'token ID');420 break;421 case 'TRANSFER':422 checkparam(amount, -1, 'amount');423 checkparam(tokenId, 'notokenid', 'token ID');424 checkparam(actualConfig.nodeEth, undefined, 'node (with setparam command)');425 checkparam(actualConfig.addressRollup, undefined, 'contract address (with setparam command)');426 checkparam(actualConfig.abiRollupPath, undefined, 'abi path (with setparam command)');427 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');428 checkparam(recipient, 'norecipient', 'recipient');429 break;430 case 'DEPOSITANDTRANSFER':431 checkparam(amount, -1, 'amount');432 checkparam(loadamount, -1, 'loadamount');433 checkparam(tokenId, 'notokenid', 'token ID');434 checkparam(actualConfig.nodeEth, undefined, 'node (with setparam command)');435 checkparam(actualConfig.addressRollup, undefined, 'contract address (with setparam command)');436 checkparam(actualConfig.abiRollupPath, undefined, 'abi path (with setparam command)');437 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');438 checkparam(recipient, 'norecipient', 'recipient');439 break;440 case 'APPROVE':441 checkparam(amount, -1, 'amount');442 checkparam(actualConfig.nodeEth, undefined, 'node (with setparam command)');443 checkparam(actualConfig.addressRollup, undefined, 'contract address (with setparam command)');444 checkparam(actualConfig.abiTokensPath, undefined, 'abi tokens path in config.json');445 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');446 break;447 default:448 throw new Error(error.INVALID_TYPE);449 }450}451function checkparamsOffchain(type, actualConfig) {452 switch (type.toUpperCase()) {453 case 'SEND':454 checkparam(amount, -1, 'amount');455 checkparam(tokenId, 'notokenid', 'token ID');456 checkparam(recipient, 'norecipient', 'recipient');457 checkparam(fee, 'nofee', 'fee');458 checkFees(fee);459 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');460 checkparam(actualConfig.urlOperator, undefined, 'operator (with setparam command)');461 break;462 case 'WITHDRAWOFFCHAIN':463 checkparam(amount, -1, 'amount');464 checkparam(tokenId, 'notokenid', 'token ID');465 checkparam(fee, 'nofee', 'fee');466 checkFees(fee);467 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');468 checkparam(actualConfig.urlOperator, undefined, 'operator (with setparam command)');469 break;470 case 'DEPOSITOFFCHAIN':471 checkparam(amount, -1, 'amount');472 checkparam(tokenId, 'notokenid', 'token ID');473 checkparam(fee, 'nofee', 'fee');474 checkFees(fee);475 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');476 checkparam(actualConfig.urlOperator, undefined, 'operator (with setparam command)');477 checkparam(ethAddr, 'noethaddr', 'Ethereum address');478 break;479 default:480 throw new Error(error.INVALID_TYPE);481 }482}483function checkParamsInfo(type, actualConfig) {484 switch (type.toUpperCase()) {485 case 'ACCOUNTS':486 checkparam(filter, 'nofilter', 'babyjubjub or ethereum or tokenid');487 checkparam(actualConfig.wallet, undefined, 'wallet path (with setparam command)');488 checkparam(actualConfig.urlOperator, undefined, 'operator (with setparam command)');489 break;490 case 'EXITS':491 checkparam(actualConfig.urlOperator, undefined, 'operator (with setparam command)');492 checkparam(tokenId, 'notokenid', 'token ID');493 break;494 default:495 throw new Error(error.INVALID_TYPE);496 }497}498function checkparam(param, def, name) {499 if (param === def) {500 console.log(`It is necessary to specify ${name}\n`);501 throw new Error(error.NO_PARAM);502 }503}504function checkFees(fee) {505 if (feeTable[fee] === undefined) {506 console.log(`Fee selected ${fee} is not valid`);507 console.log('Please, select a valid fee amoung among the next values:');508 console.log(feeTable);509 throw new Error(error.INVALID_FEE);510 }511}512function getPassword() {513 return new Promise((resolve) => {514 const mutableStdout = new Writable({515 write(chunk, encoding, callback) {516 if (!this.muted) { process.stdout.write(chunk, encoding); }517 callback();518 },519 });520 const rl = readline.createInterface({521 input: process.stdin,522 output: mutableStdout,523 terminal: true,524 });525 rl.question('Password: ', (password) => {526 rl.close();527 console.log('');528 resolve(password);529 });530 mutableStdout.muted = true;531 });532}533function printKeys(wallet) {534 console.log(`${chalk.yellow('Ethereum public key:')}`);535 console.log(` Address: ${chalk.blue(`0x${wallet.ethWallet.address}`)}\n`);536 console.log(`${chalk.yellow('Rollup public key:')}`);537 console.log(` Rollup address: ${chalk.blue(`0x${wallet.babyjubWallet.publicCompressed}`)}`);538 console.log(' Babyjubjub points: ');539 console.log(` Ax: ${chalk.blue(`0x${wallet.babyjubWallet.public.ax}`)}`);540 console.log(` Ay: ${chalk.blue(`0x${wallet.babyjubWallet.public.ay}`)}`);...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1const Web3 = require('web3');2const { Scalar } = require('ffjavascript');3/**4 * Get ether balance of a given wallet5 * @param {Object} wallet - wallet json object6 * @param {Object} actualConfig - client configuration7 * @returns {Number} - balance in ethers8 */9async function getEtherBalance(wallet, actualConfig) {10 const web3 = new Web3(new Web3.providers.HttpProvider(actualConfig.nodeUrl));11 let balance = await web3.eth.getBalance(wallet.address);12 balance = web3.utils.fromWei(balance, 'ether');13 return Number(balance);14}15/**16 * Function to get gas price given a multiplier17 * Gets current web3 gas price and multiplies it given 'multiplier' parameter18 * @param {Number} multiplier - gas multiplier19 * @param {Object} web3 - web3 object20 * @returns {String} - BigInt enconded as string21 */22async function _getGasPrice(multiplier, web3) {23 const strAvgGas = await web3.eth.getGasPrice();24 const avgGas = Scalar.e(strAvgGas);25 return Scalar.mul(avgGas, multiplier).toString();26}27/**28 * Make bid to RollupPoB29 * @param {Object} wallet - wallet json object30 * @param {Object} actualConfig - client configuration31 * @param {Number} slot - slot32 * @param {String} url - operator url33 * @param {Number} bidValue - bid value (ether)34 * @param {Number} gasLimit - gas limit35 * @param {Number} gasMul - gas multiplier36 * @returns {Object} - signed transaction37 */38async function bid(wallet, actualConfig, slot, url, bidValue, gasLimit, gasMul) {39 const web3 = new Web3(new Web3.providers.HttpProvider(actualConfig.nodeUrl));40 const rollupPoB = new web3.eth.Contract(actualConfig.pobAbi, actualConfig.pobAddress);41 const tx = {42 from: wallet.address,43 to: actualConfig.pobAddress,44 gasLimit,45 gasPrice: await _getGasPrice(gasMul, web3),46 value: web3.utils.toHex(web3.utils.toWei(bidValue.toString(), 'ether')),47 data: rollupPoB.methods.bid(slot, url).encodeABI(),48 };49 const signedTx = await web3.eth.accounts.signTransaction(tx, wallet.privateKey);50 return signedTx;51}52/**53 * Make bid to RollupPoB54 * @param {Object} wallet - wallet json object55 * @param {Object} actualConfig - client configuration56 * @param {Number} slot - slot57 * @param {String} url - operator url58 * @param {Number} bidValue - bid value (ether)59 * @param {String} beneficiary - beneficiary Address60 * @param {Number} gasLimit - gas limit61 * @param {Number} gasMul - gas multiplier62 * @returns {Object} - signed transaction63 */64async function bidWithDifferentBeneficiary(wallet, actualConfig, slot, url, bidValue, beneficiary, gasLimit, gasMul) {65 const web3 = new Web3(new Web3.providers.HttpProvider(actualConfig.nodeUrl));66 const rollupPoB = new web3.eth.Contract(actualConfig.pobAbi, actualConfig.pobAddress);67 const tx = {68 from: wallet.address,69 to: actualConfig.pobAddress,70 gasLimit,71 gasPrice: await _getGasPrice(gasMul, web3),72 value: web3.utils.toHex(web3.utils.toWei(bidValue.toString(), 'ether')),73 data: rollupPoB.methods.bidWithDifferentBeneficiary(slot, url, beneficiary).encodeABI(),74 };75 const signedTx = await web3.eth.accounts.signTransaction(tx, wallet.privateKey);76 return signedTx;77}78/**79 * Make bid to RollupPoB80 * @param {Object} wallet - wallet json object81 * @param {Object} actualConfig - client configuration82 * @param {Number} slot - slot83 * @param {String} url - operator url84 * @param {Number} bidValue - bid value (ether)85 * @param {String} beneficiary - beneficiary Address86 * @param {String} forger - forger Address87 * @param {Number} gasLimit - gas limit88 * @param {Number} gasMul - gas multiplier89 * @returns {Object} - signed transaction90 */91async function bidRelay(wallet, actualConfig, slot, url, bidValue, beneficiary, forger, gasLimit, gasMul) {92 const web3 = new Web3(new Web3.providers.HttpProvider(actualConfig.nodeUrl));93 const rollupPoB = new web3.eth.Contract(actualConfig.pobAbi, actualConfig.pobAddress);94 const tx = {95 from: wallet.address,96 to: actualConfig.pobAddress,97 gasLimit,98 gasPrice: await _getGasPrice(gasMul, web3),99 value: web3.utils.toHex(web3.utils.toWei(bidValue.toString(), 'ether')),100 data: rollupPoB.methods.bidRelay(slot, url, beneficiary, forger).encodeABI(),101 };102 const signedTx = await web3.eth.accounts.signTransaction(tx, wallet.privateKey);103 return signedTx;104}105/**106 * Make bid to RollupPoB107 * @param {Object} wallet - wallet json object108 * @param {Object} actualConfig - client configuration109 * @param {Number} slot - slot110 * @param {String} url - operator url111 * @param {Number} bidValue - bid value (ether)112 * @param {String} beneficiary - beneficiary Address113 * @param {String} forger - forger Address114 * @param {String} withdrawAddress - address to withdraw bid115 * @param {Number} gasLimit - gas limit116 * @param {Number} gasMul - gas multiplier117 * @returns {Object} - signed transaction118 */119async function bidRelayAndWithdrawAddress(wallet, actualConfig, slot, url, bidValue, beneficiary,120 forger, withdrawAddress, gasLimit, gasMul) {121 const web3 = new Web3(new Web3.providers.HttpProvider(actualConfig.nodeUrl));122 const rollupPoB = new web3.eth.Contract(actualConfig.pobAbi, actualConfig.pobAddress);123 const tx = {124 from: wallet.address,125 to: actualConfig.pobAddress,126 gasLimit,127 gasPrice: await _getGasPrice(gasMul, web3),128 value: web3.utils.toHex(web3.utils.toWei(bidValue.toString(), 'ether')),129 data: rollupPoB.methods.bidRelayAndWithdrawAddress(slot, url, beneficiary, forger, withdrawAddress).encodeABI(),130 };131 const signedTx = await web3.eth.accounts.signTransaction(tx, wallet.privateKey);132 return signedTx;133}134/**135 * Make bid to RollupPoB136 * @param {Object} wallet - wallet json object137 * @param {Object} actualConfig - client configuration138 * @param {Number} slot - slot139 * @param {String} url - operator url140 * @param {Number} bidValue - bid value (ether)141 * @param {String} beneficiary - beneficiary Address142 * @param {String} forger - forger Address143 * @param {String} withdrawAddress - address to withdraw bid144 * @param {String} bonusAddress - bonus Address145 * @param {Boolean} useBonus - use the bonus or not146 * @param {Number} gasLimit - gas limit147 * @param {Number} gasMul - gas multiplier148 * @returns {Object} - signed transaction149 */150async function bidWithDifferentAddresses(wallet, actualConfig, slot, url, bidValue, beneficiary,151 forger, withdrawAddress, bonusAddress, useBonus, gasLimit, gasMul) {152 const web3 = new Web3(new Web3.providers.HttpProvider(actualConfig.nodeUrl));153 const rollupPoB = new web3.eth.Contract(actualConfig.pobAbi, actualConfig.pobAddress);154 const tx = {155 from: wallet.address,156 to: actualConfig.pobAddress,157 gasLimit,158 gasPrice: await _getGasPrice(gasMul, web3),159 value: web3.utils.toHex(web3.utils.toWei(bidValue.toString(), 'ether')),160 data: rollupPoB.methods.bidWithDifferentAddresses(slot, url, beneficiary, forger, withdrawAddress, bonusAddress, useBonus).encodeABI(),161 };162 const signedTx = await web3.eth.accounts.signTransaction(tx, wallet.privateKey);163 return signedTx;164}165/**166 * Make bid to RollupPoB167 * @param {Object} wallet - wallet json object168 * @param {Object} actualConfig - client configuration169 * @param {Array} rangeSlot - slot170 * @param {String} url - operator url171 * @param {Array} rangeBid - bid value (ether)172 * @param {Number} gasLimit - gas limit173 * @param {Number} gasMul - gas multiplier174 * @returns {Object} - signed transaction175 */176async function multiBid(wallet, actualConfig, rangeSlot, url, rangeBid, gasLimit, gasMul) {177 const web3 = new Web3(new Web3.providers.HttpProvider(actualConfig.nodeUrl));178 const rollupPoB = new web3.eth.Contract(actualConfig.pobAbi, actualConfig.pobAddress);179 let totalAmount = web3.utils.toBN(0);180 const rangeBidWei = [];181 for (let i = 0; i < rangeBid.length; i++) {182 const bidWei = web3.utils.toWei(rangeBid[i].toString(), 'ether');183 rangeBidWei.push(bidWei);184 const auxBid = web3.utils.toBN(bidWei);185 const addBid = auxBid.mul(web3.utils.toBN(rangeSlot[i][1] - rangeSlot[i][0] + 1));186 totalAmount = totalAmount.add(addBid);187 }188 const tx = {189 from: wallet.address,190 to: actualConfig.pobAddress,191 gasLimit,192 gasPrice: await _getGasPrice(gasMul, web3),193 value: web3.utils.toHex(totalAmount),194 data: rollupPoB.methods.multiBid(rangeBidWei, rangeSlot, url).encodeABI(),195 };196 const signedTx = await web3.eth.accounts.signTransaction(tx, wallet.privateKey);197 return signedTx;198}199/**200 * Get bid from RollupPoB201 * @param {Object} wallet - wallet json object202 * @param {Object} actualConfig - client configuration203 * @param {Number} gasLimit - gas limit204 * @param {Number} gasMul - gas multiplier205 * @returns {Object} - signed transaction206 */207async function withdraw(wallet, actualConfig, gasLimit, gasMul) {208 const web3 = new Web3(new Web3.providers.HttpProvider(actualConfig.nodeUrl));209 const rollupPoB = new web3.eth.Contract(actualConfig.pobAbi, actualConfig.pobAddress);210 const tx = {211 from: wallet.address,212 to: actualConfig.pobAddress,213 gasLimit,214 gasPrice: await _getGasPrice(gasMul, web3),215 data: rollupPoB.methods.withdraw().encodeABI(),216 };217 const signedTx = await web3.eth.accounts.signTransaction(tx, wallet.privateKey);218 return signedTx;219}220module.exports = {221 bid,222 bidWithDifferentBeneficiary,223 bidRelay,224 bidRelayAndWithdrawAddress,225 bidWithDifferentAddresses,226 multiBid,227 withdraw,228 getEtherBalance,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const actualConfig = require('stryker-parent').actualConfig;2module.exports = actualConfig('stryker.conf.js');3module.exports = function(config) {4 config.set({5 });6};7module.exports = function(config) {8 config.set({9 });10};11const strykerConfig = require('./test.js');12module.exports = function(config) {13 strykerConfig(config);14};15module.exports = function(config) {16 config.set({17 });18};19const strykerConfig = require('./test.js');20module.exports = function(config) {21 strykerConfig(config);22};23module.exports = function(config) {24 config.set({25 });26};

Full Screen

Using AI Code Generation

copy

Full Screen

1const strykerParent = require('stryker-parent');2const strykerConfig = strykerParent.actualConfig;3module.exports = strykerConfig;4const strykerParent = require('stryker-parent');5module.exports = function (config) {6 const actualConfig = strykerParent.actualConfig(config);7};8const strykerParent = require('stryker-parent');9module.exports = function (config) {10 const actualConfig = strykerParent.actualConfig(config);11 actualConfig.plugins.push('stryker-plugin');12 return actualConfig;13};

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful