Review feedback from @melekes

* Fix typo on naming s/deabBeef/deadBeef/g
* Use `assert.*(t,` instead of `assert.New(t);...;assert.*(`
This commit is contained in:
Emmanuel T Odeke 2018-03-10 21:50:15 -08:00
parent 4c2f56626a
commit 58f36bb321
1 changed files with 9 additions and 13 deletions

View File

@ -12,8 +12,8 @@ import (
) )
var ( var (
deabBeefTxs = types.Txs{[]byte("DE"), []byte("AD"), []byte("BE"), []byte("EF")} deadBeefTxs = types.Txs{[]byte("DE"), []byte("AD"), []byte("BE"), []byte("EF")}
deadBeefRipEmd160Hash = deabBeefTxs.Hash() deadBeefRipEmd160Hash = deadBeefTxs.Hash()
) )
func TestValidateBlock(t *testing.T) { func TestValidateBlock(t *testing.T) {
@ -91,7 +91,7 @@ func TestValidateBlock(t *testing.T) {
{ {
block: &types.Block{ block: &types.Block{
Header: &types.Header{Height: 11, DataHash: deadBeefRipEmd160Hash}, Header: &types.Header{Height: 11, DataHash: deadBeefRipEmd160Hash},
Data: &types.Data{Txs: deabBeefTxs}, Data: &types.Data{Txs: deadBeefTxs},
}, },
commit: lite.Commit{ commit: lite.Commit{
Header: &types.Header{Height: 11}, Header: &types.Header{Height: 11},
@ -101,20 +101,18 @@ func TestValidateBlock(t *testing.T) {
// End Header.Data hash mismatch test // End Header.Data hash mismatch test
} }
assert := assert.New(t)
for i, tt := range tests { for i, tt := range tests {
err := proxy.ValidateBlock(tt.block, tt.commit) err := proxy.ValidateBlock(tt.block, tt.commit)
if tt.wantErr != "" { if tt.wantErr != "" {
if err == nil { if err == nil {
assert.FailNowf("Unexpectedly passed", "#%d", i) assert.FailNowf(t, "Unexpectedly passed", "#%d", i)
} else { } else {
assert.Contains(err.Error(), tt.wantErr, "#%d should contain the substring\n\n", i) assert.Contains(t, err.Error(), tt.wantErr, "#%d should contain the substring\n\n", i)
} }
continue continue
} }
assert.Nil(err, "#%d: expecting a nil error", i) assert.Nil(t, err, "#%d: expecting a nil error", i)
} }
} }
@ -238,19 +236,17 @@ func TestValidateBlockMeta(t *testing.T) {
// End Headers don't match test // End Headers don't match test
} }
assert := assert.New(t)
for i, tt := range tests { for i, tt := range tests {
err := proxy.ValidateBlockMeta(tt.meta, tt.commit) err := proxy.ValidateBlockMeta(tt.meta, tt.commit)
if tt.wantErr != "" { if tt.wantErr != "" {
if err == nil { if err == nil {
assert.FailNowf("Unexpectedly passed", "#%d: wanted error %q", i, tt.wantErr) assert.FailNowf(t, "Unexpectedly passed", "#%d: wanted error %q", i, tt.wantErr)
} else { } else {
assert.Contains(err.Error(), tt.wantErr, "#%d should contain the substring\n\n", i) assert.Contains(t, err.Error(), tt.wantErr, "#%d should contain the substring\n\n", i)
} }
continue continue
} }
assert.Nil(err, "#%d: expecting a nil error", i) assert.Nil(t, err, "#%d: expecting a nil error", i)
} }
} }