wearetheledger / fabric-mock-stub

Mock implementation of the fabric-shim stub for testing
https://theledger.be
MIT License
49 stars 28 forks source link

Delete Private Data Collection Key #25

Open thebubbleindex opened 5 years ago

thebubbleindex commented 5 years ago

Hi, I am encountering an issue in using the private data collection functionality. I realize this is a newer feature, however, I am wondering if all the functionality is implemented? Can private data collection entries be deleted in the fabric-mock-stub package? In particular, I am able to use the putPrivateData and getPrivateData functions, but the deletePrivateData does not seem to delete the key from the collection. I tried:

  1. putPrivateData -> key="1234", value="5678" - success
  2. deletePrivateData -> key="1234" - success
  3. queryPrivateData -> key="1234" - success

However the final query is returning the "5678" value. But it is supposed to fail. Thanks

oOhoraOo commented 4 years ago

Maybe you can fix deletePrivateData and it will work.

fabric-mock-stub/src/ChaincodeMockStub.ts

deletePrivateData(collection: string, key: string): Promise<any> {
    const value = (this.privateCollections[collection] || {})[key];

    if (value) {
        // (this.privateCollections[collection] as StateMap).delete(key);     // ← Incorrect !!
        delete this.privateCollections[collection][key];
    }

    return Promise.resolve();
}