public byte[] toByteArray() {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            write(stream);
        } catch (IOException e) {
            // Should not happen as ByteArrayOutputStream does not throw IOException on write
            throw new RuntimeException(e);
        }
        return stream.toByteArray();
    }
@Test
    public void testToByteArray_OP_PUSHDATA4() {
        // OP_PUSHDATA4
        byte[] bytes = new byte[0x0102];
        RANDOM.nextBytes(bytes);
        byte[] expected = ByteUtils.concat(new byte[] { OP_PUSHDATA4, 0x02, 0x01, 0x00, 0x00 }, bytes);
        byte[] actual = new ScriptChunk(OP_PUSHDATA4, bytes).toByteArray();
        assertArrayEquals(expected, actual);
    }