Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
feat: support multiple store tree proofs in responses (#398)
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Suprunchuk <antouhou@gmail.com>
  • Loading branch information
jawid-h and antouhou committed Aug 9, 2021
1 parent 71ac9ef commit 99ec243
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DRIVE_BRANCH=
# DASHMATE_BRANCH=
# TEST_SUITE_BRANCH=
TEST_SUITE_BRANCH=fix-document-test
# SDK_BRANCH=
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
StateTransitionBroadcastError,
Proof,
ResponseMetadata,
StoreTreeProofs,
},
} = require('@dashevo/dapi-grpc');

Expand Down Expand Up @@ -122,9 +123,18 @@ function waitForStateTransitionResultHandlerFactory(
response.setMetadata(responseMetadata);

const proof = new Proof();
const storeTreeProofs = new StoreTreeProofs();

if (stateTransition.isDocumentStateTransition()) {
storeTreeProofs.setDocumentsProof(proofObject.storeTreeProof);
} else if (stateTransition.isIdentityStateTransition()) {
storeTreeProofs.setIdentitiesProof(proofObject.storeTreeProof);
} else if (stateTransition.isDataContractStateTransition()) {
storeTreeProofs.setDataContractsProof(proofObject.storeTreeProof);
}

proof.setRootTreeProof(proofObject.rootTreeProof);
proof.setStoreTreeProof(proofObject.storeTreeProof);
proof.setStoreTreeProofs(storeTreeProofs);
proof.setSignatureLlmqHash(proofObject.signatureLlmqHash);
proof.setSignature(proofObject.signature);

Expand Down
27 changes: 7 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"all": true
},
"dependencies": {
"@dashevo/dapi-grpc": "~0.21.0-dev.1",
"@dashevo/dapi-grpc": "~0.21.0-dev.2",
"@dashevo/dashcore-lib": "~0.19.25",
"@dashevo/dashd-rpc": "^2.0.2",
"@dashevo/dpp": "~0.20.0",
Expand All @@ -47,7 +47,7 @@
"zeromq": "5.2.0"
},
"devDependencies": {
"@dashevo/dapi-client": "~0.20.0",
"@dashevo/dapi-client": "~0.21.0-dev.2",
"@dashevo/dp-services-ctl": "github:dashevo/js-dp-services-ctl#v0.19-dev",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
WaitForStateTransitionResultRequest,
StateTransitionBroadcastError,
Proof,
StoreTreeProofs,
},
} = require('@dashevo/dapi-grpc');
const createDPPMock = require('@dashevo/dpp/lib/test/mocks/createDPPMock');
Expand Down Expand Up @@ -46,6 +47,7 @@ describe('waitForStateTransitionResultHandlerFactory', () => {
let fetchProofForStateTransition;
let waitForTransactionToBeProvable;
let transactionNotFoundError;
let storeTreeProofs;

beforeEach(function beforeEach() {
const hashString = '56458F2D8A8617EA322931B72C103CDD93820004E534295183A6EF215B93C76E';
Expand Down Expand Up @@ -110,6 +112,9 @@ describe('waitForStateTransitionResultHandlerFactory', () => {
storeTreeProof: Buffer.alloc(1, 2),
};

storeTreeProofs = new StoreTreeProofs();
storeTreeProofs.setIdentitiesProof(proofFixture.storeTreeProof);

call = new GrpcCallMock(this.sinon, {
getStateTransitionHash: this.sinon.stub().returns(hash),
getProve: this.sinon.stub().returns(false),
Expand Down Expand Up @@ -215,10 +220,10 @@ describe('waitForStateTransitionResultHandlerFactory', () => {

expect(proof).to.be.an.instanceOf(Proof);
const rootTreeProof = proof.getRootTreeProof();
const storeTreeProof = proof.getStoreTreeProof();
const resultStoreTreeProof = proof.getStoreTreeProofs();

expect(rootTreeProof).to.deep.equal(proofFixture.rootTreeProof);
expect(storeTreeProof).to.deep.equal(proofFixture.storeTreeProof);
expect(resultStoreTreeProof).to.deep.equal(storeTreeProofs);

expect(driveClientMock.fetchProofs).to.be.calledOnceWithExactly({
identityIds: stateTransitionFixture.getModifiedDataIds(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
v0: {
GetDataContractResponse,
Proof,
StoreTreeProofs,
},
} = require('@dashevo/dapi-grpc');

Expand All @@ -36,6 +37,7 @@ describe('getDataContractHandlerFactory', () => {
let proofFixture;
let proofMock;
let response;
let storeTreeProofs;

beforeEach(function beforeEach() {
id = generateRandomIdentifier();
Expand All @@ -52,9 +54,12 @@ describe('getDataContractHandlerFactory', () => {
storeTreeProof: Buffer.alloc(1, 2),
};

storeTreeProofs = new StoreTreeProofs();
storeTreeProofs.setDataContractsProof(proofFixture.storeTreeProof);

proofMock = new Proof();
proofMock.setRootTreeProof(proofFixture.rootTreeProof);
proofMock.setStoreTreeProof(proofFixture.storeTreeProof);
proofMock.setStoreTreeProofs(storeTreeProofs);

response = new GetDataContractResponse();
response.setProof(proofMock);
Expand Down Expand Up @@ -88,10 +93,10 @@ describe('getDataContractHandlerFactory', () => {

expect(proof).to.be.an.instanceOf(Proof);
const rootTreeProof = proof.getRootTreeProof();
const storeTreeProof = proof.getStoreTreeProof();
const resultStoreTreeProofs = proof.getStoreTreeProofs();

expect(rootTreeProof).to.deep.equal(proofFixture.rootTreeProof);
expect(storeTreeProof).to.deep.equal(proofFixture.storeTreeProof);
expect(resultStoreTreeProofs).to.deep.equal(storeTreeProofs);

expect(driveStateRepositoryMock.fetchDataContract).to.be.calledOnceWith(id, true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
v0: {
GetDocumentsResponse,
Proof,
StoreTreeProofs,
},
} = require('@dashevo/dapi-grpc');

Expand Down Expand Up @@ -45,6 +46,7 @@ describe('getDocumentsHandlerFactory', () => {
let proofFixture;
let response;
let proofMock;
let storeTreeProofs;

beforeEach(function beforeEach() {
dataContractId = generateRandomIdentifier();
Expand Down Expand Up @@ -78,9 +80,12 @@ describe('getDocumentsHandlerFactory', () => {
storeTreeProof: Buffer.alloc(1, 2),
};

storeTreeProofs = new StoreTreeProofs();
storeTreeProofs.setDataContractsProof(proofFixture.storeTreeProof);

proofMock = new Proof();
proofMock.setRootTreeProof(proofFixture.rootTreeProof);
proofMock.setStoreTreeProof(proofFixture.storeTreeProof);
proofMock.setStoreTreeProofs(storeTreeProofs);

response = new GetDocumentsResponse();
response.setProof(proofMock);
Expand Down Expand Up @@ -158,10 +163,10 @@ describe('getDocumentsHandlerFactory', () => {

expect(proof).to.be.an.instanceOf(Proof);
const rootTreeProof = proof.getRootTreeProof();
const storeTreeProof = proof.getStoreTreeProof();
const resultStoreTreeProofs = proof.getStoreTreeProofs();

expect(rootTreeProof).to.deep.equal(proofFixture.rootTreeProof);
expect(storeTreeProof).to.deep.equal(proofFixture.storeTreeProof);
expect(resultStoreTreeProofs).to.deep.equal(storeTreeProofs);
});

it('should throw InvalidArgumentGrpcError if dataContractId is not specified', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
v0: {
GetIdentitiesByPublicKeyHashesResponse,
Proof,
StoreTreeProofs,
},
} = require('@dashevo/dapi-grpc');

Expand All @@ -33,6 +34,7 @@ describe('getIdentitiesByPublicKeyHashesHandlerFactory', () => {
let proofFixture;
let proofMock;
let response;
let storeTreeProofs;

beforeEach(function beforeEach() {
publicKeyHash = '556c2910d46fda2b327ef9d9bda850cc84d30db0';
Expand All @@ -52,9 +54,12 @@ describe('getIdentitiesByPublicKeyHashesHandlerFactory', () => {
storeTreeProof: Buffer.alloc(1, 2),
};

storeTreeProofs = new StoreTreeProofs();
storeTreeProofs.setDataContractsProof(proofFixture.storeTreeProof);

proofMock = new Proof();
proofMock.setRootTreeProof(proofFixture.rootTreeProof);
proofMock.setStoreTreeProof(proofFixture.storeTreeProof);
proofMock.setStoreTreeProofs(storeTreeProofs);

response = new GetIdentitiesByPublicKeyHashesResponse();
response.setProof(proofMock);
Expand Down Expand Up @@ -102,10 +107,10 @@ describe('getIdentitiesByPublicKeyHashesHandlerFactory', () => {

expect(proof).to.be.an.instanceOf(Proof);
const rootTreeProof = proof.getRootTreeProof();
const storeTreeProof = proof.getStoreTreeProof();
const resultStoreTreeProof = proof.getStoreTreeProofs();

expect(rootTreeProof).to.deep.equal(proofFixture.rootTreeProof);
expect(storeTreeProof).to.deep.equal(proofFixture.storeTreeProof);
expect(resultStoreTreeProof).to.deep.equal(storeTreeProofs);
});

it('should throw an InvalidArgumentGrpcError if no hashes were submitted', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
v0: {
GetIdentityResponse,
Proof,
StoreTreeProofs,
},
} = require('@dashevo/dapi-grpc');

Expand All @@ -34,6 +35,7 @@ describe('getIdentityHandlerFactory', () => {
let proofFixture;
let proofMock;
let response;
let storeTreeProofs;

beforeEach(function beforeEach() {
id = generateRandomIdentifier();
Expand All @@ -49,9 +51,12 @@ describe('getIdentityHandlerFactory', () => {
storeTreeProof: Buffer.alloc(1, 2),
};

storeTreeProofs = new StoreTreeProofs();
storeTreeProofs.setDataContractsProof(proofFixture.storeTreeProof);

proofMock = new Proof();
proofMock.setRootTreeProof(proofFixture.rootTreeProof);
proofMock.setStoreTreeProof(proofFixture.storeTreeProof);
proofMock.setStoreTreeProofs(storeTreeProofs);

response = new GetIdentityResponse();
response.setProof(proofMock);
Expand Down Expand Up @@ -95,10 +100,10 @@ describe('getIdentityHandlerFactory', () => {

expect(proof).to.be.an.instanceOf(Proof);
const rootTreeProof = proof.getRootTreeProof();
const storeTreeProof = proof.getStoreTreeProof();
const resultStoreTreeProof = proof.getStoreTreeProofs();

expect(rootTreeProof).to.deep.equal(proofFixture.rootTreeProof);
expect(storeTreeProof).to.deep.equal(proofFixture.storeTreeProof);
expect(resultStoreTreeProof).to.deep.equal(storeTreeProofs);

expect(driveStateRepositoryMock.fetchIdentity).to.be.calledOnceWith(id, true);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
v0: {
GetIdentityIdsByPublicKeyHashesResponse,
Proof,
StoreTreeProofs,
},
} = require('@dashevo/dapi-grpc');

Expand All @@ -33,6 +34,7 @@ describe('getIdentityIdsByPublicKeyHashesHandlerFactory', () => {
let proofFixture;
let proofMock;
let response;
let storeTreeProofs;

beforeEach(function beforeEach() {
publicKeyHash = '556c2910d46fda2b327ef9d9bda850cc84d30db0';
Expand All @@ -53,9 +55,12 @@ describe('getIdentityIdsByPublicKeyHashesHandlerFactory', () => {
storeTreeProof: Buffer.alloc(1, 2),
};

storeTreeProofs = new StoreTreeProofs();
storeTreeProofs.setDataContractsProof(proofFixture.storeTreeProof);

proofMock = new Proof();
proofMock.setRootTreeProof(proofFixture.rootTreeProof);
proofMock.setStoreTreeProof(proofFixture.storeTreeProof);
proofMock.setStoreTreeProofs(storeTreeProofs);

response = new GetIdentityIdsByPublicKeyHashesResponse();
response.setProof(proofMock);
Expand Down Expand Up @@ -105,10 +110,10 @@ describe('getIdentityIdsByPublicKeyHashesHandlerFactory', () => {

expect(proof).to.be.an.instanceOf(Proof);
const rootTreeProof = proof.getRootTreeProof();
const storeTreeProof = proof.getStoreTreeProof();
const resultStoreTreeProof = proof.getStoreTreeProofs();

expect(rootTreeProof).to.deep.equal(proofFixture.rootTreeProof);
expect(storeTreeProof).to.deep.equal(proofFixture.storeTreeProof);
expect(resultStoreTreeProof).to.deep.equal(storeTreeProofs);
});

it('should throw an InvalidArgumentGrpcError if no hashes were submitted', async () => {
Expand Down

0 comments on commit 99ec243

Please sign in to comment.