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

View File

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

View File

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

View File

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

View File

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

View File

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