code.vegaprotocol.io/vega@v0.79.0/wallet/tests/sc_describe_key_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 TestDescribeKey(t *testing.T) { 27 // given 28 home := t.TempDir() 29 _, passphraseFilePath := NewPassphraseFile(t, home) 30 walletName := vgrand.RandomStr(5) 31 32 // when 33 createWalletResp, err := WalletCreate(t, []string{ 34 "--home", home, 35 "--output", "json", 36 "--wallet", walletName, 37 "--passphrase-file", passphraseFilePath, 38 }) 39 40 // then 41 require.NoError(t, err) 42 AssertCreateWallet(t, createWalletResp). 43 WithName(walletName). 44 LocatedUnder(home) 45 46 // when 47 descResp, err := KeyDescribe(t, []string{ 48 "--home", home, 49 "--output", "json", 50 "--wallet", walletName, 51 "--passphrase-file", passphraseFilePath, 52 "--pubkey", createWalletResp.Key.PublicKey, 53 }) 54 55 // then 56 require.NoError(t, err) 57 AssertDescribeKey(t, descResp). 58 WithPubKey(createWalletResp.Key.PublicKey). 59 WithMeta(map[string]string{"name": "Key 1"}). 60 WithAlgorithm("vega/ed25519", 1). 61 WithTainted(false) 62 } 63 64 func TestDescribeUnknownKey(t *testing.T) { 65 // given 66 home := t.TempDir() 67 _, passphraseFilePath := NewPassphraseFile(t, home) 68 walletName := vgrand.RandomStr(5) 69 70 // when 71 createWalletResp, err := WalletCreate(t, []string{ 72 "--home", home, 73 "--output", "json", 74 "--wallet", walletName, 75 "--passphrase-file", passphraseFilePath, 76 }) 77 78 // then 79 require.NoError(t, err) 80 AssertCreateWallet(t, createWalletResp). 81 WithName(walletName). 82 LocatedUnder(home) 83 84 // when 85 descResp, err := KeyDescribe(t, []string{ 86 "--home", home, 87 "--output", "json", 88 "--wallet", walletName, 89 "--passphrase-file", passphraseFilePath, 90 "--pubkey", createWalletResp.Key.PublicKey[1:], 91 }) 92 93 // then 94 require.Error(t, err) 95 require.Nil(t, descResp) 96 }