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

Add GM for base asset ID #700

Merged
merged 9 commits into from
Mar 25, 2024
Merged

Add GM for base asset ID #700

merged 9 commits into from
Mar 25, 2024

Conversation

Dentosal
Copy link
Member

@Dentosal Dentosal added breaking A breaking api change fuel-vm Related to the `fuel-vm` crate. labels Mar 20, 2024
@Dentosal Dentosal self-assigned this Mar 20, 2024
@Dentosal Dentosal marked this pull request as ready for review March 20, 2024 23:01
@Dentosal Dentosal requested a review from a team March 20, 2024 23:01
@Dentosal Dentosal marked this pull request as draft March 21, 2024 03:41
@Dentosal Dentosal marked this pull request as ready for review March 21, 2024 04:02
@Dentosal Dentosal requested a review from a team March 21, 2024 04:02
@@ -268,6 +268,53 @@ fn get_metadata_chain_id() {
}
}

#[test]
fn get_metadata_base_asset_id() {
Copy link
Member

@MitchTurner MitchTurner Mar 21, 2024

Choose a reason for hiding this comment

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

So, I'd say that the SUT of this test is op::gm_args and the condition is GMArgs::BaseAssetId. It's confusing since we can't call gm_args natively and instead we call transact, so you could also say that transact is the SUT in that sense.

Either way, I think the structure of the test should reflect what the SUT is. In this case I include it in a gm_args_script method, so it's a little indirect but cleans up the test in a good way IMO:

// given
let base_asset_id = AssetId::from([5; 32]);
let params = ConsensusParameters {
        base_asset_id,
        ..Default::default()
    };

// when
let arg = GMArgs::BaseAssetId;
let size = AssetId::LEN;
let script = gm_args_script(arg, size);

let logged_data = run_script_and_get_logged_data(params, script);

// then
let expected = params.base_asset_id.to_bytes();
let actual = logged_data;
assert_eq!(expected, actual);

So the name of the test could be something like gm_args__base_asset_id_retrieves_value_in_params

Copy link
Member Author

Choose a reason for hiding this comment

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

I think doing that would make the test case less readable. Note how this is already an integration test, not a unit test, and it still has minimal indirection which is quite nice. I experimented a bit with something like run_script_and_get_logged_data and going that way seems to lead essentially duplicating TransactionBuilder if we want to make it reusable.

Dentosal added a commit to FuelLabs/fuel-specs that referenced this pull request Mar 21, 2024
}
}
*result = match GMArgs::try_from(imm)? {
GMArgs::GetVerifyingPredicate => context
Copy link
Collaborator

Choose a reason for hiding this comment

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

Before we were returning an ExpectedInternalContext error in the case of the internal context. Do we need to do the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. The new behavior is what the specs say. I see no reason to disallow internal contexts here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The specification says that it is allowed only in the context of the predicate:

image

And in our codebase predicate context is external context:

image

So it looks like we need ti check that it is external context=)

Copy link
Member Author

Choose a reason for hiding this comment

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

But the code already performs the check: The context.predicate() returns None outside predicate contexts, leading to TransactionValidity panic. Previously calling gm/GetVerifyingPredicate panicked with ExpectedInternalContext which was definitely incorrect. Now if we check with something like

if context.is_external() { // pseudocode
  result = context.predicate().map(...).ok_or(PanicReason::TransactionValidity)?;
} else {
  return PanicReason::ExpectedExternalContext;
}

then the only additional check we're actually performing is that Call contexts return ExpectedExternalContext instead of TransactionValidity. Is the issue just returning a wrong panic reason? Am I missing something here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohh, I missed the moment that predicate already is doing this check inside=D Hmm, maybe using of another error will make more sense, because TransactionValidity is a strange choice

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to merge this as-is, since TransactionValidity is (only) used for this kind of things currently. We can do a rename in a separate PR if needed.

@Voxelot
Copy link
Member

Voxelot commented Mar 22, 2024

looks like there are merge conflicts now

}
}
*result = match GMArgs::try_from(imm)? {
GMArgs::GetVerifyingPredicate => context
Copy link
Collaborator

Choose a reason for hiding this comment

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

The specification says that it is allowed only in the context of the predicate:

image

And in our codebase predicate context is external context:

image

So it looks like we need ti check that it is external context=)

@Dentosal Dentosal requested a review from xgreenx March 25, 2024 06:38
}
}
*result = match GMArgs::try_from(imm)? {
GMArgs::GetVerifyingPredicate => context
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohh, I missed the moment that predicate already is doing this check inside=D Hmm, maybe using of another error will make more sense, because TransactionValidity is a strange choice

@Dentosal Dentosal added this pull request to the merge queue Mar 25, 2024
Merged via the queue into master with commit bb93537 Mar 25, 2024
38 checks passed
@Dentosal Dentosal deleted the dento/gm-base-asset-id branch March 25, 2024 12:21
@xgreenx xgreenx mentioned this pull request Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking A breaking api change fuel-vm Related to the `fuel-vm` crate.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants