Skip to content

Commit

Permalink
chore: add tests and fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebulis committed Dec 24, 2019
1 parent 8247ea0 commit 0d43910
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/issued/contractInterface.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
} from "../common/smartContract/documentToSmartContracts";
import { documentRopstenRevokedWithToken } from "../../test/fixtures/v2/documentRopstenRevokedWithToken";
import { documentRopstenValidWithCertificateStore } from "../../test/fixtures/v2/documentRopstenValidWithCertificateStore";
import { documentRopstenNotIssuedWithCertificateStore } from "../../test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore";
import { documentRopstenWithNonDeployedDocumentStore } from "../../test/fixtures/v2/documentRopstenWithNonDeployedDocumentStore";
import { documentRopstenValidWithToken } from "../../test/fixtures/v2/documentRopstenValidWithToken";

Expand Down
2 changes: 1 addition & 1 deletion src/issued/verify.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Contract } from "ethers";
import { v3 } from "@govtechsg/open-attestation";
import { isIssuedOnAll, issuedStatusOnContracts, verifyIssued } from "./verify";
import { isIssued } from "./contractInterface";
import { OpenAttestationContract } from "../types/core";
import { v3 } from "@govtechsg/open-attestation";

jest.mock("./contractInterface");

Expand Down
2 changes: 1 addition & 1 deletion src/revoked/contractInterface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { constants } from "ethers";
import { Hash, OpenAttestationContract } from "../types/core";
import { v3 } from "@govtechsg/open-attestation";
import { Hash, OpenAttestationContract } from "../types/core";

export const isRevokedOnTokenRegistry = async (
smartContract: OpenAttestationContract,
Expand Down
13 changes: 12 additions & 1 deletion src/verify.v2.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @jest-environment node
*/

import { verify } from "./index";
import { isValid, verify } from "./index";
import { documentMainnetValidWithCertificateStore } from "../test/fixtures/v2/documentMainnetValidWithCertificateStore";
import { tamperedDocumentWithCertificateStore } from "../test/fixtures/v2/tamperedDocument";
import { documentRopstenValidWithCertificateStore } from "../test/fixtures/v2/documentRopstenValidWithCertificateStore";
Expand Down Expand Up @@ -69,6 +69,8 @@ describe("verify(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY"])).toStrictEqual(false);
});

it("should be valid for all checks when document with certificate store is valid on mainnet", async () => {
Expand Down Expand Up @@ -126,6 +128,9 @@ describe("verify(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
// it's not valid on ISSUER_IDENTITY (skipped) so making sure the rest is valid
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"])).toStrictEqual(true);
});

it("should be valid for all checks when document with certificate store is valid on ropsten", async () => {
Expand Down Expand Up @@ -183,6 +188,9 @@ describe("verify(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
// it's not valid on ISSUER_IDENTITY (skipped) so making sure the rest is valid
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"])).toStrictEqual(true);
});

it("should be valid for all checks when document with token registry is valid on ropsten", async () => {
Expand Down Expand Up @@ -240,6 +248,7 @@ describe("verify(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
expect(isValid(results)).toStrictEqual(true);
});

it("should fail for OpenAttestationEthereumTokenRegistryMinted when document with token registry was not issued ", async () => {
Expand Down Expand Up @@ -300,5 +309,7 @@ describe("verify(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"])).toStrictEqual(false);
});
});
14 changes: 13 additions & 1 deletion src/verify.v3.integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { verify } from "./index";
import { isValid, verify } from "./index";
import {
documentRopstenValidWithDocumentStore,
documentRopstenValidWithTokenRegistry
Expand Down Expand Up @@ -67,6 +67,8 @@ describe("verify v3(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"])).toStrictEqual(false);
});
it("should fail for OpenAttestationEthereumDocumentStoreIssued when document was not issued and OpenAttestationDnsTxt when identity is invalid", async () => {
const results = await verify(documentRopstenNotIssued, { network: "ropsten" });
Expand Down Expand Up @@ -127,6 +129,8 @@ describe("verify v3(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"])).toStrictEqual(false);
});

it("should fail for OpenAttestationEthereumDocumentStoreRevoked when document was not issued and OpenAttestationDnsTxt when identity is invalid", async () => {
Expand Down Expand Up @@ -188,6 +192,8 @@ describe("verify v3(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"])).toStrictEqual(false);
});

it("should fail for OpenAttestationDnsTxt when identity is invalid and be valid for remaining checks when document with certificate store is valid on ropsten", async () => {
Expand Down Expand Up @@ -248,6 +254,9 @@ describe("verify v3(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
// it's not valid on ISSUER_IDENTITY (skipped) so making sure the rest is valid
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"])).toStrictEqual(true);
});

it("should fail for OpenAttestationDnsTxt when identity is invalid and be valid for remaining checks when document with token registry is valid on ropsten", async () => {
Expand Down Expand Up @@ -302,5 +311,8 @@ describe("verify v3(integration)", () => {
type: "ISSUER_IDENTITY"
}
]);
// it's not valid on ISSUER_IDENTITY (skipped) so making sure the rest is valid
expect(isValid(results)).toStrictEqual(false);
expect(isValid(results, ["DOCUMENT_INTEGRITY", "DOCUMENT_STATUS"])).toStrictEqual(true);
});
});

0 comments on commit 0d43910

Please sign in to comment.