-
Notifications
You must be signed in to change notification settings - Fork 52
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 tests and refactor/document structs #871
Conversation
6278299
to
5a04926
Compare
|
||
/// Assert that mock account's `get_item` procedure has index 6 | ||
/// Assert that mock account's `get_item` procedure has index 8 | ||
#[test] | ||
fn test_check_get_item_index() { |
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.
I replaced calling foreign procedures by root in favor of using procref
. Maybe we don't want this change, but if we do, I'm not sure we need this test anymore.
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.
Sounds reasonable to me. I'm not sure if the intent of the test was to use the MAST root deliberately to test something, but perhaps @Fumuran can clarify.
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.
Excuse me for the late reply, I missed the notification.
I think using the procref
is much better, for some reason I was so fixated on obtaining the procedure's hash, that I forgot that we can just obtain it with procref
. This procedure is necessary only for checking the correct index of the get_item
procedure, but since now we use procref
this test is not needed anymore. I'll remove it in my test refactoring PR.
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.
Nice improvement of replacing quite some test code by using the MockChain
.
Not a full review yet, just some preliminary comments.
/// | ||
/// ``` | ||
/// let mut mock_chain = MockChain::default(); | ||
/// let sender = mock_chain.add_new_wallet(Auth::BasicAuth, vec![asset]); // Add a wallet with assets |
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.
Just FYI: This is no longer allowed in the new AccountBuilder after #952 since new accounts are not allowed to have assets. This can probably just be changed to be an existing 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.
I think to be a valid example this still needs to be changed to mock_chain.add_existing_wallet
since new wallets are not allowed to have assets.
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.
Removed the ability of setting assets and changed the examples
|
||
/// Assert that mock account's `get_item` procedure has index 6 | ||
/// Assert that mock account's `get_item` procedure has index 8 | ||
#[test] | ||
fn test_check_get_item_index() { |
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.
Sounds reasonable to me. I'm not sure if the intent of the test was to use the MAST root deliberately to test something, but perhaps @Fumuran can clarify.
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 to me!
I'll wait after the rebase to approve.
Mainly the comment about asserting the error conditions rather than just is_err()
would be nice, other than that just small comments.
Apologies for the delay, was feeling a bit under the weather but should be rebased with all comments addressed now |
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 great - thanks for the updates! Hope your feeling better soon, too.
Just optional comments, so I'll approve and I think you can merge when you feel it's ready.
/// | ||
/// ``` | ||
/// let mut mock_chain = MockChain::default(); | ||
/// let sender = mock_chain.add_new_wallet(Auth::BasicAuth, vec![asset]); // Add a wallet with assets |
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.
I think to be a valid example this still needs to be changed to mock_chain.add_existing_wallet
since new wallets are not allowed to have assets.
// Note: data is stored as [a0, a1, a2, a3] but loaded onto the stack as | ||
// [a3, a2, a1, a0, ...] | ||
let metadata = [ | ||
Felt::new(max_supply), | ||
Felt::new(10u64), | ||
TokenSymbol::new(token_symbol).unwrap().into(), | ||
Felt::ZERO, | ||
]; | ||
|
||
let faucet_component = AccountComponent::new(basic_fungible_faucet_library(), vec![StorageSlot::Value(metadata)]) | ||
.expect("basic fungible faucet component should satisfy the requirements of a valid account component") | ||
.with_supported_type(AccountType::FungibleFaucet); |
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.
You should be able to use the BasicFungibleFaucet
component here as on next
to write this more concisely:
let (mut account, seed, authenticator) = match auth_method { | ||
Auth::BasicAuth => { |
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.
There is some duplication in this function and add_from_account_builder
that we could deduplicate I think.
On the other hand, I will refactor add_from_account_builder
anyway (#952 (comment)) so we can just leave it as-is and I'll look at it in the follow-up PR.
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.
I forgot to do a second pass on this function. I mostly copied code because I didn't find a way to re-set the first slot (for the total issuance) in a way that fit the context of the function (ie, from AccountBuilder
before passing it on to add_from_account_builder()
)
assert_transaction_executor_error!( | ||
tx, | ||
ERR_FUNGIBLE_ASSET_DISTRIBUTE_WOULD_CAUSE_MAX_SUPPLY_TO_BE_EXCEEDED | ||
); |
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.
This is really nice now, thanks for adding this!
let non_fungible_asset_details = NonFungibleAssetDetails::new( | ||
AccountId::try_from(account_id).unwrap(), | ||
AccountId::try_from(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN).unwrap(), |
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.
AccountId::try_from(ACCOUNT_ID_NON_FUNGIBLE_FAUCET_ON_CHAIN).unwrap(), | |
Self::mock_issuer(), |
Totally optional.
@@ -106,4 +118,9 @@ impl FungibleAsset { | |||
.expect("asset is valid"), | |||
) | |||
} | |||
|
|||
/// Returns a mocked asset account ID ([ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN]). |
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.
/// Returns a mocked asset account ID ([ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN]). | |
/// Returns the account ID of the issuer of [`FungibleAsset::mock()`] ([ACCOUNT_ID_FUNGIBLE_FAUCET_ON_CHAIN]). |
objects/src/testing/storage.rs
Outdated
/// Configures storage slots for a wallet account with authentication. | ||
pub fn with_wallet_storage(&mut self, public_key: PublicKey) -> &mut Self { | ||
self.add_slot(StorageSlot::Value(public_key.into())); | ||
|
||
self | ||
} |
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.
The entire AccountStorageBuilder
is now unused. Should we remove it?
I think even in cases where we want to build custom storage for tests we should probably construct it with AccountComponent
s and if that is insufficient modify it on AccountStorage
directly like you did when setting total issuance in a faucet's reserved slot - what do you think?
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.
Yeah, I thought of completely removing this but was not sure anything else from the outside was currently relying on this. I'll remove it.
8b0caf3
to
348a905
Compare
348a905
to
8cf400d
Compare
@igamigo - since this is merged, we should be able to close a couple of related issues, right? |
Closes #446