Allow 11 characters in symbol for RPC (#10670)

* Add error in RPC for zero length symbols

* Increase RPC symbol length allowed to 11

* Add RPC tests for new symbol length checks
feature/default_network_editable
Grant Bakker 4 years ago committed by GitHub
parent 8fc2c3272a
commit 94fc420584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/scripts/controllers/preferences.js
  2. 21
      app/scripts/controllers/preferences.test.js

@ -793,9 +793,14 @@ export default class PreferencesController {
if (typeof symbol !== 'string') { if (typeof symbol !== 'string') {
throw ethErrors.rpc.invalidParams(`Invalid symbol: not a string.`); throw ethErrors.rpc.invalidParams(`Invalid symbol: not a string.`);
} }
if (!(symbol.length < 7)) { if (!(symbol.length > 0)) {
throw ethErrors.rpc.invalidParams( throw ethErrors.rpc.invalidParams(
`Invalid symbol "${symbol}": longer than 6 characters.`, `Invalid symbol "${symbol}": shorter than a character.`,
);
}
if (!(symbol.length < 12)) {
throw ethErrors.rpc.invalidParams(
`Invalid symbol "${symbol}": longer than 11 characters.`,
); );
} }
const numDecimals = parseInt(decimals, 10); const numDecimals = parseInt(decimals, 10);

@ -539,6 +539,14 @@ describe('preferences controller', function () {
decimals: 0, decimals: 0,
}), }),
); );
assert.doesNotThrow(() =>
validate({
address: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07',
symbol: 'ABCDEFGHIJK',
decimals: 0,
}),
);
assert.throws( assert.throws(
() => validate({ symbol: 'ABC', decimals: 0 }), () => validate({ symbol: 'ABC', decimals: 0 }),
'missing address should fail', 'missing address should fail',
@ -563,10 +571,19 @@ describe('preferences controller', function () {
() => () =>
validate({ validate({
address: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', address: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07',
symbol: 'ABCDEFGHI', symbol: 'ABCDEFGHIJKLM',
decimals: 0,
}),
'long symbol should fail',
);
assert.throws(
() =>
validate({
address: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07',
symbol: '',
decimals: 0, decimals: 0,
}), }),
'invalid symbol should fail', 'empty symbol should fail',
); );
assert.throws( assert.throws(
() => () =>

Loading…
Cancel
Save