Skip to content

Commit

Permalink
Add another test case where extra char is not number
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgahan-arikan committed Jun 28, 2023
1 parent 87b19b5 commit 274a02a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/provider/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const removeEIP191Prefix = (prefixedMessage: Uint8Array): Uint8Array => {
prefixAsNumber = Number(ethers.utils.hexlify(ethereumSignedMessagePartSlicedArray.slice(0, maxPrefixCharLength)))
}

if (prefixAsNumber > ethereumSignedMessagePartSlicedArray.length) {
if (prefixAsNumber > ethereumSignedMessagePartSlicedArray.length || !Number.isInteger(prefixAsNumber)) {
prefixCharLenght = maxPrefixCharLength - 1
} else {
prefixCharLenght = maxPrefixCharLength
Expand Down
2 changes: 2 additions & 0 deletions packages/provider/tests/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ export const removeIep191Prefix_test2_raw = dlcText
export const removeIep191Prefix_test3_raw = '1915 Robe' // 9 chars
export const removeIep191Prefix_test4_raw =
'123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789' // 99 chars
export const removeIep191Prefix_test5_raw = 'Robe 1915'

export const removeIep191Prefix_test1_prefixed = prefixEIP191Message(removeIep191Prefix_test1_raw)
export const removeIep191Prefix_test2_prefixed = prefixEIP191Message(dlcText)
export const removeIep191Prefix_test3_prefixed = prefixEIP191Message(removeIep191Prefix_test3_raw)
export const removeIep191Prefix_test4_prefixed = prefixEIP191Message(removeIep191Prefix_test4_raw)
export const removeIep191Prefix_test5_prefixed = prefixEIP191Message(removeIep191Prefix_test5_raw)
5 changes: 4 additions & 1 deletion packages/provider/tests/remove-eip191prefix.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
removeIep191Prefix_test3_prefixed,
removeIep191Prefix_test3_raw,
removeIep191Prefix_test4_prefixed,
removeIep191Prefix_test4_raw
removeIep191Prefix_test4_raw,
removeIep191Prefix_test5_prefixed,
removeIep191Prefix_test5_raw
} from './messages'
import { removeEIP191Prefix } from '../src/utils'
import { ethers } from 'ethers'
Expand All @@ -27,5 +29,6 @@ describe('removing eip191prefix', () => {
it('should remove prefix for case where max prefix char as number is bigger than the length of the message', () => {
expect(ethers.utils.toUtf8String(removeEIP191Prefix(removeIep191Prefix_test3_prefixed))).equal(removeIep191Prefix_test3_raw)
expect(ethers.utils.toUtf8String(removeEIP191Prefix(removeIep191Prefix_test4_prefixed))).equal(removeIep191Prefix_test4_raw)
expect(ethers.utils.toUtf8String(removeEIP191Prefix(removeIep191Prefix_test5_prefixed))).equal(removeIep191Prefix_test5_raw)
})
})

0 comments on commit 274a02a

Please sign in to comment.