code.vegaprotocol.io/vega@v0.79.0/wallet/tests/sc_annotate_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 TestAnnotateKey(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 err = KeyAnnotate(t, []string{ 48 "--home", home, 49 "--output", "json", 50 "--wallet", walletName, 51 "--passphrase-file", passphraseFilePath, 52 "--pubkey", createWalletResp.Key.PublicKey, 53 "--meta", "name:prefer-this-name", 54 }) 55 56 // then 57 require.NoError(t, err) 58 59 // when 60 descResp, err := KeyDescribe(t, []string{ 61 "--home", home, 62 "--output", "json", 63 "--wallet", walletName, 64 "--passphrase-file", passphraseFilePath, 65 "--pubkey", createWalletResp.Key.PublicKey, 66 }) 67 68 // then 69 require.NoError(t, err) 70 AssertDescribeKey(t, descResp). 71 WithMeta(map[string]string{"name": "prefer-this-name"}) 72 73 // when 74 err = KeyAnnotate(t, []string{ 75 "--home", home, 76 "--output", "json", 77 "--wallet", walletName, 78 "--passphrase-file", passphraseFilePath, 79 "--pubkey", createWalletResp.Key.PublicKey, 80 "--clear", 81 }) 82 83 // then 84 require.NoError(t, err) 85 86 // when 87 descResp, err = KeyDescribe(t, []string{ 88 "--home", home, 89 "--output", "json", 90 "--wallet", walletName, 91 "--passphrase-file", passphraseFilePath, 92 "--pubkey", createWalletResp.Key.PublicKey, 93 }) 94 95 // then 96 require.NoError(t, err) 97 AssertDescribeKey(t, descResp). 98 WithMeta(map[string]string{"name": "Key 1"}) 99 100 // when 101 err = KeyAnnotate(t, []string{ 102 "--home", home, 103 "--output", "json", 104 "--wallet", walletName, 105 "--passphrase-file", passphraseFilePath, 106 "--pubkey", createWalletResp.Key.PublicKey, 107 "--meta", "name:key-1,role:validation", 108 }) 109 110 // then 111 require.NoError(t, err) 112 113 // when 114 descResp, err = KeyDescribe(t, []string{ 115 "--home", home, 116 "--output", "json", 117 "--wallet", walletName, 118 "--passphrase-file", passphraseFilePath, 119 "--pubkey", createWalletResp.Key.PublicKey, 120 }) 121 122 // then 123 require.NoError(t, err) 124 AssertDescribeKey(t, descResp). 125 WithMeta(map[string]string{"name": "key-1", "role": "validation"}) 126 }