code.vegaprotocol.io/vega@v0.79.0/cmd/vegawallet/commands/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 cmd_test 17 18 import ( 19 "encoding/json" 20 "path/filepath" 21 "testing" 22 23 vgfs "code.vegaprotocol.io/vega/libs/fs" 24 vgrand "code.vegaprotocol.io/vega/libs/rand" 25 26 "github.com/stretchr/testify/assert" 27 ) 28 29 func NewPassphraseFile(t *testing.T, path string) (string, string) { 30 t.Helper() 31 passphrase := vgrand.RandomStr(10) 32 fuzz := vgrand.RandomStr(5) 33 34 passphraseFilePath := NewFile(t, path, fuzz+"passphrase.txt", passphrase) 35 return passphrase, passphraseFilePath 36 } 37 38 func NewFile(t *testing.T, path, fileName, data string) string { 39 t.Helper() 40 filePath := filepath.Join(path, fileName) 41 if err := vgfs.WriteFile(filePath, []byte(data)); err != nil { 42 t.Fatalf("couldn't write passphrase file: %v", err) 43 } 44 return filePath 45 } 46 47 var testTransactionJSON = `{"voteSubmission":{"proposalId":"eb2d3902fdda9c3eb6e369f2235689b871c7322cf3ab284dde3e9dfc13863a17","value":"VALUE_YES"}}` 48 49 func transactionFromJSON(t *testing.T, JSON string) map[string]any { 50 t.Helper() 51 testTransaction := make(map[string]any) 52 assert.NoError(t, json.Unmarshal([]byte(JSON), &testTransaction)) 53 return testTransaction 54 } 55 56 func testTransaction(t *testing.T) map[string]any { 57 t.Helper() 58 return transactionFromJSON(t, testTransactionJSON) 59 }