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
+6 -8
View File
@@ -1,13 +1,13 @@
import { describe, it, expect } from 'vitest';
import { Bytes } from '~/src/bytes';
import { Script } from '~/src/script';
import { Bytes } from '../src/bytes';
import { Script } from '../src/script';
describe('Success cases', () => {
// Test cases with different script representations
type ScriptCase = {
raw: Uint8Array;
raw: Bytes;
representations: {
bytes: Uint8Array;
bytes: Bytes;
asm: string;
hex: string;
};
@@ -15,13 +15,11 @@ describe('Success cases', () => {
const testCases: ScriptCase[] = [
{
raw: Bytes.fromHex(
'76a914876fbb82ec05caa6af7a3b5e5a983aae6c6cc6d688ac',
).toUint8Array(),
raw: Bytes.fromHex('76a914876fbb82ec05caa6af7a3b5e5a983aae6c6cc6d688ac'),
representations: {
bytes: Bytes.fromHex(
'76a914876fbb82ec05caa6af7a3b5e5a983aae6c6cc6d688ac',
).toUint8Array(),
),
asm: 'OP_DUP\nOP_HASH160\nOP_PUSHBYTES_20\n0x876fbb82ec05caa6af7a3b5e5a983aae6c6cc6d6\nOP_EQUALVERIFY\nOP_CHECKSIG',
hex: '76a914876fbb82ec05caa6af7a3b5e5a983aae6c6cc6d688ac',
},