Skip to content

Commit

Permalink
test: fix fetchProofForStateTransition tests and warnings (#2460)
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov authored Feb 14, 2025
1 parent d88ea46 commit ddf4e67
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function fetchProofForStateTransitionFactory(driveClient, dpp) {

const requestV0 = new GetProofsRequestV0();

let dataContractsCache = {};
const dataContractsCache = {};

if (stateTransition.isDocumentStateTransition()) {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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();
Expand Down Expand Up @@ -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());
});
Expand Down

0 comments on commit ddf4e67

Please sign in to comment.