Skip to content

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.

@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