当前位置: 首页>>代码示例>>Golang>>正文


Golang testutil.AssertEquals函数代码示例

本文整理汇总了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)
}
开发者ID:hyperledger,项目名称:fabric,代码行数:29,代码来源:blockfile_mgr_test.go

示例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()
}
开发者ID:RJAugust,项目名称:fabric,代码行数:26,代码来源:range_scan_iterator_test.go

示例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))
}
开发者ID:hyperledger,项目名称:fabric,代码行数:31,代码来源:txmgr_test.go

示例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])
}
开发者ID:yoshiharay,项目名称:fabric,代码行数:33,代码来源:blockchain_indexes_async_test.go

示例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])
}
开发者ID:hyperledger,项目名称:fabric,代码行数:33,代码来源:fs_rawledger_test.go

示例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++
	}
}
开发者ID:ZhuZhengyi,项目名称:fabric,代码行数:34,代码来源:blockchain_test.go

示例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)
}
开发者ID:hyperledger,项目名称:fabric,代码行数:30,代码来源:test_common.go

示例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))

}
开发者ID:magooster,项目名称:obc-peer,代码行数:33,代码来源:ledger_test.go

示例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)
}
开发者ID:hyperledger,项目名称:fabric,代码行数:7,代码来源:stateleveldb_test.go

示例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, "")
}
开发者ID:hyperledger,项目名称:fabric,代码行数:9,代码来源:ledger_config_test.go

示例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])
}
开发者ID:ZhuZhengyi,项目名称:fabric,代码行数:9,代码来源:config_test.go

示例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)
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:9,代码来源:bucket_cache_test.go

示例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)
}
开发者ID:hyperledger,项目名称:fabric,代码行数:57,代码来源:txmgr_test.go

示例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())
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:9,代码来源:trie_node_test.go

示例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)
}
开发者ID:ZhuZhengyi,项目名称:fabric,代码行数:10,代码来源:blockchain_test.go


注:本文中的github.com/hyperledger/fabric/core/ledger/testutil.AssertEquals函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。