本文整理匯總了Golang中github.com/hyperledger/fabric/core/ledger/testutil.AssertEquals函數的典型用法代碼示例。如果您正苦於以下問題:Golang AssertEquals函數的具體用法?Golang AssertEquals怎麽用?Golang AssertEquals使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了AssertEquals函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestBlockfileMgrFileRolling
func TestBlockfileMgrFileRolling(t *testing.T) {
env := newTestEnv(t)
blocks := testutil.ConstructTestBlocks(t, 100)
size := 0
for _, block := range blocks {
by, _, err := serializeBlock(block)
testutil.AssertNoError(t, err, "Error while serializing block")
blockBytesSize := len(by)
encodedLen := proto.EncodeVarint(uint64(blockBytesSize))
size += blockBytesSize + len(encodedLen)
}
env.conf.maxBlockfileSize = int(0.75 * float64(size))
blkfileMgrWrapper := newTestBlockfileWrapper(t, env)
blkfileMgrWrapper.addBlocks(blocks)
testutil.AssertEquals(t, blkfileMgrWrapper.blockfileMgr.cpInfo.latestFileChunkSuffixNum, 1)
blkfileMgrWrapper.testGetBlockByHash(blocks)
blkfileMgrWrapper.close()
env.Cleanup()
env = newTestEnv(t)
defer env.Cleanup()
env.conf.maxBlockfileSize = int(0.40 * float64(size))
blkfileMgrWrapper = newTestBlockfileWrapper(t, env)
defer blkfileMgrWrapper.close()
blkfileMgrWrapper.addBlocks(blocks)
testutil.AssertEquals(t, blkfileMgrWrapper.blockfileMgr.cpInfo.latestFileChunkSuffixNum, 2)
blkfileMgrWrapper.testGetBlockByHash(blocks)
}
示例2: TestRangeScanIteratorEmptyArray
func TestRangeScanIteratorEmptyArray(t *testing.T) {
testDBWrapper.CreateFreshDB(t)
stateImplTestWrapper := newStateImplTestWrapper(t)
stateDelta := statemgmt.NewStateDelta()
// insert keys
stateDelta.Set("chaincodeID1", "key1", []byte("value1"), nil)
stateDelta.Set("chaincodeID1", "key2", []byte{}, nil)
stateDelta.Set("chaincodeID1", "key3", []byte{}, nil)
stateImplTestWrapper.prepareWorkingSet(stateDelta)
stateImplTestWrapper.persistChangesAndResetInMemoryChanges()
// test range scan for chaincodeID2
rangeScanItr := stateImplTestWrapper.getRangeScanIterator("chaincodeID1", "key1", "key3")
var results = make(map[string][]byte)
for rangeScanItr.Next() {
key, value := rangeScanItr.GetKeyValue()
results[key] = value
}
t.Logf("Results = %s", results)
testutil.AssertEquals(t, len(results), 3)
testutil.AssertEquals(t, results["key3"], []byte{})
rangeScanItr.Close()
}
示例3: testIteratorWithDeletes
func testIteratorWithDeletes(t *testing.T, env testEnv) {
cID := "cID"
txMgr := env.getTxMgr()
txMgrHelper := newTxMgrTestHelper(t, txMgr)
s, _ := txMgr.NewTxSimulator()
for i := 1; i <= 10; i++ {
k := createTestKey(i)
v := createTestValue(i)
t.Logf("Adding k=[%s], v=[%s]", k, v)
s.SetState(cID, k, v)
}
s.Done()
// validate and commit RWset
txRWSet1, _ := s.GetTxSimulationResults()
txMgrHelper.validateAndCommitRWSet(txRWSet1)
s, _ = txMgr.NewTxSimulator()
s.DeleteState(cID, createTestKey(4))
s.Done()
// validate and commit RWset
txRWSet2, _ := s.GetTxSimulationResults()
txMgrHelper.validateAndCommitRWSet(txRWSet2)
queryExecuter, _ := txMgr.NewQueryExecutor()
itr, _ := queryExecuter.GetStateRangeScanIterator(cID, createTestKey(3), createTestKey(6))
defer itr.Close()
kv, _ := itr.Next()
testutil.AssertEquals(t, kv.(*ledger.KV).Key, createTestKey(3))
kv, _ = itr.Next()
testutil.AssertEquals(t, kv.(*ledger.KV).Key, createTestKey(5))
}
示例4: TestIndexesAsync_IndexPendingBlocks
func TestIndexesAsync_IndexPendingBlocks(t *testing.T) {
defaultSetting := indexBlockDataSynchronously
indexBlockDataSynchronously = false
defer func() { indexBlockDataSynchronously = defaultSetting }()
testDBWrapper.CleanDB(t)
testBlockchainWrapper := newTestBlockchainWrapper(t)
// stop the original indexer and change the indexer to Noop - so, no block is indexed
chain := testBlockchainWrapper.blockchain
chain.indexer.stop()
chain.indexer = &NoopIndexer{}
blocks, _, err := testBlockchainWrapper.populateBlockChainWithSampleData()
if err != nil {
t.Fatalf("Error populating block chain with sample data: %s", err)
}
// close the db
testDBWrapper.CloseDB(t)
// open the db again and create new instance of blockchain (and the associated async indexer)
// the indexer should index the pending blocks
testDBWrapper.OpenDB(t)
testBlockchainWrapper = newTestBlockchainWrapper(t)
defer chain.indexer.stop()
blockHash, _ := blocks[0].GetHash()
block := testBlockchainWrapper.getBlockByHash(blockHash)
testutil.AssertEquals(t, block, blocks[0])
blockHash, _ = blocks[len(blocks)-1].GetHash()
block = testBlockchainWrapper.getBlockByHash(blockHash)
testutil.AssertEquals(t, block, blocks[len(blocks)-1])
}
示例5: TestRawLedger
func TestRawLedger(t *testing.T) {
cleanup(t)
rawLedger := NewFSBasedRawLedger(testFolder)
defer rawLedger.Close()
defer cleanup(t)
// Construct test blocks and add to raw ledger
blocks := testutil.ConstructTestBlocks(t, 10)
for _, block := range blocks {
rawLedger.CommitBlock(block)
}
// test GetBlockchainInfo()
bcInfo, err := rawLedger.GetBlockchainInfo()
testutil.AssertNoError(t, err, "Error in getting BlockchainInfo")
testutil.AssertEquals(t, bcInfo.Height, uint64(10))
// test GetBlockByNumber()
block, err := rawLedger.GetBlockByNumber(2)
testutil.AssertNoError(t, err, "Error in getting block by number")
testutil.AssertEquals(t, block, blocks[1])
// get blocks iterator for block number starting from 3
itr, err := rawLedger.GetBlocksIterator(3)
testutil.AssertNoError(t, err, "Error in getting iterator")
blockHolder, err := itr.Next()
testutil.AssertNoError(t, err, "")
testutil.AssertEquals(t, blockHolder.(ledger.BlockHolder).GetBlock(), blocks[2])
// get next block from iterator. The block should be 4th block
blockHolder, err = itr.Next()
testutil.AssertNoError(t, err, "")
testutil.AssertEquals(t, blockHolder.(ledger.BlockHolder).GetBlock(), blocks[3])
}
示例6: TestBlockChain_SimpleChain
func TestBlockChain_SimpleChain(t *testing.T) {
testDBWrapper.CleanDB(t)
blockchainTestWrapper := newTestBlockchainWrapper(t)
blockchain := blockchainTestWrapper.blockchain
allBlocks, allStateHashes, err := blockchainTestWrapper.populateBlockChainWithSampleData()
if err != nil {
t.Logf("Error populating block chain with sample data: %s", err)
t.Fail()
}
testutil.AssertEquals(t, blockchain.getSize(), uint64(len(allBlocks)))
testutil.AssertEquals(t, blockchainTestWrapper.fetchBlockchainSizeFromDB(), uint64(len(allBlocks)))
for i := range allStateHashes {
t.Logf("Checking state hash for block number = [%d]", i)
testutil.AssertEquals(t, blockchainTestWrapper.getBlock(uint64(i)).GetStateHash(), allStateHashes[i])
}
for i := range allBlocks {
t.Logf("Checking block hash for block number = [%d]", i)
blockhash, _ := blockchainTestWrapper.getBlock(uint64(i)).GetHash()
expectedBlockHash, _ := allBlocks[i].GetHash()
testutil.AssertEquals(t, blockhash, expectedBlockHash)
}
testutil.AssertNil(t, blockchainTestWrapper.getBlock(uint64(0)).PreviousBlockHash)
i := 1
for i < len(allBlocks) {
t.Logf("Checking previous block hash for block number = [%d]", i)
expectedPreviousBlockHash, _ := allBlocks[i-1].GetHash()
testutil.AssertEquals(t, blockchainTestWrapper.getBlock(uint64(i)).PreviousBlockHash, expectedPreviousBlockHash)
i++
}
}
示例7: TestBasicRW
// TestBasicRW tests basic read-write
func TestBasicRW(t *testing.T, db statedb.VersionedDB) {
db.Open()
defer db.Close()
val, err := db.GetState("ns", "key1")
testutil.AssertNoError(t, err, "")
testutil.AssertNil(t, val)
batch := statedb.NewUpdateBatch()
vv1 := statedb.VersionedValue{Value: []byte("value1"), Version: version.NewHeight(1, 1)}
vv2 := statedb.VersionedValue{Value: []byte("value2"), Version: version.NewHeight(1, 2)}
vv3 := statedb.VersionedValue{Value: []byte("value3"), Version: version.NewHeight(1, 3)}
vv4 := statedb.VersionedValue{Value: []byte{}, Version: version.NewHeight(1, 4)}
batch.Put("ns1", "key1", vv1.Value, vv1.Version)
batch.Put("ns1", "key2", vv2.Value, vv2.Version)
batch.Put("ns2", "key3", vv3.Value, vv3.Version)
batch.Put("ns2", "key4", vv4.Value, vv4.Version)
savePoint := version.NewHeight(2, 5)
db.ApplyUpdates(batch, savePoint)
vv, _ := db.GetState("ns1", "key1")
testutil.AssertEquals(t, vv, &vv1)
vv, _ = db.GetState("ns2", "key4")
testutil.AssertEquals(t, vv, &vv4)
sp, err := db.GetLatestSavePoint()
testutil.AssertNoError(t, err, "")
testutil.AssertEquals(t, sp, savePoint)
}
示例8: TestTransactionResult
func TestTransactionResult(t *testing.T) {
ledgerTestWrapper := createFreshDBAndTestLedgerWrapper(t)
ledger := ledgerTestWrapper.ledger
// Block 0
ledger.BeginTxBatch(0)
ledger.TxBegin("txUuid1")
ledger.SetState("chaincode1", "key1", []byte("value1A"))
ledger.SetState("chaincode2", "key2", []byte("value2A"))
ledger.SetState("chaincode3", "key3", []byte("value3A"))
ledger.TxFinished("txUuid1", true)
transaction, uuid := buildTestTx(t)
transactionResult := &protos.TransactionResult{Uuid: uuid, ErrorCode: 500, Error: "bad"}
ledger.CommitTxBatch(0, []*protos.Transaction{transaction}, []*protos.TransactionResult{transactionResult}, []byte("proof"))
block := ledgerTestWrapper.GetBlockByNumber(0)
nonHashData := block.GetNonHashData()
if nonHashData == nil {
t.Fatal("Expected block to have non hash data, but non hash data was nil.")
}
if nonHashData.TransactionResults == nil || len(nonHashData.TransactionResults) == 0 {
t.Fatal("Expected block to have non hash data transaction results.")
}
testutil.AssertEquals(t, nonHashData.TransactionResults[0].Uuid, uuid)
testutil.AssertEquals(t, nonHashData.TransactionResults[0].Error, "bad")
testutil.AssertEquals(t, nonHashData.TransactionResults[0].ErrorCode, uint32(500))
}
示例9: testCompositeKey
func testCompositeKey(t *testing.T, ns string, key string) {
compositeKey := constructCompositeKey(ns, key)
t.Logf("compositeKey=%#v", compositeKey)
ns1, key1 := splitCompositeKey(compositeKey)
testutil.AssertEquals(t, ns1, ns)
testutil.AssertEquals(t, key1, key)
}
示例10: TestGetCouchDBDefinition
func TestGetCouchDBDefinition(t *testing.T) {
setUpCoreYAMLConfig()
defer testutil.ResetConfigToDefaultValues()
viper.Set("ledger.state.stateDatabase", "CouchDB")
couchDBDef := GetCouchDBDefinition()
testutil.AssertEquals(t, couchDBDef.URL, "127.0.0.1:5984")
testutil.AssertEquals(t, couchDBDef.Username, "")
testutil.AssertEquals(t, couchDBDef.Password, "")
}
示例11: TestConfigInit
func TestConfigInit(t *testing.T) {
configs := viper.GetStringMap("ledger.state.dataStructure.configs")
t.Logf("Configs loaded from yaml = %#v", configs)
testDBWrapper.CleanDB(t)
stateImpl := NewStateImpl()
stateImpl.Initialize(configs)
testutil.AssertEquals(t, conf.getNumBucketsAtLowestLevel(), configs[ConfigNumBuckets])
testutil.AssertEquals(t, conf.getMaxGroupingAtEachLevel(), configs[ConfigMaxGroupingAtEachLevel])
}
示例12: TestBucketCache
func TestBucketCache(t *testing.T) {
testutil.SetLogLevel(logging.INFO, "buckettree")
rootHash1, rootHash2, rootHash3, rootHash4 := testGetRootHashes(t, false)
rootHash5, rootHash6, rootHash7, rootHash8 := testGetRootHashes(t, true)
testutil.AssertEquals(t, rootHash1, rootHash5)
testutil.AssertEquals(t, rootHash2, rootHash6)
testutil.AssertEquals(t, rootHash3, rootHash7)
testutil.AssertEquals(t, rootHash4, rootHash8)
}
示例13: testIterator
func testIterator(t *testing.T, env testEnv, numKeys int, startKeyNum int, endKeyNum int) {
cID := "cID"
txMgr := env.getTxMgr()
txMgrHelper := newTxMgrTestHelper(t, txMgr)
s, _ := txMgr.NewTxSimulator()
for i := 1; i <= numKeys; i++ {
k := createTestKey(i)
v := createTestValue(i)
t.Logf("Adding k=[%s], v=[%s]", k, v)
s.SetState(cID, k, v)
}
s.Done()
// validate and commit RWset
txRWSet, _ := s.GetTxSimulationResults()
txMgrHelper.validateAndCommitRWSet(txRWSet)
var startKey string
var endKey string
var begin int
var end int
if startKeyNum != 0 {
begin = startKeyNum
startKey = createTestKey(startKeyNum)
} else {
begin = 1 //first key in the db
startKey = ""
}
if endKeyNum != 0 {
endKey = createTestKey(endKeyNum)
end = endKeyNum
} else {
endKey = ""
end = numKeys + 1 //last key in the db
}
expectedCount := end - begin
queryExecuter, _ := txMgr.NewQueryExecutor()
itr, _ := queryExecuter.GetStateRangeScanIterator(cID, startKey, endKey)
count := 0
for {
kv, _ := itr.Next()
if kv == nil {
break
}
keyNum := begin + count
k := kv.(*ledger.KV).Key
v := kv.(*ledger.KV).Value
t.Logf("Retrieved k=%s, v=%s at count=%d start=%s end=%s", k, v, count, startKey, endKey)
testutil.AssertEquals(t, k, createTestKey(keyNum))
testutil.AssertEquals(t, v, createTestValue(keyNum))
count++
}
testutil.AssertEquals(t, count, expectedCount)
}
示例14: testTrieNodeMarshalUnmarshal
func testTrieNodeMarshalUnmarshal(trieNode *trieNode, t *testing.T) {
trieNodeTestWrapper := &trieNodeTestWrapper{trieNode, t}
serializedContent := trieNodeTestWrapper.marshal()
trieNodeFromUnmarshal := trieNodeTestWrapper.unmarshal(trieNode.trieKey, serializedContent)
testutil.AssertEquals(t, trieNodeFromUnmarshal.trieKey, trieNode.trieKey)
testutil.AssertEquals(t, trieNodeFromUnmarshal.value, trieNode.value)
testutil.AssertEquals(t, trieNodeFromUnmarshal.childrenCryptoHashes, trieNode.childrenCryptoHashes)
testutil.AssertEquals(t, trieNodeFromUnmarshal.getNumChildren(), trieNode.getNumChildren())
}
示例15: TestBlockchain_InfoNoBlock
func TestBlockchain_InfoNoBlock(t *testing.T) {
testDBWrapper.CleanDB(t)
blockchainTestWrapper := newTestBlockchainWrapper(t)
blockchain := blockchainTestWrapper.blockchain
blockchainInfo, err := blockchain.getBlockchainInfo()
testutil.AssertNoError(t, err, "Error while invoking getBlockchainInfo() on an emply blockchain")
testutil.AssertEquals(t, blockchainInfo.Height, uint64(0))
testutil.AssertEquals(t, blockchainInfo.CurrentBlockHash, nil)
testutil.AssertEquals(t, blockchainInfo.PreviousBlockHash, nil)
}