Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: cli: adding wallet tests #8079

Merged
merged 7 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions cli/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -66,7 +68,7 @@ var walletNew = &cli.Command{
return err
}

fmt.Println(nk.String())
afmt.Println(nk.String())

return nil
},
Expand Down Expand Up @@ -100,6 +102,8 @@ var walletList = &cli.Command{
defer closer()
ctx := ReqContext(cctx)

afmt := NewAppFmt(cctx.App)

addrs, err := api.WalletList(ctx)
if err != nil {
return err
Expand All @@ -120,7 +124,7 @@ var walletList = &cli.Command{

for _, addr := range addrs {
if cctx.Bool("addr-only") {
fmt.Println(addr.String())
afmt.Println(addr.String())
} else {
a, err := api.StateGetActor(ctx, addr, types.EmptyTSK)
if err != nil {
Expand Down Expand Up @@ -187,6 +191,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())
Expand All @@ -203,9 +209,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
Expand All @@ -223,12 +229,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
},
}
Expand Down Expand Up @@ -270,6 +278,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")
}
Expand All @@ -289,7 +299,7 @@ var walletExport = &cli.Command{
return err
}

fmt.Println(hex.EncodeToString(b))
afmt.Println(hex.EncodeToString(b))
return nil
},
}
Expand Down Expand Up @@ -403,6 +413,8 @@ var walletSign = &cli.Command{
defer closer()
ctx := ReqContext(cctx)

afmt := NewAppFmt(cctx.App)

if !cctx.Args().Present() || cctx.NArg() != 2 {
return fmt.Errorf("must specify signing address and message to sign")
}
Expand All @@ -427,7 +439,7 @@ var walletSign = &cli.Command{

sigBytes := append([]byte{byte(sig.Type)}, sig.Data...)

fmt.Println(hex.EncodeToString(sigBytes))
afmt.Println(hex.EncodeToString(sigBytes))
return nil
},
}
Expand All @@ -444,6 +456,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")
}
Expand Down Expand Up @@ -476,10 +490,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")
},
}
Expand Down Expand Up @@ -547,6 +561,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"))
Expand Down Expand Up @@ -622,7 +638,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")))
Expand All @@ -632,7 +648,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
}

Expand All @@ -647,7 +663,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))
}
Expand Down Expand Up @@ -681,6 +697,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")
Expand Down Expand Up @@ -722,7 +740,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
},
Expand Down
Loading