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
Merged

Conversation

decentraldev1
Copy link
Contributor

@decentraldev1
Copy link
Contributor Author

Going a step further, maybe we can remove REVERSE_OPS directly.

Which a bit redundant

Copy link
Member

@junderw junderw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make fix for the logic change. Also add a test to show that hex pushdatas that look like numbers in REVERSE_OPS are properly done as PUSHDATA.

ts_src/script.ts Outdated Show resolved Hide resolved
@junderw
Copy link
Member

junderw commented Dec 25, 2024

Thanks for the fix and tests.

Could you also add a test for fromASM similar to how this edge case test for toASM works?:

describe('toASM', () => {
const OP_RETURN = bscript.OPS.OP_RETURN;
it('encodes empty buffer as OP_0', () => {
const chunks = [OP_RETURN, Buffer.from([])];
assert.strictEqual(bscript.toASM(chunks), 'OP_RETURN OP_0');
});
for (let i = 1; i <= 16; i++) {
it(`encodes one byte buffer [${i}] as OP_${i}`, () => {
const chunks = [OP_RETURN, Buffer.from([i])];
assert.strictEqual(bscript.toASM(chunks), 'OP_RETURN OP_' + i);
});
}
});

See how this test is testing an edge case for toASM (making sure empty array is OP_FALSE)

Can you add an edge case test for fromASM testing that '82 83 84' becomes [1, 130, 1, 131, 1, 132]

@decentraldev1
Copy link
Contributor Author

Thanks for the fix and tests.

Could you also add a test for fromASM similar to how this edge case test for toASM works?:

describe('toASM', () => {
const OP_RETURN = bscript.OPS.OP_RETURN;
it('encodes empty buffer as OP_0', () => {
const chunks = [OP_RETURN, Buffer.from([])];
assert.strictEqual(bscript.toASM(chunks), 'OP_RETURN OP_0');
});
for (let i = 1; i <= 16; i++) {
it(`encodes one byte buffer [${i}] as OP_${i}`, () => {
const chunks = [OP_RETURN, Buffer.from([i])];
assert.strictEqual(bscript.toASM(chunks), 'OP_RETURN OP_' + i);
});
}
});

See how this test is testing an edge case for toASM (making sure empty array is OP_FALSE)

Can you add an edge case test for fromASM testing that '82 83 84' becomes [1, 130, 1, 131, 1, 132]

of course

@junderw junderw merged commit 2a2d82e into bitcoinjs:master Dec 27, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants