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

test: Add more high-level methods to MockChain #807

Merged
merged 43 commits into from
Aug 22, 2024

Conversation

igamigo
Copy link
Collaborator

@igamigo igamigo commented Jul 29, 2024

Addresses #446
Closes #788

@igamigo igamigo marked this pull request as ready for review July 30, 2024 12:36
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Thank you! Looks good! This is not a full review yet, but I left some comments inline.

miden-tx/src/testing/mock_chain.rs Outdated Show resolved Hide resolved
miden-tx/src/testing/mock_chain.rs Outdated Show resolved Hide resolved
miden-tx/src/testing/mock_chain.rs Outdated Show resolved Hide resolved
miden-tx/src/testing/mock_chain.rs Outdated Show resolved Hide resolved
Comment on lines 207 to 231
pub fn add_executed_transaction(&mut self, transaction: ExecutedTransaction) {
let mut account = transaction.initial_account().clone();
account.apply_delta(transaction.account_delta()).unwrap();

// disregard private accounts, so it's easier to retrieve data
let account_update_details = AccountUpdateDetails::New(account.clone());

let block_account_update = BlockAccountUpdate::new(
transaction.account_id(),
account.hash(),
account_update_details,
vec![transaction.id()],
);
self.pending_objects.updated_accounts.push(block_account_update);

for note in transaction.input_notes().iter() {
// TODO: check that nullifiers are not duplicate
self.pending_objects.created_nullifiers.push(note.nullifier());
self.removed_notes.push(note.id());
}

// TODO: check that notes are not duplicate
let output_notes: Vec<OutputNote> = transaction.output_notes().iter().cloned().collect();
self.pending_objects.output_note_batches.push(output_notes);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This method doesn't seems to be currently used - but it seems like it could be quite useful. Are there no tests where we could use it?

miden-tx/src/testing/mock_chain.rs Outdated Show resolved Hide resolved
miden-tx/src/testing/mock_chain.rs Outdated Show resolved Hide resolved
miden-tx/src/testing/mock_chain.rs Outdated Show resolved Hide resolved
Comment on lines +570 to +574
pub struct MockChainBuilder {
accounts: Vec<Account>,
notes: Vec<Note>,
starting_block_num: u32,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The relation between MockChain and MockChain builder is a bit unclear to me. It probably makes sense to write some documentation about how these supposed to be used, but also, if we have a MockChainBuilder:

  • Shouldn't all mutators on the MockChain be private to this module?
  • Does MockChain need pending_objects field?

Basically, if we have a builder we usually add things to the builder and then build an object that doesn't need to be mutated further - but here it seems like the pattern is a bit different?

In general, I like the idea of having a separate builder - but I think if we go this way, we should move things like add_nullifier(), add_new_wallet(), seal_block() etc. to be on the builder rather than on the MockChain.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think organization of this file could be improved a bit (i.e., by grouping related methods into sections and maybe splitting things out into several files under the same module).

Also, should improve documentation here quite a bit both to document individual functions but also to describe how these structs are expected to be used. But we can probably do this after we align on the high-level interfaces (e.g., see comment on MockChain vs. MockChainBuilder).

@igamigo igamigo changed the base branch from next to bobbin-miden-vm-migration August 16, 2024 20:49
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left some comments inline - most of them are small nits.

Also, some comments from the previous review still apply. But I'd rather merge this PR sooner and then address the remaining cleanup of the MockChain in a followup PR.

miden-lib/asm/kernels/transaction/api.masm Outdated Show resolved Hide resolved
miden-lib/asm/kernels/transaction/lib/constants.masm Outdated Show resolved Hide resolved
miden-lib/asm/miden/tx.masm Outdated Show resolved Hide resolved
miden-lib/asm/kernels/transaction/lib/tx.masm Outdated Show resolved Hide resolved
objects/src/accounts/code/mod.rs Outdated Show resolved Hide resolved
miden-tx/src/testing/tx_context.rs Show resolved Hide resolved
miden-tx/src/executor/mast_store.rs Outdated Show resolved Hide resolved
miden-tx/src/testing/executor.rs Outdated Show resolved Hide resolved
miden-tx/src/tests/mod.rs Outdated Show resolved Hide resolved
miden-tx/src/tests/kernel_tests/test_prologue.rs Outdated Show resolved Hide resolved
@bobbinth bobbinth mentioned this pull request Aug 22, 2024
2 tasks
@igamigo igamigo requested a review from bobbinth August 22, 2024 20:23
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file used somewhere? If not, we should delete it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah - I see! Let's then rename miden-tx/src/testing/tx_context.rs into miden-tx/src/testing/tx_context/mod.rs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just saw this was already addressed. Sorry I missed it before!

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a couple of small comments inline. The main one is about removing miden-tx/src/testing/tx_context/builder.rs file, which I don't think is being used.

miden-tx/src/testing/tx_context.rs Show resolved Hide resolved
miden-tx/src/testing/tx_context.rs Outdated Show resolved Hide resolved
@igamigo igamigo merged commit e78efd1 into bobbin-miden-vm-migration Aug 22, 2024
13 checks passed
@igamigo igamigo deleted the igamigo-hl-mockchain branch August 22, 2024 21:20
bobbinth pushed a commit that referenced this pull request Aug 23, 2024
* feat: High level mockchain methods; re-enable and fix kernel tests
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