|
4 | 4 | assertIsStrictHexString, |
5 | 5 | isHexString, |
6 | 6 | isStrictHexString, |
| 7 | + isValidHexAddress, |
7 | 8 | remove0x, |
8 | 9 | } from './hex'; |
9 | 10 |
|
@@ -151,6 +152,54 @@ describe('assertIsStrictHexString', () => { |
151 | 152 | }); |
152 | 153 | }); |
153 | 154 |
|
| 155 | +describe('isValidHexAddress', () => { |
| 156 | + describe('with allowNonPrefixed option set to true', () => { |
| 157 | + it.each([ |
| 158 | + '0000000000000000000000000000000000000000', |
| 159 | + 'd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', |
| 160 | + '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', |
| 161 | + '0x0000000000000000000000000000000000000000', |
| 162 | + ])('returns true for a valid prefixed hex address', (hexString) => { |
| 163 | + expect(isValidHexAddress(hexString)).toBe(true); |
| 164 | + }); |
| 165 | + |
| 166 | + it.each([ |
| 167 | + '0000000000000000000000000000000000000000', |
| 168 | + 'd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', |
| 169 | + ])('returns true for a valid non-prefixed hex address', (hexString) => { |
| 170 | + expect(isValidHexAddress(hexString)).toBe(true); |
| 171 | + }); |
| 172 | + }); |
| 173 | + |
| 174 | + describe('with allowNonPrefixed option set to false', () => { |
| 175 | + it.each([ |
| 176 | + '0000000000000000000000000000000000000000', |
| 177 | + 'd8dA6BF26964aF9D7eEd9e03E53415D37aA96045', |
| 178 | + ])('returns false for a valid non-prefixed hex address', (hexString) => { |
| 179 | + expect(isValidHexAddress(hexString, { allowNonPrefixed: false })).toBe( |
| 180 | + false, |
| 181 | + ); |
| 182 | + }); |
| 183 | + }); |
| 184 | + |
| 185 | + it.each([ |
| 186 | + '12345g', |
| 187 | + '1234567890abcdefg', |
| 188 | + '1234567890abcdefG', |
| 189 | + '1234567890abcdefABCDEFg', |
| 190 | + '1234567890abcdefABCDEF1234567890abcdefABCDEFg', |
| 191 | + '0x', |
| 192 | + '0x0', |
| 193 | + '0x12345g', |
| 194 | + '0x1234567890abcdefg', |
| 195 | + '0x1234567890abcdefG', |
| 196 | + '0x1234567890abcdefABCDEFg', |
| 197 | + '0x1234567890abcdefABCDEF1234567890abcdefABCDEFg', |
| 198 | + ])('returns false for an invalid hex address', (hexString) => { |
| 199 | + expect(isValidHexAddress(hexString)).toBe(false); |
| 200 | + }); |
| 201 | +}); |
| 202 | + |
154 | 203 | describe('add0x', () => { |
155 | 204 | it('adds a 0x-prefix to a string', () => { |
156 | 205 | expect(add0x('12345')).toBe('0x12345'); |
|
0 commit comments