code.vegaprotocol.io/vega@v0.79.0/wallet/tests/helpers_for_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 tests_test
    17  
    18  import (
    19  	"fmt"
    20  	"path/filepath"
    21  	"testing"
    22  
    23  	vgfs "code.vegaprotocol.io/vega/libs/fs"
    24  	vgrand "code.vegaprotocol.io/vega/libs/rand"
    25  )
    26  
    27  const testRecoveryPhrase = "swing ceiling chaos green put insane ripple desk match tip melt usual shrug turkey renew icon parade veteran lens govern path rough page render"
    28  
    29  func NewPassphraseFile(t *testing.T, path string) (string, string) {
    30  	t.Helper()
    31  	passphrase := vgrand.RandomStr(10)
    32  	passphraseFilePath := NewFile(t, path, fmt.Sprintf("passphrase-%s.txt", passphrase), passphrase)
    33  	return passphrase, passphraseFilePath
    34  }
    35  
    36  func NewFile(t *testing.T, path, fileName, data string) string {
    37  	t.Helper()
    38  	filePath := filepath.Join(path, fileName)
    39  	if err := vgfs.WriteFile(filePath, []byte(data)); err != nil {
    40  		t.Fatalf("couldn't write passphrase file: %v", err)
    41  	}
    42  	return filePath
    43  }
    44  
    45  func FakeNetwork(name string) string {
    46  	return fmt.Sprintf(`
    47  Name = "%s"
    48  Level = "info"
    49  MaximumTokenDuration = "1h0m0s"
    50  Port = 8000
    51  Host = "127.0.0.1"
    52  
    53  [API.GRPC]
    54  Retries = 5
    55  Hosts = [
    56      "example.com:3007",
    57  ]
    58  
    59  [API.REST]
    60  Hosts = [
    61      "https://example.com/rest"
    62  ]
    63  
    64  [API.GraphQL]
    65  Hosts = [
    66      "https://example.com/gql/query"
    67  ]
    68  `, name)
    69  }