Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading