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.
193 lines
5.2 KiB
193 lines
5.2 KiB
4 years ago
|
import { strict as assert } from 'assert';
|
||
4 years ago
|
import { isPrefixedFormattedHexString } from '../../../shared/modules/network.utils';
|
||
5 years ago
|
|
||
|
import {
|
||
5 years ago
|
ENVIRONMENT_TYPE_POPUP,
|
||
|
ENVIRONMENT_TYPE_NOTIFICATION,
|
||
|
ENVIRONMENT_TYPE_FULLSCREEN,
|
||
|
ENVIRONMENT_TYPE_BACKGROUND,
|
||
4 years ago
|
} from '../../../shared/constants/app';
|
||
4 years ago
|
import { getEnvironmentType, sufficientBalance } from './util';
|
||
7 years ago
|
|
||
5 years ago
|
describe('app utils', function () {
|
||
|
describe('getEnvironmentType', function () {
|
||
|
it('should return popup type', function () {
|
||
4 years ago
|
const environmentType = getEnvironmentType(
|
||
|
'http://extension-id/popup.html',
|
||
4 years ago
|
);
|
||
|
assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should return notification type', function () {
|
||
4 years ago
|
const environmentType = getEnvironmentType(
|
||
|
'http://extension-id/notification.html',
|
||
4 years ago
|
);
|
||
|
assert.equal(environmentType, ENVIRONMENT_TYPE_NOTIFICATION);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should return fullscreen type for home.html', function () {
|
||
4 years ago
|
const environmentType = getEnvironmentType(
|
||
|
'http://extension-id/home.html',
|
||
4 years ago
|
);
|
||
|
assert.equal(environmentType, ENVIRONMENT_TYPE_FULLSCREEN);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should return fullscreen type for phishing.html', function () {
|
||
4 years ago
|
const environmentType = getEnvironmentType(
|
||
|
'http://extension-id/phishing.html',
|
||
4 years ago
|
);
|
||
|
assert.equal(environmentType, ENVIRONMENT_TYPE_FULLSCREEN);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should return background type', function () {
|
||
4 years ago
|
const environmentType = getEnvironmentType(
|
||
|
'http://extension-id/_generated_background_page.html',
|
||
4 years ago
|
);
|
||
|
assert.equal(environmentType, ENVIRONMENT_TYPE_BACKGROUND);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should return the correct type for a URL with a hash fragment', function () {
|
||
4 years ago
|
const environmentType = getEnvironmentType(
|
||
|
'http://extension-id/popup.html#hash',
|
||
4 years ago
|
);
|
||
|
assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should return the correct type for a URL with query parameters', function () {
|
||
4 years ago
|
const environmentType = getEnvironmentType(
|
||
|
'http://extension-id/popup.html?param=foo',
|
||
4 years ago
|
);
|
||
|
assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP);
|
||
|
});
|
||
5 years ago
|
|
||
5 years ago
|
it('should return the correct type for a URL with query parameters and a hash fragment', function () {
|
||
4 years ago
|
const environmentType = getEnvironmentType(
|
||
|
'http://extension-id/popup.html?param=foo#hash',
|
||
4 years ago
|
);
|
||
|
assert.equal(environmentType, ENVIRONMENT_TYPE_POPUP);
|
||
|
});
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
describe('SufficientBalance', function () {
|
||
|
it('returns true if max tx cost is equal to balance.', function () {
|
||
|
const tx = {
|
||
4 years ago
|
value: '0x1',
|
||
|
gas: '0x2',
|
||
|
gasPrice: '0x3',
|
||
4 years ago
|
};
|
||
|
const balance = '0x8';
|
||
7 years ago
|
|
||
4 years ago
|
const result = sufficientBalance(tx, balance);
|
||
|
assert.ok(result, 'sufficient balance found.');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('returns true if max tx cost is less than balance.', function () {
|
||
|
const tx = {
|
||
4 years ago
|
value: '0x1',
|
||
|
gas: '0x2',
|
||
|
gasPrice: '0x3',
|
||
4 years ago
|
};
|
||
|
const balance = '0x9';
|
||
7 years ago
|
|
||
4 years ago
|
const result = sufficientBalance(tx, balance);
|
||
|
assert.ok(result, 'sufficient balance found.');
|
||
|
});
|
||
7 years ago
|
|
||
5 years ago
|
it('returns false if max tx cost is more than balance.', function () {
|
||
|
const tx = {
|
||
4 years ago
|
value: '0x1',
|
||
|
gas: '0x2',
|
||
|
gasPrice: '0x3',
|
||
4 years ago
|
};
|
||
|
const balance = '0x6';
|
||
7 years ago
|
|
||
4 years ago
|
const result = sufficientBalance(tx, balance);
|
||
|
assert.ok(!result, 'insufficient balance found.');
|
||
|
});
|
||
|
});
|
||
4 years ago
|
|
||
|
describe('isPrefixedFormattedHexString', function () {
|
||
|
it('should return true for valid hex strings', function () {
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('0x1'),
|
||
|
true,
|
||
4 years ago
|
'should return true',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('0xa'),
|
||
|
true,
|
||
4 years ago
|
'should return true',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('0xabcd1123fae909aad87452'),
|
||
|
true,
|
||
4 years ago
|
'should return true',
|
||
4 years ago
|
);
|
||
|
});
|
||
4 years ago
|
|
||
|
it('should return false for invalid hex strings', function () {
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('0x'),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('0x0'),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('0x01'),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString(' 0x1'),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('0x1 '),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('0x1afz'),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString('z'),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString(2),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
|
assert.equal(
|
||
4 years ago
|
isPrefixedFormattedHexString(['0x1']),
|
||
|
false,
|
||
4 years ago
|
'should return false',
|
||
4 years ago
|
);
|
||
4 years ago
|
|
||
4 years ago
|
assert.equal(
|
||
|
isPrefixedFormattedHexString(),
|
||
|
false,
|
||
|
'should return false',
|
||
|
);
|
||
|
});
|
||
|
});
|
||
|
});
|