code.vegaprotocol.io/vega@v0.79.0/wallet/tests/sc_import_wallet_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 "testing" 20 21 vgrand "code.vegaprotocol.io/vega/libs/rand" 22 23 "github.com/stretchr/testify/require" 24 ) 25 26 func TestImportWalletV1(t *testing.T) { 27 // given 28 home := t.TempDir() 29 _, passphraseFilePath := NewPassphraseFile(t, home) 30 recoveryPhraseFilePath := NewFile(t, home, "recovery-phrase.txt", testRecoveryPhrase) 31 walletName := vgrand.RandomStr(5) 32 33 // when 34 importWalletResp, err := WalletImport(t, []string{ 35 "--home", home, 36 "--output", "json", 37 "--wallet", walletName, 38 "--passphrase-file", passphraseFilePath, 39 "--recovery-phrase-file", recoveryPhraseFilePath, 40 "--version", "1", 41 }) 42 43 // then 44 require.NoError(t, err) 45 AssertImportWallet(t, importWalletResp). 46 WithName(walletName). 47 WithPublicKey("30ebce58d94ad37c4ff6a9014c955c20e12468da956163228cc7ec9b98d3a371"). 48 LocatedUnder(home) 49 50 // when 51 walletInfoResp, err := WalletDescribe(t, []string{ 52 "--home", home, 53 "--output", "json", 54 "--wallet", walletName, 55 "--passphrase-file", passphraseFilePath, 56 }) 57 58 // then 59 require.NoError(t, err) 60 AssertWalletInfo(t, walletInfoResp). 61 IsHDWallet(). 62 WithVersion(1) 63 64 // when 65 listKeysResp1, err := KeyList(t, []string{ 66 "--home", home, 67 "--output", "json", 68 "--wallet", walletName, 69 "--passphrase-file", passphraseFilePath, 70 }) 71 72 // then 73 require.NoError(t, err) 74 require.NotNil(t, listKeysResp1) 75 require.Len(t, listKeysResp1.Keys, 1) 76 77 // when 78 generateKeyResp, err := KeyGenerate(t, []string{ 79 "--home", home, 80 "--output", "json", 81 "--wallet", walletName, 82 "--passphrase-file", passphraseFilePath, 83 "--meta", "name:key-1,role:validation", 84 }) 85 86 // then 87 require.NoError(t, err) 88 AssertGenerateKey(t, generateKeyResp). 89 WithMetadata(map[string]string{"name": "key-1", "role": "validation"}). 90 WithPublicKey("de998bab8d15a6f6b9584251ff156c2424ccdf1de8ba00e4933595773e9e00dc") 91 92 // when 93 listKeysResp2, err := KeyList(t, []string{ 94 "--home", home, 95 "--output", "json", 96 "--wallet", walletName, 97 "--passphrase-file", passphraseFilePath, 98 }) 99 100 // then 101 require.NoError(t, err) 102 require.NotNil(t, listKeysResp2) 103 require.Len(t, listKeysResp2.Keys, 2) 104 } 105 106 func TestImportWalletV2(t *testing.T) { 107 // given 108 home := t.TempDir() 109 _, passphraseFilePath := NewPassphraseFile(t, home) 110 recoveryPhraseFilePath := NewFile(t, home, "recovery-phrase.txt", testRecoveryPhrase) 111 walletName := vgrand.RandomStr(5) 112 113 // when 114 importWalletResp, err := WalletImport(t, []string{ 115 "--home", home, 116 "--output", "json", 117 "--wallet", walletName, 118 "--passphrase-file", passphraseFilePath, 119 "--recovery-phrase-file", recoveryPhraseFilePath, 120 "--version", "2", 121 }) 122 123 // then 124 require.NoError(t, err) 125 AssertImportWallet(t, importWalletResp). 126 WithName(walletName). 127 WithPublicKey("b5fd9d3c4ad553cb3196303b6e6df7f484cf7f5331a572a45031239fd71ad8a0"). 128 LocatedUnder(home) 129 130 // when 131 walletInfoResp, err := WalletDescribe(t, []string{ 132 "--home", home, 133 "--output", "json", 134 "--wallet", walletName, 135 "--passphrase-file", passphraseFilePath, 136 }) 137 138 // then 139 require.NoError(t, err) 140 AssertWalletInfo(t, walletInfoResp). 141 IsHDWallet(). 142 WithVersion(2) 143 144 // when 145 listKeysResp1, err := KeyList(t, []string{ 146 "--home", home, 147 "--output", "json", 148 "--wallet", walletName, 149 "--passphrase-file", passphraseFilePath, 150 }) 151 152 // then 153 require.NoError(t, err) 154 require.NotNil(t, listKeysResp1) 155 require.Len(t, listKeysResp1.Keys, 1) 156 157 // when 158 generateKeyResp, err := KeyGenerate(t, []string{ 159 "--home", home, 160 "--output", "json", 161 "--wallet", walletName, 162 "--passphrase-file", passphraseFilePath, 163 "--meta", "name:key-1,role:validation", 164 }) 165 166 // then 167 require.NoError(t, err) 168 AssertGenerateKey(t, generateKeyResp). 169 WithMetadata(map[string]string{"name": "key-1", "role": "validation"}). 170 WithPublicKey("988eae323a07f12363c17025c23ee58ea32ac3912398e16bb0b56969f57adc52") 171 172 // when 173 listKeysResp2, err := KeyList(t, []string{ 174 "--home", home, 175 "--output", "json", 176 "--wallet", walletName, 177 "--passphrase-file", passphraseFilePath, 178 }) 179 180 // then 181 require.NoError(t, err) 182 require.NotNil(t, listKeysResp2) 183 require.Len(t, listKeysResp2.Keys, 2) 184 }