コード例 #1
0
func TestGetDockerHostConfig(t *testing.T) {
	os.Setenv("HYPERLEDGER_VM_DOCKER_HOSTCONFIG_NETWORKMODE", "overlay")
	os.Setenv("HYPERLEDGER_VM_DOCKER_HOSTCONFIG_CPUSHARES", fmt.Sprint(1024*1024*1024*2))
	config.SetupTestConfig("./../../../peer")
	hostConfig := getDockerHostConfig()
	testutil.AssertNotNil(t, hostConfig)
	testutil.AssertEquals(t, hostConfig.NetworkMode, "overlay")
	testutil.AssertEquals(t, hostConfig.LogConfig.Type, "json-file")
	testutil.AssertEquals(t, hostConfig.LogConfig.Config["max-size"], "50m")
	testutil.AssertEquals(t, hostConfig.LogConfig.Config["max-file"], "5")
	testutil.AssertEquals(t, hostConfig.Memory, int64(1024*1024*1024*2))
	testutil.AssertEquals(t, hostConfig.CPUShares, int64(1024*1024*1024*2))
}
コード例 #2
0
func testBlockFileStreamUnexpectedEOF(t *testing.T, numBlocks int, partialBlockBytes []byte) {
	env := newTestEnv(t)
	defer env.Cleanup()
	w := newTestBlockfileWrapper(t, env)
	blockfileMgr := w.blockfileMgr
	blocks := testutil.ConstructTestBlocks(t, numBlocks)
	w.addBlocks(blocks)
	blockfileMgr.currentFileWriter.append(partialBlockBytes, true)
	w.close()
	s, err := newBlockfileStream(blockfileMgr.rootDir, 0, 0)
	defer s.close()
	testutil.AssertNoError(t, err, "Error in constructing blockfile stream")

	for i := 0; i < numBlocks; i++ {
		blockBytes, err := s.nextBlockBytes()
		testutil.AssertNotNil(t, blockBytes)
		testutil.AssertNoError(t, err, "Error in getting next block")
	}
	blockBytes, err := s.nextBlockBytes()
	testutil.AssertNil(t, blockBytes)
	testutil.AssertSame(t, err, ErrUnexpectedEndOfBlockfile)
}
コード例 #3
0
ファイル: state_trie_test.go プロジェクト: Colearo/fabric
func TestStateTrie_ComputeHash_WithDB_Staggered_Keys(t *testing.T) {
	testDBWrapper.CleanDB(t)
	stateTrie := NewStateTrie()
	stateTrieTestWrapper := &stateTrieTestWrapper{stateTrie, t}

	/////////////////////////////////////////////////////////
	// Test1 - Add a few staggered keys
	/////////////////////////////////////////////////////////
	stateDelta := statemgmt.NewStateDelta()
	stateDelta.Set("ID", "key1", []byte("value_key1"), nil)
	stateDelta.Set("ID", "key", []byte("value_key"), nil)
	stateDelta.Set("ID", "k", []byte("value_k"), nil)
	expectedHashKey1 := expectedCryptoHashForTest(newTrieKey("ID", "key1"), []byte("value_key1"))
	expectedHashKey := expectedCryptoHashForTest(newTrieKey("ID", "key"), []byte("value_key"), expectedHashKey1)
	expectedHashK := expectedCryptoHashForTest(newTrieKey("ID", "k"), []byte("value_k"), expectedHashKey)
	rootHash1 := stateTrieTestWrapper.PrepareWorkingSetAndComputeCryptoHash(stateDelta)
	testutil.AssertEquals(t, rootHash1, expectedHashK)
	stateTrieTestWrapper.PersistChangesAndResetInMemoryChanges()

	/////////////////////////////////////////////////////////
	// Test2 - Add a new key in path of existing staggered keys
	/////////////////////////////////////////////////////////
	t.Logf("- Add a new key in path of existing staggered keys -")
	stateDelta = statemgmt.NewStateDelta()
	stateDelta.Set("ID", "ke", []byte("value_ke"), nil)
	expectedHashKe := expectedCryptoHashForTest(newTrieKey("ID", "ke"), []byte("value_ke"), expectedHashKey)
	expectedHashK = expectedCryptoHashForTest(newTrieKey("ID", "k"), []byte("value_k"), expectedHashKe)
	rootHash2 := stateTrieTestWrapper.PrepareWorkingSetAndComputeCryptoHash(stateDelta)
	testutil.AssertEquals(t, rootHash2, expectedHashK)
	stateTrieTestWrapper.PersistChangesAndResetInMemoryChanges()

	/////////////////////////////////////////////////////////
	// Test3 - Change value of one of the existing keys
	/////////////////////////////////////////////////////////
	stateDelta = statemgmt.NewStateDelta()
	stateDelta.Set("ID", "ke", []byte("value_ke_new"), nil)
	expectedHashKe = expectedCryptoHashForTest(newTrieKey("ID", "ke"), []byte("value_ke_new"), expectedHashKey)
	expectedHashK = expectedCryptoHashForTest(newTrieKey("ID", "k"), []byte("value_k"), expectedHashKe)
	rootHash3 := stateTrieTestWrapper.PrepareWorkingSetAndComputeCryptoHash(stateDelta)
	testutil.AssertEquals(t, rootHash3, expectedHashK)
	stateTrieTestWrapper.PersistChangesAndResetInMemoryChanges()

	/////////////////////////////////////////////////////////
	// Test4 - delete one of the existing keys
	/////////////////////////////////////////////////////////
	stateDelta = statemgmt.NewStateDelta()
	stateDelta.Delete("ID", "ke", nil)
	expectedHashK = expectedCryptoHashForTest(newTrieKey("ID", "k"), []byte("value_k"), expectedHashKey)
	rootHash4 := stateTrieTestWrapper.PrepareWorkingSetAndComputeCryptoHash(stateDelta)
	testutil.AssertEquals(t, rootHash4, expectedHashK)
	stateTrieTestWrapper.PersistChangesAndResetInMemoryChanges()
	// Delete should not remove the key from db because, this key has children
	testutil.AssertNotNil(t, testDBWrapper.GetFromStateCF(t, newTrieKey("ID", "ke").getEncodedBytes()))
	testutil.AssertEquals(t, rootHash1, rootHash4)

	//////////////////////////////////////////////////////////////
	// Test4 -  Add one more key as a sibling of an intermediate node
	//////////////////////////////////////////////////////////////
	stateDelta = statemgmt.NewStateDelta()
	stateDelta.Set("ID", "kez", []byte("value_kez"), nil)
	expectedHashKez := expectedCryptoHashForTest(newTrieKey("ID", "kez"), []byte("value_kez"))
	expectedHashKe = expectedCryptoHashForTest(nil, nil, expectedHashKey, expectedHashKez)
	expectedHashK = expectedCryptoHashForTest(newTrieKey("ID", "k"), []byte("value_k"), expectedHashKe)
	rootHash5 := stateTrieTestWrapper.PrepareWorkingSetAndComputeCryptoHash(stateDelta)
	testutil.AssertEquals(t, rootHash5, expectedHashK)
}