diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-08-22 19:27:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-22 19:27:40 +0800 |
commit | 0bc9083bff341cc7841fb1ccd84fa50e6749151d (patch) | |
tree | c188a96044d78d9446213fe565152d13a33a0858 | |
parent | e376189bc69682b2445f344966332c63d8e9fa4d (diff) | |
parent | 4207400f8a9ebd8e7cbf0b7f9edf72e6f01db7db (diff) | |
download | dexon-sol-tools-0bc9083bff341cc7841fb1ccd84fa50e6749151d.tar dexon-sol-tools-0bc9083bff341cc7841fb1ccd84fa50e6749151d.tar.gz dexon-sol-tools-0bc9083bff341cc7841fb1ccd84fa50e6749151d.tar.bz2 dexon-sol-tools-0bc9083bff341cc7841fb1ccd84fa50e6749151d.tar.lz dexon-sol-tools-0bc9083bff341cc7841fb1ccd84fa50e6749151d.tar.xz dexon-sol-tools-0bc9083bff341cc7841fb1ccd84fa50e6749151d.tar.zst dexon-sol-tools-0bc9083bff341cc7841fb1ccd84fa50e6749151d.zip |
Merge pull request #124 from 0xProject/reject-checksummed-addresses
Reject checksummed addresses
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/schemas/basic_type_schemas.ts | 2 | ||||
-rw-r--r-- | src/utils/assert.ts | 4 | ||||
-rw-r--r-- | test/0x.js_test.ts | 2 | ||||
-rw-r--r-- | test/schema_test.ts | 12 | ||||
-rw-r--r-- | test/token_wrapper_test.ts | 2 | ||||
-rw-r--r-- | yarn.lock | 6 |
8 files changed, 24 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 19181c403..a830106f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +v0.9.4 - _Aug 22, 2017_ +------------------------ + * Add clear error message when checksummed address is passed to a public method (#124) + v0.9.3 - _Aug 22, 2017_ ------------------------ * Update contract artifacts to include latest Kovan and Mainnet deploys. diff --git a/package.json b/package.json index 021c9fc1a..ec4b11b3e 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "types-ethereumjs-util": "^0.0.5", "typescript": "^2.4.1", "web3-provider-engine": "^13.0.1", - "web3-typescript-typings": "^0.3.0", + "web3-typescript-typings": "^0.3.2", "webpack": "^3.1.0" }, "dependencies": { diff --git a/src/schemas/basic_type_schemas.ts b/src/schemas/basic_type_schemas.ts index c3b81185d..5d66cf79b 100644 --- a/src/schemas/basic_type_schemas.ts +++ b/src/schemas/basic_type_schemas.ts @@ -1,7 +1,7 @@ export const addressSchema = { id: '/addressSchema', type: 'string', - pattern: '^0[xX][0-9A-Fa-f]{40}$', + pattern: '^0x[0-9a-f]{40}$', }; export const numberSchema = { diff --git a/src/utils/assert.ts b/src/utils/assert.ts index 969209208..0e6169b44 100644 --- a/src/utils/assert.ts +++ b/src/utils/assert.ts @@ -24,6 +24,10 @@ export const assert = { isETHAddressHex(variableName: string, value: string): void { const web3 = new Web3(); this.assert(web3.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value)); + this.assert( + web3.isAddress(value) && !web3.isChecksumAddress(value), + `Checksummed addresses are not supported. Convert ${variableName} to lower case before passing`, + ); }, doesBelongToStringEnum(variableName: string, value: string, stringEnum: any /* There is no base type for every string enum */): void { diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 03bf21e96..2b4e80ea3 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -57,7 +57,7 @@ describe('ZeroEx library', () => { ).to.become(false); }); it('should return false if the address doesn\'t pertain to the signature & data', async () => { - const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'; + const validUnrelatedAddress = '0x8b0292b11a196601ed2ce54b665cafeca0347d42'; expect(ZeroEx.isValidSignature(dataHex, signature, validUnrelatedAddress)).to.be.false(); return expect( (zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync(dataHex, signature, diff --git a/test/schema_test.ts b/test/schema_test.ts index 1fac2b380..e47f8b8e5 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -42,11 +42,17 @@ describe('Schema', () => { }); describe('#addressSchema', () => { it('should validate valid addresses', () => { - const testCases = ['0x8b0292B11a196601eD2ce54B665CaFEca0347D42', constants.NULL_ADDRESS]; + const testCases = ['0x8b0292b11a196601ed2ce54b665cafeca0347d42', constants.NULL_ADDRESS]; validateAgainstSchema(testCases, addressSchema); }); it('should fail for invalid addresses', () => { - const testCases = ['0x', '0', '0x00', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42']; + const testCases = [ + '0x', + '0', + '0x00', + '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42', + '0x8b0292B11a196601eD2ce54B665CaFEca0347D42', + ]; const shouldFail = true; validateAgainstSchema(testCases, addressSchema, shouldFail); }); @@ -159,7 +165,7 @@ describe('Schema', () => { name: 'Zero Ex', symbol: 'ZRX', decimals: 100500, - address: '0x8b0292B11a196601eD2ce54B665CaFEca0347D42', + address: '0x8b0292b11a196601ed2ce54b665cafeca0347d42', url: 'https://0xproject.com', }; it('should validate valid token', () => { diff --git a/test/token_wrapper_test.ts b/test/token_wrapper_test.ts index 45d5caa5b..8c680b754 100644 --- a/test/token_wrapper_test.ts +++ b/test/token_wrapper_test.ts @@ -165,7 +165,7 @@ describe('TokenWrapper', () => { }); it('should return a balance of 0 for a non-existent owner address', async () => { const token = tokens[0]; - const nonExistentOwner = '0x198C6Ad858F213Fb31b6FE809E25040E6B964593'; + const nonExistentOwner = '0x198c6ad858f213fb31b6fe809e25040e6b964593'; const balance = await zeroEx.token.getBalanceAsync(token.address, nonExistentOwner); const expectedBalance = new BigNumber(0); return expect(balance).to.be.bignumber.equal(expectedBalance); @@ -5047,9 +5047,9 @@ web3-provider-engine@^8.4.0: xhr "^2.2.0" xtend "^4.0.1" -web3-typescript-typings@^0.3.0: - version "0.3.0" - resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.3.0.tgz#1df583d8d9012059802dee90f72144576e0ab4fe" +web3-typescript-typings@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.3.2.tgz#75f65fe452e35e2b96192908199dbb7a9ab5bcc3" dependencies: bignumber.js "^4.0.2" |