Skip to content

Commit

Permalink
Minor fix on _basicAddress regexp (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool authored Feb 12, 2024
1 parent 3e25bcb commit 9d4e0e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/src/credentials/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class EthereumAddress implements Comparable<EthereumAddress> {
}

static final RegExp _basicAddress =
RegExp(r'^(0x)?[0-9a-f]{40}', caseSensitive: false);
RegExp(r'^(0x)?[0-9a-f]{40}$', caseSensitive: false);

/// The length of an ethereum address, in bytes.
static const addressByteLength = 20;
Expand Down
27 changes: 27 additions & 0 deletions test/credentials/address_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,39 @@ const _lowerCaseToEip55 = {
'0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb',
};

const _addressValidation = {
'0x4d7920656d61696c206973206a6f686e40646f652e636f6d202d2031373037373336343236393430':
false,
'4d7920656d61696c206973206a6f686e40646f652e636f6d202d2031373037373336343236393430':
false,
'0x4d7920656d61696c206973206a6f686e40646f650': false,
'4d7920656d61696c206973206a6f686e40646f650': false,
'0x52908400098527886e0f7030069857d2e4169ee7': true,
'52908400098527886e0f7030069857d2e4169ee7': true,
'0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb': true,
};

void main() {
bool _isValid(String address) {
try {
EthereumAddress.fromHex(address);
return true;
} catch (e) {
return false;
}
}

group('accepts and parses EIP 55', () {
_lowerCaseToEip55.forEach((lower, eip55) {
test('parses $lower -> $eip55', () {
expect(EthereumAddress.fromHex(lower).hexEip55, eip55);
});
});

_addressValidation.forEach((address, valid) {
test('parses $address -> valid $valid', () {
expect(_isValid(address), valid);
});
});
});
}

0 comments on commit 9d4e0e4

Please sign in to comment.