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: meta transaction account creation scenarios #8568

Merged
merged 5 commits into from
Feb 17, 2023

Conversation

jakmeier
Copy link
Contributor

Integration tests for different ways of creating accounts.

This adds some test utilities for implicit accounts, and it fixes the
meta tx checker functions to also work with implicit accounts, as
they don't use the account name as seed for the access key.

Integration tests for different ways of creating accounts.

This adds some test utilities for implicit accounts, and it fixes the
meta tx checker functions to also work with implicit accounts, as
they don't use the account name as seed for the access key.
@jakmeier jakmeier requested a review from a team as a code owner February 14, 2023 10:40
pub fn from_implicit_account(account_id: &AccountId) -> Self {
assert!(account_id.is_implicit());
let mut public_key_data = Vec::with_capacity(33);
public_key_data.push(KeyType::ED25519 as u8);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Parts of this code seem to be taken/copied almost verbatim from runtime/runtime/src/actions.rs so this would perhaps be better off living in a common (non-test-utils) code that either tests or code could use.

(If that's not feasible for any reason, the actions.rs code could be adjusted at least to replace the magic 0 constant with the KeyType as is done here, as you're touching the relevant code anyway…)

Copy link
Contributor Author

@jakmeier jakmeier Feb 17, 2023

Choose a reason for hiding this comment

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

Yeah, we even have another instance of this code copied into near-mirror.

But I don't like editing production code in test-only PRs that are by themself already quite complicated. I'd rather fix this in a separate issue:

#8588

Comment on lines 201 to 203
self.cfg.fee(ActionCosts::transfer).send_fee(sir)
+ self.cfg.fee(ActionCosts::create_account).send_fee(sir)
+ self.cfg.fee(ActionCosts::add_full_access_key).send_fee(sir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Huh, do I understand correctly this is effectively making any transfer to an implicit account via a meta transaction to include a fee for creating a (named?) account? What is the motivation behind this? Isn’t that not necessary today? What happens if the implicit account already exists and the intent is to test a basic transfer from one account via a meta transaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's unfortunately already what happens today on mainnet, regardless of meta transactions.
I just learned about this this week, which lead me to write this comment on another NEP: near/NEPs#448 (comment)
Others seemed also somewhat surprised. ^^

This test util (which I added very recently) was just wrong / incompatible with implicit accounts.

Motivation: You don't know ahead of time if you need to create it or not but you must inlcude enough gas to cover all cases.
I hope we can get around to fix the implicit account creation flow and make it go through CreateAccount instead of (ab)using the transfer action for it, which would allow dropping the extra cost here. See also near/NEPs#462

}

/// Try creating an implicit account with `CreateAction` which is not allowed in
/// or outside meta transactions and must fail with `OnlyImplicitAccountCreationAllowed`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Observation: isn’t this error variant a misnomer? We’re saying that you can only create implicit accounts where the expectation really is that you can only create named accounts…?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good point, very confusing.

I think the naming wants to say, "you are trying to create a 64 char length account, this is only allowed in the fancy new implicit account creation flow", where "fancy and new" refers back to 2020 and this NEP that introduced the feature: near/NEPs#71

Before that, named accounts were the only type of account.

Copy link
Member

Choose a reason for hiding this comment

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

As it is confusing for all of us - can we rename error to smth like OnlyNamedAccountCreationAllowed in separate PR? If this is part of protocol, we can try renaming enum name but leave conversion to string as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I believe it's not a protocol change to rename this, the borsh representation should be fine and I don't think we store errors as strings anywhere it matters. But the RPC consumers might care, we have had unfortunate surprises around that in the past.

For now I filed this: #8598

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I added a TODO in the code comment

}

/// Try creating an implicit account with `CreateAction` which is not allowed in
/// or outside meta transactions and must fail with `OnlyImplicitAccountCreationAllowed`.
Copy link
Member

Choose a reason for hiding this comment

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

As it is confusing for all of us - can we rename error to smth like OnlyNamedAccountCreationAllowed in separate PR? If this is part of protocol, we can try renaming enum name but leave conversion to string as is.

@near-bulldozer near-bulldozer bot merged commit ba3bc8b into near:master Feb 17, 2023
@jakmeier jakmeier deleted the meta-tx-integrations-tests-4 branch February 17, 2023 22:29
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.

3 participants