-
Notifications
You must be signed in to change notification settings - Fork 47
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
Revisit Account::initialize_from_components
and add AccountBuilder::build_existing
#969
Conversation
348a905
to
8cf400d
Compare
9d676a9
to
513694f
Compare
There was a problem hiding this 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 could of small comments inline - but also, would be great for @igamigo to review the PR.
}; | ||
|
||
self.available_accounts | ||
.insert(account.id(), MockAccount::new(account.clone(), seed, authenticator)); | ||
|
||
self.add_account(account.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we no longer need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps @igamigo can clarify this. It's not clear to me when adding new accounts in the chain whether they must be added to both available_accounts and pending_objects or only the former.
It seems the former is sufficient, so since we're adding the account to available_accounts adding it to pending_objects seems unnecessary. And we're already not doing it for the "existing faucet" case (this is from current next), so I made it consistent:
miden-base/miden-tx/src/testing/mock_chain/mod.rs
Lines 475 to 479 in 6e0e29f
self.available_accounts | |
.insert(account.id(), MockAccount::new(account.clone(), seed, authenticator)); | |
MockFungibleFaucet(account) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally the intent was to keep MockChain
consistent with how the actual chain would evolve, (currently not entirely the case since some updates are not performed entirely as they should) considering things like updates to the account and note trees. For new accounts, I don't think it's needed to add the account to pending objects, but I believe I originally added it for convenience (since it did not hurt either).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
}; | ||
|
||
self.available_accounts | ||
.insert(account.id(), MockAccount::new(account.clone(), seed, authenticator)); | ||
|
||
self.add_account(account.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally the intent was to keep MockChain
consistent with how the actual chain would evolve, (currently not entirely the case since some updates are not performed entirely as they should) considering things like updates to the account and note trees. For new accounts, I don't think it's needed to add the account to pending objects, but I believe I originally added it for convenience (since it did not hurt either).
Changes
AccountBuilder::build_testing
and addAccountBuilder::build_existing
. This means we have a clear separation now betweenAccountBuilder::build
which builds a new account and is available generally andAccountBuilder::build_existing
which builds an existing account and is available only undertesting
.Account::initialize_from_components
private and replace usages withAccountBuilder
. It turns out that we don't need to build accounts with a specificAccountId
anywhere in tests so those occurrences were changed to generate a new one instead.nonce
field in theAccountBuilder
was no longer needed so I removed it. The nonce is set inbuild
andbuild_existing
directly.MockChain
to add new accounts were all adding the build accounts toMockChain::available_accounts
and some methods also toMockChain::pending_objects
which seemed unnecessary. I'm not 100% sure whether this is fine though.closes #949
Builds on top of #871 and should be merged after that one but is otherwise ready for review.