Use Bytes Primitive

This commit is contained in:
Jim Hamill
2025-07-23 00:27:41 +00:00
parent 9af5dc0087
commit e72c678785
10 changed files with 62 additions and 72 deletions
@@ -5,9 +5,9 @@ import { Bytes } from '../src/bytes';
describe('Success cases', () => {
// Test cases with different block header representations
type BlockHeaderCase = {
raw: Uint8Array;
raw: Bytes;
representations: {
bytes: Uint8Array;
bytes: Bytes;
hex: string;
};
};
@@ -16,11 +16,11 @@ describe('Success cases', () => {
{
raw: Bytes.fromHex(
'0000602093ea70b294aeef69db85981bd387285824fc5af732e487010000000000000000135576e1ba9cae5509d60b4fbb9e66612f35b5ee8db264cb12612d46cc8db60b5e34a164d46b021864abbb1d',
).toUint8Array(),
),
representations: {
bytes: Bytes.fromHex(
'0000602093ea70b294aeef69db85981bd387285824fc5af732e487010000000000000000135576e1ba9cae5509d60b4fbb9e66612f35b5ee8db264cb12612d46cc8db60b5e34a164d46b021864abbb1d',
).toUint8Array(),
),
hex: '0000602093ea70b294aeef69db85981bd387285824fc5af732e487010000000000000000135576e1ba9cae5509d60b4fbb9e66612f35b5ee8db264cb12612d46cc8db60b5e34a164d46b021864abbb1d',
},
},
@@ -35,19 +35,19 @@ describe('Success cases', () => {
fromMethods.forEach(({ name, key }) => {
it.each(testCases)(`${name}()`, ({ raw, representations }) => {
const blockHeader = BlockHeader[name](representations[key]);
expect(blockHeader.toRaw()).toStrictEqual(raw);
expect(blockHeader.toRaw()).toEqual(raw);
});
});
// Test generic from method
it.each(testCases)('from(Uint8Array)', ({ raw, representations }) => {
const blockHeader = BlockHeader.from(representations.bytes);
expect(blockHeader.toRaw()).toStrictEqual(raw);
expect(blockHeader.toRaw()).toEqual(raw);
});
it.each(testCases)('from(string)', ({ raw, representations }) => {
const blockHeader = BlockHeader.from(representations.hex);
expect(blockHeader.toRaw()).toStrictEqual(raw);
expect(blockHeader.toRaw()).toEqual(raw);
});
// Test to methods with their respective types