Browse Source

Harden tests

pull/1204/head
Alexander Simmerl 7 years ago
committed by Ethan Buchman
parent
commit
38d18ca11a
2 changed files with 75 additions and 8 deletions
  1. +3
    -3
      types/priv_validator/socket.go
  2. +72
    -5
      types/priv_validator/socket_test.go

+ 3
- 3
types/priv_validator/socket.go View File

@ -137,7 +137,7 @@ func (pvsc *PrivValidatorSocketClient) SignVote(chainID string, vote *types.Vote
return err
}
*vote = *res.(SignVoteMsg).Vote
*vote = *res.(*SignVoteMsg).Vote
return nil
}
@ -154,7 +154,7 @@ func (pvsc *PrivValidatorSocketClient) SignProposal(chainID string, proposal *ty
return err
}
*proposal = *res.(SignProposalMsg).Proposal
*proposal = *res.(*SignProposalMsg).Proposal
return nil
}
@ -171,7 +171,7 @@ func (pvsc *PrivValidatorSocketClient) SignHeartbeat(chainID string, heartbeat *
return err
}
*heartbeat = *res.(SignHeartbeatMsg).Heartbeat
*heartbeat = *res.(*SignHeartbeatMsg).Heartbeat
return nil
}


+ 72
- 5
types/priv_validator/socket_test.go View File

@ -1,13 +1,14 @@
package types
import (
"reflect"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
crypto "github.com/tendermint/go-crypto"
data "github.com/tendermint/go-wire/data"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tmlibs/log"
)
@ -15,7 +16,7 @@ import (
func TestPrivValidatorSocketServer(t *testing.T) {
var (
assert, require = assert.New(t), require.New(t)
chainID = "test-chain"
chainID = "test-chain-secret"
logger = log.TestingLogger()
signer = types.GenSigner()
clientPrivKey = crypto.GenPrivKeyEd25519()
@ -49,7 +50,73 @@ func TestPrivValidatorSocketServer(t *testing.T) {
assert.True(pvsc.IsRunning())
if have, want := pvsc.PubKey(), pvss.privVal.PubKey(); !reflect.DeepEqual(have, want) {
t.Errorf("have %v, want %v", have, want)
}
assert.Equal(pvsc.Address(), data.Bytes(pvss.privVal.PubKey().Address()))
assert.Equal(pvsc.PubKey(), pvss.privVal.PubKey())
err = pvsc.SignProposal(chainID, &types.Proposal{
Timestamp: time.Now(),
})
require.Nil(err)
err = pvsc.SignVote(chainID, &types.Vote{
Timestamp: time.Now(),
Type: types.VoteTypePrecommit,
})
require.Nil(err)
err = pvsc.SignHeartbeat(chainID, &types.Heartbeat{})
require.Nil(err)
}
func TestPrivValidatorSocketServerWithoutSecret(t *testing.T) {
var (
assert, require = assert.New(t), require.New(t)
chainID = "test-chain-secret"
logger = log.TestingLogger()
signer = types.GenSigner()
privVal = NewTestPrivValidator(signer)
pvss = NewPrivValidatorSocketServer(
logger,
chainID,
"127.0.0.1:0",
1,
privVal,
nil,
)
)
err := pvss.Start()
require.Nil(err)
defer pvss.Stop()
assert.True(pvss.IsRunning())
pvsc := NewPrivValidatorSocketClient(
logger,
pvss.listener.Addr().String(),
nil,
)
err = pvsc.Start()
require.Nil(err)
defer pvsc.Stop()
assert.True(pvsc.IsRunning())
assert.Equal(pvsc.Address(), data.Bytes(pvss.privVal.PubKey().Address()))
assert.Equal(pvsc.PubKey(), pvss.privVal.PubKey())
err = pvsc.SignProposal(chainID, &types.Proposal{
Timestamp: time.Now(),
})
require.Nil(err)
err = pvsc.SignVote(chainID, &types.Vote{
Timestamp: time.Now(),
Type: types.VoteTypePrecommit,
})
require.Nil(err)
err = pvsc.SignHeartbeat(chainID, &types.Heartbeat{})
require.Nil(err)
}

Loading…
Cancel
Save