code.vegaprotocol.io/vega@v0.79.0/wallet/tests/sc_sign_and_verify_command_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 TestSignCommand(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", "2", 41 }) 42 43 // then 44 require.NoError(t, err) 45 AssertImportWallet(t, importWalletResp). 46 WithName(walletName). 47 LocatedUnder(home) 48 49 // when 50 signResp, err := SignCommand(t, []string{ 51 "--home", home, 52 "--output", "json", 53 "--wallet", walletName, 54 "--chain-id", vgrand.RandomStr(5), 55 "--pubkey", importWalletResp.Key.PublicKey, 56 "--passphrase-file", passphraseFilePath, 57 "--tx-height", "150", 58 "--tx-block-hash", "1da3c57bfc2ff8fac2bd2160e5bed5f88f49d1d54d655918cf0758585f248ef7", 59 "--pow-difficulty", "2", 60 "--pow-hash-function", "sha3_24_rounds", 61 `{"voteSubmission": {"proposalId": "1da3c57bfc2ff8fac2bd2160e5bed5f88f49d1d54d655918cf0758585f248ef7", "value": "VALUE_YES"}}`, 62 }) 63 64 // then 65 require.NoError(t, err) 66 AssertSignCommand(t, signResp) 67 } 68 69 func TestSignCommandWithTaintedKey(t *testing.T) { 70 // given 71 home := t.TempDir() 72 _, passphraseFilePath := NewPassphraseFile(t, home) 73 recoveryPhraseFilePath := NewFile(t, home, "recovery-phrase.txt", testRecoveryPhrase) 74 walletName := vgrand.RandomStr(5) 75 76 // when 77 importWalletResp, err := WalletImport(t, []string{ 78 "--home", home, 79 "--output", "json", 80 "--wallet", walletName, 81 "--passphrase-file", passphraseFilePath, 82 "--recovery-phrase-file", recoveryPhraseFilePath, 83 "--version", "2", 84 }) 85 86 // then 87 require.NoError(t, err) 88 AssertImportWallet(t, importWalletResp). 89 WithName(walletName). 90 WithPublicKey("b5fd9d3c4ad553cb3196303b6e6df7f484cf7f5331a572a45031239fd71ad8a0"). 91 LocatedUnder(home) 92 93 // when 94 err = KeyTaint(t, []string{ 95 "--home", home, 96 "--output", "json", 97 "--wallet", walletName, 98 "--pubkey", importWalletResp.Key.PublicKey, 99 "--passphrase-file", passphraseFilePath, 100 }) 101 102 // then 103 require.NoError(t, err) 104 105 // when 106 signResp, err := SignCommand(t, []string{ 107 "--home", home, 108 "--output", "json", 109 "--wallet", walletName, 110 "--chain-id", vgrand.RandomStr(5), 111 "--pubkey", importWalletResp.Key.PublicKey, 112 "--passphrase-file", passphraseFilePath, 113 "--tx-height", "150", 114 "--tx-block-hash", "1da3c57bfc2ff8fac2bd2160e5bed5f88f49d1d54d655918cf0758585f248ef7", 115 "--pow-difficulty", "2", 116 "--pow-hash-function", "sha3_24_rounds", 117 `{"voteSubmission": {"proposalId": "1da3c57bfc2ff8fac2bd2160e5bed5f88f49d1d54d655918cf0758585f248ef7", "value": "VALUE_YES"}}`, 118 }) 119 120 // then 121 require.EqualError(t, err, "could not sign the transaction: the public key is tainted") 122 require.Nil(t, signResp) 123 124 // when 125 err = KeyUntaint(t, []string{ 126 "--home", home, 127 "--output", "json", 128 "--wallet", walletName, 129 "--pubkey", importWalletResp.Key.PublicKey, 130 "--passphrase-file", passphraseFilePath, 131 }) 132 133 // then 134 require.NoError(t, err) 135 136 // when 137 signResp, err = SignCommand(t, []string{ 138 "--home", home, 139 "--output", "json", 140 "--wallet", walletName, 141 "--chain-id", vgrand.RandomStr(5), 142 "--pubkey", importWalletResp.Key.PublicKey, 143 "--passphrase-file", passphraseFilePath, 144 "--tx-height", "150", 145 "--tx-block-hash", "1da3c57bfc2ff8fac2bd2160e5bed5f88f49d1d54d655918cf0758585f248ef7", 146 "--pow-difficulty", "2", 147 "--pow-hash-function", "sha3_24_rounds", 148 `{"voteSubmission": {"proposalId": "1da3c57bfc2ff8fac2bd2160e5bed5f88f49d1d54d655918cf0758585f248ef7", "value": "VALUE_YES"}}`, 149 }) 150 151 // then 152 require.NoError(t, err) 153 AssertSignCommand(t, signResp) 154 }