-
Notifications
You must be signed in to change notification settings - Fork 8.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FAB-1038] Rework commiter to be more general
As part of the work needed for FAB-1038 to complete, this commit abstracts out transaction validation entity and extacts related code out of noopssinglechain/client.go. Change-Id: I6949c99abab6f58472dd8e95929201e2a472f13d Signed-off-by: Artem Barger <bartem@il.ibm.com>
- Loading branch information
Showing
4 changed files
with
270 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright IBM Corp. 2016 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 txvalidator | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hyperledger/fabric/core/ledger/kvledger" | ||
"github.com/hyperledger/fabric/core/ledger/testutil" | ||
"github.com/hyperledger/fabric/core/ledger/util" | ||
"github.com/hyperledger/fabric/protos/common" | ||
pb "github.com/hyperledger/fabric/protos/peer" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type mockVsccValidator struct { | ||
} | ||
|
||
func (v *mockVsccValidator) VSCCValidateTx(payload *common.Payload, envBytes []byte) error { | ||
return nil | ||
} | ||
|
||
func TestKVLedgerBlockStorage(t *testing.T) { | ||
conf := kvledger.NewConf("/tmp/tests/ledger/", 0) | ||
defer os.RemoveAll("/tmp/tests/ledger/") | ||
|
||
ledger, _ := kvledger.NewKVLedger(conf) | ||
defer ledger.Close() | ||
|
||
validator := &txValidator{ledger, &mockVsccValidator{}} | ||
|
||
bcInfo, _ := ledger.GetBlockchainInfo() | ||
testutil.AssertEquals(t, bcInfo, &pb.BlockchainInfo{ | ||
Height: 0, CurrentBlockHash: nil, PreviousBlockHash: nil}) | ||
|
||
simulator, _ := ledger.NewTxSimulator() | ||
simulator.SetState("ns1", "key1", []byte("value1")) | ||
simulator.SetState("ns1", "key2", []byte("value2")) | ||
simulator.SetState("ns1", "key3", []byte("value3")) | ||
simulator.Done() | ||
|
||
simRes, _ := simulator.GetTxSimulationResults() | ||
block := testutil.ConstructBlock(t, [][]byte{simRes}, true) | ||
|
||
validator.Validate(block) | ||
|
||
txsfltr := util.NewFilterBitArrayFromBytes(block.Metadata.Metadata[common.BlockMetadataIndex_TRANSACTIONS_FILTER]) | ||
|
||
assert.True(t, !txsfltr.IsSet(uint(0))) | ||
assert.True(t, !txsfltr.IsSet(uint(1))) | ||
assert.True(t, !txsfltr.IsSet(uint(2))) | ||
} |
Oops, something went wrong.