Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Move defaults to purser-core/constants
Browse files Browse the repository at this point in the history
  • Loading branch information
chmanie committed Apr 23, 2020
1 parent 75f617a commit ffd6884
Show file tree
Hide file tree
Showing 20 changed files with 51 additions and 237 deletions.
154 changes: 0 additions & 154 deletions packages/defaults.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/purser-core/__tests__/GenericWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
addressValidator,
} from '../src/validators';
import { addressNormalizer, hexSequenceNormalizer } from '../src/normalizers';
import { CHAIN_IDS } from '../src/defaults';
import { CHAIN_IDS } from '../src/constants';

jest.mock('hdkey');
jest.mock('ethers/utils');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
recoveryParamNormalizer,
} from '../../src/normalizers';

import { HEX_HASH_TYPE } from '../../src/defaults';
import { HEX_HASH_TYPE } from '../../src/constants';

jest.mock('ethereumjs-util');
jest.mock('../../src/normalizers');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
hexSequenceValidator,
} from '../../src/validators';
import { bigNumber } from '../../src/utils';
import { TRANSACTION } from '../../src/defaults';
import { TRANSACTION } from '../../src/constants';

jest.mock('../../src/validators');
jest.mock('../../src/utils');
Expand Down Expand Up @@ -98,7 +98,7 @@ describe('`Core` Module', () => {
expect(validatedTransactionObject).toHaveProperty('inputData');
});
test('Has defaults for all object values (except for `to`)', async () => {
mockedBigNumber.mockImplementation(number => number);
mockedBigNumber.mockImplementation((number) => number);
const validatedTransactionObject = transactionObjectValidator();
expect(validatedTransactionObject).toHaveProperty(
'gasPrice',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { recoveryParamNormalizer } from '../../src/normalizers';

import { SIGNATURE } from '../../src/defaults';
import { SIGNATURE } from '../../src/constants';

describe('`Core` Module', () => {
describe('`recoveryParamNormalizer()` normalizer', () => {
Expand Down
18 changes: 7 additions & 11 deletions packages/purser-core/__tests__/utils/bigNumber.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BN from 'bn.js';

import { bigNumber } from '../../src/utils';
import * as defaults from '../../src/defaults';
import * as constants from '../../src/constants';

describe('`Core` Module', () => {
describe('`bigNumber()` util', () => {
Expand All @@ -16,25 +16,21 @@ describe('`Core` Module', () => {
expect(bigNumberInstance).toHaveProperty('fromGwei');
});
test('Correctly converts to WEI', () => {
const bigNumberWei = bigNumber(1)
.toWei()
.toString();
expect(bigNumberWei).toEqual(`${defaults.WEI_MINIFICATION}`);
const bigNumberWei = bigNumber(1).toWei().toString();
expect(bigNumberWei).toEqual(`${constants.WEI_MINIFICATION}`);
});
test('Correctly converts from WEI', () => {
const bigNumberValue = bigNumber(`${defaults.WEI_MINIFICATION}`)
const bigNumberValue = bigNumber(`${constants.WEI_MINIFICATION}`)
.fromWei()
.toString();
expect(bigNumberValue).toEqual(`1`);
});
test('Correctly converts to GWEI', () => {
const bigNumberGwei = bigNumber(1)
.toGwei()
.toString();
expect(bigNumberGwei).toEqual(`${defaults.GWEI_MINIFICATION}`);
const bigNumberGwei = bigNumber(1).toGwei().toString();
expect(bigNumberGwei).toEqual(`${constants.GWEI_MINIFICATION}`);
});
test('Correctly converts from GWEI', () => {
const bigNumberValue = bigNumber(`${defaults.GWEI_MINIFICATION}`)
const bigNumberValue = bigNumber(`${constants.GWEI_MINIFICATION}`)
.fromGwei()
.toString();
expect(bigNumberValue).toEqual(`1`);
Expand Down
22 changes: 11 additions & 11 deletions packages/purser-core/__tests__/utils/verbose.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { verbose } from '../../src/utils';
import * as defaults from '../../src/defaults';
import * as constants from '../../src/constants';

// @ts-ignore
global.console = {
Expand All @@ -10,35 +10,35 @@ global.console = {
describe('`Core` Module', () => {
describe('`verbose()` util', () => {
test('Should be verbose if the environment is not defined', () => {
const env = defaults.ENV;
const env = constants.ENV;
// @ts-ignore
defaults.ENV = undefined;
constants.ENV = undefined;
const isVerbose = verbose();
expect(isVerbose).toBeTruthy();
// @ts-ignore
defaults.ENV = env;
constants.ENV = env;
});
test("Should be verbose if we're in a development environment", () => {
const env = defaults.ENV;
const env = constants.ENV;
// @ts-ignore
defaults.ENV = 'development';
constants.ENV = 'development';
const isVerbose = verbose();
expect(isVerbose).toBeTruthy();
// @ts-ignore
defaults.ENV = env;
constants.ENV = env;
});
test("Should NOT be verbose if we're not in `development` env", () => {
const env = defaults.ENV;
const env = constants.ENV;
// @ts-ignore
defaults.ENV = 'production';
constants.ENV = 'production';
let isVerbose = verbose();
expect(isVerbose).not.toBeTruthy();
// @ts-ignore
defaults.ENV = 'testing';
constants.ENV = 'testing';
isVerbose = verbose();
expect(isVerbose).not.toBeTruthy();
// @ts-ignore
defaults.ENV = env;
constants.ENV = env;
});
});
});
8 changes: 4 additions & 4 deletions packages/purser-core/__tests__/utils/warning.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jestMocked } from '../../../testutils';

import { warning } from '../../src/utils';
import * as defaults from '../../src/defaults';
import * as constants from '../../src/constants';

// @ts-ignore
global.console = {
Expand All @@ -18,7 +18,7 @@ describe('`Core` Module', () => {
describe('`warning()` util', () => {
beforeEach(() => {
// @ts-ignore
defaults.ENV = 'development';
constants.ENV = 'development';
});
afterEach(() => {
mockWarn.mockClear();
Expand All @@ -30,7 +30,7 @@ describe('`Core` Module', () => {
});
test("Doesn't log a message when in production", () => {
// @ts-ignore
defaults.ENV = 'production';
constants.ENV = 'production';
warning(message);
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('`Core` Module', () => {
});
test("Doesn't log a message when in production", () => {
// @ts-ignore
defaults.ENV = 'production';
constants.ENV = 'production';
warning(message);
expect(console.warn).not.toHaveBeenCalled();
});
Expand Down
2 changes: 1 addition & 1 deletion packages/purser-core/src/ExtendedBigNumber.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BN from 'bn.js';

import { WEI_MINIFICATION, GWEI_MINIFICATION } from './defaults';
import { WEI_MINIFICATION, GWEI_MINIFICATION } from './constants';

const oneWei = new BN(WEI_MINIFICATION.toString());
const oneGwei = new BN(GWEI_MINIFICATION.toString());
Expand Down
2 changes: 1 addition & 1 deletion packages/purser-core/src/GenericWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { addressNormalizer, hexSequenceNormalizer } from './normalizers';

import { genericClass as messages } from './messages';
import { HEX_HASH_TYPE, SPLITTER, CHAIN_IDS } from './defaults';
import { HEX_HASH_TYPE, SPLITTER, CHAIN_IDS } from './constants';
import {
AddressObject,
WalletType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


import { DerivationPathDefaultType } from './types';

/*
Expand Down Expand Up @@ -55,21 +53,21 @@ export const MATCH = {
/*
* Used to separate misc. derivation paths or urls
*/
export const SPLITTER: string = '/';
export const SPLITTER = '/';

/*
* Used to better inform the user when a variable doesn't have a value
* (Used in Error messsages)
*/
export const UNDEFINED: string = 'undefined';
export const UNDEFINED = 'undefined';

/*
* Hash types
*/
export const HEX_HASH_TYPE: BufferEncoding = 'hex';

export const WEI_MINIFICATION: number = 1e18;
export const GWEI_MINIFICATION: number = 1e9;
export const WEI_MINIFICATION = 1e18;
export const GWEI_MINIFICATION = 1e9;

/*
* Default class descriptors.
Expand Down Expand Up @@ -98,7 +96,7 @@ export const DESCRIPTORS = {
/*
* Defaults for the transaction object
*/
export const TRANSACTION = {
export const TRANSACTION = {
CHAIN_ID: 1,
GAS_PRICE: '9000000000', // 9 Gwei
GAS_LIMIT: '21000',
Expand All @@ -117,7 +115,7 @@ export const SIGNATURE = {
RECOVERY_EVEN: 28,
};

export const HTTPS_PROTOCOL: string = 'https:';
export const HTTPS_PROTOCOL = 'https:';

/*
* Chain IDs
Expand Down
Loading

0 comments on commit ffd6884

Please sign in to comment.