Skip to content

Commit

Permalink
kvledger pkg -- consistently use testify/require (#1440)
Browse files Browse the repository at this point in the history
Signed-off-by: senthil <[email protected]>
  • Loading branch information
cendhu authored Jun 23, 2020
1 parent 0c67955 commit 833438f
Show file tree
Hide file tree
Showing 7 changed files with 298 additions and 300 deletions.
6 changes: 3 additions & 3 deletions core/ledger/kvledger/coll_elg_notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/core/ledger"
"github.com/hyperledger/fabric/core/ledger/mock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCollElgNotifier(t *testing.T) {
Expand Down Expand Up @@ -66,8 +66,8 @@ func TestCollElgNotifier(t *testing.T) {

// event triggered should only contain "coll3" as this is the only collection
// for which peer became from ineligile to eligible by upgrade tx
assert.Equal(t, uint64(500), mockCollElgListener.receivedCommittingBlk)
assert.Equal(t,
require.Equal(t, uint64(500), mockCollElgListener.receivedCommittingBlk)
require.Equal(t,
map[string][]string{
"cc1": {"coll3"},
},
Expand Down
28 changes: 14 additions & 14 deletions core/ledger/kvledger/hashcheck_pvtdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwsetutil"
"github.com/hyperledger/fabric/core/ledger/mock"
"github.com/hyperledger/fabric/protoutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestConstructValidInvalidBlocksPvtData(t *testing.T) {
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestConstructValidInvalidBlocksPvtData(t *testing.T) {

pubSimulationResults := &rwset.TxReadWriteSet{}
err := proto.Unmarshal(pubSimResBytesBlk1Tx7, pubSimulationResults)
assert.NoError(t, err)
require.NoError(t, err)
tx7PvtdataHash := pubSimulationResults.NsRwset[0].CollectionHashedRwset[0].PvtRwsetHash

// construct block1
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestConstructValidInvalidBlocksPvtData(t *testing.T) {
Block: blk1,
PvtData: pvtDataBlk1,
MissingPvtData: missingData}
assert.NoError(t, lg.(*kvLedger).commitToPvtAndBlockStore(blockAndPvtData1))
require.NoError(t, lg.(*kvLedger).commitToPvtAndBlockStore(blockAndPvtData1))

// construct pvtData from missing data in tx3, tx6, and tx7
pvtdata := []*ledger.ReconciledPvtdata{
Expand All @@ -106,11 +106,11 @@ func TestConstructValidInvalidBlocksPvtData(t *testing.T) {
}

blocksValidPvtData, hashMismatched, err := constructValidAndInvalidPvtData(pvtdata, lg.(*kvLedger).blockStore)
assert.NoError(t, err)
assert.Equal(t, len(expectedValidBlocksPvtData), len(blocksValidPvtData))
assert.ElementsMatch(t, expectedValidBlocksPvtData[1], blocksValidPvtData[1])
require.NoError(t, err)
require.Equal(t, len(expectedValidBlocksPvtData), len(blocksValidPvtData))
require.ElementsMatch(t, expectedValidBlocksPvtData[1], blocksValidPvtData[1])
// should not include the pvtData passed for the tx7 even in hashmismatched as ns-6:coll-2 does not exist in tx7
assert.Len(t, hashMismatched, 0)
require.Len(t, hashMismatched, 0)

// construct pvtData from missing data in tx7 with wrong pvtData
wrongPvtDataBlk1Tx7, _ = produceSamplePvtdata(t, 7, []string{"ns-1:coll-2"}, [][]byte{v6})
Expand All @@ -135,10 +135,10 @@ func TestConstructValidInvalidBlocksPvtData(t *testing.T) {
}

blocksValidPvtData, hashMismatches, err := constructValidAndInvalidPvtData(pvtdata, lg.(*kvLedger).blockStore)
assert.NoError(t, err)
assert.Len(t, blocksValidPvtData, 0)
require.NoError(t, err)
require.Len(t, blocksValidPvtData, 0)

assert.ElementsMatch(t, expectedHashMismatches, hashMismatches)
require.ElementsMatch(t, expectedHashMismatches, hashMismatches)
}

func produceSamplePvtdata(t *testing.T, txNum uint64, nsColls []string, values [][]byte) (*ledger.TxPvtData, []byte) {
Expand All @@ -152,9 +152,9 @@ func produceSamplePvtdata(t *testing.T, txNum uint64, nsColls []string, values [
builder.AddToPvtAndHashedWriteSet(ns, coll, key, value)
}
simRes, err := builder.GetTxSimulationResults()
assert.NoError(t, err)
require.NoError(t, err)
pubSimulationResultsBytes, err := proto.Marshal(simRes.PubSimulationResults)
assert.NoError(t, err)
require.NoError(t, err)
return &ledger.TxPvtData{SeqInBlock: txNum, WriteSet: simRes.PvtSimulationResults}, pubSimulationResultsBytes
}

Expand All @@ -167,7 +167,7 @@ func TestRemoveCollFromTxPvtReadWriteSet(t *testing.T) {
)

removeCollFromTxPvtReadWriteSet(txpvtrwset, "ns-1", "coll-1")
assert.Equal(
require.Equal(
t,
testutilConstructSampleTxPvtRwset(
[]*testNsColls{
Expand All @@ -179,7 +179,7 @@ func TestRemoveCollFromTxPvtReadWriteSet(t *testing.T) {
)

removeCollFromTxPvtReadWriteSet(txpvtrwset, "ns-1", "coll-2")
assert.Equal(
require.Equal(
t,
testutilConstructSampleTxPvtRwset(
[]*testNsColls{
Expand Down
Loading

0 comments on commit 833438f

Please sign in to comment.