add assert to output for wallet sign

This commit is contained in:
TheMenko 2022-03-01 02:34:52 +01:00
parent 0708268c75
commit 4a5b0b87ea
2 changed files with 11 additions and 3 deletions

View File

@ -413,6 +413,8 @@ var walletSign = &cli.Command{
defer closer() defer closer()
ctx := ReqContext(cctx) ctx := ReqContext(cctx)
afmt := NewAppFmt(cctx.App)
if !cctx.Args().Present() || cctx.NArg() != 2 { if !cctx.Args().Present() || cctx.NArg() != 2 {
return fmt.Errorf("must specify signing address and message to sign") return fmt.Errorf("must specify signing address and message to sign")
} }
@ -437,7 +439,7 @@ var walletSign = &cli.Command{
sigBytes := append([]byte{byte(sig.Type)}, sig.Data...) sigBytes := append([]byte{byte(sig.Type)}, sig.Data...)
fmt.Println(hex.EncodeToString(sigBytes)) afmt.Println(hex.EncodeToString(sigBytes))
return nil return nil
}, },
} }

View File

@ -201,7 +201,7 @@ func TestWalletExport(t *testing.T) {
} }
func TestWalletSign(t *testing.T) { func TestWalletSign(t *testing.T) {
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletSign)) app, mockApi, buffer, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletSign))
defer done() defer done()
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -213,13 +213,19 @@ func TestWalletSign(t *testing.T) {
msg, err := hex.DecodeString("01") msg, err := hex.DecodeString("01")
assert.NoError(t, err) assert.NoError(t, err)
signature := crypto.Signature{} signature := crypto.Signature{
Type: crypto.SigTypeSecp256k1,
Data: []byte{0x01},
}
mockApi.EXPECT().WalletSign(ctx, addr, msg).Return(&signature, nil) mockApi.EXPECT().WalletSign(ctx, addr, msg).Return(&signature, nil)
sigBytes := append([]byte{byte(signature.Type)}, signature.Data...)
//stm: @CLI_WALLET_SIGN_001 //stm: @CLI_WALLET_SIGN_001
err = app.Run([]string{"wallet", "sign", "f01234", "01"}) err = app.Run([]string{"wallet", "sign", "f01234", "01"})
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, buffer.String(), hex.EncodeToString(sigBytes))
} }
func TestWalletVerify(t *testing.T) { func TestWalletVerify(t *testing.T) {