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 method to get Method by name #345

Merged
merged 16 commits into from Jun 15, 2022
Merged

Add method to get Method by name #345

merged 16 commits into from Jun 15, 2022

Conversation

barnjamin
Copy link
Contributor

@barnjamin barnjamin commented Jun 6, 2022

I expect a common use case when preparing an ATC group will be to grab a Method from some parsed json file.

Rather than forcing the dev to maintain a separate list we should offer some utility method to get the Method by name.

@jasonpaulos
Copy link
Member

This feature makes sense, but I think it would be more useful as a method on the Contract & Interface classes, so you can just do my_contract.get_method_by_name("...").

It looks like you've properly handled the issue where two methods have the same name, which was my primary concern.

All the SDKs would benefit from a method like this.

@barnjamin barnjamin requested review from tzaffi and ahangsu and removed request for michaeldiamant June 7, 2022 18:45

## Copy feature files into the project resources
mkdir -p test/features
cp -r test-harness/features/* test/features

exit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will revert once things look ok

Copy link
Contributor

@ahangsu ahangsu left a comment

Choose a reason for hiding this comment

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

just one comment/question about the return of get_method_by_name, the rest is fine

algosdk/abi/contract.py Outdated Show resolved Hide resolved
@barnjamin barnjamin requested a review from ahangsu June 8, 2022 20:08
algosdk/abi/contract.py Outdated Show resolved Hide resolved
Co-authored-by: Zeph Grunschlag <tzaffi@users.noreply.github.com>
@@ -49,3 +49,23 @@ def undictify(d: dict) -> "Interface":
method_list = [Method.undictify(method) for method in d["methods"]]
desc = d["desc"] if "desc" in d else None
return Interface(name=name, desc=desc, methods=method_list)

def get_method_by_name(self, name: str) -> Method:
methods_filtered = list(
Copy link
Contributor

Choose a reason for hiding this comment

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

similar bias here.... general question, and not for this PR. Seems like there's a lot of overlap between contract and interface. Having a common abstract supertype might make sense.

Copy link
Member

Choose a reason for hiding this comment

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

I think a change like this is a little outside of the scope of this PR, but it is something we should consider.

I definitely dislike how much code is repeated between the two methods though. Perhaps a short term solution is to define a get_method_by_name(methods: list[Method], name: str) -> Method helper function which implements the logic, then call into it from both Interface.get_method_by_name and Contract.get_method_by_name? I think all SDKs would benefit from this @barnjamin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If itll be abstracted in another PR anyway, I'm inclined to leave it as is for now unless it makes you want to puke

Copy link
Member

Choose a reason for hiding this comment

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

I've not thought through all the implications of making Contract inherit from Interface, so I'm not sure if/when we'd want to make that change. In an effort to not hold up these PRs because of that, I think they should be mergable on their own, which means trying to avoid duplicate code.

From a maintenance perspective there's way fewer opportunities for problems if the function is implemented in just one place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, just added it

@barnjamin barnjamin requested a review from tzaffi June 13, 2022 15:20
Copy link
Contributor

@tzaffi tzaffi left a comment

Choose a reason for hiding this comment

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

Has testing been conducted using these steps against the scenarios in the accompanying SDK testing PR?

It's possible to merge the other one first, assuming the suggestion to add a special tag to the scenarios such as @abi.contract is taken.

@barnjamin
Copy link
Contributor Author

Has testing been conducted using these steps against the scenarios in the accompanying algorand/algorand-sdk-testing#185?

Yes, the green check on cdd0b8d still had the sdk tests but I can add the special tag if that makes it easier to see

@tzaffi
Copy link
Contributor

tzaffi commented Jun 13, 2022

Has testing been conducted using these steps against the scenarios in the accompanying algorand/algorand-sdk-testing#185?

Yes, the green check on cdd0b8d still had the sdk tests but I can add the special tag if that makes it easier to see

Got it. So since the SDK Testing PR has 3 approvals, once you're confident that the tag trick works, it would be great if you merged it in. It's annoying to have perfectly fine PR's lingering unmerged. The downside is that it's causing a proliferation of cucumber tags, but that can easily be cleaned up at a later date.

Copy link
Contributor

@ahangsu ahangsu left a comment

Choose a reason for hiding this comment

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

I think the implementation for pysdk is good nuf, the only thing ahead is adding a special tag on cucumber test?

Copy link
Contributor

@tzaffi tzaffi left a comment

Choose a reason for hiding this comment

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

LGTM (🤞 on the tests passing)

Copy link
Contributor

@ahangsu ahangsu left a comment

Choose a reason for hiding this comment

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

lgtm

@barnjamin barnjamin merged commit 13196fa into develop Jun 15, 2022
@barnjamin barnjamin deleted the get-method-by-name branch June 15, 2022 14:56
algochoi added a commit that referenced this pull request Jun 16, 2022
Refactoring

Revert and refactor unit tests

Finish moving tests to separate modules

Remove test feature files

adding method to ABIResult (#342)

* adding method to ABIResult

Add method to get Method by name (#345)

* adding util method to get a Method from an interface or contract by name string

Change paths for tests

Change makefile
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

4 participants