Skip to content

Commit fa0868c

Browse files
committed
address review feedback
1 parent 6984194 commit fa0868c

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

cmd/operator/multisign.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ package main
33
import (
44
"encoding/hex"
55
"encoding/json"
6+
"errors"
67
"fmt"
8+
"io"
79
"strings"
810

911
"github.com/klever-io/klever-go/cmd/operator/utils"
@@ -153,7 +155,9 @@ func subMS() []*cobra.Command {
153155
Use: "sign [txHash]",
154156
Short: "sign a transaction from multisign API and post the signature",
155157
Example: `operator ms sign <txHash> — sign specific TX by hash
156-
operator ms sign — interactively choose from pending transactions`,
158+
operator ms sign <txHash> -s — sign specific TX by hash; skip confirmation prompt
159+
operator ms sign — interactively choose from pending transactions
160+
operator ms sign -s — interactively choose from pending transactions; skip confirmation prompt`,
157161
Args: cobra.MaximumNArgs(1),
158162
RunE: func(cmd *cobra.Command, args []string) error {
159163
log.Info("signing transaction from multisign API", "address", signerAddress)
@@ -165,7 +169,7 @@ operator ms sign — interactively choose from pending transactions`,
165169
log.Info("fetching pending transactions for signing")
166170
result := make([]MSApiTransaction, 0)
167171
err = utils.GetURL(fmt.Sprintf("%s/transaction/by-address/%s", multisignAPI, signerAddress), &result)
168-
if err != nil && err.Error() != "EOF" {
172+
if err != nil && !errors.Is(err, io.EOF) {
169173
return err
170174
}
171175
if len(result) == 0 {

cmd/operator/multisign_test.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func TestDoSignAndPost_AutoSign_Success(t *testing.T) {
118118

119119
autoSign = true
120120
signerAddress = "addr_A"
121-
_, rawPriv, _ := ed25519.GenerateKey(nil)
122121

122+
pubKey, rawPriv, _ := ed25519.GenerateKey(nil)
123123
privateKey = &mock.PrivateKeyMock{
124124
ScalarMock: func() crypto.Scalar {
125125
return &mock.ScalarMock{
@@ -129,22 +129,35 @@ func TestDoSignAndPost_AutoSign_Success(t *testing.T) {
129129
}
130130
},
131131
}
132+
133+
expectedAddress := walletPubKeyConverter.Encode(pubKey)
134+
135+
var capturedBody MSApiEncoded
132136
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
137+
require.NoError(t, json.NewDecoder(r.Body).Decode(&capturedBody))
133138
w.Header().Set("Content-Type", "application/json")
134139
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "error": ""})
135140
}))
136141
defer srv.Close()
137142
multisignAPI = srv.URL
143+
138144
tx := &MSApiTransaction{
139145
Hash: validHash,
140146
Signers: []MSApiSigner{{Address: "addr_A", Signed: false}},
141147
Raw: &transaction.Transaction{
142148
Signature: make([][]byte, 0),
143-
RawData: &transaction.Transaction_Raw{},
149+
RawData: &transaction.Transaction_Raw{
150+
Sender: pubKey,
151+
},
144152
},
145153
}
154+
146155
err := doSignAndPost(tx)
147156
assert.NoError(t, err)
157+
158+
assert.Equal(t, expectedAddress, capturedBody.Address, "posted address should be the bech32-encoded sender pubkey")
159+
assert.Len(t, tx.Raw.Signature, 1, "a signature should have been appended to the transaction")
160+
assert.NotEmpty(t, tx.Raw.Signature[0], "appended signature should not be empty")
148161
}
149162

150163
// --- doPostMSTransactionSignature ---

cmd/operator/multsignHelper.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/hex"
55
"encoding/json"
66
"fmt"
7+
"io"
78
"strconv"
89
"strings"
910
"time"
@@ -158,7 +159,7 @@ func getMSApiTransaction(hash string) (*MSApiTransaction, error) {
158159
result := MSApiTransaction{}
159160
err = utils.GetURL(fmt.Sprintf("%s/transaction/%s", multisignAPI, hash), &result)
160161
if err != nil {
161-
if err.Error() == "EOF" {
162+
if errors.Is(err, io.EOF) {
162163
return nil, fmt.Errorf("transaction with hash %s not found in multisign API", hash)
163164
}
164165
return nil, err

0 commit comments

Comments
 (0)