From ddf4e67fea0f9dfd7abfdfa63244fbe8fe62a607 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Fri, 14 Feb 2025 11:28:08 +0700 Subject: [PATCH] test: fix `fetchProofForStateTransition` tests and warnings (#2460) --- .../fetchProofForStateTransitionFactory.js | 2 +- ...etchProofForStateTransitionFactory.spec.js | 48 ++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/packages/dapi/lib/externalApis/drive/fetchProofForStateTransitionFactory.js b/packages/dapi/lib/externalApis/drive/fetchProofForStateTransitionFactory.js index 35d9fd34e69..4b8de795000 100644 --- a/packages/dapi/lib/externalApis/drive/fetchProofForStateTransitionFactory.js +++ b/packages/dapi/lib/externalApis/drive/fetchProofForStateTransitionFactory.js @@ -30,7 +30,7 @@ function fetchProofForStateTransitionFactory(driveClient, dpp) { const requestV0 = new GetProofsRequestV0(); - let dataContractsCache = {}; + const dataContractsCache = {}; if (stateTransition.isDocumentStateTransition()) { const { diff --git a/packages/dapi/test/unit/externalApis/drive/fetchProofForStateTransitionFactory.spec.js b/packages/dapi/test/unit/externalApis/drive/fetchProofForStateTransitionFactory.spec.js index 841a6e73cac..20a3635d097 100644 --- a/packages/dapi/test/unit/externalApis/drive/fetchProofForStateTransitionFactory.spec.js +++ b/packages/dapi/test/unit/externalApis/drive/fetchProofForStateTransitionFactory.spec.js @@ -8,9 +8,13 @@ const { }, } = require('@dashevo/dapi-grpc'); +const { default: loadWasmDpp, DashPlatformProtocol, StateTransitionTypes } = require('@dashevo/wasm-dpp'); + const generateRandomIdentifierAsync = require('@dashevo/wasm-dpp/lib/test/utils/generateRandomIdentifierAsync'); -const { StateTransitionTypes } = require('@dashevo/wasm-dpp'); +const getDocumentsFixture = require('@dashevo/wasm-dpp/lib/test/fixtures/getDocumentsFixture'); +const getBlsAdapterMock = require('@dashevo/wasm-dpp/lib/test/mocks/getBlsAdapterMock'); +const createStateRepositoryMock = require('@dashevo/wasm-dpp/lib/test/mocks/createStateRepositoryMock'); const fetchProofForStateTransitionFactory = require('../../../../lib/externalApis/drive/fetchProofForStateTransitionFactory'); describe('fetchProofForStateTransition', () => { @@ -22,6 +26,25 @@ describe('fetchProofForStateTransition', () => { let masternodeVoteResponse; let stateTransitionFixture; + let dpp; + + before(async () => { + await loadWasmDpp(); + }); + + beforeEach(async function beforeEachHandler() { + const blsAdapter = await getBlsAdapterMock(); + const stateRepositoryMock = createStateRepositoryMock(this.sinon); + + dpp = new DashPlatformProtocol( + blsAdapter, + 1, + stateRepositoryMock, + { generate: () => crypto.randomBytes(32) }, + 1, + ); + }); + beforeEach(async function beforeEach() { const { GetProofsResponseV0 } = GetProofsResponse; dataContractsProofResponse = new GetProofsResponse(); @@ -79,18 +102,21 @@ describe('fetchProofForStateTransition', () => { .equal(dataContractsProofResponse.serializeBinary()); }); - it('should fetch documents proofs', async function it() { - stateTransitionFixture.isDocumentStateTransition.returns(true); - stateTransitionFixture.getTransitions = this.sinon.stub().returns([ - { - getDataContractId: this.sinon.stub().returns(await generateRandomIdentifierAsync()), - getType: this.sinon.stub().returns('niceDocument'), - getId: this.sinon.stub().returns(await generateRandomIdentifierAsync()), - hasPrefundedBalance: this.sinon.stub().returns(true), + it('should fetch documents proofs', async () => { + const documents = await getDocumentsFixture(); + + const identityId = documents[0].getOwnerId(); + const contractId = documents[0].getDataContractId(); + + const transition = dpp.document.createStateTransition({ + create: documents, + }, { + [identityId.toString()]: { + [contractId.toString()]: 1, }, - ]); + }); - const result = await fetchProofForStateTransition(stateTransitionFixture); + const result = await fetchProofForStateTransition(transition); expect(result.serializeBinary()).to.deep .equal(documentsProofResponse.serializeBinary()); });