Skip to content

Commit

Permalink
🚨 Added testcases for deleteState and deletePrivateData, for issue we…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nagahora Suguru committed Jul 25, 2020
1 parent 6f2e56b commit 07dffdd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,34 @@ describe('Test Mockstub', () => {
}
});


it('Should be able to delete state', async () => {

const stub = new ChaincodeMockStub('mock', chaincode);
const response: ChaincodeResponse = await stub.mockInvoke('test', ['createCar', 'CAR0', 'prop1', 'prop2', 'prop3', 'test']);
expect(response.status).to.eq(200);
expect(Object.keys(stub.state).length).to.equal(1);
expect(Object.keys(stub.privateCollections["carDetails"]).length).to.equal(1);

await stub.deleteState('CAR0');

expect(Object.keys(stub.state).length).to.equal(0);
expect(Object.keys(stub.privateCollections["carDetails"]).length).to.equal(1);

});

it('Should be able to delete private data', async () => {

const stub = new ChaincodeMockStub('mock', chaincode);
const response: ChaincodeResponse = await stub.mockInvoke('test', ['createCar', 'CAR0', 'prop1', 'prop2', 'prop3', 'test']);
expect(response.status).to.eq(200);
expect(Object.keys(stub.state).length).to.equal(1);
expect(Object.keys(stub.privateCollections["carDetails"]).length).to.equal(1);

let res = await stub.deletePrivateData("carDetails", 'CAR0');

expect(Object.keys(stub.state).length).to.equal(1);
expect(Object.keys(stub.privateCollections["carDetails"]).length).to.equal(0);
});

});

0 comments on commit 07dffdd

Please sign in to comment.