Browse Source

blockchain: test fixes

pull/677/head
Ethan Buchman 7 years ago
parent
commit
78a682e4b6
3 changed files with 11 additions and 9 deletions
  1. +1
    -2
      blockchain/reactor_test.go
  2. +9
    -7
      blockchain/store_test.go
  3. +1
    -0
      p2p/pex_reactor.go

+ 1
- 2
blockchain/reactor_test.go View File

@ -26,8 +26,7 @@ func makeStateAndBlockStore(logger log.Logger) (*sm.State, *BlockStore) {
return state, blockStore return state, blockStore
} }
func newBlockchainReactor(logger log.Logger, maxBlockHeight int) *BlockchainReactor {
logger := log.TestingLogger()
func newBlockchainReactor(logger log.Logger, maxBlockHeight int64) *BlockchainReactor {
state, blockStore := makeStateAndBlockStore(logger) state, blockStore := makeStateAndBlockStore(logger)
// Make the blockchainReactor itself // Make the blockchainReactor itself


+ 9
- 7
blockchain/store_test.go View File

@ -7,6 +7,7 @@ import (
"runtime/debug" "runtime/debug"
"strings" "strings"
"testing" "testing"
"time"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -32,7 +33,7 @@ func TestNewBlockStore(t *testing.T) {
db := db.NewMemDB() db := db.NewMemDB()
db.Set(blockStoreKey, []byte(`{"height": 10000}`)) db.Set(blockStoreKey, []byte(`{"height": 10000}`))
bs := NewBlockStore(db) bs := NewBlockStore(db)
assert.Equal(t, bs.Height(), 10000, "failed to properly parse blockstore")
assert.Equal(t, bs.Height(), int64(10000), "failed to properly parse blockstore")
panicCausers := []struct { panicCausers := []struct {
data []byte data []byte
@ -56,7 +57,7 @@ func TestNewBlockStore(t *testing.T) {
db.Set(blockStoreKey, nil) db.Set(blockStoreKey, nil)
bs = NewBlockStore(db) bs = NewBlockStore(db)
assert.Equal(t, bs.Height(), 0, "expecting nil bytes to be unmarshaled alright")
assert.Equal(t, bs.Height(), int64(0), "expecting nil bytes to be unmarshaled alright")
} }
func TestBlockStoreGetReader(t *testing.T) { func TestBlockStoreGetReader(t *testing.T) {
@ -110,10 +111,10 @@ var (
func TestBlockStoreSaveLoadBlock(t *testing.T) { func TestBlockStoreSaveLoadBlock(t *testing.T) {
state, bs := makeStateAndBlockStore(log.NewTMLogger(new(bytes.Buffer))) state, bs := makeStateAndBlockStore(log.NewTMLogger(new(bytes.Buffer)))
require.Equal(t, bs.Height(), 0, "initially the height should be zero")
require.Equal(t, bs.Height(), int64(0), "initially the height should be zero")
// check there are no blocks at various heights // check there are no blocks at various heights
noBlockHeights := []int{0, -1, 100, 1000, 2}
noBlockHeights := []int64{0, -1, 100, 1000, 2}
for i, height := range noBlockHeights { for i, height := range noBlockHeights {
if g := bs.LoadBlock(height); g != nil { if g := bs.LoadBlock(height); g != nil {
t.Errorf("#%d: height(%d) got a block; want nil", i, height) t.Errorf("#%d: height(%d) got a block; want nil", i, height)
@ -135,6 +136,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) {
Height: 1, Height: 1,
NumTxs: 100, NumTxs: 100,
ChainID: "block_test", ChainID: "block_test",
Time: time.Now(),
} }
header2 := header1 header2 := header1
header2.Height = 4 header2.Height = 4
@ -306,7 +308,7 @@ func binarySerializeIt(v interface{}) []byte {
func TestLoadBlockPart(t *testing.T) { func TestLoadBlockPart(t *testing.T) {
bs, db := freshBlockStore() bs, db := freshBlockStore()
height, index := 10, 1
height, index := int64(10), 1
loadPart := func() (interface{}, error) { loadPart := func() (interface{}, error) {
part := bs.LoadBlockPart(height, index) part := bs.LoadBlockPart(height, index)
return part, nil return part, nil
@ -334,7 +336,7 @@ func TestLoadBlockPart(t *testing.T) {
func TestLoadBlockMeta(t *testing.T) { func TestLoadBlockMeta(t *testing.T) {
bs, db := freshBlockStore() bs, db := freshBlockStore()
height := 10
height := int64(10)
loadMeta := func() (interface{}, error) { loadMeta := func() (interface{}, error) {
meta := bs.LoadBlockMeta(height) meta := bs.LoadBlockMeta(height)
return meta, nil return meta, nil
@ -363,7 +365,7 @@ func TestLoadBlockMeta(t *testing.T) {
func TestBlockFetchAtHeight(t *testing.T) { func TestBlockFetchAtHeight(t *testing.T) {
state, bs := makeStateAndBlockStore(log.NewTMLogger(new(bytes.Buffer))) state, bs := makeStateAndBlockStore(log.NewTMLogger(new(bytes.Buffer)))
require.Equal(t, bs.Height(), 0, "initially the height should be zero")
require.Equal(t, bs.Height(), int64(0), "initially the height should be zero")
block := makeBlock(bs.Height()+1, state) block := makeBlock(bs.Height()+1, state)
partSet := block.MakePartSet(2) partSet := block.MakePartSet(2)


+ 1
- 0
p2p/pex_reactor.go View File

@ -264,6 +264,7 @@ func (r *PEXReactor) ensurePeers() {
if dialling := r.Switch.IsDialing(try); dialling { if dialling := r.Switch.IsDialing(try); dialling {
continue continue
} }
// XXX: does this work ?!
if connected := r.Switch.Peers().Has(try.IP.String()); connected { if connected := r.Switch.Peers().Has(try.IP.String()); connected {
continue continue
} }


Loading…
Cancel
Save