Files
cli/pkg/dependencies/min_version_test.go
2026-01-08 20:36:16 -08:00

97 lines
3.3 KiB
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package dependencies
import (
"testing"
"github.com/luxfi/cli/internal/mocks"
"github.com/luxfi/cli/pkg/application"
"github.com/luxfi/constants"
"github.com/luxfi/sdk/models"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
var testCLIMinVersion = []byte(`{"evm":"v0.7.3","rpc":39,"luxd":{"Local Network":{"latest-version":"v1.20.3", "minimum-version":""},"DevNet":{"latest-version":"v1.20.3", "minimum-version":""},"Testnet":{"latest-version":"v1.20.3", "minimum-version":"v1.20.3-testnet"},"Mainnet":{"latest-version":"v1.20.3", "minimum-version":"v1.20.3"}}}`)
func TestCheckMinDependencyVersion(t *testing.T) {
tests := []struct {
name string
dependency string
expectedError bool
cliDependencyData []byte
customVersion string
network models.Network
}{
{
name: "custom luxd dependency equal to cli minimum supported version of luxd",
dependency: constants.LuxdRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.20.3-testnet",
network: models.NewTestnetNetwork(),
},
{
name: "custom luxd dependency higher than cli minimum supported version of luxd",
dependency: constants.LuxdRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.20.3",
network: models.NewTestnetNetwork(),
},
{
name: "custom luxd dependency equal to cli minimum supported version of luxd",
dependency: constants.LuxdRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.20.3-testnet",
network: models.NewTestnetNetwork(),
},
{
name: "custom luxd dependency higher than cli minimum supported version of luxd",
dependency: constants.LuxdRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.20.4",
network: models.NewTestnetNetwork(),
},
{
name: "custom luxd dependency lower than cli minimum supported version of luxd",
dependency: constants.LuxdRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: true,
customVersion: "v1.12.2",
network: models.NewTestnetNetwork(),
},
{
name: "custom luxd dependency for network that doesn't have minimum supported version of luxd",
dependency: constants.LuxdRepoName,
cliDependencyData: testCLIMinVersion,
expectedError: false,
customVersion: "v1.12.2",
network: models.NewLocalNetwork(),
},
}
for _, tt := range tests {
mockDownloader := &mocks.Downloader{}
mockDownloader.On("Download", mock.MatchedBy(func(url string) bool {
return url == constants.CLILatestDependencyURL
})).Return(tt.cliDependencyData, nil)
app := application.New()
app.Downloader = mockDownloader
t.Run(tt.name, func(t *testing.T) {
err := CheckVersionIsOverMin(app, tt.dependency, tt.network, tt.customVersion)
if tt.expectedError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
})
}
}