github.com/ahlemtn/fabric@v2.1.1+incompatible/core/chaincode/active_transactions_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package chaincode_test 8 9 import ( 10 "github.com/hyperledger/fabric/core/chaincode" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/ginkgo/extensions/table" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("ActiveTransactions", func() { 17 var activeTx *chaincode.ActiveTransactions 18 19 BeforeEach(func() { 20 activeTx = chaincode.NewActiveTransactions() 21 }) 22 23 It("tracks active transactions", func() { 24 // Add unique transactions 25 ok := activeTx.Add("channel-id", "tx-id") 26 Expect(ok).To(BeTrue(), "a new transaction should return true") 27 ok = activeTx.Add("channel-id", "tx-id-2") 28 Expect(ok).To(BeTrue(), "adding a different transaction id should return true") 29 ok = activeTx.Add("channel-id-2", "tx-id") 30 Expect(ok).To(BeTrue(), "adding a different channel-id should return true") 31 32 // Attempt to add a transaction that already exists 33 ok = activeTx.Add("channel-id", "tx-id") 34 Expect(ok).To(BeFalse(), "attempting to an existing transaction should return false") 35 36 // Remove existing and make sure the ID can be reused 37 activeTx.Remove("channel-id", "tx-id") 38 ok = activeTx.Add("channel-id", "tx-id") 39 Expect(ok).To(BeTrue(), "using a an id that has been removed should return true") 40 }) 41 42 DescribeTable("NewTxKey", 43 func(channelID, txID, expected string) { 44 result := chaincode.NewTxKey(channelID, txID) 45 Expect(result).To(Equal(expected)) 46 }, 47 Entry("empty channel and tx", "", "", ""), 48 Entry("empty channel", "", "tx-1", "tx-1"), 49 Entry("empty tx", "chan-1", "", "chan-1"), 50 Entry("channel and tx", "chan-1", "tx-1", "chan-1tx-1"), 51 ) 52 })