@@ -24,6 +24,9 @@ import (
24
24
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
25
25
"github.com/hyperledger/fabric/common/ledger/testutil"
26
26
"github.com/hyperledger/fabric/core/ledger"
27
+ "github.com/hyperledger/fabric/core/ledger/util"
28
+ "github.com/hyperledger/fabric/protos/common"
29
+ "github.com/hyperledger/fabric/protos/peer"
27
30
"github.com/spf13/viper"
28
31
)
29
32
@@ -124,6 +127,45 @@ func TestHistory(t *testing.T) {
124
127
testutil .AssertEquals (t , count , 3 )
125
128
}
126
129
130
+ func TestHistoryForInvalidTran (t * testing.T ) {
131
+
132
+ env := NewTestHistoryEnv (t )
133
+ defer env .cleanup ()
134
+ provider := env .testBlockStorageEnv .provider
135
+ store1 , err := provider .OpenBlockStore ("ledger1" )
136
+ testutil .AssertNoError (t , err , "Error upon provider.OpenBlockStore()" )
137
+ defer store1 .Shutdown ()
138
+
139
+ //block1
140
+ simulator , _ := env .txmgr .NewTxSimulator ()
141
+ value1 := []byte ("value1" )
142
+ simulator .SetState ("ns1" , "key7" , value1 )
143
+ simulator .Done ()
144
+ simRes , _ := simulator .GetTxSimulationResults ()
145
+ bg := testutil .NewBlockGenerator (t )
146
+ block1 := bg .NextBlock ([][]byte {simRes }, false )
147
+
148
+ //for this invalid tran test, set the transaction to invalid
149
+ txsFilter := util .TxValidationFlags (block1 .Metadata .Metadata [common .BlockMetadataIndex_TRANSACTIONS_FILTER ])
150
+ txsFilter .SetFlag (0 , peer .TxValidationCode_INVALID_OTHER_REASON )
151
+ block1 .Metadata .Metadata [common .BlockMetadataIndex_TRANSACTIONS_FILTER ] = txsFilter
152
+
153
+ err = store1 .AddBlock (block1 )
154
+ testutil .AssertNoError (t , err , "" )
155
+ err = env .testHistoryDB .Commit (block1 )
156
+ testutil .AssertNoError (t , err , "" )
157
+
158
+ qhistory , err := env .testHistoryDB .NewHistoryQueryExecutor (store1 )
159
+ testutil .AssertNoError (t , err , "Error upon NewHistoryQueryExecutor" )
160
+
161
+ itr , err2 := qhistory .GetHistoryForKey ("ns1" , "key7" )
162
+ testutil .AssertNoError (t , err2 , "Error upon GetHistoryForKey()" )
163
+
164
+ // test that there are no history values, since the tran was marked as invalid
165
+ kmod , _ := itr .Next ()
166
+ testutil .AssertNil (t , kmod )
167
+ }
168
+
127
169
//TestSavepoint tests that save points get written after each block and get returned via GetBlockNumfromSavepoint
128
170
func TestHistoryDisabled (t * testing.T ) {
129
171
0 commit comments