Skip to content

Commit

Permalink
update deps, update eslint for node.js style imports
Browse files Browse the repository at this point in the history
  • Loading branch information
shrpne committed Jan 29, 2020
1 parent 3c9ec04 commit 2168726
Show file tree
Hide file tree
Showing 10 changed files with 3,720 additions and 2,593 deletions.
15 changes: 11 additions & 4 deletions .eslintrc.js
Expand Up @@ -25,7 +25,7 @@ module.exports = {
// ],
// // add your custom rules here
rules: {
'indent': ["error", 4],
'indent': ['error', 4],
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
Expand All @@ -41,16 +41,23 @@ module.exports = {
'no-param-reassign': 0,
'no-underscore-dangle': 0,
'no-else-return': 0,
"no-unused-vars": ["warn", { "vars": "all", "args": "after-used", "ignoreRestSiblings": false }],
'no-unused-vars': ['warn', { 'vars': 'all', 'args': 'after-used', 'ignoreRestSiblings': false }],
'no-use-before-define' : 0,
'import/extensions': ['error', 'always', {ignorePackages: true} ],
},
overrides: [
{
files: ['examples/*'],
rules: {
"import/no-extraneous-dependencies": 0,
'import/no-extraneous-dependencies': 0,
'no-console': 0,
}
}
},
{
files: ['test/*'],
rules: {
'import/extensions': 0,
}
},
]
};
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## 0.15.1 - 2020-01-29
- fix naming typo
- update deps

## 0.15.0 - 2019-12-16
- add `addressToString` method
- add `checkToString` method
Expand Down
6,183 changes: 3,650 additions & 2,533 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "minterjs-util",
"version": "0.15.0",
"version": "0.15.1",
"description": "Utils for Minter",
"main": "dist/cjs/index.js",
"module": "src/index.js",
Expand Down Expand Up @@ -52,28 +52,28 @@
"elliptic": "^6.5.2",
"ethereumjs-util": "^6.2.0",
"ethjs-util": "^0.1.6",
"minterjs-tx": "^7.1.1",
"minterjs-tx": "^7.2.1",
"secp256k1": "^3.7.1"
},
"devDependencies": {
"@babel/cli": "^7.7.5",
"@babel/core": "^7.7.5",
"@babel/preset-env": "^7.7.6",
"babel-jest": "^24.9.0",
"@babel/cli": "^7.8.3",
"@babel/core": "^7.8.3",
"@babel/preset-env": "^7.8.3",
"babel-jest": "^25.1.0",
"coveralls": "^3.0.9",
"eslint": "^6.7.2",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.19.1",
"jest": "^24.9.0",
"eslint-plugin-import": "^2.20.0",
"jest": "^25.1.0",
"pre-commit": "^1.2.2",
"rollup": "^1.27.13",
"rollup": "^1.30.1",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.1.3"
"rollup-plugin-terser": "^5.2.0"
}
}
40 changes: 19 additions & 21 deletions src/fee.js
@@ -1,7 +1,5 @@
import {padToEven, isHexString, getBinarySize} from 'ethjs-util';
import {
TX_TYPE_SEND, TX_TYPE_SELL, TX_TYPE_SELL_ALL, TX_TYPE_BUY, TX_TYPE_CREATE_COIN, TX_TYPE_DECLARE_CANDIDACY, TX_TYPE_SET_CANDIDATE_ON, TX_TYPE_SET_CANDIDATE_OFF, TX_TYPE_DELEGATE, TX_TYPE_UNBOND, TX_TYPE_REDEEM_CHECK, TX_TYPE_CREATE_MULTISIG, TX_TYPE_MULTISEND, TX_TYPE_EDIT_CANDIDATE,
} from 'minterjs-tx/src/tx-types';
import {TX_TYPE} from 'minterjs-tx';

/**
*
Expand All @@ -17,8 +15,8 @@ export function getFeeValue(txType, {payload, coinSymbol, multisendCount} = {})
txType = `0x${padToEven(txType.toString(16)).toUpperCase()}`;
}

if (txType === TX_TYPE_MULTISEND && !(multisendCount >= 1)) {
throw new Error('`multisendCount` should be positive integer when tx type is TX_TYPE_MULTISEND');
if (txType === TX_TYPE.MULTISEND && !(multisendCount >= 1)) {
throw new Error('`multisendCount` should be positive integer when tx type is TX_TYPE.MULTISEND');
}


Expand All @@ -35,9 +33,9 @@ export function getFeeValue(txType, {payload, coinSymbol, multisendCount} = {})
const COIN_UNIT = 0.001;
const COIN_UNIT_PART = 1 / COIN_UNIT; // negate js math quirks, ex.: 18 * 0.001 = 0.018000000000000002
// multisend fee = base fee + extra fee based on count
const multisendExtraCountFee = txType === TX_TYPE_MULTISEND ? (multisendCount - 1) * 5 : 0;
const multisendExtraCountFee = txType === TX_TYPE.MULTISEND ? (multisendCount - 1) * 5 : 0;
// coin symbol extra fee, value in base coin (not in units)
const coinSymbolFee = txType === TX_TYPE_CREATE_COIN ? getCoinSymbolFee(coinSymbol) : 0;
const coinSymbolFee = txType === TX_TYPE.CREATE_COIN ? getCoinSymbolFee(coinSymbol) : 0;
return (baseUnits + payloadLength * 2 + multisendExtraCountFee) / COIN_UNIT_PART + coinSymbolFee;
}

Expand All @@ -64,18 +62,18 @@ export const COIN_SYMBOL_FEES = {
* @type {{string: number}}
*/
export const BASE_FEES = {
[TX_TYPE_SEND]: 10,
[TX_TYPE_SELL]: 100,
[TX_TYPE_SELL_ALL]: 100,
[TX_TYPE_BUY]: 100,
[TX_TYPE_CREATE_COIN]: 0,
[TX_TYPE_DECLARE_CANDIDACY]: 10000,
[TX_TYPE_DELEGATE]: 200,
[TX_TYPE_UNBOND]: 200,
[TX_TYPE_REDEEM_CHECK]: 30,
[TX_TYPE_SET_CANDIDATE_ON]: 100,
[TX_TYPE_SET_CANDIDATE_OFF]: 100,
[TX_TYPE_CREATE_MULTISIG]: 100,
[TX_TYPE_MULTISEND]: 10, // 10+(n-1)*5 units
[TX_TYPE_EDIT_CANDIDATE]: 10000,
[TX_TYPE.SEND]: 10,
[TX_TYPE.SELL]: 100,
[TX_TYPE.SELL_ALL]: 100,
[TX_TYPE.BUY]: 100,
[TX_TYPE.CREATE_COIN]: 0,
[TX_TYPE.DECLARE_CANDIDACY]: 10000,
[TX_TYPE.DELEGATE]: 200,
[TX_TYPE.UNBOND]: 200,
[TX_TYPE.REDEEM_CHECK]: 30,
[TX_TYPE.SET_CANDIDATE_ON]: 100,
[TX_TYPE.SET_CANDIDATE_OFF]: 100,
[TX_TYPE.CREATE_MULTISIG]: 100,
[TX_TYPE.MULTISEND]: 10, // 10+(n-1)*5 units
[TX_TYPE.EDIT_CANDIDATE]: 10000,
};
10 changes: 5 additions & 5 deletions src/index.js
@@ -1,12 +1,12 @@
import {publicToAddress, publicToString, isValidPublic} from './public';
import {convert, convertFromPip, convertToPip} from './converter';
import {publicToAddress, publicToString, isValidPublic} from './public.js';
import {convert, convertFromPip, convertToPip} from './converter.js';
import {
mPrefixToHex, mPrefixStrip, mToBuffer, toBuffer, addressToString, checkToString, privateToAddressString, isMinterPrefixed, isValidAddress, isValidCheck, isValidTransaction, isValidPublicKeyString,
} from './prefix';
import {getFeeValue} from './fee';
} from './prefix.js';
import {getFeeValue} from './fee.js';
import {
sellCoin, sellCoinByBip, buyCoin, buyCoinByCoin,
} from './coin-math';
} from './coin-math.js';

export {
convert,
Expand Down
6 changes: 3 additions & 3 deletions src/prefix.js
Expand Up @@ -59,9 +59,9 @@ export function addressToString(address) {
return `Mx${address.toString('hex')}`;
}

export function checkToString(address) {
address = toBuffer(address);
return `Mc${address.toString('hex')}`;
export function checkToString(check) {
check = toBuffer(check);
return `Mc${check.toString('hex')}`;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/public.js
@@ -1,7 +1,7 @@
import secp256k1 from 'secp256k1';
import {keccak} from 'ethereumjs-util/dist/hash';
import {keccak} from 'ethereumjs-util/dist/hash.js';
import assert from 'assert';
import { isValidPublicKeyString, mToBuffer, toBuffer } from './prefix';
import { isValidPublicKeyString, mToBuffer, toBuffer } from './prefix.js';

/**
* Returns the ethereum address of a given public key.
Expand Down
5 changes: 3 additions & 2 deletions test/coin-math.test.js
@@ -1,10 +1,11 @@
import Big from 'big.js';
import {
sellCoin, sellCoinByBip, buyCoin, buyCoinByCoin,
} from '~/src';

describe('coin math', () => {
test('sellCoin', () => {
expect(sellCoin({supply: 100, reserve: 1000, crr: 0.1}, 1)).toEqual('95.6179249911957');
expect(new Big(sellCoin({supply: 100, reserve: 1000, crr: 0.1}, 1)).toFixed(12)).toEqual('95.617924991196');
});
test('sellCoin crr 0', () => {
expect(sellCoin({supply: 100, reserve: 1000, crr: 0}, 1)).toEqual('0');
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('coin math', () => {
});

test('buyCoinByCoin', () => {
expect(buyCoinByCoin({supply: 100, reserve: 1000, crr: 0.1}, 1)).toEqual('104.6221254112047');
expect(new Big(buyCoinByCoin({supply: 100, reserve: 1000, crr: 0.1}, 1)).toFixed(12)).toEqual('104.622125411205');
});
test('buyCoinByCoin crr 0', () => {
expect(buyCoinByCoin({supply: 100, reserve: 1000, crr: 0}, 1)).toEqual('0');
Expand Down
24 changes: 12 additions & 12 deletions test/fee.test.js
@@ -1,4 +1,4 @@
import {TX_TYPE_SEND, TX_TYPE_CREATE_COIN, TX_TYPE_MULTISEND} from 'minterjs-tx';
import {TX_TYPE} from 'minterjs-tx';
import { getFeeValue } from '~/src';

describe('getFeeValue', () => {
Expand All @@ -7,34 +7,34 @@ describe('getFeeValue', () => {
});

test('send without payload', () => {
expect(getFeeValue(TX_TYPE_SEND)).toEqual(0.01);
expect(getFeeValue(TX_TYPE.SEND)).toEqual(0.01);
});

test('send with payload', () => {
expect(getFeeValue(TX_TYPE_SEND, {payload: 'asd'})).toEqual(0.016);
expect(getFeeValue(TX_TYPE.SEND, {payload: 'asd'})).toEqual(0.016);
});

test('send with unicode payload', () => {
expect(getFeeValue(TX_TYPE_SEND, {payload: 'asé'})).toEqual(0.018);
expect(getFeeValue(TX_TYPE.SEND, {payload: 'asé'})).toEqual(0.018);
});

test('create coin', () => {
expect(getFeeValue(TX_TYPE_CREATE_COIN, {coinSymbol: 'ABCDEFG'})).toEqual(100);
expect(getFeeValue(TX_TYPE_CREATE_COIN, {coinSymbol: 'ABCDEFGHIJ'})).toEqual(100);
expect(getFeeValue(TX_TYPE_CREATE_COIN, {coinSymbol: 'ABC'})).toEqual(1000000);
expect(getFeeValue(TX_TYPE.CREATE_COIN, {coinSymbol: 'ABCDEFG'})).toEqual(100);
expect(getFeeValue(TX_TYPE.CREATE_COIN, {coinSymbol: 'ABCDEFGHIJ'})).toEqual(100);
expect(getFeeValue(TX_TYPE.CREATE_COIN, {coinSymbol: 'ABC'})).toEqual(1000000);
});

test('create coin without coinSymbolLength', () => {
expect(getFeeValue(TX_TYPE_CREATE_COIN)).toEqual(100);
expect(getFeeValue(TX_TYPE.CREATE_COIN)).toEqual(100);
});

test('multisend', () => {
expect(getFeeValue(TX_TYPE_MULTISEND, {multisendCount: 1})).toEqual(0.01);
expect(getFeeValue(TX_TYPE_MULTISEND, {multisendCount: 2})).toEqual(0.015);
expect(getFeeValue(TX_TYPE_MULTISEND, {multisendCount: 5})).toEqual(0.03);
expect(getFeeValue(TX_TYPE.MULTISEND, {multisendCount: 1})).toEqual(0.01);
expect(getFeeValue(TX_TYPE.MULTISEND, {multisendCount: 2})).toEqual(0.015);
expect(getFeeValue(TX_TYPE.MULTISEND, {multisendCount: 5})).toEqual(0.03);
});

test('multisend throws without multisendCount', () => {
expect(() => getFeeValue(TX_TYPE_MULTISEND)).toThrow();
expect(() => getFeeValue(TX_TYPE.MULTISEND)).toThrow();
});
});

0 comments on commit 2168726

Please sign in to comment.