Skip to content

Commit

Permalink
fixup! FAB-14068 filter creation and retrieval methods
Browse files Browse the repository at this point in the history
Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
  • Loading branch information
MHBauer committed Jan 22, 2020
1 parent 77251ea commit 2fdc65d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 3 additions & 3 deletions fab3/ethservice.go
Expand Up @@ -601,11 +601,11 @@ func (s *ethService) GetFilterChanges(_ *http.Request, filterID *types.FilterID,

func (s *ethService) GetFilterLogs(_ *http.Request, filterID *types.FilterID, alwaysLogs *[]interface{}) error {
id := filterID.ID
var f logsFilter
var f *logsFilter
// get the filter
s.filterMapLock.Lock()
if e, ok := s.filterMap[id]; ok {
if f, ok := e.(*logsFilter); !ok {
if f, ok = e.(*logsFilter); !ok {
s.filterMapLock.Unlock()
return fmt.Errorf("Filter id %d is not for retrieving logs, it is %T", id, f)
}
Expand All @@ -620,7 +620,7 @@ func (s *ethService) GetFilterLogs(_ *http.Request, filterID *types.FilterID, al
// delegate to existing function
var removed bool
s.UninstallFilter(nil, filterID, &removed)
return fmt.Errorf("No filter found for id %d", id)
return fmt.Errorf("U No filter found for id %d", id)
}
// use the filter
var logs []types.Log
Expand Down
21 changes: 20 additions & 1 deletion fab3/ethservice_test.go
Expand Up @@ -1483,10 +1483,29 @@ var _ = Describe("Ethservice", func() {
})
})

Context("logsFilter", func() {
Context("getFilterLogs", func() {
BeforeEach(func() {
By("setting the legder up to have one block")
mockLedgerClient.QueryInfoReturns(&fab.BlockchainInfoResponse{BCI: &common.BlockchainInfo{Height: 1}}, nil)
})

It("errors on asking for a newBlock filter", func() {
var reply string
By("Installing a newBlock filter")
Expect(ethservice.NewBlockFilter(&http.Request{}, nil, &reply)).ToNot(HaveOccurred())
id, err := strconv.ParseUint(reply, 0, 16)
Expect(err).ToNot(HaveOccurred())

filter := types.FilterID{ID: id}

var ret []interface{}
Expect(ethservice.GetFilterLogs(&http.Request{}, &filter, &ret)).To(HaveOccurred())
})

It("gets logs the same way as GetLogs", func() {
var logsArgs *types.GetLogsArgs = &types.GetLogsArgs{}
var reply string

By("creating the filter with default args")
Expect(ethservice.NewFilter(&http.Request{}, logsArgs, &reply)).ToNot(HaveOccurred())
id, err := strconv.ParseUint(reply, 0, 16)
Expand Down

0 comments on commit 2fdc65d

Please sign in to comment.