From 7012bd018c35cd85953a0446bddcfdc553213b77 Mon Sep 17 00:00:00 2001 From: Nebulis Date: Thu, 26 Dec 2019 16:12:58 +0800 Subject: [PATCH] chore: add tests for test function --- ...stationEthereumDocumentStoreIssued.test.ts | 38 +++++++++++++++- ...tationEthereumDocumentStoreRevoked.test.ts | 43 +++++++++++++++++-- ...stationEthereumTokenRegistryMinted.test.ts | 41 +++++++++++++++++- 3 files changed, 115 insertions(+), 7 deletions(-) diff --git a/src/verifiers/documentStoreIssued/openAttestationEthereumDocumentStoreIssued.test.ts b/src/verifiers/documentStoreIssued/openAttestationEthereumDocumentStoreIssued.test.ts index 78b1fbc7..4f291b32 100644 --- a/src/verifiers/documentStoreIssued/openAttestationEthereumDocumentStoreIssued.test.ts +++ b/src/verifiers/documentStoreIssued/openAttestationEthereumDocumentStoreIssued.test.ts @@ -3,10 +3,46 @@ import { documentRopstenValidWithCertificateStore } from "../../../test/fixtures import { documentRopstenNotIssuedWithDocumentStore } from "../../../test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore"; import { documentRopstenNotIssuedWithCertificateStore } from "../../../test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore"; import { documentRopstenValidWithDocumentStore as v2documentRopstenValidWithDocumentStore } from "../../../test/fixtures/v2/documentRopstenValidWithDocumentStore"; -import { documentRopstenValidWithDocumentStore } from "../../../test/fixtures/v3/documentRopstenValid"; +import { + documentRopstenValidWithDocumentStore, + documentRopstenValidWithTokenRegistry +} from "../../../test/fixtures/v3/documentRopstenValid"; import { documentRopstenNotIssued } from "../../../test/fixtures/v3/documentRopstenNotIssued"; +import { documentRopstenNotIssuedWithTokenRegistry } from "../../../test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry"; describe("openAttestationEthereumDocumentStoreIssued", () => { + describe("test", () => { + it("should return true when v2 document has at least one certificate store", () => { + const test = openAttestationEthereumDocumentStoreIssued.test(documentRopstenNotIssuedWithCertificateStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(true); + }); + it("should return true when v2 document has at least one document store", () => { + const test = openAttestationEthereumDocumentStoreIssued.test(documentRopstenNotIssuedWithDocumentStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(true); + }); + it("should return false when v2 document uses token registry", () => { + const test = openAttestationEthereumDocumentStoreIssued.test(documentRopstenNotIssuedWithTokenRegistry, { + network: "ropsten" + }); + expect(test).toStrictEqual(false); + }); + it("should return true when v3 document uses DOCUMENT_STORE method", () => { + const test = openAttestationEthereumDocumentStoreIssued.test(documentRopstenValidWithDocumentStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(true); + }); + it("should return false when v3 document uses TOKEN_REGISTRY method", () => { + const test = openAttestationEthereumDocumentStoreIssued.test(documentRopstenValidWithTokenRegistry, { + network: "ropsten" + }); + expect(test).toStrictEqual(false); + }); + }); describe("v2", () => { it("should return an invalid fragment when document with certificate store has not been issued", async () => { const fragment = await openAttestationEthereumDocumentStoreIssued.verify( diff --git a/src/verifiers/documentStoreRevoked/openAttestationEthereumDocumentStoreRevoked.test.ts b/src/verifiers/documentStoreRevoked/openAttestationEthereumDocumentStoreRevoked.test.ts index aaf27feb..eee616ef 100644 --- a/src/verifiers/documentStoreRevoked/openAttestationEthereumDocumentStoreRevoked.test.ts +++ b/src/verifiers/documentStoreRevoked/openAttestationEthereumDocumentStoreRevoked.test.ts @@ -3,12 +3,47 @@ import { documentRopstenRevokedWithDocumentStore } from "../../../test/fixtures/ import { documentRopstenNotIssuedWithDocumentStore } from "../../../test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore"; import { documentRopstenRevokedWithCertificateStore } from "../../../test/fixtures/v2/documentRopstenRevokedWithCertificateStore"; import { documentRopstenNotIssuedWithCertificateStore } from "../../../test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore"; -import { documentRopstenValidWithDocumentStore as v3documentRopstenValidWithDocumentStore } from "../../../test/fixtures/v3/documentRopstenValid"; +import { + documentRopstenValidWithDocumentStore as v3documentRopstenValidWithDocumentStore, + documentRopstenValidWithTokenRegistry +} from "../../../test/fixtures/v3/documentRopstenValid"; import { documentRopstenRevoked } from "../../../test/fixtures/v3/documentRopstenRevoked"; -import { openAttestationEthereumDocumentStoreIssued } from "../documentStoreIssued/openAttestationEthereumDocumentStoreIssued"; import { documentRopstenValidWithDocumentStore as v2documentRopstenValidWithDocumentStore } from "../../../test/fixtures/v2/documentRopstenValidWithDocumentStore"; +import { documentRopstenNotIssuedWithTokenRegistry } from "../../../test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry"; describe("openAttestationEthereumDocumentStoreRevoked", () => { + describe("test", () => { + it("should return true when v2 document has at least one certificate store", () => { + const test = openAttestationEthereumDocumentStoreRevoked.test(documentRopstenNotIssuedWithCertificateStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(true); + }); + it("should return true when v2 document has at least one document store", () => { + const test = openAttestationEthereumDocumentStoreRevoked.test(documentRopstenNotIssuedWithDocumentStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(true); + }); + it("should return false when v2 document uses token registry", () => { + const test = openAttestationEthereumDocumentStoreRevoked.test(documentRopstenNotIssuedWithTokenRegistry, { + network: "ropsten" + }); + expect(test).toStrictEqual(false); + }); + it("should return true when v3 document uses DOCUMENT_STORE method", () => { + const test = openAttestationEthereumDocumentStoreRevoked.test(v3documentRopstenValidWithDocumentStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(true); + }); + it("should return false when v3 document uses TOKEN_REGISTRY method", () => { + const test = openAttestationEthereumDocumentStoreRevoked.test(documentRopstenValidWithTokenRegistry, { + network: "ropsten" + }); + expect(test).toStrictEqual(false); + }); + }); describe("v2", () => { it("should return an invalid fragment when document with document store has been revoked", async () => { const fragment = await openAttestationEthereumDocumentStoreRevoked.verify( @@ -101,7 +136,7 @@ describe("openAttestationEthereumDocumentStoreRevoked", () => { }); }); it("should return an error fragment when document mixes document store and other verifier method", async () => { - const fragment = await openAttestationEthereumDocumentStoreIssued.verify( + const fragment = await openAttestationEthereumDocumentStoreRevoked.verify( { ...v2documentRopstenValidWithDocumentStore, data: { @@ -120,7 +155,7 @@ describe("openAttestationEthereumDocumentStoreRevoked", () => { } ); expect(fragment).toStrictEqual({ - name: "OpenAttestationEthereumDocumentStoreIssued", + name: "OpenAttestationEthereumDocumentStoreRevoked", type: "DOCUMENT_STATUS", data: new Error(`No document store for issuer "Foo Issuer"`), message: `No document store for issuer "Foo Issuer"`, diff --git a/src/verifiers/openAttestationEthereumTokenRegistryMinted.test.ts b/src/verifiers/openAttestationEthereumTokenRegistryMinted.test.ts index b1a8bcef..e17f2980 100644 --- a/src/verifiers/openAttestationEthereumTokenRegistryMinted.test.ts +++ b/src/verifiers/openAttestationEthereumTokenRegistryMinted.test.ts @@ -1,10 +1,47 @@ import { openAttestationEthereumTokenRegistryMinted } from "./openAttestationEthereumTokenRegistryMinted"; import { documentRopstenNotIssuedWithTokenRegistry } from "../../test/fixtures/v2/documentRopstenNotIssuedWithTokenRegistry"; import { documentRopstenValidWithToken } from "../../test/fixtures/v2/documentRopstenValidWithToken"; -import { documentRopstenValidWithTokenRegistry as v3documentRopstenValidWithTokenRegistry } from "../../test/fixtures/v3/documentRopstenValid"; +import { + documentRopstenValidWithDocumentStore as v3documentRopstenValidWithDocumentStore, + documentRopstenValidWithTokenRegistry as v3documentRopstenValidWithTokenRegistry +} from "../../test/fixtures/v3/documentRopstenValid"; import { documentRopstenNotIssuedWithTokenRegistry as v3documentRopstenNotIssuedWithTokenRegistry } from "../../test/fixtures/v3/documentRopstenNotIssuedWithTokenRegistry"; +import { documentRopstenNotIssuedWithCertificateStore } from "../../test/fixtures/v2/documentRopstenNotIssuedWithCertificateStore"; +import { documentRopstenNotIssuedWithDocumentStore } from "../../test/fixtures/v2/documentRopstenNotIssuedWithDocumentStore"; -describe("openAttestationEthereumTokenRegistryIssued", () => { +describe("openAttestationEthereumTokenRegistryMinted", () => { + describe("test", () => { + it("should return false when v2 document uses certificate store", () => { + const test = openAttestationEthereumTokenRegistryMinted.test(documentRopstenNotIssuedWithCertificateStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(false); + }); + it("should return false when v2 document uses document store", () => { + const test = openAttestationEthereumTokenRegistryMinted.test(documentRopstenNotIssuedWithDocumentStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(false); + }); + it("should return true when v2 document has at least one token registry", () => { + const test = openAttestationEthereumTokenRegistryMinted.test(documentRopstenNotIssuedWithTokenRegistry, { + network: "ropsten" + }); + expect(test).toStrictEqual(true); + }); + it("should return false when v3 document uses DOCUMENT_STORE method", () => { + const test = openAttestationEthereumTokenRegistryMinted.test(v3documentRopstenValidWithDocumentStore, { + network: "ropsten" + }); + expect(test).toStrictEqual(false); + }); + it("should return true when v3 document uses TOKEN_REGISTRY method", () => { + const test = openAttestationEthereumTokenRegistryMinted.test(v3documentRopstenNotIssuedWithTokenRegistry, { + network: "ropsten" + }); + expect(test).toStrictEqual(true); + }); + }); describe("v2", () => { it("should return an invalid fragment when document with token registry has not been minted", async () => { const fragment = await openAttestationEthereumTokenRegistryMinted.verify(