-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change
SignatureLikeSchema
to HexBytesSchema
- Loading branch information
Showing
11 changed files
with
71 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/validation/entities/schemas/__tests__/hexbytes.schema.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { HexBytesSchema } from '@/validation/entities/schemas/hexbytes.schema'; | ||
|
||
describe('HexBytesSchema', () => { | ||
it('should return true if the value is a valid hex bytes', () => { | ||
const value = faker.string.hexadecimal({ length: 4 }); | ||
|
||
const result = HexBytesSchema.safeParse(value); | ||
|
||
expect(result.success).toBe(true); | ||
}); | ||
|
||
it('should return false if the value is not a valid hex bytes', () => { | ||
const value = faker.string.hexadecimal({ length: 3 }); | ||
|
||
const result = HexBytesSchema.safeParse(value); | ||
|
||
expect(!result.success && result.error.issues).toStrictEqual([ | ||
{ | ||
code: 'custom', | ||
message: 'Invalid hex bytes', | ||
path: [], | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { HexSchema } from '@/validation/entities/schemas/hex.schema'; | ||
|
||
function isHexBytes(value: `0x${string}`): boolean { | ||
return value.length % 2 === 0; | ||
} | ||
|
||
export const HexBytesSchema = HexSchema.refine(isHexBytes, { | ||
message: 'Invalid hex bytes', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters