From 347e99580976b465f34e4ac0b94dbf0b82259e40 Mon Sep 17 00:00:00 2001 From: senthil Date: Wed, 3 May 2017 18:51:42 +0530 Subject: [PATCH] [FAB-3413] Increase coverage for core/ledger/util This CR increases coverage for util.go and txvalidationflag.go to 100%. Will remove filterbitarray.go and filterbitarray_test.go in a separate CR as these files are not being used. Change-Id: I2a6c9d97af0a4674a3b6a019da3a93f0a01468fb Signed-off-by: senthil --- core/ledger/util/txvalidationflags_test.go | 36 ++++++++++++++++++++++ core/ledger/util/util_test.go | 34 ++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 core/ledger/util/txvalidationflags_test.go create mode 100644 core/ledger/util/util_test.go diff --git a/core/ledger/util/txvalidationflags_test.go b/core/ledger/util/txvalidationflags_test.go new file mode 100644 index 00000000000..ede1407e4af --- /dev/null +++ b/core/ledger/util/txvalidationflags_test.go @@ -0,0 +1,36 @@ +/* +Copyright IBM Corp. 2017 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "testing" + + "github.com/hyperledger/fabric/protos/peer" + "github.com/stretchr/testify/assert" +) + +func TestTransactionValidationFlags(t *testing.T) { + txFlags := NewTxValidationFlags(10) + assert.Equal(t, 10, len(txFlags)) + + txFlags.SetFlag(0, peer.TxValidationCode_VALID) + assert.Equal(t, peer.TxValidationCode_VALID, txFlags.Flag(0)) + assert.Equal(t, true, txFlags.IsValid(0)) + + txFlags.SetFlag(1, peer.TxValidationCode_MVCC_READ_CONFLICT) + assert.Equal(t, true, txFlags.IsInvalid(1)) +} diff --git a/core/ledger/util/util_test.go b/core/ledger/util/util_test.go new file mode 100644 index 00000000000..4c617c6cd6b --- /dev/null +++ b/core/ledger/util/util_test.go @@ -0,0 +1,34 @@ +/* +Copyright IBM Corp. 2017 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package util + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestGetSortedKeys(t *testing.T) { + mapKeyValue := make(map[string]int) + mapKeyValue["blue"] = 10 + mapKeyValue["apple"] = 15 + mapKeyValue["red"] = 12 + mapKeyValue["123"] = 22 + mapKeyValue["a"] = 33 + mapKeyValue[""] = 30 + assert.Equal(t, []string{"", "123", "a", "apple", "blue", "red"}, GetSortedKeys(mapKeyValue)) +}