diff --git a/node/Drive.js b/node/Drive.js index c0e6ad40..eb4048e7 100644 --- a/node/Drive.js +++ b/node/Drive.js @@ -181,7 +181,7 @@ class Drive { * * @param {DataContract} dataContract * @param {string} documentType - * @param {BlockInfo} [blockInfo] + * @param {number} [epochIndex] * @param [query] * @param [query.where] * @param [query.limit] @@ -192,7 +192,13 @@ class Drive { * * @returns {Promise<[Document[], number]>} */ - async queryDocuments(dataContract, documentType, blockInfo = undefined, query = {}, useTransaction = false) { + async queryDocuments( + dataContract, + documentType, + epochIndex = undefined, + query = {}, + useTransaction = false, + ) { const encodedQuery = await cbor.encodeAsync(query); const [encodedDocuments, , processingFee] = await driveQueryDocumentsAsync.call( @@ -200,7 +206,7 @@ class Drive { encodedQuery, dataContract.id.toBuffer(), documentType, - blockInfo, + epochIndex, useTransaction, ); diff --git a/node/src/lib.rs b/node/src/lib.rs index 5c679fb1..ec61be27 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -578,7 +578,7 @@ impl DriveWrapper { let js_query_cbor = cx.argument::(0)?; let js_contract_id = cx.argument::(1)?; let js_document_type_name = cx.argument::(2)?; - let js_epoch_info = cx.argument::(3)?; + let js_maybe_epoch_index = cx.argument::(3)?; // TODO We need dry run for validation let js_using_transaction = cx.argument::(4)?; let js_callback = cx.argument::(5)?.root(&mut cx); @@ -590,7 +590,20 @@ impl DriveWrapper { let query_cbor = converter::js_buffer_to_vec_u8(js_query_cbor, &mut cx); let contract_id = converter::js_buffer_to_vec_u8(js_contract_id, &mut cx); let document_type_name = js_document_type_name.value(&mut cx); - let epoch_info = Epoch::new(js_epoch_info.value(&mut cx) as u16); + + let maybe_epoch: Option = if !js_maybe_epoch_index.is_a::(&mut cx) { + let js_epoch_index = js_maybe_epoch_index.downcast_or_throw::(&mut cx)?; + + let epoch_index = u16::try_from(js_epoch_index.value(&mut cx) as i64) + .or_else(|_| cx.throw_range_error("`epochs` must fit in u16"))?; + + let epoch = Epoch::new(epoch_index); + + Some(epoch) + } else { + None + }; + let using_transaction = js_using_transaction.value(&mut cx); drive @@ -599,7 +612,7 @@ impl DriveWrapper { &query_cbor, <[u8; 32]>::try_from(contract_id).unwrap(), document_type_name.as_str(), - Some(&epoch_info), + maybe_epoch.as_ref(), using_transaction.then_some(transaction).flatten(), ); diff --git a/node/test/.eslintrc b/node/test/.eslintrc new file mode 100644 index 00000000..720ced73 --- /dev/null +++ b/node/test/.eslintrc @@ -0,0 +1,12 @@ +{ + "env": { + "node": true, + "mocha": true + }, + "rules": { + "import/no-extraneous-dependencies": "off" + }, + "globals": { + "expect": true + } +} diff --git a/node/test/Drive.spec.js b/node/test/Drive.spec.js index 14f09e38..ddf6730b 100644 --- a/node/test/Drive.spec.js +++ b/node/test/Drive.spec.js @@ -192,9 +192,6 @@ describe('Drive', () => { it('should not update a document with dry run flag', async () => { const documentWithoutIndices = documents[0]; - // TODO: It should work without document creation - // await drive.createDocument(documentWithoutIndices, blockInfo); - documentWithoutIndices.set('name', 'Boooooooooooooooooooooob'); const result = await drive.updateDocument(documentWithoutIndices, blockInfo, false, true); @@ -203,8 +200,7 @@ describe('Drive', () => { expect(result).to.have.property('storageFee'); expect(result).to.have.property('removedFromIdentities'); - // TODO: Processing fee doesn't work for v0.23 - expect(result.processingFee).to.be.equals(0); + expect(result.processingFee).to.be.greaterThan(0); expect(result.storageFee).to.be.greaterThan(0, 'storage fee must be higher than 0'); expect(await drive.getGroveDB().getRootHash()).to.deep.equals(initialRootHash); @@ -335,7 +331,7 @@ describe('Drive', () => { ); // eslint-disable-next-line no-unused-vars - const [fetchedDocuments, processingCost] = await drive.queryDocuments(dataContract, 'indexedDocument', blockInfo, { + const [fetchedDocuments, processingCost] = await drive.queryDocuments(dataContract, 'indexedDocument', blockInfo.epoch, { where: [['lastName', '==', 'Kennedy']], }); @@ -348,7 +344,7 @@ describe('Drive', () => { it('should return empty array if documents are not exist', async () => { // eslint-disable-next-line no-unused-vars - const [fetchedDocuments, processingCost] = await drive.queryDocuments(dataContract, 'indexedDocument', blockInfo, { + const [fetchedDocuments, processingCost] = await drive.queryDocuments(dataContract, 'indexedDocument', blockInfo.epoch, { where: [['lastName', '==', 'Kennedy']], }); diff --git a/node/test/GroveDB.spec.js b/node/test/GroveDB.spec.js index cecc049f..a4bd9115 100644 --- a/node/test/GroveDB.spec.js +++ b/node/test/GroveDB.spec.js @@ -1157,7 +1157,12 @@ describe('GroveDB', () => { await groveDb.insert( ePath, Buffer.from('ebKey'), - { type: 'item', epoch: 0, ownerId, value: ebValue }, + { + type: 'item', + epoch: 0, + ownerId, + value: ebValue, + }, ); }); diff --git a/node/test/utils.js b/node/test/utils.js index 2b784960..434c9cfb 100644 --- a/node/test/utils.js +++ b/node/test/utils.js @@ -14,4 +14,4 @@ function expectFeeResult(feeResult) { module.exports = { expectFeeResult, -}; \ No newline at end of file +}; diff --git a/package-lock.json b/package-lock.json index 25fda2ea..d6cba3a2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dashevo/rs-drive", - "version": "0.23.0-pr.170.4", + "version": "0.23.0-pr.170.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@dashevo/rs-drive", - "version": "0.23.0-pr.170.4", + "version": "0.23.0-pr.170.5", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 0830fe89..487f6a64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dashevo/rs-drive", - "version": "0.23.0-pr.170.4", + "version": "0.23.0-pr.170.5", "description": "Node.JS binding for Rust Drive", "main": "node/Drive.js", "scripts": {