From 811c92d77c4f37a73935f41a8126f10764451765 Mon Sep 17 00:00:00 2001 From: Nebulis Date: Wed, 2 Oct 2019 16:21:26 +0800 Subject: [PATCH] fix: esm build --- src/common/documentStore.integration.test.ts | 87 ------------------- src/common/documentStore.ts | 21 ----- .../smartContract/issuerToSmartContract.ts | 4 +- tsconfig.json | 3 +- 4 files changed, 4 insertions(+), 111 deletions(-) delete mode 100644 src/common/documentStore.integration.test.ts delete mode 100644 src/common/documentStore.ts diff --git a/src/common/documentStore.integration.test.ts b/src/common/documentStore.integration.test.ts deleted file mode 100644 index e73892b6..00000000 --- a/src/common/documentStore.integration.test.ts +++ /dev/null @@ -1,87 +0,0 @@ -/** - * @jest-environment node - */ -import { documentStore } from "./documentStore"; - -describe("documentStoreApi(integration)", () => { - it("should reject if the contract is not deployed", async () => { - await expect( - documentStore({ - storeAddress: "0x0000000000000000000000000000000000000000", - method: "isIssued", - args: [ - "0x0000000000000000000000000000000000000000000000000000000000000000" - ], - network: "homestead" - }) - ).rejects.toThrow("contract not deployed"); - }); - - it("should reject for args not conforming to ABI", async () => { - await expect( - documentStore({ - storeAddress: "0x007d40224f6562461633ccfbaffd359ebb2fc9ba", - method: "isIssued", - args: ["0000"], - network: "homestead" - }) - ).rejects.toThrow("invalid input argument"); - }); - - it("should reject for undefined function", async () => { - await expect( - documentStore({ - storeAddress: "0x007d40224f6562461633ccfbaffd359ebb2fc9ba", - method: "foobar", - args: [ - "0x0000000000000000000000000000000000000000000000000000000000000000" - ], - network: "homestead" - }) - ).rejects.toThrow("Cannot read property 'apply' of undefined"); - }); - - it("should works for isIssued", async () => { - const issuedStatus = await documentStore({ - storeAddress: "0x007d40224f6562461633ccfbaffd359ebb2fc9ba", - method: "isIssued", - args: [ - "0x1a040999254caaf7a33cba67ec6a9b862da1dacf8a0d1e3bb76347060fc615d6" - ], - network: "homestead" - }); - expect(issuedStatus).toBe(true); - - const notIssuedStatus = await documentStore({ - storeAddress: "0x007d40224f6562461633ccfbaffd359ebb2fc9ba", - method: "isIssued", - args: [ - "0x0000000000000000000000000000000000000000000000000000000000000000" - ], - network: "homestead" - }); - expect(notIssuedStatus).toBe(false); - }); - - it("should works for isRevoked", async () => { - const revokedStatus = await documentStore({ - storeAddress: "0x007d40224f6562461633ccfbaffd359ebb2fc9ba", - method: "isRevoked", - args: [ - "0x0000000000000000000000000000000000000000000000000000000000000001" - ], - network: "homestead" - }); - expect(revokedStatus).toBe(true); - - const notRevokedStatus = await documentStore({ - storeAddress: "0x007d40224f6562461633ccfbaffd359ebb2fc9ba", - method: "isRevoked", - args: [ - "0x0000000000000000000000000000000000000000000000000000000000000000" - ], - network: "homestead" - }); - expect(notRevokedStatus).toBe(false); - }); -}); diff --git a/src/common/documentStore.ts b/src/common/documentStore.ts deleted file mode 100644 index 35b7724b..00000000 --- a/src/common/documentStore.ts +++ /dev/null @@ -1,21 +0,0 @@ -import * as ethers from "ethers"; -import * as abi from "./smartContract/abi/documentStore.json"; -import { INFURA_API_KEY } from "../config"; -import { Hash } from "../types"; - -interface DocumentStore { - network: string; - storeAddress: Hash; - method: string; - args: any; -} -export const documentStore = async ({ - network, - storeAddress, - method, - args -}: DocumentStore) => { - const provider = new ethers.providers.InfuraProvider(network, INFURA_API_KEY); - const contract = new ethers.Contract(storeAddress, abi, provider); - return contract.functions[method](...args); -}; diff --git a/src/common/smartContract/issuerToSmartContract.ts b/src/common/smartContract/issuerToSmartContract.ts index a98bf9ac..340f8caa 100644 --- a/src/common/smartContract/issuerToSmartContract.ts +++ b/src/common/smartContract/issuerToSmartContract.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { contractInstance } from "./contractInstance"; import { TYPES } from "./constants"; -import * as tokenRegistryAbi from "./abi/tokenRegistry.json"; -import * as documentStoreAbi from "./abi/documentStore.json"; +import tokenRegistryAbi from "./abi/tokenRegistry.json"; +import documentStoreAbi from "./abi/documentStore.json"; import { Issuer, OpenAttestationContract } from "../../types"; export const issuerToSmartContract = ( diff --git a/tsconfig.json b/tsconfig.json index bc3cbaec..ed1cc3af 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,8 @@ "baseUrl": ".", "skipLibCheck": true, "resolveJsonModule": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "esModuleInterop": true }, "include": ["./src/**/*"] }