Skip to content

Commit

Permalink
[FAB-10686] testutil->testify txmgr/lockbasedtxmgr
Browse files Browse the repository at this point in the history
Change-Id: Ie40e1d66bdc1122c5ae15e19f0ae51572dec5816
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm committed Sep 22, 2018
1 parent e32bbda commit 6f8622c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 82 deletions.
12 changes: 6 additions & 6 deletions core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func TestPvtdataResultsItr(t *testing.T) {
queryHelper := newQueryHelper(txMgr, nil)

resItr, err := queryHelper.getPrivateDataRangeScanIterator("ns1", "coll1", "key1", "key3")
testutil.AssertNoError(t, err, "")
assert.NoError(t, err)
testItr(t, resItr, "ns1", "coll1", []string{"key1", "key2"})

resItr, err = queryHelper.getPrivateDataRangeScanIterator("ns4", "coll1", "key1", "key3")
testutil.AssertNoError(t, err, "")
assert.NoError(t, err)
testItr(t, resItr, "ns4", "coll1", []string{})
}

Expand All @@ -63,12 +63,12 @@ func testItr(t *testing.T, itr commonledger.ResultsIterator, expectedNs string,
pvtdataKV := queryResult.(*queryresult.KV)
ns := pvtdataKV.Namespace
key := pvtdataKV.Key
testutil.AssertEquals(t, ns, expectedNs)
testutil.AssertEquals(t, key, expectedKey)
assert.Equal(t, expectedNs, ns)
assert.Equal(t, expectedKey, key)
}
last, err := itr.Next()
testutil.AssertNoError(t, err, "")
testutil.AssertNil(t, last)
assert.NoError(t, err)
assert.Nil(t, last)
}

func TestPrivateDataMetadataRetrievalByHash(t *testing.T) {
Expand Down
17 changes: 9 additions & 8 deletions core/ledger/kvledger/txmgmt/txmgr/lockbasedtxmgr/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/hyperledger/fabric/protos/common"
"github.com/hyperledger/fabric/protos/ledger/queryresult"
"github.com/hyperledger/fabric/protos/ledger/rwset"
"github.com/stretchr/testify/assert"
)

type testEnv interface {
Expand Down Expand Up @@ -82,10 +83,10 @@ func (env *lockBasedEnv) init(t *testing.T, testLedgerID string, btlPolicy pvtda
env.t = t
env.testDBEnv.Init(t)
env.testDB = env.testDBEnv.GetDBHandle(testLedgerID)
testutil.AssertNoError(t, err, "")
assert.NoError(t, err)
env.testBookkeepingEnv = bookkeeping.NewTestEnv(t)
env.txmgr, err = NewLockBasedTxMgr(testLedgerID, env.testDB, nil, btlPolicy, env.testBookkeepingEnv.TestProvider)
testutil.AssertNoError(t, err, "")
assert.NoError(t, err)
}

func (env *lockBasedEnv) getTxMgr() txmgr.TxMgr {
Expand Down Expand Up @@ -119,32 +120,32 @@ func (h *txMgrTestHelper) validateAndCommitRWSet(txRWSet *rwset.TxReadWriteSet)
rwSetBytes, _ := proto.Marshal(txRWSet)
block := h.bg.NextBlock([][]byte{rwSetBytes})
err := h.txMgr.ValidateAndPrepare(&ledger.BlockAndPvtData{Block: block, BlockPvtData: nil}, true)
testutil.AssertNoError(h.t, err, "")
assert.NoError(h.t, err)
txsFltr := util.TxValidationFlags(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
invalidTxNum := 0
for i := 0; i < len(block.Data.Data); i++ {
if txsFltr.IsInvalid(i) {
invalidTxNum++
}
}
testutil.AssertEquals(h.t, invalidTxNum, 0)
assert.Equal(h.t, 0, invalidTxNum)
err = h.txMgr.Commit()
testutil.AssertNoError(h.t, err, "")
assert.NoError(h.t, err)
}

func (h *txMgrTestHelper) checkRWsetInvalid(txRWSet *rwset.TxReadWriteSet) {
rwSetBytes, _ := proto.Marshal(txRWSet)
block := h.bg.NextBlock([][]byte{rwSetBytes})
err := h.txMgr.ValidateAndPrepare(&ledger.BlockAndPvtData{Block: block, BlockPvtData: nil}, true)
testutil.AssertNoError(h.t, err, "")
assert.NoError(h.t, err)
txsFltr := util.TxValidationFlags(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER])
invalidTxNum := 0
for i := 0; i < len(block.Data.Data); i++ {
if txsFltr.IsInvalid(i) {
invalidTxNum++
}
}
testutil.AssertEquals(h.t, invalidTxNum, 1)
assert.Equal(h.t, 1, invalidTxNum)
}

func populateCollConfigForTest(t *testing.T, txMgr *LockBasedTxMgr, nsColls []collConfigkey, ht *version.Height) {
Expand All @@ -167,7 +168,7 @@ func populateCollConfigForTest(t *testing.T, txMgr *LockBasedTxMgr, nsColls []co

for ns, pkg := range m {
pkgBytes, err := proto.Marshal(pkg)
testutil.AssertNoError(t, err, "")
assert.NoError(t, err)
updates.PubUpdates.Put(lsccNamespace, constructCollectionConfigKey(ns), pkgBytes, ht)
}
txMgr.db.ApplyPrivacyAwareUpdates(updates, ht)
Expand Down
Loading

0 comments on commit 6f8622c

Please sign in to comment.