code.vegaprotocol.io/vega@v0.79.0/wallet/tests/sc_generate_keys_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 TestGenerateKey(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 WithMeta(map[string]string{"name": "Key 1"}). 59 WithAlgorithm("vega/ed25519", 1). 60 WithTainted(false) 61 62 // when 63 generateKeyResp, err := KeyGenerate(t, []string{ 64 "--home", home, 65 "--output", "json", 66 "--wallet", walletName, 67 "--passphrase-file", passphraseFilePath, 68 "--meta", "name:key-2,role:validation", 69 }) 70 71 // then 72 require.NoError(t, err) 73 AssertGenerateKey(t, generateKeyResp). 74 WithMetadata(map[string]string{"name": "key-2", "role": "validation"}) 75 76 // when 77 descResp, err = KeyDescribe(t, []string{ 78 "--home", home, 79 "--output", "json", 80 "--wallet", walletName, 81 "--passphrase-file", passphraseFilePath, 82 "--pubkey", generateKeyResp.PublicKey, 83 }) 84 85 // then 86 require.NoError(t, err) 87 AssertDescribeKey(t, descResp). 88 WithMeta(map[string]string{"name": "key-2", "role": "validation"}). 89 WithAlgorithm("vega/ed25519", 1). 90 WithTainted(false) 91 }