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

Update protocol generator to include definitions of performatives and fields #522

Open
solarw opened this issue Jan 4, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@solarw
Copy link
Collaborator

solarw commented Jan 4, 2023

At the moment Message class generated does not have a good programmatic definition of performatives and fields relation

This relation check is done in code as

 Check correct contents
            actual_nb_of_contents = len(self._body) - DEFAULT_BODY_SIZE
            expected_nb_of_contents = 0
            if self.performative == SigningMessage.Performative.SIGN_TRANSACTION:
                expected_nb_of_contents = 2
                enforce(
                    isinstance(self.terms, CustomTerms),
                    "Invalid type for content 'terms'. Expected 'Terms'. Found '{}'.".format(
                        type(self.terms)
                    ),
                )
                enforce(
                    isinstance(self.raw_transaction, CustomRawTransaction),
                    "Invalid type for content 'raw_transaction'. Expected 'RawTransaction'. Found '{}'.".format(
                        type(self.raw_transaction)
                    ),
                )
            elif self.performative == SigningMessage.Performative.SIGN_MESSAGE:
                expected_nb_of_contents = 2
                enforce(
                    isinstance(self.terms, CustomTerms),
                    "Invalid type for content 'terms'. Expected 'Terms'. Found '{}'.".format(
                        type(self.terms)
                    ),
                )
                enforce(
                    isinstance(self.raw_message, CustomRawMessage),
                    "Invalid type for content 'raw_message'. Expected 'RawMessage'. Found '{}'.".format(
                        type(self.raw_message)
                    ),
                )

but can be replaced with something like

class SomeMessage:

PERFORMATIVES_FIELDS = {Performative1: (("field1", Field1Type), ("str_field", str))}

and all the checks can be done using this definition.

it will give more flexibility, like check on message creation with list of missing fields in error
introspection features, like code can check how to construct message or provide list of expected fields.

also can help to build automated tests of message encoding/decoding

@DavidMinarsch DavidMinarsch added the enhancement New feature or request label Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants