0xMiden / 0xMiden/protocol

Refactor `MockChainNote` to always hold the full note details

Abierto
#2,307 4 comentarios 0 reacciones 1 asignado Reclamado por @bigeez Ver en GitHub
good first issue tests
Lenguaje dominante
Rust
Estrellas
132
Forks
167
Merge medio
1 d 23 h
PR fusionados (30 d)
110

Descripción

In tests, when we want to add a `Private` note at genesis, we do:
```rust
let input_note = builder.add_p2id_note(
account.id(),
account.id(),
&[FungibleAsset::mock(0)],
NoteType::Private,
)?;
```
and then inside of `add_p2id_note`, we add the note as [`self.add_output_note(OutputNote::Full(note.clone()));`](https://github.com/0xMiden/miden-base/blob/eb0c396d48506c30c3fdc859ddaabbb8bfaf6b00/crates/miden-testing/src/mock_chain/chain_builder.rs#L559) to the `MockChainBuilder`.

This is fine, but it causes [`MockChain::apply_block`](https://github.com/0xMiden/miden-base/blob/eb0c396d48506c30c3fdc859ddaabbb8bfaf6b00/crates/miden-testing/src/mock_chain/chain.rs#L902-L903) to later treat these notes always as `Public`:
```rust
if let OutputNote::Full(note) = created_note {
self.committed_notes
.insert(note.id(), MockChainNote::Public(note.clone(), note_inclusion_proof));
} else {
```

---

The current implementation (and as an extension, this PR) doesn't seem to cause issues, I think because even the `MockChainNote::public` but wrapping a **private note** contains the correct underlying note details (i.e. `note.metadata().is_private() will still be correct).

But this makes me realize that maybe the `MockChainNote` struct doesn't really serve its purpose and should be refactored (e.g. to always hold the full note details).

_Originally posted by @mmagician in https://github.com/0xMiden/miden-base/pull/2205#discussion_r2672135301_

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.