From 26fcca73b7c9c702458c046afc058bac3e067059 Mon Sep 17 00:00:00 2001 From: Ivan Shumkov Date: Tue, 8 Mar 2022 22:20:38 +0700 Subject: [PATCH] fix(drive): documents have mixed owner ids (#283) --- .../synchronizeMasternodeIdentitiesFactory.js | 22 ++++++++++--------- ...hronizeMasternodeIdentitiesFactory.spec.js | 3 +-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/js-drive/lib/identity/masternode/synchronizeMasternodeIdentitiesFactory.js b/packages/js-drive/lib/identity/masternode/synchronizeMasternodeIdentitiesFactory.js index e35c696be0b..137e571ab65 100644 --- a/packages/js-drive/lib/identity/masternode/synchronizeMasternodeIdentitiesFactory.js +++ b/packages/js-drive/lib/identity/masternode/synchronizeMasternodeIdentitiesFactory.js @@ -137,19 +137,21 @@ function synchronizeMasternodeIdentitiesFactory( } // Process masternode reward contract updates - if (documentsToCreate.length > 0 || documentsToDelete > 0) { - const chunkedDocuments = splitDocumentsIntoChunks({ - create: documentsToCreate, - delete: documentsToDelete, + + for (const document of documentsToCreate) { + const documentsBatchTransition = transactionalDpp.document.createStateTransition({ + create: [document], }); - for (const documentsChunk of chunkedDocuments) { - const documentsBatchTransition = transactionalDpp.document.createStateTransition( - documentsChunk, - ); + await transactionalDpp.stateTransition.apply(documentsBatchTransition); + } - await transactionalDpp.stateTransition.apply(documentsBatchTransition); - } + for (const document of documentsToDelete) { + const documentsBatchTransition = transactionalDpp.document.createStateTransition({ + delete: [document], + }); + + await transactionalDpp.stateTransition.apply(documentsBatchTransition); } } diff --git a/packages/js-drive/test/unit/identity/masternode/synchronizeMasternodeIdentitiesFactory.spec.js b/packages/js-drive/test/unit/identity/masternode/synchronizeMasternodeIdentitiesFactory.spec.js index 97ba7a38d43..a5ddf2ea447 100644 --- a/packages/js-drive/test/unit/identity/masternode/synchronizeMasternodeIdentitiesFactory.spec.js +++ b/packages/js-drive/test/unit/identity/masternode/synchronizeMasternodeIdentitiesFactory.spec.js @@ -198,7 +198,7 @@ describe('synchronizeMasternodeIdentitiesFactory', () => { { mnList: smlFixture.concat(newSmlFixture) }, ); - const newIdentities = { create: [documentsFixture[0]], delete: [] }; + const newIdentities = { create: [documentsFixture[0]] }; handleNewMasternodeMock.returns(newIdentities); splitDocumentsIntoChunksMock.returns([newIdentities]); @@ -222,7 +222,6 @@ describe('synchronizeMasternodeIdentitiesFactory', () => { expect(handleUpdatedPubKeyOperatorMock).to.be.not.called(); expect(stateRepositoryMock.fetchDocuments).to.be.not.called(); - expect(splitDocumentsIntoChunksMock).to.be.calledWithExactly(newIdentities); expect(transactionalDppMock.document.createStateTransition) .to.be.calledWithExactly(newIdentities); expect(transactionalDppMock.stateTransition.apply).to.be.calledWithExactly(