refactor(@embark/utils): move transaction utils into utils package

This commit is contained in:
Pascal Precht 2019-04-30 16:01:28 +02:00 committed by Pascal Precht
parent 7174f55c6c
commit 03d779ef5e
6 changed files with 18 additions and 15 deletions

View File

@ -16,6 +16,7 @@ import {
decodeParams, decodeParams,
sha3 sha3
} from './web3Utils'; } from './web3Utils';
import { getAddressToContract, getTransactionParams } from './transactionUtils';
import AccountParser from './accountParser'; import AccountParser from './accountParser';
const { extendZeroAddressShorthand, replaceZeroAddressShorthand } = AddressUtils; const { extendZeroAddressShorthand, replaceZeroAddressShorthand } = AddressUtils;
@ -186,6 +187,8 @@ const Utils = {
decodeParams, decodeParams,
dockerHostSwap, dockerHostSwap,
exit, exit,
getAddressToContract,
getTransactionParams,
isDocker, isDocker,
checkIsAvailable, checkIsAvailable,
findNextPort, findNextPort,

View File

@ -1,18 +1,18 @@
import { Contract } from "embark"; import { Contract } from "embark";
import { decodeParams, sha3 } from "embark-utils";
import { ABIDefinition } from "web3/eth/abi"; import { ABIDefinition } from "web3/eth/abi";
import { decodeParams, sha3 } from "./web3Utils";
export interface AddressToContract { interface AddressToContract {
name: string; name: string;
functions: { [functionName: string]: FunctionSignature; }; functions: { [functionName: string]: FunctionSignature; };
silent?: boolean; silent?: boolean;
} }
export interface AddressToContractArray { interface AddressToContractArray {
[address: string]: AddressToContract; [address: string]: AddressToContract;
} }
export interface FunctionSignature { interface FunctionSignature {
abi: ABIDefinition; abi: ABIDefinition;
functionName?: string; functionName?: string;
name: string; name: string;

View File

@ -1,6 +1,6 @@
const async = require('async'); const async = require('async');
const utils = require('../../utils/utils.js'); const utils = require('../../utils/utils.js');
const {getAddressToContract, getTransactionParams} = require('../../utils/transactionUtils'); import { getAddressToContract, getTransactionParams } from 'embark-utils';
class ConsoleListener { class ConsoleListener {
constructor(embark, options) { constructor(embark, options) {

View File

@ -1,7 +1,7 @@
const Base = require('mocha/lib/reporters/base'); const Base = require('mocha/lib/reporters/base');
const ms = require('mocha/lib/ms'); const ms = require('mocha/lib/ms');
const color = Base.color; const color = Base.color;
const {getAddressToContract, getTransactionParams} = require('../../utils/transactionUtils'); import {getAddressToContract, getTransactionParams} from 'embark-utils';
class EmbarkApiSpec extends Base { class EmbarkApiSpec extends Base {
constructor(runner, options) { constructor(runner, options) {

View File

@ -3,7 +3,7 @@ const {expect} = require('chai');
const sinon = require('sinon'); const sinon = require('sinon');
const Events = require('../../lib/core/events'); const Events = require('../../lib/core/events');
const Logger = require('embark-logger'); const Logger = require('embark-logger');
const transactionUtils = require('../../lib/utils/transactionUtils'); import { getAddressToContract } from 'embark-utils';
const ConsoleListener = require('../../lib/modules/console_listener'); const ConsoleListener = require('../../lib/modules/console_listener');
const IPC = require('../../lib/core/ipc.js'); const IPC = require('../../lib/core/ipc.js');
require('colors'); require('colors');
@ -131,7 +131,7 @@ describe('Console Listener', function () {
describe('#listenForLogRequests', function () { describe('#listenForLogRequests', function () {
it('should emit the correct contracts logs', function (done) { it('should emit the correct contracts logs', function (done) {
transactionUtils.getAddressToContract(contractsList, consoleListener.addressToContract); getAddressToContract(contractsList, consoleListener.addressToContract);
consoleListener._onIpcLogRequest(ipcRequest); consoleListener._onIpcLogRequest(ipcRequest);
const expectedContractLog = { const expectedContractLog = {
@ -174,7 +174,7 @@ describe('Console Listener', function () {
it('should emit a log for a non-contract log', function (done) { it('should emit a log for a non-contract log', function (done) {
ipcRequest.type = 'something-other-than-contract-log'; ipcRequest.type = 'something-other-than-contract-log';
transactionUtils.getAddressToContract(contractsList, consoleListener.addressToContract); getAddressToContract(contractsList, consoleListener.addressToContract);
consoleListener._onIpcLogRequest(ipcRequest); consoleListener._onIpcLogRequest(ipcRequest);
expect(loggerInfos[0]).to.be.equal(JSON.stringify(ipcRequest)); expect(loggerInfos[0]).to.be.equal(JSON.stringify(ipcRequest));

View File

@ -1,6 +1,6 @@
/*globals describe, it, beforeEach*/ /*globals describe, it, beforeEach*/
const {expect} = require('chai'); const {expect} = require('chai');
const transactionUtils = require('../lib/utils/transactionUtils'); import { getAddressToContract, getTransactionParams } from 'embark-utils';
require('colors'); require('colors');
let contractsList; let contractsList;
@ -78,20 +78,20 @@ describe('Transaction Utils', () => {
describe('#getAddressToContract', () => { describe('#getAddressToContract', () => {
it('should not update contracts list when no contracts', () => { it('should not update contracts list when no contracts', () => {
contractsList = []; contractsList = [];
const result = transactionUtils.getAddressToContract(contractsList, {}); const result = getAddressToContract(contractsList, {});
expect(result).to.deep.equal({}); expect(result).to.deep.equal({});
}); });
it('should not update contracts list when not deployed', () => { it('should not update contracts list when not deployed', () => {
contractsList[0].deployedAddress = undefined; contractsList[0].deployedAddress = undefined;
const result = transactionUtils.getAddressToContract(contractsList, {}); const result = getAddressToContract(contractsList, {});
expect(result).to.deep.equal({}); expect(result).to.deep.equal({});
}); });
it('should update contracts list', () => { it('should update contracts list', () => {
const result = transactionUtils.getAddressToContract(contractsList, {}); const result = getAddressToContract(contractsList, {});
expect(result).to.deep.equal({ expect(result).to.deep.equal({
"0x12345": { "0x12345": {
@ -160,8 +160,8 @@ describe('Transaction Utils', () => {
describe('#getTransactionParams', () => { describe('#getTransactionParams', () => {
it('should return the param string and function name', () => { it('should return the param string and function name', () => {
const result = transactionUtils.getAddressToContract(contractsList, {}); const result = getAddressToContract(contractsList, {});
const {functionName, paramString} = transactionUtils.getTransactionParams(result['0x12345'], '0x60fe47b100000000000000000000000099db99c77ad807f89829f5bda99527438f64a798'); const {functionName, paramString} = getTransactionParams(result['0x12345'], '0x60fe47b100000000000000000000000099db99c77ad807f89829f5bda99527438f64a798');
expect(functionName).to.equal('set'); expect(functionName).to.equal('set');
expect(paramString).to.equal('878372847193751743539905734564138820017777321880'); expect(paramString).to.equal('878372847193751743539905734564138820017777321880');