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

feat: isClassDeclared createBulkInvocations, fix cairo0 test #1211

Merged
merged 5 commits into from
Sep 3, 2024

Conversation

tabaktoni
Copy link
Collaborator

@tabaktoni tabaktoni commented Aug 30, 2024

Motivation and Resolution

Fix #1209

Usage related changes

New
Test if class is already declared from ContractClassIdentifier

provider.isClassDeclared(contractClassIdentifier: ContractClassIdentifier, blockIdentifier?: BlockIdentifier)

Build bulk invocations with auto-detect declared class and declare order sort
provider.createBulkInvocations(invocations: Invocations)

provider.prepareInvocations(invocations: Invocations)

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

Copy link
Collaborator

@penovicp penovicp left a comment

Choose a reason for hiding this comment

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

Two minor nitpicks, in general lgtm

* 2. Order declarations first
* @param invocations
*/
public async createBulkInvocations(invocations: Invocations) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest renaming the method, I feel like users might make a mistake and think it's similar to accountInvocationsFactory(). Admittedly I haven't come up with a surefire alternative, maybe something like sanitizeInvocations().

const result = await this.getClass(classHash, blockIdentifier);
return result instanceof Object;
} catch (error) {
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be filtered for instances of LibraryError and re-throw otherwise.

Copy link
Collaborator

@PhilippeR26 PhilippeR26 left a comment

Choose a reason for hiding this comment

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

Just little naming concerns.

/**
* DeclareContractPayload with classHash or contract defined
*/
export type ContractClassIdentifier = DeclareContractPayload | { classHash: string };
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why an object containing the classHash? Seems complicated.
I think that the easiest way for the user is something like this :

export type ContractClassIdentifier = DeclareContractPayload | BigNumberish;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it would be ambiguous.
Class can be identified by classHash or by contract, in case of BigNumberish it can be both and non-specific.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For me, a class is only identified by its hash, and nothing else.

Copy link
Collaborator

@PhilippeR26 PhilippeR26 Sep 2, 2024

Choose a reason for hiding this comment

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

And if you have the address of an instance of a class, you have already the answer of the
question is classDeclared.
It's more than weird to ask if a parent is existing if you have already one of its children....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And if you have the address of an instance of a class, you have already the answer of the question is classDeclared. It's more than weird to ask if a parent is existing if you have already one of its children....

Agree, and this does not contain an address. What address are you referring to?

Copy link
Collaborator Author

@tabaktoni tabaktoni Sep 3, 2024

Choose a reason for hiding this comment

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

It does not deal with Contract instance nor addresses, just with Contract Class aka. definition classHash

ContractClassIdentifier is

{
  contract: CompiledContract | string;
  classHash?: string;
  casm?: CompiledSierraCasm;
  compiledClassHash?: string;
};

In this case it covers cases for:

  1. identifying class from its source code by computing classHash from contract
  2. optional zero computing and classHash is already provided
  3. less computing by providing optional params for classHash
or 
{ classHash: string }

This case cover providing non-optional classHash

So that in the end, you can get classHash which is in essence ContractClassIdentifier.

Changing it to

export type ContractClassIdentifier = DeclareContractPayload | BigNumberish;

In this case, BigNumberish represents classHash but in the source, we used mixed cases sometimes string sometimes BigNumberish.

Solutions:
1.
Another case is that we set | { classHash: BigNumberish }.
This case is less ambiguous and I think we can do it.
2. create type ClassHashIdentifier: BigNumberish
and than do:

export type ContractClassIdentifier = DeclareContractPayload | ClassHashIdentifier;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For me, a class is only identified by its hash, and nothing else.

Yes but you can provide that classHash or you can provide source code and we can compute classHash from it.
So both source code and classHash are identifiers

* 2. Order declarations first
* @param invocations
*/
public async createBulkInvocations(invocations: Invocations) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with @penovicp ; all these public functions with bulk in their names are not understood by the users.
Such names are OK for internal functions, but are problematic for basic users usage.
We have already this problem with getEstimateFeeBulk & parseFeeEstimateBulkResponse.
My proposal : buildInvocations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

prepareBulkInvocations ?
prepareInvocations ?

Copy link
Collaborator

@PhilippeR26 PhilippeR26 left a comment

Choose a reason for hiding this comment

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

OK for me.

@tabaktoni tabaktoni merged commit 9fdf54f into develop Sep 3, 2024
2 of 3 checks passed
github-actions bot pushed a commit that referenced this pull request Sep 4, 2024
# [6.14.0](v6.13.1...v6.14.0) (2024-09-04)

### Features

* isClassDeclared  prepareInvocations, fix cairo0 test ([#1211](#1211)) ([9fdf54f](9fdf54f))
Copy link

github-actions bot commented Sep 4, 2024

🎉 This issue has been resolved in version 6.14.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failing tests on devnet v0.2.0-rc.x
3 participants