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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/precompiles/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ package precompiles
import (
_ "embed"

"github.com/ethereum/go-ethereum/common"
"github.com/ava-labs/subnet-evm/precompile/contracts/nativeminter"
"github.com/ava-labs/subnet-evm/precompile/contracts/warp"
)

var NativeMinterPrecompile = common.HexToAddress("0x0200000000000000000000000000000000000001")
var (
NativeMinterPrecompile = nativeminter.ContractAddress
WarpPrecompile = warp.ContractAddress
)
32 changes: 32 additions & 0 deletions pkg/precompiles/warp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) 2022, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package precompiles

import (
_ "embed"
"fmt"

"github.com/ava-labs/avalanche-cli/pkg/contract"
"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?

rpcURL string,
) (ids.ID, error) {
out, err := contract.CallToMethod(
rpcURL,
WarpPrecompile,
"getBlockchainID()->(bytes32)",
)
if err != nil {
return ids.Empty, err
}
if len(out) == 0 {
return ids.Empty, fmt.Errorf("error at getBlockchainID call: no return value")
}
received, ok := out[0].([32]byte)
if !ok {
return ids.Empty, fmt.Errorf("error at getBlockchainID call, expected ids.ID, got %T", out[0])
}
return received, nil
}
Loading