Skip to content

Commit

Permalink
fix: tests and build everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan committed Jun 21, 2021
1 parent 9b9cba8 commit 0262cd0
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 44 deletions.
5 changes: 5 additions & 0 deletions blockchain/msgs_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package blockchain

import (
"context"
"encoding/hex"
"math"
"testing"

"github.com/gogo/protobuf/proto"
mdutils "github.com/ipfs/go-merkledag/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -83,6 +85,9 @@ func TestBlockchainMessageVectors(t *testing.T) {
block := types.MakeBlock(int64(3), []types.Tx{types.Tx("Hello World")}, nil, nil, types.Messages{}, nil)
block.Version.Block = 11 // overwrite updated protocol version

_, err := block.RowSet(context.TODO(), mdutils.Mock())
require.NoError(t, err)

bpb, err := block.ToProto()
require.NoError(t, err)

Expand Down
9 changes: 7 additions & 2 deletions blockchain/v0/reactor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package v0

import (
"context"
"crypto/sha256"
"fmt"
"os"
Expand Down Expand Up @@ -294,9 +295,13 @@ func makeTxs(height int64) (txs []types.Tx) {
}

func makeBlock(height int64, state sm.State, lastCommit *types.Commit) *types.Block {
block, _ := state.MakeBlock(height, makeTxs(height), nil,
b := state.MakeBlock(height, makeTxs(height), nil,
nil, types.Messages{}, lastCommit, state.Validators.GetProposer().Address)
return block
_, err := b.RowSet(context.TODO(), mdutils.Mock())
if err != nil {
panic(err)
}
return b
}

type testApp struct {
Expand Down
4 changes: 2 additions & 2 deletions consensus/byzantine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *St
// Avoid sending on internalMsgQueue and running consensus state.

// Create a new proposal block from state/txs from the mempool.
block1, blockParts1 := cs.createProposalBlock()
block1, blockParts1, _ := cs.createProposalBlock()
polRound, propBlockID := cs.ValidRound, types.BlockID{Hash: block1.Hash(), PartSetHeader: blockParts1.Header()}
proposal1 := types.NewProposal(height, round, polRound, propBlockID, &block1.DataAvailabilityHeader)
p1, err := proposal1.ToProto()
Expand All @@ -396,7 +396,7 @@ func byzantineDecideProposalFunc(t *testing.T, height int64, round int32, cs *St
deliverTxsRange(cs, 0, 1)

// Create a new proposal block from state/txs from the mempool.
block2, blockParts2 := cs.createProposalBlock()
block2, blockParts2, _ := cs.createProposalBlock()
polRound, propBlockID = cs.ValidRound, types.BlockID{Hash: block2.Hash(), PartSetHeader: blockParts2.Header()}
proposal2 := types.NewProposal(height, round, polRound, propBlockID, &block2.DataAvailabilityHeader)
p2, err := proposal2.ToProto()
Expand Down
2 changes: 1 addition & 1 deletion consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func decideProposal(
round int32,
) (proposal *types.Proposal, block *types.Block) {
cs1.mtx.Lock()
block, blockParts := cs1.createProposalBlock()
block, blockParts, _ := cs1.createProposalBlock()
validRound := cs1.ValidRound
chainID := cs1.state.ChainID
cs1.mtx.Unlock()
Expand Down
7 changes: 4 additions & 3 deletions consensus/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/lazyledger/lazyledger-core/libs/bits"
tmrand "github.com/lazyledger/lazyledger-core/libs/rand"
"github.com/lazyledger/lazyledger-core/p2p"
"github.com/lazyledger/lazyledger-core/p2p/ipld"
tmcons "github.com/lazyledger/lazyledger-core/proto/tendermint/consensus"
tmproto "github.com/lazyledger/lazyledger-core/proto/tendermint/types"
"github.com/lazyledger/lazyledger-core/types"
Expand Down Expand Up @@ -48,7 +49,7 @@ func TestMsgToProto(t *testing.T) {
pbParts, err := parts.ToProto()
require.NoError(t, err)

roots, err := types.NmtRootsFromBytes([][]byte{tmrand.Bytes(2*consts.NamespaceSize + tmhash.Size)})
roots, err := ipld.NmtRootsFromBytes([][]byte{tmrand.Bytes(2*consts.NamespaceSize + tmhash.Size)})
require.NoError(t, err)
proposal := types.Proposal{
Type: tmproto.ProposalType,
Expand All @@ -58,7 +59,7 @@ func TestMsgToProto(t *testing.T) {
BlockID: bi,
Timestamp: time.Now(),
Signature: tmrand.Bytes(20),
DAHeader: &types.DataAvailabilityHeader{
DAHeader: &ipld.DataAvailabilityHeader{
RowsRoots: roots,
ColumnRoots: roots,
},
Expand Down Expand Up @@ -361,7 +362,7 @@ func TestConsMsgsVectors(t *testing.T) {
BlockID: bi,
Timestamp: date,
Signature: []byte("add_more_exclamation"),
DAHeader: &types.DataAvailabilityHeader{},
DAHeader: &ipld.DataAvailabilityHeader{},
}
pbProposal, err := proposal.ToProto()
require.NoError(t, err)
Expand Down
16 changes: 10 additions & 6 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
newValidatorTx1 := kvstore.MakeValSetChangeTx(valPubKey1ABCI, testMinPower)
err = assertMempool(css[0].txNotifier).CheckTx(newValidatorTx1, nil, mempl.TxInfo{})
assert.Nil(t, err)
propBlock, _ := css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, _, _ := css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlockParts := propBlock.MakePartSet(partSize)
blockID := types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}

Expand Down Expand Up @@ -401,7 +401,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
updateValidatorTx1 := kvstore.MakeValSetChangeTx(updatePubKey1ABCI, 25)
err = assertMempool(css[0].txNotifier).CheckTx(updateValidatorTx1, nil, mempl.TxInfo{})
assert.Nil(t, err)
propBlock, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, _, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlockParts = propBlock.MakePartSet(partSize)
blockID = types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}

Expand Down Expand Up @@ -439,7 +439,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
newValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, testMinPower)
err = assertMempool(css[0].txNotifier).CheckTx(newValidatorTx3, nil, mempl.TxInfo{})
assert.Nil(t, err)
propBlock, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, _, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlockParts = propBlock.MakePartSet(partSize)
blockID = types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
newVss := make([]*validatorStub, nVals+1)
Expand Down Expand Up @@ -515,7 +515,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
removeValidatorTx3 := kvstore.MakeValSetChangeTx(newVal3ABCI, 0)
err = assertMempool(css[0].txNotifier).CheckTx(removeValidatorTx3, nil, mempl.TxInfo{})
assert.Nil(t, err)
propBlock, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, _, _ = css[0].createProposalBlock() // changeProposer(t, cs1, vs2)
propBlockParts = propBlock.MakePartSet(partSize)
blockID = types.BlockID{Hash: propBlock.Hash(), PartSetHeader: propBlockParts.Header()}
newVss = make([]*validatorStub, nVals+3)
Expand Down Expand Up @@ -1001,8 +1001,7 @@ func makeBlock(state sm.State, lastBlock *types.Block, lastBlockMeta *types.Bloc
lastCommit = types.NewCommit(vote.Height, vote.Round,
lastBlockMeta.BlockID, []types.CommitSig{vote.CommitSig()})
}

return state.MakeBlock(
block := state.MakeBlock(
height,
[]types.Tx{},
nil,
Expand All @@ -1011,6 +1010,11 @@ func makeBlock(state sm.State, lastBlock *types.Block, lastBlockMeta *types.Bloc
lastCommit,
state.Validators.GetProposer().Address,
)
_, err := block.RowSet(context.TODO(), mdutils.Mock())
if err != nil {
panic(err)
}
return block, block.MakePartSet(types.BlockPartSizeBytes)
}

type badApp struct {
Expand Down
4 changes: 2 additions & 2 deletions consensus/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestStateBadProposal(t *testing.T) {
proposalCh := subscribe(cs1.eventBus, types.EventQueryCompleteProposal)
voteCh := subscribe(cs1.eventBus, types.EventQueryVote)

propBlock, _ := cs1.createProposalBlock() // changeProposer(t, cs1, vs2)
propBlock, _, _ := cs1.createProposalBlock() // changeProposer(t, cs1, vs2)

// make the second validator the proposer by incrementing round
round++
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestStateOversizedBlock(t *testing.T) {
timeoutProposeCh := subscribe(cs1.eventBus, types.EventQueryTimeoutPropose)
voteCh := subscribe(cs1.eventBus, types.EventQueryVote)

propBlock, _ := cs1.createProposalBlock()
propBlock, _, _ := cs1.createProposalBlock()
propBlock.Data.Txs = []types.Tx{tmrand.Bytes(2001)}
propBlock.Header.DataHash = propBlock.DataAvailabilityHeader.Hash()

Expand Down
10 changes: 8 additions & 2 deletions evidence/pool_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package evidence_test

import (
"context"
"os"
"testing"
"time"
Expand Down Expand Up @@ -175,6 +176,8 @@ func TestEvidencePoolUpdate(t *testing.T) {
val, evidenceChainID)
lastCommit := makeCommit(height, val.PrivKey.PubKey().Address())
block := types.MakeBlock(height+1, []types.Tx{}, []types.Evidence{ev}, nil, types.Messages{}, lastCommit)
_, err = block.RowSet(context.TODO(), mdutils.Mock())
require.NoError(t, err)
// update state (partially)
state.LastBlockHeight = height + 1
state.LastBlockTime = defaultEvidenceTime.Add(22 * time.Minute)
Expand Down Expand Up @@ -400,13 +403,16 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) *store.Bloc

for i := int64(1); i <= state.LastBlockHeight; i++ {
lastCommit := makeCommit(i-1, valAddr)
block, _ := state.MakeBlock(i, []types.Tx{}, nil, nil,
block := state.MakeBlock(i, []types.Tx{}, nil, nil,
types.Messages{}, lastCommit, state.Validators.GetProposer().Address)
block.Header.Time = defaultEvidenceTime.Add(time.Duration(i) * time.Minute)
block.Header.Version = tmversion.Consensus{Block: version.BlockProtocol, App: 1}
const parts = 1
partSet := block.MakePartSet(parts)

_, err := block.RowSet(context.TODO(), mdutils.Mock())
if err != nil {
panic(err)
}
seenCommit := makeCommit(i, valAddr)
blockStore.SaveBlock(block, partSet, seenCommit)
}
Expand Down
3 changes: 1 addition & 2 deletions light/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

format "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"
"github.com/lazyledger/nmt/namespace"

"github.com/lazyledger/lazyledger-core/libs/log"
tmmath "github.com/lazyledger/lazyledger-core/libs/math"
Expand Down Expand Up @@ -700,7 +699,7 @@ func (c *Client) verifySequential(
c.dag,
interimBlock.DataAvailabilityHeader,
numSamples,
func(data namespace.PrefixedData8) {}, // noop
func(ipld.NamespacedShare) {}, // noop
)
if err != nil {
return fmt.Errorf("data availability sampling failed; ipld.ValidateAvailability: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion light/provider/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/lazyledger/lazyledger-core/light/provider"
"github.com/lazyledger/lazyledger-core/p2p/ipld"
rpcclient "github.com/lazyledger/lazyledger-core/rpc/client"
rpchttp "github.com/lazyledger/lazyledger-core/rpc/client/http"
"github.com/lazyledger/lazyledger-core/types"
Expand Down Expand Up @@ -181,7 +182,7 @@ func (p *http) signedHeader(ctx context.Context, height *int64) (*types.SignedHe
return nil, provider.ErrNoResponse
}

func (p *http) daHeader(ctx context.Context, height *int64) (*types.DataAvailabilityHeader, error) {
func (p *http) daHeader(ctx context.Context, height *int64) (*ipld.DataAvailabilityHeader, error) {
for attempt := 1; attempt <= maxRetryAttempts; attempt++ {
daHeaderRes, err := p.client.DataAvailabilityHeader(ctx, height)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ func TestCreateProposalBlock(t *testing.T) {
)

commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
block, _ := blockExec.CreateProposalBlock(
block, _, _ := blockExec.CreateProposalBlock(
height,
state, commit,
proposerAddr,
Expand Down Expand Up @@ -391,7 +391,7 @@ func TestMaxTxsProposalBlockSize(t *testing.T) {
)

commit := types.NewCommit(height-1, 0, types.BlockID{}, nil)
block, _ := blockExec.CreateProposalBlock(
block, _, _ := blockExec.CreateProposalBlock(
height,
state, commit,
proposerAddr,
Expand Down Expand Up @@ -498,7 +498,7 @@ func TestMaxProposalBlockSize(t *testing.T) {
commit.Signatures = append(commit.Signatures, cs)
}

block, partSet := blockExec.CreateProposalBlock(
block, partSet, _ := blockExec.CreateProposalBlock(
math.MaxInt64,
state, commit,
proposerAddr,
Expand Down
3 changes: 2 additions & 1 deletion privval/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/lazyledger/lazyledger-core/crypto/tmhash"
tmjson "github.com/lazyledger/lazyledger-core/libs/json"
tmrand "github.com/lazyledger/lazyledger-core/libs/rand"
"github.com/lazyledger/lazyledger-core/p2p/ipld"
tmproto "github.com/lazyledger/lazyledger-core/proto/tendermint/types"
"github.com/lazyledger/lazyledger-core/types"
tmtime "github.com/lazyledger/lazyledger-core/types/time"
Expand Down Expand Up @@ -350,6 +351,6 @@ func newProposal(height int64, round int32, blockID types.BlockID) *types.Propos
Round: round,
BlockID: blockID,
Timestamp: tmtime.Now(),
DAHeader: &types.DataAvailabilityHeader{},
DAHeader: &ipld.DataAvailabilityHeader{},
}
}
3 changes: 2 additions & 1 deletion privval/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/lazyledger/lazyledger-core/crypto/ed25519"
cryptoenc "github.com/lazyledger/lazyledger-core/crypto/encoding"
"github.com/lazyledger/lazyledger-core/crypto/tmhash"
"github.com/lazyledger/lazyledger-core/p2p/ipld"
cryptoproto "github.com/lazyledger/lazyledger-core/proto/tendermint/crypto"
privproto "github.com/lazyledger/lazyledger-core/proto/tendermint/privval"
tmproto "github.com/lazyledger/lazyledger-core/proto/tendermint/types"
Expand Down Expand Up @@ -54,7 +55,7 @@ func exampleProposal() *types.Proposal {
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
},
},
DAHeader: &types.DataAvailabilityHeader{},
DAHeader: &ipld.DataAvailabilityHeader{},
}
}

Expand Down
7 changes: 4 additions & 3 deletions privval/signer_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/lazyledger/lazyledger-core/crypto"
"github.com/lazyledger/lazyledger-core/crypto/tmhash"
tmrand "github.com/lazyledger/lazyledger-core/libs/rand"
"github.com/lazyledger/lazyledger-core/p2p/ipld"
cryptoproto "github.com/lazyledger/lazyledger-core/proto/tendermint/crypto"
privvalproto "github.com/lazyledger/lazyledger-core/proto/tendermint/privval"
tmproto "github.com/lazyledger/lazyledger-core/proto/tendermint/types"
Expand Down Expand Up @@ -125,7 +126,7 @@ func TestSignerProposal(t *testing.T) {
POLRound: 2,
BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}},
Timestamp: ts,
DAHeader: &types.DataAvailabilityHeader{},
DAHeader: &ipld.DataAvailabilityHeader{},
}
want := &types.Proposal{
Type: tmproto.ProposalType,
Expand All @@ -134,7 +135,7 @@ func TestSignerProposal(t *testing.T) {
POLRound: 2,
BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}},
Timestamp: ts,
DAHeader: &types.DataAvailabilityHeader{},
DAHeader: &ipld.DataAvailabilityHeader{},
}

tc := tc
Expand Down Expand Up @@ -342,7 +343,7 @@ func TestSignerSignProposalErrors(t *testing.T) {
BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}},
Timestamp: ts,
Signature: []byte("signature"),
DAHeader: &types.DataAvailabilityHeader{},
DAHeader: &ipld.DataAvailabilityHeader{},
}

p, err := proposal.ToProto()
Expand Down
3 changes: 2 additions & 1 deletion rpc/core/types/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/lazyledger/lazyledger-core/crypto"
"github.com/lazyledger/lazyledger-core/libs/bytes"
"github.com/lazyledger/lazyledger-core/p2p"
"github.com/lazyledger/lazyledger-core/p2p/ipld"
tmproto "github.com/lazyledger/lazyledger-core/proto/tendermint/types"
"github.com/lazyledger/lazyledger-core/types"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ type ResultCommit struct {
}

type ResultDataAvailabilityHeader struct {
types.DataAvailabilityHeader `json:"data_availability_header"`
ipld.DataAvailabilityHeader `json:"data_availability_header"`
}

// ABCI results from a block
Expand Down
2 changes: 1 addition & 1 deletion state/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestBeginBlockValidators(t *testing.T) {
lastCommit := types.NewCommit(1, 0, prevBlockID, tc.lastCommitSigs)

// block for height 2
block, _ := state.MakeBlock(2, makeTxs(2), nil, nil,
block := state.MakeBlock(2, makeTxs(2), nil, nil,
types.Messages{}, lastCommit, state.Validators.GetProposer().Address)

_, err = sm.ExecCommitBlock(proxyApp.Consensus(), block, log.TestingLogger(), stateStore, 1)
Expand Down
Loading

0 comments on commit 0262cd0

Please sign in to comment.