add fmt output checks
This commit is contained in:
parent
8a2d27309d
commit
fce9ff237a
@ -56,6 +56,8 @@ var walletNew = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
afmt := NewAppFmt(cctx.App)
|
||||
|
||||
t := cctx.Args().First()
|
||||
if t == "" {
|
||||
t = "secp256k1"
|
||||
@ -66,7 +68,7 @@ var walletNew = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(nk.String())
|
||||
afmt.Println(nk.String())
|
||||
|
||||
return nil
|
||||
},
|
||||
@ -187,6 +189,8 @@ var walletBalance = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
afmt := NewAppFmt(cctx.App)
|
||||
|
||||
var addr address.Address
|
||||
if cctx.Args().First() != "" {
|
||||
addr, err = address.NewFromString(cctx.Args().First())
|
||||
@ -203,9 +207,9 @@ var walletBalance = &cli.Command{
|
||||
}
|
||||
|
||||
if balance.Equals(types.NewInt(0)) {
|
||||
fmt.Printf("%s (warning: may display 0 if chain sync in progress)\n", types.FIL(balance))
|
||||
afmt.Printf("%s (warning: may display 0 if chain sync in progress)\n", types.FIL(balance))
|
||||
} else {
|
||||
fmt.Printf("%s\n", types.FIL(balance))
|
||||
afmt.Printf("%s\n", types.FIL(balance))
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -223,12 +227,14 @@ var walletGetDefault = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
afmt := NewAppFmt(cctx.App)
|
||||
|
||||
addr, err := api.WalletDefaultAddress(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", addr.String())
|
||||
afmt.Printf("%s\n", addr.String())
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@ -270,6 +276,8 @@ var walletExport = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
afmt := NewAppFmt(cctx.App)
|
||||
|
||||
if !cctx.Args().Present() {
|
||||
return fmt.Errorf("must specify key to export")
|
||||
}
|
||||
@ -289,7 +297,7 @@ var walletExport = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println(hex.EncodeToString(b))
|
||||
afmt.Println(hex.EncodeToString(b))
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@ -444,6 +452,8 @@ var walletVerify = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
afmt := NewAppFmt(cctx.App)
|
||||
|
||||
if !cctx.Args().Present() || cctx.NArg() != 3 {
|
||||
return fmt.Errorf("must specify signing address, message, and signature to verify")
|
||||
}
|
||||
@ -476,10 +486,10 @@ var walletVerify = &cli.Command{
|
||||
return err
|
||||
}
|
||||
if ok {
|
||||
fmt.Println("valid")
|
||||
afmt.Println("valid")
|
||||
return nil
|
||||
}
|
||||
fmt.Println("invalid")
|
||||
afmt.Println("invalid")
|
||||
return NewCliError("CLI Verify called with invalid signature")
|
||||
},
|
||||
}
|
||||
@ -547,6 +557,8 @@ var walletMarketWithdraw = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
afmt := NewAppFmt(cctx.App)
|
||||
|
||||
var wallet address.Address
|
||||
if cctx.String("wallet") != "" {
|
||||
wallet, err = address.NewFromString(cctx.String("wallet"))
|
||||
@ -622,7 +634,7 @@ var walletMarketWithdraw = &cli.Command{
|
||||
return xerrors.Errorf("fund manager withdraw error: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("WithdrawBalance message cid: %s\n", smsg)
|
||||
afmt.Printf("WithdrawBalance message cid: %s\n", smsg)
|
||||
|
||||
// wait for it to get mined into a block
|
||||
wait, err := api.StateWaitMsg(ctx, smsg, uint64(cctx.Int("confidence")))
|
||||
@ -632,7 +644,7 @@ var walletMarketWithdraw = &cli.Command{
|
||||
|
||||
// check it executed successfully
|
||||
if wait.Receipt.ExitCode != 0 {
|
||||
fmt.Println(cctx.App.Writer, "withdrawal failed!")
|
||||
afmt.Println(cctx.App.Writer, "withdrawal failed!")
|
||||
return err
|
||||
}
|
||||
|
||||
@ -647,7 +659,7 @@ var walletMarketWithdraw = &cli.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Successfully withdrew %s \n", types.FIL(withdrawn))
|
||||
afmt.Printf("Successfully withdrew %s \n", types.FIL(withdrawn))
|
||||
if withdrawn.LessThan(amt) {
|
||||
fmt.Printf("Note that this is less than the requested amount of %s \n", types.FIL(amt))
|
||||
}
|
||||
@ -681,6 +693,8 @@ var walletMarketAdd = &cli.Command{
|
||||
defer closer()
|
||||
ctx := ReqContext(cctx)
|
||||
|
||||
afmt := NewAppFmt(cctx.App)
|
||||
|
||||
// Get amount param
|
||||
if !cctx.Args().Present() {
|
||||
return fmt.Errorf("must pass amount to add")
|
||||
@ -722,7 +736,7 @@ var walletMarketAdd = &cli.Command{
|
||||
return xerrors.Errorf("add balance error: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("AddBalance message cid: %s\n", smsg)
|
||||
afmt.Printf("AddBalance message cid: %s\n", smsg)
|
||||
|
||||
return nil
|
||||
},
|
||||
|
@ -2,6 +2,9 @@ package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/filecoin-project/go-address"
|
||||
@ -13,23 +16,26 @@ import (
|
||||
types "github.com/filecoin-project/lotus/chain/types"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/multiformats/go-multihash"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestWalletNew(t *testing.T) {
|
||||
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletNew))
|
||||
app, mockApi, buffer, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletNew))
|
||||
defer done()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
keyType := types.KeyType("secp256k1")
|
||||
address := address.Address{}
|
||||
address, err := address.NewFromString("t0123")
|
||||
assert.NoError(t, err)
|
||||
|
||||
mockApi.EXPECT().WalletNew(ctx, keyType).Return(address, nil)
|
||||
|
||||
err := app.Run([]string{"wallet", "new"})
|
||||
err = app.Run([]string{"wallet", "new"})
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, buffer.String(), address.String())
|
||||
}
|
||||
|
||||
func TestWalletList(t *testing.T) {
|
||||
@ -109,7 +115,7 @@ func TestWalletList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWalletBalance(t *testing.T) {
|
||||
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletBalance))
|
||||
app, mockApi, buffer, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletBalance))
|
||||
defer done()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@ -124,21 +130,24 @@ func TestWalletBalance(t *testing.T) {
|
||||
|
||||
err = app.Run([]string{"wallet", "balance", "f01234"})
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, buffer.String(), balance.String())
|
||||
}
|
||||
|
||||
func TestWalletGetDefault(t *testing.T) {
|
||||
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletGetDefault))
|
||||
app, mockApi, buffer, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletGetDefault))
|
||||
defer done()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
addr := address.Address{}
|
||||
addr, err := address.NewFromString("t0123")
|
||||
assert.NoError(t, err)
|
||||
|
||||
mockApi.EXPECT().WalletDefaultAddress(ctx).Return(addr, nil)
|
||||
|
||||
err := app.Run([]string{"wallet", "default"})
|
||||
err = app.Run([]string{"wallet", "default"})
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, buffer.String(), addr.String())
|
||||
}
|
||||
|
||||
func TestWalletSetDefault(t *testing.T) {
|
||||
@ -158,7 +167,7 @@ func TestWalletSetDefault(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWalletExport(t *testing.T) {
|
||||
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletExport))
|
||||
app, mockApi, buffer, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletExport))
|
||||
defer done()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@ -167,12 +176,19 @@ func TestWalletExport(t *testing.T) {
|
||||
addr, err := address.NewIDAddress(1234)
|
||||
assert.NoError(t, err)
|
||||
|
||||
keyInfo := types.KeyInfo{}
|
||||
keyInfo := types.KeyInfo{
|
||||
Type: types.KTSecp256k1,
|
||||
PrivateKey: []byte("0x000000000000000000001"),
|
||||
}
|
||||
|
||||
mockApi.EXPECT().WalletExport(ctx, addr).Return(&keyInfo, nil)
|
||||
|
||||
ki, err := json.Marshal(keyInfo)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = app.Run([]string{"wallet", "export", "f01234"})
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, buffer.String(), hex.EncodeToString(ki))
|
||||
}
|
||||
|
||||
func TestWalletSign(t *testing.T) {
|
||||
@ -182,10 +198,12 @@ func TestWalletSign(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
addr, err := address.NewIDAddress(1234)
|
||||
addr, err := address.NewFromString("f01234")
|
||||
assert.NoError(t, err)
|
||||
|
||||
msg, err := hex.DecodeString("01")
|
||||
assert.NoError(t, err)
|
||||
|
||||
msg := []byte{1}
|
||||
signature := crypto.Signature{}
|
||||
|
||||
mockApi.EXPECT().WalletSign(ctx, addr, msg).Return(&signature, nil)
|
||||
@ -195,7 +213,7 @@ func TestWalletSign(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWalletVerify(t *testing.T) {
|
||||
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletVerify))
|
||||
app, mockApi, buffer, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletVerify))
|
||||
defer done()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@ -214,6 +232,7 @@ func TestWalletVerify(t *testing.T) {
|
||||
|
||||
err = app.Run([]string{"wallet", "verify", "f01234", "01", "01"})
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, buffer.String(), "valid")
|
||||
}
|
||||
|
||||
func TestWalletDelete(t *testing.T) {
|
||||
@ -233,7 +252,7 @@ func TestWalletDelete(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWalletMarketWithdraw(t *testing.T) {
|
||||
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletMarket))
|
||||
app, mockApi, buffer, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletMarket))
|
||||
defer done()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@ -247,7 +266,9 @@ func TestWalletMarketWithdraw(t *testing.T) {
|
||||
Locked: big.NewInt(10),
|
||||
}
|
||||
|
||||
cid := cid.Cid{}
|
||||
h, err := hex.DecodeString("12209cbc07c3f991725836a3aa2a581ca2029198aa420b9d99bc0e131d9f3e2cbe47")
|
||||
assert.NoError(t, err)
|
||||
cid := cid.NewCidV0(multihash.Multihash(h))
|
||||
msgLookup := api.MsgLookup{}
|
||||
|
||||
var networkVers apitypes.NetworkVersion
|
||||
@ -264,10 +285,11 @@ func TestWalletMarketWithdraw(t *testing.T) {
|
||||
|
||||
err = app.Run([]string{"wallet", "market", "withdraw", "--wallet", addr.String()})
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, buffer.String(), fmt.Sprintf("WithdrawBalance message cid: %s", cid))
|
||||
}
|
||||
|
||||
func TestWalletMarketAdd(t *testing.T) {
|
||||
app, mockApi, _, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletMarket))
|
||||
app, mockApi, buffer, done := NewMockAppWithFullAPI(t, WithCategory("wallet", walletMarket))
|
||||
defer done()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
@ -276,13 +298,16 @@ func TestWalletMarketAdd(t *testing.T) {
|
||||
toAddr := address.Address{}
|
||||
defaultAddr := address.Address{}
|
||||
|
||||
cid := cid.Cid{}
|
||||
h, err := hex.DecodeString("12209cbc07c3f991725836a3aa2a581ca2029198aa420b9d99bc0e131d9f3e2cbe47")
|
||||
assert.NoError(t, err)
|
||||
cid := cid.NewCidV0(multihash.Multihash(h))
|
||||
|
||||
gomock.InOrder(
|
||||
mockApi.EXPECT().WalletDefaultAddress(ctx).Return(defaultAddr, nil),
|
||||
mockApi.EXPECT().MarketAddBalance(ctx, defaultAddr, toAddr, big.NewInt(80)).Return(cid, nil),
|
||||
)
|
||||
|
||||
err := app.Run([]string{"wallet", "market", "add", "0.000000000000000080", "--address", toAddr.String()})
|
||||
err = app.Run([]string{"wallet", "market", "add", "0.000000000000000080", "--address", toAddr.String()})
|
||||
assert.NoError(t, err)
|
||||
assert.Contains(t, buffer.String(), fmt.Sprintf("AddBalance message cid: %s", cid))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user