-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: terminal pretty printer also prints BigInt's value/amount
hide BigInt and assume it is a "Balance" (possible liability)
- Loading branch information
1 parent
309363d
commit 3f239a1
Showing
2 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package aeternity | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/aeternity/aepp-sdk-go/utils" | ||
) | ||
|
||
func Test_printIf_BigIntBalancePrinted(t *testing.T) { | ||
type args struct { | ||
title string | ||
v *utils.BigInt | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "Test that printIf() recognizes the utils.BigInt special case", | ||
args: args{ | ||
title: "Title", | ||
v: utils.NewBigIntFromUint64(1377), | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
rescueStdout := os.Stdout | ||
r, w, _ := os.Pipe() | ||
os.Stdout = w | ||
|
||
printIf(tt.args.title, tt.args.v) | ||
|
||
w.Close() | ||
out, _ := ioutil.ReadAll(r) | ||
outs := string(out) | ||
os.Stdout = rescueStdout | ||
fmt.Println("DEBUG", outs) | ||
|
||
expected := tt.args.v.Text(10) | ||
if !strings.Contains(outs, expected) { | ||
t.Fatalf("The terminal pretty printer printIf did not print out the value of the BigInt, which was %s", expected) | ||
} | ||
}) | ||
} | ||
} |