Ejemplo n.º 1
0
	Context("Ledger with preexisting uncommitted state", func() {

		BeforeEach(func() {
			ledgerPtr = InitSpec()

			Expect(ledgerPtr.BeginTxBatch(1)).To(BeNil())
			ledgerPtr.TxBegin("txUuid")
			Expect(ledgerPtr.SetState("chaincode1", "key1", []byte("value1"))).To(BeNil())
			Expect(ledgerPtr.SetState("chaincode2", "key2", []byte("value2"))).To(BeNil())
			Expect(ledgerPtr.SetState("chaincode3", "key3", []byte("value3"))).To(BeNil())
			ledgerPtr.TxFinished("txUuid", true)
		})

		It("should return uncommitted state from memory", func() {
			state, _ := ledgerPtr.GetState("chaincode1", "key1", false)
			Expect(state).To(Equal([]byte("value1")))
			state, _ = ledgerPtr.GetState("chaincode2", "key2", false)
			Expect(state).To(Equal([]byte("value2")))
			state, _ = ledgerPtr.GetState("chaincode3", "key3", false)
			Expect(state).To(Equal([]byte("value3")))
		})
		It("should not return committed state", func() {
			state, _ := ledgerPtr.GetState("chaincode1", "key1", true)
			Expect(state).To(BeNil())
			state, _ = ledgerPtr.GetState("chaincode2", "key2", true)
			Expect(state).To(BeNil())
			state, _ = ledgerPtr.GetState("chaincode3", "key3", true)
			Expect(state).To(BeNil())
		})
		It("should successfully rollback the batch", func() {