Skip to content

Commit

Permalink
fix(drive)!: document query and delete issues (#303)
Browse files Browse the repository at this point in the history
Co-authored-by: Quantum Explorer <quantum@dash.org>
  • Loading branch information
shumkov and QuantumExplorer authored Mar 18, 2022
1 parent b31d4df commit 35d3656
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
8 changes: 4 additions & 4 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ class DataContractStoreRepository {
*
* @param {DataContract} dataContract
* @param {boolean} [useTransaction=false]
* @return {Promise<number>}
* @return {Promise<void>}
*/
async store(dataContract, useTransaction = false) {
try {
return await this.storage.getDrive().applyContract(dataContract, useTransaction);
return await this.storage.getDrive().applyContract(
dataContract,
new Date('2022-03-17T15:08:26.132Z'),
useTransaction,
);
} finally {
if (this.logger) {
this.logger.trace({
Expand Down
12 changes: 10 additions & 2 deletions packages/js-drive/lib/document/DocumentRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ class DocumentRepository {
if (isExists) {
method = 'updateDocument';
result = await this.storage.getDrive()
.updateDocument(document, useTransaction);
.updateDocument(
document,
new Date('2022-03-17T15:08:26.132Z'),
useTransaction,
);
} else {
result = await this.storage.getDrive()
.createDocument(document, useTransaction);
.createDocument(
document,
new Date('2022-03-17T15:08:26.132Z'),
useTransaction,
);
}
} finally {
if (this.logger) {
Expand Down
2 changes: 1 addition & 1 deletion packages/js-drive/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@dashevo/feature-flags-contract": "workspace:~",
"@dashevo/grpc-common": "workspace:~",
"@dashevo/masternode-reward-shares-contract": "workspace:~",
"@dashevo/rs-drive": "~0.22.0-dev.17",
"@dashevo/rs-drive": "~0.22.0-dev.19",
"ajv": "^8.6.0",
"ajv-keywords": "^5.0.0",
"awilix": "^4.2.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('DataContractStoreRepository', () => {

beforeEach(async () => {
rsDrive = new Drive('./db/grovedb_test');
store = new GroveDBStore(rsDrive, noopLogger, 'testStore');
store = new GroveDBStore(rsDrive, noopLogger);

decodeProtocolEntity = decodeProtocolEntityFactory();

Expand Down Expand Up @@ -108,7 +108,7 @@ describe('DataContractStoreRepository', () => {
});

it('should fetch Data Contract', async () => {
await store.getDrive().applyContract(dataContract, false);
await store.getDrive().applyContract(dataContract, new Date(), false);

const storedDataContract = await repository.fetch(dataContract.getId());

Expand All @@ -119,7 +119,7 @@ describe('DataContractStoreRepository', () => {
it('should fetch Data Contract using transaction', async () => {
await store.startTransaction();

await store.getDrive().applyContract(dataContract, true);
await store.getDrive().applyContract(dataContract, new Date(), true);

const notFoundDataContract = await repository.fetch(dataContract.getId(), false);

Expand Down
18 changes: 10 additions & 8 deletions packages/js-drive/test/unit/document/DocumentRepository.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ describe('DocumentRepository', () => {
{ useTransaction: false },
);

expect(driveMock.createDocument).to.be.calledOnceWithExactly(
document,
false,
);
expect(driveMock.createDocument.getCall(0).args).to.have.lengthOf(3);

expect(driveMock.createDocument.getCall(0).args[0]).to.equals(document);
expect(driveMock.createDocument.getCall(0).args[1]).to.be.instanceOf(Date);
expect(driveMock.createDocument.getCall(0).args[2]).to.equals(false);

expect(loggerMock.info).to.be.calledOnce();
});
Expand All @@ -100,10 +101,11 @@ describe('DocumentRepository', () => {
{ useTransaction: true },
);

expect(driveMock.updateDocument).to.be.calledOnceWithExactly(
document,
true,
);
expect(driveMock.updateDocument.getCall(0).args).to.have.lengthOf(3);

expect(driveMock.updateDocument.getCall(0).args[0]).to.equals(document);
expect(driveMock.updateDocument.getCall(0).args[1]).to.be.instanceOf(Date);
expect(driveMock.updateDocument.getCall(0).args[2]).to.equals(true);
});
});

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ __metadata:
"@dashevo/feature-flags-contract": "workspace:~"
"@dashevo/grpc-common": "workspace:~"
"@dashevo/masternode-reward-shares-contract": "workspace:~"
"@dashevo/rs-drive": ~0.22.0-dev.17
"@dashevo/rs-drive": ~0.22.0-dev.19
"@types/pino": ^6.3.0
ajv: ^8.6.0
ajv-keywords: ^5.0.0
Expand Down Expand Up @@ -1783,16 +1783,16 @@ __metadata:
languageName: node
linkType: hard

"@dashevo/rs-drive@npm:~0.22.0-dev.17":
version: 0.22.0-dev.17
resolution: "@dashevo/rs-drive@npm:0.22.0-dev.17"
"@dashevo/rs-drive@npm:~0.22.0-dev.19":
version: 0.22.0-dev.19
resolution: "@dashevo/rs-drive@npm:0.22.0-dev.19"
dependencies:
"@dashevo/dpp": ~0.22.0-dev.7
cargo-cp-artifact: ^0.1.6
cbor: ^8.1.0
neon-load-or-build: ^2.2.2
neon-tag-prebuild: "github:shumkov/neon-tag-prebuild#patch-1"
checksum: 96f6c4823b81ee165dc09cb36d15839d46c0fb9c12b978fbf568eb734e0249e9f4e0284df477411941d9ef03ea000de15271834f8a57d541fc31e78bf8d78916
checksum: cdc9c6733735efa000f4abeee7905835382d500c5876bf38e255edc46a5f309cd527d5614caa1921c726833b45b5742bdb2e0e9b8ef066b3d6b9b14d72b6290d
languageName: node
linkType: hard

Expand Down

0 comments on commit 35d3656

Please sign in to comment.