Skip to content

Commit cd56bde

Browse files
e2e fuji script
1 parent 44d1454 commit cd56bde

File tree

6 files changed

+419
-62
lines changed

6 files changed

+419
-62
lines changed

bootstrap_validators.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[
2+
{
3+
"NodeID": "NodeID-8gb3QvLJmyAjkURJMpzq5fxDZPjrpoTR6",
4+
"Weight": 100,
5+
"Balance": 100000000,
6+
"BLSPublicKey": "0xa89c0b65cf830708bde9535d9059122483102b6720a1553f2fb7229ca86429bbb65acddc719153739fcf42af7e2a43fe",
7+
"BLSProofOfPossession": "0x81cc42db64d8bcc7ce0d1fd04a85cab2593b46b4a8932cc25d931f9810a2ad4cbf1a1e5e63c93eff29a7c50e28ea0ba60d613ddbe3a0f3347c12e16dbb97ea279d23396a8eac230c22d97f87245e5e5911609e39551782ee28ec67afcdf15334",
8+
"ChangeOwnerAddr": "P-fuji1377nx80rx3pzneup5qywgdgdsmzntql7trcqlg",
9+
"ValidationID": ""
10+
},
11+
{
12+
"NodeID": "NodeID-7xkPpKbncCJSC5NzYGd2aQe3G9tyxS37d",
13+
"Weight": 100,
14+
"Balance": 100000000,
15+
"BLSPublicKey": "0x91dccaf85f9dd3f8551e93896744234b9294ca872ba07796c6728643fd39d6bad98049b46553a2d594781f9ac6557179",
16+
"BLSProofOfPossession": "0xa4fceabb8865f1f120c676c7b1c1c68afecd33ca0df1769d3533955be86f6b0cf810e310b721556c18a47b2b349b5e0117bce978c081e58841c5bc48dc117cb57d7e35a65dc25d98bad77f5a266c5c0e24d801105778fa78dbcbf43cf6b1103f",
17+
"ChangeOwnerAddr": "P-fuji1377nx80rx3pzneup5qywgdgdsmzntql7trcqlg",
18+
"ValidationID": ""
19+
}
20+
]

cmd/blockchaincmd/convert.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func StartLocalMachine(
122122
availableBalance uint64,
123123
httpPorts []uint,
124124
stakingPorts []uint,
125+
cmd *cobra.Command,
125126
) (bool, error) {
126127
var err error
127128
if network.Kind == models.Local {
@@ -147,7 +148,7 @@ func StartLocalMachine(
147148
useLocalMachine = true
148149
}
149150
// ask user if we want to use local machine if cluster is not provided
150-
if !useLocalMachine && clusterNameFlagValue == "" {
151+
if !cmd.Flags().Changed("use-local-machine") && !useLocalMachine && clusterNameFlagValue == "" {
151152
ux.Logger.PrintToUser("You can use your local machine as a bootstrap validator on the blockchain")
152153
ux.Logger.PrintToUser("This means that you don't have to to set up a remote server on a cloud service (e.g. AWS / GCP) to be a validator on the blockchain.")
153154

@@ -538,7 +539,7 @@ func convertSubnetToL1(
538539
}
539540

540541
// convertBlockchain is the cobra command run for converting subnets into sovereign L1
541-
func convertBlockchain(_ *cobra.Command, args []string) error {
542+
func convertBlockchain(cmd *cobra.Command, args []string) error {
542543
blockchainName := args[0]
543544

544545
chains, err := ValidateSubnetNameAndGetChains(args)
@@ -673,6 +674,7 @@ func convertBlockchain(_ *cobra.Command, args []string) error {
673674
availableBalance,
674675
httpPorts,
675676
stakingPorts,
677+
cmd,
676678
); err != nil {
677679
return err
678680
} else if cancel {

cmd/blockchaincmd/deploy.go

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -581,73 +581,76 @@ func deployBlockchain(cmd *cobra.Command, args []string) error {
581581
deployBalance := uint64(deployBalanceAVAX * float64(units.Avax))
582582
// whether user has created Avalanche Nodes when blockchain deploy command is called
583583
if sidecar.Sovereign {
584-
if changeOwnerAddress == "" {
585-
// use provided key as change owner unless already set
586-
if pAddr, err := kc.PChainFormattedStrAddresses(); err == nil && len(pAddr) > 0 {
587-
changeOwnerAddress = pAddr[0]
588-
ux.Logger.PrintToUser("Using [%s] to be set as a change owner for leftover AVAX", changeOwnerAddress)
589-
}
590-
}
591-
if !generateNodeID {
592-
if cancel, err := StartLocalMachine(
593-
network,
594-
sidecar,
595-
blockchainName,
596-
deployBalance,
597-
availableBalance,
598-
httpPorts,
599-
stakingPorts,
600-
); err != nil {
601-
return err
602-
} else if cancel {
603-
return nil
604-
}
605-
}
606-
switch {
607-
case len(bootstrapEndpoints) > 0:
584+
if len(bootstrapValidators) == 0 {
608585
if changeOwnerAddress == "" {
609-
changeOwnerAddress, err = blockchain.GetKeyForChangeOwner(app, network)
610-
if err != nil {
611-
return err
586+
// use provided key as change owner unless already set
587+
if pAddr, err := kc.PChainFormattedStrAddresses(); err == nil && len(pAddr) > 0 {
588+
changeOwnerAddress = pAddr[0]
589+
ux.Logger.PrintToUser("Using [%s] to be set as a change owner for leftover AVAX", changeOwnerAddress)
612590
}
613591
}
614-
for _, endpoint := range bootstrapEndpoints {
615-
infoClient := info.NewClient(endpoint)
616-
ctx, cancel := utils.GetAPILargeContext()
617-
defer cancel()
618-
nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx)
619-
if err != nil {
592+
if !generateNodeID {
593+
if cancel, err := StartLocalMachine(
594+
network,
595+
sidecar,
596+
blockchainName,
597+
deployBalance,
598+
availableBalance,
599+
httpPorts,
600+
stakingPorts,
601+
cmd,
602+
); err != nil {
620603
return err
604+
} else if cancel {
605+
return nil
621606
}
622-
publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:])
623-
pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:])
624-
625-
bootstrapValidators = append(bootstrapValidators, models.SubnetValidator{
626-
NodeID: nodeID.String(),
627-
Weight: constants.BootstrapValidatorWeight,
628-
Balance: deployBalance,
629-
BLSPublicKey: publicKey,
630-
BLSProofOfPossession: pop,
631-
ChangeOwnerAddr: changeOwnerAddress,
632-
})
633-
}
634-
case clusterNameFlagValue != "":
635-
// for remote clusters we don't need to ask for bootstrap validators and can read it from filesystem
636-
bootstrapValidators, err = getClusterBootstrapValidators(clusterNameFlagValue, network, deployBalance)
637-
if err != nil {
638-
return fmt.Errorf("error getting bootstrap validators from cluster %s: %w", clusterNameFlagValue, err)
639607
}
608+
switch {
609+
case len(bootstrapEndpoints) > 0:
610+
if changeOwnerAddress == "" {
611+
changeOwnerAddress, err = blockchain.GetKeyForChangeOwner(app, network)
612+
if err != nil {
613+
return err
614+
}
615+
}
616+
for _, endpoint := range bootstrapEndpoints {
617+
infoClient := info.NewClient(endpoint)
618+
ctx, cancel := utils.GetAPILargeContext()
619+
defer cancel()
620+
nodeID, proofOfPossession, err := infoClient.GetNodeID(ctx)
621+
if err != nil {
622+
return err
623+
}
624+
publicKey = "0x" + hex.EncodeToString(proofOfPossession.PublicKey[:])
625+
pop = "0x" + hex.EncodeToString(proofOfPossession.ProofOfPossession[:])
626+
627+
bootstrapValidators = append(bootstrapValidators, models.SubnetValidator{
628+
NodeID: nodeID.String(),
629+
Weight: constants.BootstrapValidatorWeight,
630+
Balance: deployBalance,
631+
BLSPublicKey: publicKey,
632+
BLSProofOfPossession: pop,
633+
ChangeOwnerAddr: changeOwnerAddress,
634+
})
635+
}
636+
case clusterNameFlagValue != "":
637+
// for remote clusters we don't need to ask for bootstrap validators and can read it from filesystem
638+
bootstrapValidators, err = getClusterBootstrapValidators(clusterNameFlagValue, network, deployBalance)
639+
if err != nil {
640+
return fmt.Errorf("error getting bootstrap validators from cluster %s: %w", clusterNameFlagValue, err)
641+
}
640642

641-
default:
642-
bootstrapValidators, err = promptBootstrapValidators(
643-
network,
644-
changeOwnerAddress,
645-
numBootstrapValidators,
646-
deployBalance,
647-
availableBalance,
648-
)
649-
if err != nil {
650-
return err
643+
default:
644+
bootstrapValidators, err = promptBootstrapValidators(
645+
network,
646+
changeOwnerAddress,
647+
numBootstrapValidators,
648+
deployBalance,
649+
availableBalance,
650+
)
651+
if err != nil {
652+
return err
653+
}
651654
}
652655
}
653656
} else if network.Kind == models.Local {

compatibility_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/ava-labs/avalanche-cli/internal/mocks"
7+
"github.com/stretchr/testify/mock"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestGetLatestCLISupportedDependencyVersion(t *testing.T) {
12+
testCases := []struct {
13+
name string
14+
dependency string
15+
expectedError bool
16+
expectedResult string
17+
}{
18+
{
19+
name: "valid dependency",
20+
dependency: "github.com/example/package",
21+
expectedError: false,
22+
expectedResult: "v1.0.0",
23+
},
24+
{
25+
name: "empty dependency",
26+
dependency: "",
27+
expectedError: true,
28+
expectedResult: "",
29+
},
30+
{
31+
name: "invalid dependency format",
32+
dependency: "invalid/format",
33+
expectedError: true,
34+
expectedResult: "",
35+
},
36+
}
37+
38+
for _, tc := range testCases {
39+
t.Run(tc.name, func(t *testing.T) {
40+
result, err := GetLatestCLISupportedDependencyVersion(tc.dependency)
41+
42+
if tc.expectedError {
43+
require.Error(t, err)
44+
} else {
45+
require.NoError(t, err)
46+
require.Equal(t, tc.expectedResult, result)
47+
}
48+
})
49+
}
50+
}
51+
52+
func TestDownloader(t *testing.T) {
53+
mockDownloader := &mocks.Downloader{}
54+
mockDownloader.On("Download", mock.MatchedBy(func(url string) bool {
55+
return url == "https://github.com/ava-labs/avalanchego/releases/download/v1.17.1/avalanchego-linux-amd64-v1.17.1.tar.gz"
56+
})).Return(zipBytes1, nil)
57+
58+
mockDownloader.On("Download", mock.MatchedBy(func(url string) bool {
59+
return url == "https://github.com/ava-labs/avalanchego/releases/download/v1.18.5/avalanchego-macos-v1.18.5.zip"
60+
})).Return(zipBytes2, nil)
61+
}

scripts/check_node_status.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
# Function to check if all nodes are bootstrapped and healthy
4+
check_nodes_status() {
5+
# Run the command and capture its output
6+
local output
7+
output=$(./bin/avalanche node status newNodes)
8+
9+
# Check if all nodes are bootstrapped and healthy
10+
if echo "$output" | grep -q "BOOTSTRAPPED" && echo "$output" | grep -q "OK"; then
11+
# Count the number of nodes that are both bootstrapped and healthy
12+
local bootstrapped_count=$(echo "$output" | grep -c "BOOTSTRAPPED")
13+
local healthy_count=$(echo "$output" | grep -c "OK")
14+
15+
# If the counts match (meaning all nodes are both bootstrapped and healthy)
16+
if [ "$bootstrapped_count" -eq "$healthy_count" ]; then
17+
echo "All nodes are bootstrapped and healthy!"
18+
return 0
19+
fi
20+
fi
21+
return 1
22+
}
23+
24+
echo "Starting node status check..."
25+
echo "Will check every 30 seconds until all nodes are bootstrapped and healthy."
26+
27+
# Loop until all nodes are bootstrapped and healthy
28+
while true; do
29+
if check_nodes_status; then
30+
echo "All nodes are ready!"
31+
exit 0
32+
fi
33+
34+
echo "Not all nodes are ready yet. Waiting 30 seconds..."
35+
sleep 30
36+
done

0 commit comments

Comments
 (0)