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 function to get blockchain id from warp precompile #2633

Merged
merged 3 commits into from
Feb 26, 2025

Conversation

felipemadero
Copy link
Collaborator

Why this should be merged

To avoid the user to input information we cat retrieve from the validators

How this works

How this was tested

How is this documented

if err != nil {
return ids.Empty, err
}
received, b := out[0].([32]byte)
Copy link
Collaborator

@learyce learyce Feb 25, 2025

Choose a reason for hiding this comment

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

Do we need to validate the out array here before we check the 0 index? Also, is the type conversion safe to call or do we need to catch any potential errors from it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the second question, I could be rusty on Go. More so, I am looking to confirm that this conversion fails, if it'll throw an uncaught error

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

First question. We are counting that the underlying implementation, if does not error, returns out
with the appropriate size. This is the current semantic.
That say, better to check for len!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Second question. The type conversion is safe if you also get the b boolean. I mean, there is no uncaught error.

If you do

received := out[0].([32]byte)

you can have uncaught error.

If you do

received, b := out[0].([32]byte)

you will have b==false in conversion error

return ids.Empty, err
}
received, b := out[0].([32]byte)
if !b {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the variable b?

Copy link
Collaborator

Choose a reason for hiding this comment

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

if the value exists, should prob rename it to ok @felipemadero

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

b == type conversion ok

"github.com/ava-labs/avalanchego/ids"
)

func WarpPrecompileGetBlockchainID(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have any sort of framework/etc in place for testing functions like these (ie one's that would require a lot of mocking)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

we can test this on local network. Do u want to create separate PR for this? @felipemadero

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we don't have framework in place for testing this as unit test. we usually do E2E testing with a local network
deployment, not with a mock. for sure we can consider mocking if we want to really add testing for
all code paths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

really, how to unit test this stuff, and how to properly tests the commands ux, for example
(prompts, flags paths), needs good design

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

open to freely talk on implementation options

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

regarding testing this specific feature on E2E, we don't have a command to return blockchain ID,
but it is going to be part of a larger feature in the short term.
#2637

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

do we want to add annotations to the functions to point to the specific E2E?

@sukantoraymond sukantoraymond changed the base branch from main to add-validator-remote-l1 February 26, 2025 00:45
@sukantoraymond sukantoraymond force-pushed the get-chain-id-from-warp branch 2 times, most recently from 001d27a to 8947a39 Compare February 26, 2025 01:19
@felipemadero felipemadero changed the base branch from add-validator-remote-l1 to main February 26, 2025 14:01
@sukantoraymond sukantoraymond merged commit 7fcef28 into main Feb 26, 2025
37 checks passed
@sukantoraymond sukantoraymond deleted the get-chain-id-from-warp branch February 26, 2025 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done ✅
Development

Successfully merging this pull request may close these issues.

3 participants