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

Improve execution environment type validation #844

Merged
merged 6 commits into from Oct 31, 2022

Conversation

Mrtenz
Copy link
Member

@Mrtenz Mrtenz commented Oct 11, 2022

This improves the type validation in execution-environments. The auto-generated OpenRPC types aren't great, for example:

export function isSnapRpcResult(obj: any, _argumentName?: string): obj is SnapRpcResult {
    return (
        true
    )
}

I replaced those with type guards from the @metamask/utils package, and some new type guards.

To do

  • Add validators for getHandlerArguments.

@Mrtenz Mrtenz force-pushed the mrtenz/improve-ee-type-validation branch from a92976d to a940237 Compare October 31, 2022 08:25
@Mrtenz Mrtenz marked this pull request as ready for review October 31, 2022 08:35
@Mrtenz Mrtenz requested a review from a team as a code owner October 31, 2022 08:35
const OkStruct = literal('OK');

export const PingRequestArgumentsStruct = optional(
union([literal(undefined), array()]),
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a union if it is optional?

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 I ran into some issues otherwise, and needed this to keep it compatible.

packages/execution-environments/src/common/validation.ts Outdated Show resolved Hide resolved
@Mrtenz Mrtenz force-pushed the mrtenz/improve-ee-type-validation branch from 930a7d5 to 1425abe Compare October 31, 2022 11:29
@Mrtenz Mrtenz merged commit 5871dbb into main Oct 31, 2022
@Mrtenz Mrtenz deleted the mrtenz/improve-ee-type-validation branch October 31, 2022 11:47
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.

None yet

2 participants