code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/service_run_test.go (about)

     1  // Copyright (C) 2023 Gobalsky Labs Limited
     2  //
     3  // This program is free software: you can redistribute it and/or modify
     4  // it under the terms of the GNU Affero General Public License as
     5  // published by the Free Software Foundation, either version 3 of the
     6  // License, or (at your option) any later version.
     7  //
     8  // This program is distributed in the hope that it will be useful,
     9  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    10  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11  // GNU Affero General Public License for more details.
    12  //
    13  // You should have received a copy of the GNU Affero General Public License
    14  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    15  
    16  package cmd_test
    17  
    18  import (
    19  	"testing"
    20  
    21  	cmd "code.vegaprotocol.io/vega/cmd/vegawallet/commands"
    22  	"code.vegaprotocol.io/vega/cmd/vegawallet/commands/flags"
    23  	vgrand "code.vegaprotocol.io/vega/libs/rand"
    24  
    25  	"github.com/stretchr/testify/assert"
    26  )
    27  
    28  func TestRunServiceFlags(t *testing.T) {
    29  	t.Run("Missing loads-token flag with tokens passphrase flag fails", testRunServiceFlagsTokenPassphraseWithoutWithLOngLivingTokenFails)
    30  	t.Run("Missing network fails", testRunServiceFlagsMissingNetworkFails)
    31  }
    32  
    33  func testRunServiceFlagsTokenPassphraseWithoutWithLOngLivingTokenFails(t *testing.T) {
    34  	testDir := t.TempDir()
    35  
    36  	// given
    37  	_, passphraseFilePath := NewPassphraseFile(t, testDir)
    38  	networkName := vgrand.RandomStr(10)
    39  	f := &cmd.RunServiceFlags{
    40  		Network:              networkName,
    41  		TokensPassphraseFile: passphraseFilePath,
    42  	}
    43  
    44  	// when
    45  	err := f.Validate(&cmd.RootFlags{
    46  		Home: testDir,
    47  	})
    48  
    49  	// then
    50  	assert.ErrorIs(t, err, flags.OneOfParentsFlagMustBeSpecifiedError("tokens-passphrase-file", "load-tokens"))
    51  }
    52  
    53  func testRunServiceFlagsMissingNetworkFails(t *testing.T) {
    54  	testDir := t.TempDir()
    55  
    56  	// given
    57  	f := newRunServiceFlags(t)
    58  	f.Network = ""
    59  
    60  	// when
    61  	err := f.Validate(&cmd.RootFlags{
    62  		Home: testDir,
    63  	})
    64  
    65  	// then
    66  	assert.ErrorIs(t, err, flags.MustBeSpecifiedError("network"))
    67  }
    68  
    69  func newRunServiceFlags(t *testing.T) *cmd.RunServiceFlags {
    70  	t.Helper()
    71  
    72  	networkName := vgrand.RandomStr(10)
    73  
    74  	return &cmd.RunServiceFlags{
    75  		Network: networkName,
    76  	}
    77  }