Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize OPS type from Record to Enum #2189

Merged
merged 12 commits into from
Dec 27, 2024
23 changes: 23 additions & 0 deletions test/script.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ describe('script', () => {
});
});

describe('fromASM', () => {
const OPS = bscript.OPS;
it('decodes OP_FALSE as empty buffer', () => {
const string = 'OP_RETURN OP_FALSE';
assert.deepStrictEqual(
bscript.fromASM(string),
Uint8Array.from([OPS.OP_RETURN, OPS.OP_FALSE]),
);
});

it("decodes a series of numbers from '82 to 96' correctly", () => {
decentraldev1 marked this conversation as resolved.
Show resolved Hide resolved
const asm = Array.from({ length: 15 }, (_, i) =>
(i + 130).toString(16).padStart(2, '0'),
).join(' ');
const expected = Array.from({ length: 15 }, (_, i) => [
1,
i + 130,
]).flat();
const result = bscript.fromASM(asm);
assert.deepStrictEqual(result, Uint8Array.from(expected));
});
});

describe('toASM', () => {
const OP_RETURN = bscript.OPS.OP_RETURN;
it('encodes empty buffer as OP_0', () => {
Expand Down