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

all: replace fmt.Print* calls with t.Log* in tests #19670

Merged
merged 9 commits into from
Jul 17, 2019
5 changes: 2 additions & 3 deletions cmd/puppeth/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"reflect"
"strings"
Expand Down Expand Up @@ -61,7 +60,7 @@ func TestAlethSturebyConverter(t *testing.T) {
got := strings.Split(c.Sdump(spec), "\n")
for i := 0; i < len(exp) && i < len(got); i++ {
if exp[i] != got[i] {
fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i])
t.Logf("got: %v\nexp: %v\n", exp[i], got[i])
}
}
}
Expand Down Expand Up @@ -102,7 +101,7 @@ func TestParitySturebyConverter(t *testing.T) {
got := strings.Split(c.Sdump(spec), "\n")
for i := 0; i < len(exp) && i < len(got); i++ {
if exp[i] != got[i] {
fmt.Printf("got: %v\nexp: %v\n", exp[i], got[i])
t.Logf("got: %v\nexp: %v\n", exp[i], got[i])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/freezer_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func print(t *testing.T, f *freezerTable, item uint64) {
if err != nil {
t.Fatal(err)
}
fmt.Printf("db[%d] = %x\n", item, a)
t.Logf("db[%d] = %x\n", item, a)
}

// TestFreezerBasics test initializing a freezertable from scratch, writing to the table,
Expand Down
74 changes: 37 additions & 37 deletions crypto/ecies/ecies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ func TestKDF(t *testing.T) {

k, err := concatKDF(h, msg, nil, 64)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}
if len(k) != 64 {
fmt.Printf("KDF: generated key is the wrong size (%d instead of 64\n", len(k))
t.Logf("KDF: generated key is the wrong size (%d instead of 64\n", len(k))
t.FailNow()
}
}
Expand Down Expand Up @@ -97,31 +97,31 @@ func cmpPublic(pub1, pub2 PublicKey) bool {
func TestSharedKey(t *testing.T) {
prv1, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}
skLen := MaxSharedKeyLength(&prv1.PublicKey) / 2

prv2, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

sk1, err := prv1.GenerateShared(&prv2.PublicKey, skLen, skLen)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

sk2, err := prv2.GenerateShared(&prv1.PublicKey, skLen, skLen)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

if !bytes.Equal(sk1, sk2) {
fmt.Println(ErrBadSharedKeys.Error())
t.Log(ErrBadSharedKeys.Error())
t.FailNow()
}
}
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestSharedKeyPadding(t *testing.T) {
// test shared secret generation
sk1, err := prv0.GenerateShared(&prv1.PublicKey, 16, 16)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
}

sk2, err := prv1.GenerateShared(&prv0.PublicKey, 16, 16)
Expand All @@ -169,25 +169,25 @@ func TestSharedKeyPadding(t *testing.T) {
func TestTooBigSharedKey(t *testing.T) {
prv1, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

prv2, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

_, err = prv1.GenerateShared(&prv2.PublicKey, 32, 32)
if err != ErrSharedKeyTooBig {
fmt.Println("ecdh: shared key should be too large for curve")
t.Log("ecdh: shared key should be too large for curve")
t.FailNow()
}

_, err = prv2.GenerateShared(&prv1.PublicKey, 32, 32)
if err != ErrSharedKeyTooBig {
fmt.Println("ecdh: shared key should be too large for curve")
t.Log("ecdh: shared key should be too large for curve")
t.FailNow()
}
}
Expand All @@ -196,7 +196,7 @@ func TestTooBigSharedKey(t *testing.T) {
func BenchmarkGenerateKeyP256(b *testing.B) {
for i := 0; i < b.N; i++ {
if _, err := GenerateKey(rand.Reader, elliptic.P256(), nil); err != nil {
fmt.Println(err.Error())
b.Log(err.Error())
b.FailNow()
}
}
Expand All @@ -206,14 +206,14 @@ func BenchmarkGenerateKeyP256(b *testing.B) {
func BenchmarkGenSharedKeyP256(b *testing.B) {
prv, err := GenerateKey(rand.Reader, elliptic.P256(), nil)
if err != nil {
fmt.Println(err.Error())
b.Log(err.Error())
b.FailNow()
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := prv.GenerateShared(&prv.PublicKey, 16, 16)
if err != nil {
fmt.Println(err.Error())
b.Log(err.Error())
b.FailNow()
}
}
Expand All @@ -223,14 +223,14 @@ func BenchmarkGenSharedKeyP256(b *testing.B) {
func BenchmarkGenSharedKeyS256(b *testing.B) {
prv, err := GenerateKey(rand.Reader, crypto.S256(), nil)
if err != nil {
fmt.Println(err.Error())
b.Log(err.Error())
b.FailNow()
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := prv.GenerateShared(&prv.PublicKey, 16, 16)
if err != nil {
fmt.Println(err.Error())
b.Log(err.Error())
b.FailNow()
}
}
Expand All @@ -240,37 +240,37 @@ func BenchmarkGenSharedKeyS256(b *testing.B) {
func TestEncryptDecrypt(t *testing.T) {
prv1, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

prv2, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

message := []byte("Hello, world.")
ct, err := Encrypt(rand.Reader, &prv2.PublicKey, message, nil, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

pt, err := prv2.Decrypt(ct, nil, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

if !bytes.Equal(pt, message) {
fmt.Println("ecies: plaintext doesn't match message")
t.Log("ecies: plaintext doesn't match message")
t.FailNow()
}

_, err = prv1.Decrypt(ct, nil, nil)
if err == nil {
fmt.Println("ecies: encryption should not have succeeded")
t.Log("ecies: encryption should not have succeeded")
t.FailNow()
}
}
Expand Down Expand Up @@ -341,48 +341,48 @@ func TestParamSelection(t *testing.T) {
func testParamSelection(t *testing.T, c testCase) {
params := ParamsFromCurve(c.Curve)
if params == nil && c.Expected != nil {
fmt.Printf("%s (%s)\n", ErrInvalidParams.Error(), c.Name)
t.Logf("%s (%s)\n", ErrInvalidParams.Error(), c.Name)
t.FailNow()
} else if params != nil && !cmpParams(params, c.Expected) {
fmt.Printf("ecies: parameters should be invalid (%s)\n",
t.Logf("ecies: parameters should be invalid (%s)\n",
c.Name)
t.FailNow()
}

prv1, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Printf("%s (%s)\n", err.Error(), c.Name)
t.Logf("%s (%s)\n", err.Error(), c.Name)
t.FailNow()
}

prv2, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Printf("%s (%s)\n", err.Error(), c.Name)
t.Logf("%s (%s)\n", err.Error(), c.Name)
t.FailNow()
}

message := []byte("Hello, world.")
ct, err := Encrypt(rand.Reader, &prv2.PublicKey, message, nil, nil)
if err != nil {
fmt.Printf("%s (%s)\n", err.Error(), c.Name)
t.Logf("%s (%s)\n", err.Error(), c.Name)
t.FailNow()
}

pt, err := prv2.Decrypt(ct, nil, nil)
if err != nil {
fmt.Printf("%s (%s)\n", err.Error(), c.Name)
t.Logf("%s (%s)\n", err.Error(), c.Name)
t.FailNow()
}

if !bytes.Equal(pt, message) {
fmt.Printf("ecies: plaintext doesn't match message (%s)\n",
t.Logf("ecies: plaintext doesn't match message (%s)\n",
c.Name)
t.FailNow()
}

_, err = prv1.Decrypt(ct, nil, nil)
if err == nil {
fmt.Printf("ecies: encryption should not have succeeded (%s)\n",
t.Logf("ecies: encryption should not have succeeded (%s)\n",
c.Name)
t.FailNow()
}
Expand All @@ -396,22 +396,22 @@ func TestBasicKeyValidation(t *testing.T) {

prv, err := GenerateKey(rand.Reader, DefaultCurve, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

message := []byte("Hello, world.")
ct, err := Encrypt(rand.Reader, &prv.PublicKey, message, nil, nil)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

for _, b := range badBytes {
ct[0] = b
_, err := prv.Decrypt(ct, nil, nil)
if err != ErrInvalidPublicKey {
fmt.Println("ecies: validated an invalid key")
t.Log("ecies: validated an invalid key")
t.FailNow()
}
}
Expand Down Expand Up @@ -450,18 +450,18 @@ func TestSharedKeyStatic(t *testing.T) {

sk1, err := prv1.GenerateShared(&prv2.PublicKey, skLen, skLen)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

sk2, err := prv2.GenerateShared(&prv1.PublicKey, skLen, skLen)
if err != nil {
fmt.Println(err.Error())
t.Log(err.Error())
t.FailNow()
}

if !bytes.Equal(sk1, sk2) {
fmt.Println(ErrBadSharedKeys.Error())
t.Log(ErrBadSharedKeys.Error())
t.FailNow()
}

Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1620,8 +1620,8 @@ func TestRemoteHeaderRequestSpan(t *testing.T) {
if failed {
res := strings.Replace(fmt.Sprint(data), " ", ",", -1)
exp := strings.Replace(fmt.Sprint(tt.expected), " ", ",", -1)
fmt.Printf("got: %v\n", res)
fmt.Printf("exp: %v\n", exp)
t.Logf("got: %v\n", res)
t.Logf("exp: %v\n", exp)
t.Errorf("test %d: wrong values", i)
}
}
Expand Down
Loading