cli/wallet: fail if signer is missing in tx

This commit is contained in:
Evgeniy Stratonikov 2021-03-03 16:05:33 +03:00
parent 7553c1ac96
commit 8a4b97171a
2 changed files with 26 additions and 0 deletions

View file

@ -75,6 +75,21 @@ func TestSignMultisigTx(t *testing.T) {
"--to", priv.Address(), "--token", "NEO", "--amount", "1",
"--out", txPath)
simplePriv, err := keys.NewPrivateKey()
require.NoError(t, err)
{ // Simple signer, not in signers.
e.In.WriteString("acc\rpass\rpass\r")
e.Run(t, "neo-go", "wallet", "import",
"--wallet", wallet1Path,
"--wif", simplePriv.WIF())
t.Run("sign with missing signer", func(t *testing.T) {
e.In.WriteString("pass\r")
e.RunWithError(t, "neo-go", "wallet", "sign",
"--wallet", wallet1Path, "--address", simplePriv.Address(),
"--in", txPath, "--out", txPath)
})
}
e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "sign",
"--rpc-endpoint", "http://"+e.RPC.Addr,

View file

@ -36,6 +36,17 @@ func signStoredTransaction(ctx *cli.Context) error {
return cli.NewExitError("verifiable item is not a transaction", 1)
}
signerFound := false
for i := range tx.Signers {
if tx.Signers[i].Account == acc.Contract.ScriptHash() {
signerFound = true
break
}
}
if !signerFound {
return cli.NewExitError("tx signers don't contain provided account", 1)
}
priv := acc.PrivateKey()
sign := priv.Sign(tx.GetSignedPart())
if err := c.AddSignature(acc.Contract, priv.PublicKey(), sign); err != nil {