You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
511 lines
16 KiB
511 lines
16 KiB
4 years ago
|
import assert from 'assert';
|
||
|
import sinon from 'sinon';
|
||
|
import proxyquire from 'proxyquire';
|
||
7 years ago
|
import {
|
||
7 years ago
|
BASE_TOKEN_GAS_COST,
|
||
7 years ago
|
SIMPLE_GAS_COST,
|
||
7 years ago
|
INSUFFICIENT_FUNDS_ERROR,
|
||
|
INSUFFICIENT_TOKENS_ERROR,
|
||
4 years ago
|
} from './send.constants';
|
||
7 years ago
|
|
||
|
const stubs = {
|
||
6 years ago
|
addCurrencies: sinon.stub().callsFake((a, b) => {
|
||
4 years ago
|
let [a1, b1] = [a, b];
|
||
4 years ago
|
if (String(a).match(/^0x.+/u)) {
|
||
4 years ago
|
a1 = Number(String(a).slice(2));
|
||
5 years ago
|
}
|
||
4 years ago
|
if (String(b).match(/^0x.+/u)) {
|
||
4 years ago
|
b1 = Number(String(b).slice(2));
|
||
5 years ago
|
}
|
||
4 years ago
|
return a1 + b1;
|
||
7 years ago
|
}),
|
||
6 years ago
|
conversionUtil: sinon.stub().callsFake((val) => parseInt(val, 16)),
|
||
4 years ago
|
conversionGTE: sinon
|
||
|
.stub()
|
||
|
.callsFake((obj1, obj2) => obj1.value >= obj2.value),
|
||
7 years ago
|
multiplyCurrencies: sinon.stub().callsFake((a, b) => `${a}x${b}`),
|
||
4 years ago
|
calcTokenAmount: sinon.stub().callsFake((a, d) => `calc:${a}${d}`),
|
||
7 years ago
|
rawEncode: sinon.stub().returns([16, 1100]),
|
||
4 years ago
|
conversionGreaterThan: sinon
|
||
|
.stub()
|
||
|
.callsFake((obj1, obj2) => obj1.value > obj2.value),
|
||
|
conversionLessThan: sinon
|
||
|
.stub()
|
||
|
.callsFake((obj1, obj2) => obj1.value < obj2.value),
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
4 years ago
|
const sendUtils = proxyquire('./send.utils.js', {
|
||
6 years ago
|
'../../helpers/utils/conversion-util': {
|
||
7 years ago
|
addCurrencies: stubs.addCurrencies,
|
||
|
conversionUtil: stubs.conversionUtil,
|
||
|
conversionGTE: stubs.conversionGTE,
|
||
|
multiplyCurrencies: stubs.multiplyCurrencies,
|
||
7 years ago
|
conversionGreaterThan: stubs.conversionGreaterThan,
|
||
|
conversionLessThan: stubs.conversionLessThan,
|
||
7 years ago
|
},
|
||
6 years ago
|
'../../helpers/utils/token-util': { calcTokenAmount: stubs.calcTokenAmount },
|
||
7 years ago
|
'ethereumjs-abi': {
|
||
|
rawEncode: stubs.rawEncode,
|
||
|
},
|
||
4 years ago
|
});
|
||
7 years ago
|
|
||
|
const {
|
||
|
calcGasTotal,
|
||
4 years ago
|
estimateGasForSend,
|
||
7 years ago
|
doesAmountErrorRequireUpdate,
|
||
|
generateTokenTransferData,
|
||
|
getAmountErrorObject,
|
||
7 years ago
|
getGasFeeErrorObject,
|
||
7 years ago
|
getToAddressForGasUpdate,
|
||
7 years ago
|
calcTokenBalance,
|
||
|
isBalanceSufficient,
|
||
|
isTokenBalanceSufficient,
|
||
7 years ago
|
removeLeadingZeroes,
|
||
4 years ago
|
} = sendUtils;
|
||
7 years ago
|
|
||
5 years ago
|
describe('send utils', function () {
|
||
|
describe('calcGasTotal()', function () {
|
||
|
it('should call multiplyCurrencies with the correct params and return the multiplyCurrencies return', function () {
|
||
4 years ago
|
const result = calcGasTotal(12, 15);
|
||
|
assert.strictEqual(result, '12x15');
|
||
|
const call_ = stubs.multiplyCurrencies.getCall(0).args;
|
||
4 years ago
|
assert.deepStrictEqual(call_, [
|
||
4 years ago
|
12,
|
||
|
15,
|
||
|
{
|
||
7 years ago
|
toNumericBase: 'hex',
|
||
5 years ago
|
multiplicandBase: 16,
|
||
|
multiplierBase: 16,
|
||
4 years ago
|
},
|
||
4 years ago
|
]);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('doesAmountErrorRequireUpdate()', function () {
|
||
7 years ago
|
const config = {
|
||
|
'should return true if balances are different': {
|
||
|
balance: 0,
|
||
|
prevBalance: 1,
|
||
|
expectedResult: true,
|
||
|
},
|
||
|
'should return true if gasTotals are different': {
|
||
|
gasTotal: 0,
|
||
|
prevGasTotal: 1,
|
||
|
expectedResult: true,
|
||
|
},
|
||
|
'should return true if token balances are different': {
|
||
|
tokenBalance: 0,
|
||
|
prevTokenBalance: 1,
|
||
5 years ago
|
sendToken: { address: '0x0' },
|
||
7 years ago
|
expectedResult: true,
|
||
|
},
|
||
|
'should return false if they are all the same': {
|
||
|
balance: 1,
|
||
|
prevBalance: 1,
|
||
|
gasTotal: 1,
|
||
|
prevGasTotal: 1,
|
||
|
tokenBalance: 1,
|
||
|
prevTokenBalance: 1,
|
||
5 years ago
|
sendToken: { address: '0x0' },
|
||
7 years ago
|
expectedResult: false,
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
Object.entries(config).forEach(([description, obj]) => {
|
||
5 years ago
|
it(description, function () {
|
||
4 years ago
|
assert.strictEqual(
|
||
|
doesAmountErrorRequireUpdate(obj),
|
||
|
obj.expectedResult,
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('generateTokenTransferData()', function () {
|
||
5 years ago
|
it('should return undefined if not passed a send token', function () {
|
||
4 years ago
|
assert.strictEqual(
|
||
4 years ago
|
generateTokenTransferData({
|
||
|
toAddress: 'mockAddress',
|
||
|
amount: '0xa',
|
||
|
sendToken: undefined,
|
||
|
}),
|
||
|
undefined,
|
||
4 years ago
|
);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should call abi.rawEncode with the correct params', function () {
|
||
4 years ago
|
stubs.rawEncode.resetHistory();
|
||
4 years ago
|
generateTokenTransferData({
|
||
|
toAddress: 'mockAddress',
|
||
|
amount: 'ab',
|
||
|
sendToken: { address: '0x0' },
|
||
4 years ago
|
});
|
||
4 years ago
|
assert.deepStrictEqual(stubs.rawEncode.getCall(0).args, [
|
||
4 years ago
|
['address', 'uint256'],
|
||
|
['mockAddress', '0xab'],
|
||
4 years ago
|
]);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should return encoded token transfer data', function () {
|
||
4 years ago
|
assert.strictEqual(
|
||
4 years ago
|
generateTokenTransferData({
|
||
|
toAddress: 'mockAddress',
|
||
|
amount: '0xa',
|
||
|
sendToken: { address: '0x0' },
|
||
|
}),
|
||
4 years ago
|
'0xa9059cbb104c',
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('getAmountErrorObject()', function () {
|
||
7 years ago
|
const config = {
|
||
|
'should return insufficientFunds error if isBalanceSufficient returns false': {
|
||
|
amount: 15,
|
||
|
balance: 1,
|
||
|
conversionRate: 3,
|
||
|
gasTotal: 17,
|
||
|
primaryCurrency: 'ABC',
|
||
|
expectedResult: { amount: INSUFFICIENT_FUNDS_ERROR },
|
||
|
},
|
||
5 years ago
|
'should not return insufficientFunds error if sendToken is truthy': {
|
||
7 years ago
|
amount: '0x0',
|
||
|
balance: 1,
|
||
|
conversionRate: 3,
|
||
|
gasTotal: 17,
|
||
|
primaryCurrency: 'ABC',
|
||
5 years ago
|
sendToken: { address: '0x0', symbol: 'DEF', decimals: 0 },
|
||
7 years ago
|
decimals: 0,
|
||
|
tokenBalance: 'sometokenbalance',
|
||
|
expectedResult: { amount: null },
|
||
|
},
|
||
7 years ago
|
'should return insufficientTokens error if token is selected and isTokenBalanceSufficient returns false': {
|
||
|
amount: '0x10',
|
||
|
balance: 100,
|
||
|
conversionRate: 3,
|
||
|
decimals: 10,
|
||
|
gasTotal: 17,
|
||
|
primaryCurrency: 'ABC',
|
||
5 years ago
|
sendToken: { address: '0x0' },
|
||
7 years ago
|
tokenBalance: 123,
|
||
|
expectedResult: { amount: INSUFFICIENT_TOKENS_ERROR },
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
Object.entries(config).forEach(([description, obj]) => {
|
||
5 years ago
|
it(description, function () {
|
||
4 years ago
|
assert.deepStrictEqual(getAmountErrorObject(obj), obj.expectedResult);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('getGasFeeErrorObject()', function () {
|
||
7 years ago
|
const config = {
|
||
|
'should return insufficientFunds error if isBalanceSufficient returns false': {
|
||
|
balance: 16,
|
||
|
conversionRate: 3,
|
||
|
gasTotal: 17,
|
||
|
primaryCurrency: 'ABC',
|
||
|
expectedResult: { gasFee: INSUFFICIENT_FUNDS_ERROR },
|
||
|
},
|
||
|
'should return null error if isBalanceSufficient returns true': {
|
||
|
balance: 16,
|
||
|
conversionRate: 3,
|
||
|
gasTotal: 15,
|
||
|
primaryCurrency: 'ABC',
|
||
|
expectedResult: { gasFee: null },
|
||
|
},
|
||
4 years ago
|
};
|
||
4 years ago
|
Object.entries(config).forEach(([description, obj]) => {
|
||
5 years ago
|
it(description, function () {
|
||
4 years ago
|
assert.deepStrictEqual(getGasFeeErrorObject(obj), obj.expectedResult);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('calcTokenBalance()', function () {
|
||
4 years ago
|
it('should return the calculated token balance', function () {
|
||
4 years ago
|
assert.strictEqual(
|
||
4 years ago
|
calcTokenBalance({
|
||
|
sendToken: {
|
||
|
address: '0x0',
|
||
|
decimals: 11,
|
||
|
},
|
||
|
usersToken: {
|
||
|
balance: 20,
|
||
|
},
|
||
|
}),
|
||
|
'calc:2011',
|
||
4 years ago
|
);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('isBalanceSufficient()', function () {
|
||
|
it('should correctly call addCurrencies and return the result of calling conversionGTE', function () {
|
||
4 years ago
|
stubs.conversionGTE.resetHistory();
|
||
7 years ago
|
const result = isBalanceSufficient({
|
||
|
amount: 15,
|
||
|
balance: 100,
|
||
|
conversionRate: 3,
|
||
|
gasTotal: 17,
|
||
|
primaryCurrency: 'ABC',
|
||
4 years ago
|
});
|
||
4 years ago
|
assert.deepStrictEqual(stubs.addCurrencies.getCall(0).args, [
|
||
4 years ago
|
15,
|
||
|
17,
|
||
|
{
|
||
|
aBase: 16,
|
||
|
bBase: 16,
|
||
|
toNumericBase: 'hex',
|
||
|
},
|
||
4 years ago
|
]);
|
||
4 years ago
|
assert.deepStrictEqual(stubs.conversionGTE.getCall(0).args, [
|
||
4 years ago
|
{
|
||
|
value: 100,
|
||
|
fromNumericBase: 'hex',
|
||
|
fromCurrency: 'ABC',
|
||
|
conversionRate: 3,
|
||
|
},
|
||
|
{
|
||
|
value: 32,
|
||
|
fromNumericBase: 'hex',
|
||
|
conversionRate: 3,
|
||
|
fromCurrency: 'ABC',
|
||
|
},
|
||
4 years ago
|
]);
|
||
7 years ago
|
|
||
4 years ago
|
assert.strictEqual(result, true);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('isTokenBalanceSufficient()', function () {
|
||
|
it('should correctly call conversionUtil and return the result of calling conversionGTE', function () {
|
||
4 years ago
|
stubs.conversionGTE.resetHistory();
|
||
|
stubs.conversionUtil.resetHistory();
|
||
7 years ago
|
const result = isTokenBalanceSufficient({
|
||
|
amount: '0x10',
|
||
|
tokenBalance: 123,
|
||
|
decimals: 10,
|
||
4 years ago
|
});
|
||
4 years ago
|
assert.deepStrictEqual(stubs.conversionUtil.getCall(0).args, [
|
||
4 years ago
|
'0x10',
|
||
|
{
|
||
|
fromNumericBase: 'hex',
|
||
|
},
|
||
4 years ago
|
]);
|
||
4 years ago
|
assert.deepStrictEqual(stubs.conversionGTE.getCall(0).args, [
|
||
4 years ago
|
{
|
||
|
value: 123,
|
||
|
fromNumericBase: 'hex',
|
||
|
},
|
||
|
{
|
||
|
value: 'calc:1610',
|
||
|
},
|
||
4 years ago
|
]);
|
||
7 years ago
|
|
||
4 years ago
|
assert.strictEqual(result, false);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
describe('estimateGasForSend', function () {
|
||
7 years ago
|
const baseMockParams = {
|
||
|
blockGasLimit: '0x64',
|
||
|
selectedAddress: 'mockAddress',
|
||
|
to: '0xisContract',
|
||
4 years ago
|
estimateGasMethod: sinon.stub().callsFake(({ to }) => {
|
||
|
if (typeof to === 'string' && to.match(/willFailBecauseOf:/u)) {
|
||
4 years ago
|
throw new Error(to.match(/:(.+)$/u)[1]);
|
||
4 years ago
|
}
|
||
4 years ago
|
return { toString: (n) => `0xabc${n}` };
|
||
4 years ago
|
}),
|
||
4 years ago
|
};
|
||
7 years ago
|
const baseExpectedCall = {
|
||
|
from: 'mockAddress',
|
||
|
gas: '0x64x0.95',
|
||
|
to: '0xisContract',
|
||
6 years ago
|
value: '0xff',
|
||
4 years ago
|
};
|
||
7 years ago
|
|
||
5 years ago
|
beforeEach(function () {
|
||
7 years ago
|
global.eth = {
|
||
4 years ago
|
getCode: sinon
|
||
|
.stub()
|
||
|
.callsFake((address) =>
|
||
|
Promise.resolve(address.match(/isContract/u) ? 'not-0x' : '0x'),
|
||
|
),
|
||
4 years ago
|
};
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
afterEach(function () {
|
||
4 years ago
|
baseMockParams.estimateGasMethod.resetHistory();
|
||
|
global.eth.getCode.resetHistory();
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call ethQuery.estimateGasForSend with the expected params', async function () {
|
||
4 years ago
|
const result = await estimateGasForSend(baseMockParams);
|
||
|
assert.strictEqual(baseMockParams.estimateGasMethod.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
|
baseMockParams.estimateGasMethod.getCall(0).args[0],
|
||
|
{
|
||
|
gasPrice: undefined,
|
||
|
value: undefined,
|
||
|
...baseExpectedCall,
|
||
|
},
|
||
4 years ago
|
);
|
||
|
assert.strictEqual(result, '0xabc16');
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call ethQuery.estimateGasForSend with the expected params when initialGasLimitHex is lower than the upperGasLimit', async function () {
|
||
4 years ago
|
const result = await estimateGasForSend({
|
||
|
...baseMockParams,
|
||
|
blockGasLimit: '0xbcd',
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(baseMockParams.estimateGasMethod.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
|
baseMockParams.estimateGasMethod.getCall(0).args[0],
|
||
|
{
|
||
|
gasPrice: undefined,
|
||
|
value: undefined,
|
||
|
...baseExpectedCall,
|
||
|
gas: '0xbcdx0.95',
|
||
|
},
|
||
4 years ago
|
);
|
||
|
assert.strictEqual(result, '0xabc16x1.5');
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call ethQuery.estimateGasForSend with a value of 0x0 and the expected data and to if passed a sendToken', async function () {
|
||
4 years ago
|
const result = await estimateGasForSend({
|
||
|
data: 'mockData',
|
||
|
sendToken: { address: 'mockAddress' },
|
||
|
...baseMockParams,
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(baseMockParams.estimateGasMethod.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
|
baseMockParams.estimateGasMethod.getCall(0).args[0],
|
||
|
{
|
||
|
...baseExpectedCall,
|
||
|
gasPrice: undefined,
|
||
|
value: '0x0',
|
||
|
data: '0xa9059cbb104c',
|
||
|
to: 'mockAddress',
|
||
|
},
|
||
4 years ago
|
);
|
||
|
assert.strictEqual(result, '0xabc16');
|
||
|
});
|
||
7 years ago
|
|
||
4 years ago
|
it('should call ethQuery.estimateGasForSend without a recipient if the recipient is empty and data passed', async function () {
|
||
4 years ago
|
const data = 'mockData';
|
||
|
const to = '';
|
||
|
const result = await estimateGasForSend({ ...baseMockParams, data, to });
|
||
|
assert.strictEqual(baseMockParams.estimateGasMethod.callCount, 1);
|
||
4 years ago
|
assert.deepStrictEqual(
|
||
|
baseMockParams.estimateGasMethod.getCall(0).args[0],
|
||
|
{
|
||
|
gasPrice: undefined,
|
||
|
value: '0xff',
|
||
|
data,
|
||
|
from: baseExpectedCall.from,
|
||
|
gas: baseExpectedCall.gas,
|
||
|
},
|
||
4 years ago
|
);
|
||
|
assert.strictEqual(result, '0xabc16');
|
||
|
});
|
||
6 years ago
|
|
||
5 years ago
|
it(`should return ${SIMPLE_GAS_COST} if ethQuery.getCode does not return '0x'`, async function () {
|
||
4 years ago
|
assert.strictEqual(baseMockParams.estimateGasMethod.callCount, 0);
|
||
4 years ago
|
const result = await estimateGasForSend({
|
||
|
...baseMockParams,
|
||
|
to: '0x123',
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(result, SIMPLE_GAS_COST);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it(`should return ${SIMPLE_GAS_COST} if not passed a sendToken or truthy to address`, async function () {
|
||
4 years ago
|
assert.strictEqual(baseMockParams.estimateGasMethod.callCount, 0);
|
||
|
const result = await estimateGasForSend({ ...baseMockParams, to: null });
|
||
|
assert.strictEqual(result, SIMPLE_GAS_COST);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it(`should not return ${SIMPLE_GAS_COST} if passed a sendToken`, async function () {
|
||
4 years ago
|
assert.strictEqual(baseMockParams.estimateGasMethod.callCount, 0);
|
||
4 years ago
|
const result = await estimateGasForSend({
|
||
|
...baseMockParams,
|
||
|
to: '0x123',
|
||
|
sendToken: { address: '0x0' },
|
||
4 years ago
|
});
|
||
|
assert.notStrictEqual(result, SIMPLE_GAS_COST);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it(`should return ${BASE_TOKEN_GAS_COST} if passed a sendToken but no to address`, async function () {
|
||
4 years ago
|
const result = await estimateGasForSend({
|
||
|
...baseMockParams,
|
||
|
to: null,
|
||
|
sendToken: { address: '0x0' },
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(result, BASE_TOKEN_GAS_COST);
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it(`should return the adjusted blockGasLimit if it fails with a 'Transaction execution error.'`, async function () {
|
||
4 years ago
|
const result = await estimateGasForSend({
|
||
|
...baseMockParams,
|
||
|
to: 'isContract willFailBecauseOf:Transaction execution error.',
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(result, '0x64x0.95');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it(`should return the adjusted blockGasLimit if it fails with a 'gas required exceeds allowance or always failing transaction.'`, async function () {
|
||
4 years ago
|
const result = await estimateGasForSend({
|
||
|
...baseMockParams,
|
||
|
to:
|
||
|
'isContract willFailBecauseOf:gas required exceeds allowance or always failing transaction.',
|
||
4 years ago
|
});
|
||
|
assert.strictEqual(result, '0x64x0.95');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it(`should reject other errors`, async function () {
|
||
7 years ago
|
try {
|
||
4 years ago
|
await estimateGasForSend({
|
||
|
...baseMockParams,
|
||
|
to: 'isContract willFailBecauseOf:some other error',
|
||
4 years ago
|
});
|
||
7 years ago
|
} catch (err) {
|
||
4 years ago
|
assert.strictEqual(err.message, 'some other error');
|
||
7 years ago
|
}
|
||
4 years ago
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('getToAddressForGasUpdate()', function () {
|
||
|
it('should return empty string if all params are undefined or null', function () {
|
||
4 years ago
|
assert.strictEqual(getToAddressForGasUpdate(undefined, null), '');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should return the first string that is not defined or null in lower case', function () {
|
||
4 years ago
|
assert.strictEqual(getToAddressForGasUpdate('A', null), 'a');
|
||
|
assert.strictEqual(getToAddressForGasUpdate(undefined, 'B'), 'b');
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('removeLeadingZeroes()', function () {
|
||
|
it('should remove leading zeroes from int when user types', function () {
|
||
4 years ago
|
assert.strictEqual(removeLeadingZeroes('0'), '0');
|
||
|
assert.strictEqual(removeLeadingZeroes('1'), '1');
|
||
|
assert.strictEqual(removeLeadingZeroes('00'), '0');
|
||
|
assert.strictEqual(removeLeadingZeroes('01'), '1');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should remove leading zeroes from int when user copy/paste', function () {
|
||
4 years ago
|
assert.strictEqual(removeLeadingZeroes('001'), '1');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should remove leading zeroes from float when user types', function () {
|
||
4 years ago
|
assert.strictEqual(removeLeadingZeroes('0.'), '0.');
|
||
|
assert.strictEqual(removeLeadingZeroes('0.0'), '0.0');
|
||
|
assert.strictEqual(removeLeadingZeroes('0.00'), '0.00');
|
||
|
assert.strictEqual(removeLeadingZeroes('0.001'), '0.001');
|
||
|
assert.strictEqual(removeLeadingZeroes('0.10'), '0.10');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('should remove leading zeroes from float when user copy/paste', function () {
|
||
4 years ago
|
assert.strictEqual(removeLeadingZeroes('00.1'), '0.1');
|
||
|
});
|
||
|
});
|
||
|
});
|