From e76392e330cdc9cdc9f3edc7f2bf66e072d46cfd Mon Sep 17 00:00:00 2001 From: Ricardo Domingos Date: Wed, 20 Dec 2017 23:21:30 +0100 Subject: [PATCH] types: Update String() test to assert Prevote type --- types/vote_test.go | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/types/vote_test.go b/types/vote_test.go index 032cc9472..cb7f02e41 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -32,6 +32,29 @@ func exampleVote() *Vote { } } +func examplePrevote() *Vote { + var stamp, err = time.Parse(timeFormat, "2017-12-25T03:00:01.234Z") + if err != nil { + panic(err) + } + + return &Vote{ + ValidatorAddress: []byte("addr"), + ValidatorIndex: 56789, + Height: 12345, + Round: 2, + Timestamp: stamp, + Type: byte(1), + BlockID: BlockID{ + Hash: []byte("hash"), + PartsHeader: PartSetHeader{ + Total: 1000000, + Hash: []byte("parts_hash"), + }, + }, + } +} + func TestVoteSignable(t *testing.T) { vote := exampleVote() signBytes := SignBytes("test_chain_id", vote) @@ -45,10 +68,22 @@ func TestVoteSignable(t *testing.T) { } func TestVoteString(t *testing.T) { - str := exampleVote().String() - expected := `Vote{56789:616464720000 12345/02/2(Precommit) 686173680000 {} @ 2017-12-25T03:00:01.234Z}` - if str != expected { - t.Errorf("Got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str) + tc := []struct { + name string + in string + out string + }{ + {"Precommit", exampleVote().String(), `Vote{56789:616464720000 12345/02/2(Precommit) 686173680000 {} @ 2017-12-25T03:00:01.234Z}`}, + {"Prevote", examplePrevote().String(), `Vote{56789:616464720000 12345/02/1(Prevote) 686173680000 {} @ 2017-12-25T03:00:01.234Z}`}, + } + + for _, tt := range tc { + tt := tt + t.Run(tt.name, func(st *testing.T) { + if tt.in != tt.out { + t.Errorf("Got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", tt.in, tt.out) + } + }) } }