Skip to content
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
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version: "1.26.10"
go-version-file: go.mod

- name: Verify go.mod is tidy
run: |
Expand All @@ -37,17 +37,17 @@ jobs:

- name: Run staticcheck
env:
GOTOOLCHAIN: go1.26.10
GOTOOLCHAIN: local
run: go run honnef.co/go/tools/cmd/staticcheck@v0.8.2 ./...

- name: Run staticcheck (tagged e2e)
env:
GOTOOLCHAIN: go1.26.10
GOTOOLCHAIN: local
run: go run honnef.co/go/tools/cmd/staticcheck@v0.8.2 -tags=clie2e,networke2e ./e2e/...

- name: Run govulncheck
env:
GOTOOLCHAIN: go1.26.10
GOTOOLCHAIN: local
run: go run golang.org/x/vuln/cmd/govulncheck@v1.2.0 ./...

- name: Run tests
Expand All @@ -56,6 +56,13 @@ jobs:
- name: Run CLI e2e smoke tests
run: go test -tags=clie2e -v ./e2e/... -run "Help|Params|MissingArgs|RemovedOldNames|UnknownSubcommand"

# Go 1.27+ enables encoding/json v2 by default. Run the smoke tests with
# it so JSON decoding regressions surface without a newer toolchain.
- name: Run CLI e2e smoke tests (encoding/json v2)
env:
GOEXPERIMENT: jsonv2
run: go test -tags=clie2e ./e2e/... -run "Help|Params|MissingArgs|RemovedOldNames|UnknownSubcommand"

- name: Compile integration tests
run: go test -tags=integration -run '^$' ./pkg/pchain/...

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nightly-network-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version: "1.26.10"
go-version-file: go.mod

- name: Verify Fuji key secret is configured
env:
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ jobs:
goos: darwin
goarch: arm64
cc: cc
- runner: macos-latest
goos: darwin
goarch: amd64
cc: cc
runs-on: ${{ matrix.runner }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4

- name: Set up Go
uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version: "1.26.10"
go-version-file: go.mod

- name: Install cross-compiler
if: matrix.cross_deps != ''
Expand Down
5 changes: 5 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ builds:
goarch:
- amd64
- arm64
ignore:
# avalanchego does not support darwin/amd64: its firewood FFI ships no
# x86_64-apple-darwin library.
- goos: darwin
goarch: amd64
ldflags:
- -s -w -X github.com/ava-labs/platform-cli/cmd.version={{.Version}}
overrides:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Minimal CLI for Avalanche P-Chain operations.
## Installation

Requirements:
- Go 1.24.13+
- Go 1.26.11+
- A cgo toolchain (C compiler)
- Linux (amd64, arm64) or macOS (arm64); macOS on Intel (darwin/amd64) is not supported

```bash
go install github.com/ava-labs/platform-cli@main
Expand Down
6 changes: 3 additions & 3 deletions cmd/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/platform"
ethcommon "github.com/ava-labs/libevm/common"
"github.com/ava-labs/platform-cli/pkg/network"
"github.com/ava-labs/platform-cli/pkg/pchain"
Expand Down Expand Up @@ -198,7 +198,7 @@ remaining balance. The command refuses to issue an empty owner unless you set
}

// Gather validator info from IPs or generate mock
var validators []*txs.ConvertSubnetToL1Validator
var validators []*platform.ConvertSubnetToL1Validator
if subnetMockVal {
// For mock, use the first weight if provided, otherwise 0 (default)
var mockWeight uint64
Expand All @@ -212,7 +212,7 @@ remaining balance. The command refuses to issue an empty owner unless you set
if err != nil {
return fmt.Errorf("failed to generate mock validator: %w", err)
}
validators = []*txs.ConvertSubnetToL1Validator{mockVal}
validators = []*platform.ConvertSubnetToL1Validator{mockVal}
fmt.Printf("Using mock validator (NodeID: %x)\n", mockVal.NodeID)
} else if hasManualValidators {
validators, err = buildManualL1Validators(
Expand Down
24 changes: 12 additions & 12 deletions cmd/validators_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/vms/platformvm/platform"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/message"
nodeutil "github.com/ava-labs/platform-cli/pkg/node"
"github.com/ava-labs/platform-cli/pkg/wallet"
Expand All @@ -34,7 +34,7 @@ const defaultValidatorWeight uint64 = 100

// gatherL1Validators queries validator nodes and builds conversion validators.
// If weights is non-nil, it must have the same length as validatorAddrs.
func gatherL1Validators(ctx context.Context, validatorAddrs []string, balance float64, weights []uint64) ([]*txs.ConvertSubnetToL1Validator, error) {
func gatherL1Validators(ctx context.Context, validatorAddrs []string, balance float64, weights []uint64) ([]*platform.ConvertSubnetToL1Validator, error) {
if len(validatorAddrs) == 0 {
return nil, fmt.Errorf("no validator addresses provided")
}
Expand All @@ -48,7 +48,7 @@ func gatherL1Validators(ctx context.Context, validatorAddrs []string, balance fl
return nil, fmt.Errorf("invalid validator balance: %w", err)
}

validators := make([]*txs.ConvertSubnetToL1Validator, 0, len(validatorAddrs))
validators := make([]*platform.ConvertSubnetToL1Validator, 0, len(validatorAddrs))
for i, addr := range validatorAddrs {
uri, err := normalizeNodeURI(addr)
if err != nil {
Expand All @@ -69,7 +69,7 @@ func gatherL1Validators(ctx context.Context, validatorAddrs []string, balance fl
weight = weights[i]
}

validators = append(validators, &txs.ConvertSubnetToL1Validator{
validators = append(validators, &platform.ConvertSubnetToL1Validator{
NodeID: nodeID.Bytes(),
Weight: weight,
Balance: balanceNAVAX,
Expand All @@ -83,7 +83,7 @@ func gatherL1Validators(ctx context.Context, validatorAddrs []string, balance fl
// buildManualL1Validators builds conversion validators from manually provided data.
// All inputs are comma-separated lists and must be aligned by index.
// If weights is non-nil, it must have the same length as the other lists.
func buildManualL1Validators(nodeIDs, blsPubKeys, blsPoPs string, balance float64, weights []uint64) ([]*txs.ConvertSubnetToL1Validator, error) {
func buildManualL1Validators(nodeIDs, blsPubKeys, blsPoPs string, balance float64, weights []uint64) ([]*platform.ConvertSubnetToL1Validator, error) {
if strings.TrimSpace(nodeIDs) == "" || strings.TrimSpace(blsPubKeys) == "" || strings.TrimSpace(blsPoPs) == "" {
return nil, fmt.Errorf("manual validator mode requires --validator-node-ids, --validator-bls-public-keys, and --validator-bls-pops")
}
Expand All @@ -109,7 +109,7 @@ func buildManualL1Validators(nodeIDs, blsPubKeys, blsPoPs string, balance float6
return nil, fmt.Errorf("invalid validator balance: %w", err)
}

validators := make([]*txs.ConvertSubnetToL1Validator, 0, len(idsList))
validators := make([]*platform.ConvertSubnetToL1Validator, 0, len(idsList))
for i := range idsList {
nodeID, err := ids.NodeIDFromString(idsList[i])
if err != nil {
Expand All @@ -125,7 +125,7 @@ func buildManualL1Validators(nodeIDs, blsPubKeys, blsPoPs string, balance float6
weight = weights[i]
}

validators = append(validators, &txs.ConvertSubnetToL1Validator{
validators = append(validators, &platform.ConvertSubnetToL1Validator{
NodeID: nodeID.Bytes(),
Weight: weight,
Balance: balanceNAVAX,
Expand All @@ -137,7 +137,7 @@ func buildManualL1Validators(nodeIDs, blsPubKeys, blsPoPs string, balance float6
}

// sortAndValidateL1Validators sorts validators by NodeID bytes and rejects duplicates.
func sortAndValidateL1Validators(validators []*txs.ConvertSubnetToL1Validator) error {
func sortAndValidateL1Validators(validators []*platform.ConvertSubnetToL1Validator) error {
sort.Slice(validators, func(i, j int) bool {
return bytes.Compare(validators[i].NodeID, validators[j].NodeID) < 0
})
Expand Down Expand Up @@ -232,7 +232,7 @@ func parsePChainAddress(addr, hrp string) (ids.ShortID, error) {
// any P-Chain key can disable the validator and spend its remaining balance.
// Unless allowEmpty is set, an empty owner returns errEmptyValidatorOwner.
func setL1ValidatorOwners(
validators []*txs.ConvertSubnetToL1Validator,
validators []*platform.ConvertSubnetToL1Validator,
remainingBalanceOwners []ids.ShortID,
deactivationOwners []ids.ShortID,
defaultOwner ids.ShortID,
Expand Down Expand Up @@ -262,7 +262,7 @@ func setL1ValidatorOwners(
// align with validators in input order, so the owners must be set before the
// sort.
func finalizeL1Validators(
validators []*txs.ConvertSubnetToL1Validator,
validators []*platform.ConvertSubnetToL1Validator,
remainingBalanceOwners []ids.ShortID,
deactivationOwners []ids.ShortID,
defaultOwner ids.ShortID,
Expand Down Expand Up @@ -364,7 +364,7 @@ func normalizeNodeURI(addr string) (string, error) {

// generateMockValidator creates a mock validator with valid BLS credentials for testing.
// If weight is 0, defaultValidatorWeight (100) is used as the default.
func generateMockValidator(balance float64, weight uint64) (*txs.ConvertSubnetToL1Validator, error) {
func generateMockValidator(balance float64, weight uint64) (*platform.ConvertSubnetToL1Validator, error) {
// Validate balance to prevent overflow
balanceNAVAX, err := avaxToNAVAX(balance)
if err != nil {
Expand Down Expand Up @@ -392,7 +392,7 @@ func generateMockValidator(balance float64, weight uint64) (*txs.ConvertSubnetTo
return nil, fmt.Errorf("failed to generate proof of possession: %w", err)
}

return &txs.ConvertSubnetToL1Validator{
return &platform.ConvertSubnetToL1Validator{
NodeID: nodeID,
Weight: weight,
Balance: balanceNAVAX,
Expand Down
14 changes: 7 additions & 7 deletions cmd/validators_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/ava-labs/avalanchego/utils/crypto/bls"
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner"
"github.com/ava-labs/avalanchego/utils/formatting/address"
"github.com/ava-labs/avalanchego/vms/platformvm/platform"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/message"
)

Expand Down Expand Up @@ -428,9 +428,9 @@ func TestGatherL1Validators_InputValidation(t *testing.T) {
}

func TestSortAndValidateL1Validators_SortsByNodeID(t *testing.T) {
v1 := &txs.ConvertSubnetToL1Validator{NodeID: []byte{0x02}, Weight: 1}
v2 := &txs.ConvertSubnetToL1Validator{NodeID: []byte{0x01}, Weight: 1}
validators := []*txs.ConvertSubnetToL1Validator{v1, v2}
v1 := &platform.ConvertSubnetToL1Validator{NodeID: []byte{0x02}, Weight: 1}
v2 := &platform.ConvertSubnetToL1Validator{NodeID: []byte{0x01}, Weight: 1}
validators := []*platform.ConvertSubnetToL1Validator{v1, v2}

if err := sortAndValidateL1Validators(validators); err != nil {
t.Fatalf("sortAndValidateL1Validators() error = %v", err)
Expand All @@ -441,7 +441,7 @@ func TestSortAndValidateL1Validators_SortsByNodeID(t *testing.T) {
}

func TestSortAndValidateL1Validators_DuplicateNodeID(t *testing.T) {
validators := []*txs.ConvertSubnetToL1Validator{
validators := []*platform.ConvertSubnetToL1Validator{
{NodeID: []byte{0x01}, Weight: 1},
{NodeID: []byte{0x01}, Weight: 1},
}
Expand Down Expand Up @@ -646,7 +646,7 @@ func TestSetL1ValidatorOwners(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
validators := []*txs.ConvertSubnetToL1Validator{
validators := []*platform.ConvertSubnetToL1Validator{
{NodeID: []byte{0x01}},
{NodeID: []byte{0x02}},
}
Expand Down Expand Up @@ -680,7 +680,7 @@ func TestSetL1ValidatorOwners(t *testing.T) {
func TestFinalizeL1ValidatorsKeepsOwnersWithValidators(t *testing.T) {
addr1 := ids.GenerateTestShortID()
addr2 := ids.GenerateTestShortID()
validators := []*txs.ConvertSubnetToL1Validator{
validators := []*platform.ConvertSubnetToL1Validator{
{NodeID: []byte{0x02}},
{NodeID: []byte{0x01}},
}
Expand Down
8 changes: 4 additions & 4 deletions e2e/pchain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"github.com/ava-labs/avalanchego/utils/crypto/bls/signer/localsigner"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/platformvm"
"github.com/ava-labs/avalanchego/vms/platformvm/platform"
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
"github.com/ava-labs/avalanchego/vms/platformvm/txs"
"github.com/ava-labs/platform-cli/pkg/crosschain"
"github.com/ava-labs/platform-cli/pkg/network"
"github.com/ava-labs/platform-cli/pkg/pchain"
Expand Down Expand Up @@ -173,7 +173,7 @@ func getTestFullWallet(t *testing.T) (*wallet.FullWallet, network.Config) {

// generateMockValidator creates a mock validator with valid BLS credentials.
// The validator won't be a real node, but has cryptographically valid PoP.
func generateMockValidator(t *testing.T, balance uint64) *txs.ConvertSubnetToL1Validator {
func generateMockValidator(t *testing.T, balance uint64) *platform.ConvertSubnetToL1Validator {
t.Helper()

// Generate random NodeID (20 bytes)
Expand All @@ -193,7 +193,7 @@ func generateMockValidator(t *testing.T, balance uint64) *txs.ConvertSubnetToL1V
t.Fatalf("failed to generate proof of possession: %v", err)
}

return &txs.ConvertSubnetToL1Validator{
return &platform.ConvertSubnetToL1Validator{
NodeID: nodeID,
Weight: units.Schmeckle, // 1 weight unit
Balance: balance,
Expand Down Expand Up @@ -783,7 +783,7 @@ func TestL1Lifecycle(t *testing.T) {
// Generate mock validator with valid BLS credentials
// Balance: 1 AVAX for the validator
mockValidator := generateMockValidator(t, 1*units.Avax)
validators := []*txs.ConvertSubnetToL1Validator{mockValidator}
validators := []*platform.ConvertSubnetToL1Validator{mockValidator}

t.Logf(" Mock validator NodeID: %x", mockValidator.NodeID)

Expand Down
Loading
Loading