Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

feat: use Drive 0.16 endpoints #309

Merged
merged 2 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/externalApis/drive/DriveStateRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ class DriveStateRepository {
* @return {Promise<Buffer>}
*/
async fetchDataContract(contractId) {
return this.request(`/dataContracts/${contractId}`);
return this.request(
'/dataContracts',
{
contractId,
},
);
}

/**
Expand All @@ -81,8 +86,12 @@ class DriveStateRepository {
*/
async fetchDocuments(contractId, type, options) {
const serializedDocumentsArray = await this.request(
`/dataContracts/${contractId}/documents/${type}`,
options,
'/dataContracts/documents',
{
...options,
contractId,
type,
},
);

return cbor.decode(serializedDocumentsArray);
Expand All @@ -96,7 +105,12 @@ class DriveStateRepository {
* @return {Promise<Buffer>}
*/
async fetchIdentity(id) {
return this.request(`/identities/${id}`);
return this.request(
'/identities',
{
id,
},
);
}

/**
Expand Down
12 changes: 6 additions & 6 deletions test/unit/api/drive/DriveStateRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ describe('DriveStateRepository', () => {
const result = await drive.fetchDataContract(contractId);

expect(drive.client.request).to.have.been.calledOnceWithExactly('abci_query', {
path: `/dataContracts/${contractId}`,
data: cbor.encode({}).toString('hex'), // cbor encoded empty object
path: '/dataContracts',
data: cbor.encode({ contractId }).toString('hex'), // cbor encoded empty object
});
expect(result).to.be.deep.equal(buffer);
});
Expand All @@ -121,8 +121,8 @@ describe('DriveStateRepository', () => {
const result = await drive.fetchDocuments(contractId, type, options);

expect(drive.client.request).to.have.been.calledOnceWithExactly('abci_query', {
path: `/dataContracts/${contractId}/documents/${type}`,
data: cbor.encode(options).toString('hex'), // cbor encoded empty object
path: '/dataContracts/documents',
data: cbor.encode({ ...options, contractId, type }).toString('hex'), // cbor encoded empty object
});
expect(result).to.be.deep.equal([]);
});
Expand All @@ -145,8 +145,8 @@ describe('DriveStateRepository', () => {
const result = await drive.fetchIdentity(identityId);

expect(drive.client.request).to.have.been.calledOnceWithExactly('abci_query', {
path: `/identities/${identityId}`,
data: cbor.encode({}).toString('hex'), // cbor encoded empty object
path: '/identities',
data: cbor.encode({ id: identityId }).toString('hex'), // cbor encoded empty object
});
expect(result).to.be.deep.equal(buffer);
});
Expand Down