Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

It there any way to use Stub.GetQueryResult? #48

Closed
r3code opened this issue May 17, 2020 · 5 comments
Closed

It there any way to use Stub.GetQueryResult? #48

r3code opened this issue May 17, 2020 · 5 comments

Comments

@r3code
Copy link

r3code commented May 17, 2020

I want to read data as a sorted list. I added CouchDB query:

func list(c router.Context) (interface{}, error) {
	queryString := `{
        "selector": {},
        "sort": [
            {"id": "asc"}
        ]
	}`

	iter, err1 := c.Stub().GetQueryResult(queryString)
	if err1 != nil {
		return nil, errors.Wrap(err1, "failed to GetQueryResult")
	}
	defer iter.Close()

	items := []interface{}{}
	for iter.HasNext() {
		kvResult, err := iter.Next()
		if err != nil {
			return nil, errors.Wrap(err1, "fetch error")
		}
		item := QueueItem{}
		err2 := json.Unmarshal(kvResult.Value, &item)
		if err2 != nil {
			return nil, errors.Wrap(err1, "value unmarshal error")
		}
		items = append(items, item)
	}
	return items, nil
}

But the test by mock tells me `failed to GetQueryResult: not implemented.
Is it so because I run the test with mock?

@vadiminshakov
Copy link

@r3code
Copy link
Author

r3code commented May 18, 2020

@vadiminshakov Thanks! I'll use a real network then for such tests.

@r3code r3code closed this as completed May 18, 2020
@akoita
Copy link

akoita commented May 22, 2020

Hi,

After having noticed the limitations of the mock which is in the Fabric source code, I came across CCKit which offers a mock with more possibilities and especially an advanced testing approach with Ginkgo and Gomega.

But I notice that an essential operation like the simulation of CouchDB requests is not supported. Do you plan to add this feature? How else do you test the operations of your chaincodes that execute CouchDB queries?

For information, this other implementation of the chaincode stub in TypesScript provides support for testing CouchDB requests: https://github.com/wearetheledger/fabric-mock-stub.

@vitiko
Copy link
Collaborator

vitiko commented May 26, 2020

Hi, at the moment we don't have plans to add a simulation of CouchDB requests, cause we mostly use encrypted protobuf marshaling to bytes and rich queries can't work with encrypted data. But you can try to do it for the case of JSON data modeling and add pull requests.

@akoita
Copy link

akoita commented May 29, 2020

Hi,
All right, I understand.
For now, I don't plan to implement the simulation of CouchDB requests either, but it would be a pleasure to submit a PR if I happen to implement it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants