Skip to content

Commit

Permalink
feat: config other networks (#251)
Browse files Browse the repository at this point in the history
* feat: config other networks

* chore: gt way

* chore: comment
  • Loading branch information
simboonlong authored Jan 16, 2023
1 parent 0533caf commit 6b1c6b9
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 117 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ key
/.vscode/
/vc-test-suite
.DS_Store

# create config related
wallet.json
example-configs
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ There are 2 ways of using this command to generate a config file, both in which,

These are the reference config templates:

- [v2 config template](https://raw.githubusercontent.com/TradeTrust/tradetrust-config/master/build/config-reference-v2.json)
- [v3 config template](https://raw.githubusercontent.com/TradeTrust/tradetrust-config/master/build/config-reference-v3.json).
- [v2 config template](https://raw.githubusercontent.com/TradeTrust/tradetrust-config/master/build/reference/config-v2.json)
- [v3 config template](https://raw.githubusercontent.com/TradeTrust/tradetrust-config/master/build/reference/config-v3.json).

Step 1: Generate a wallet.json file & add funds into wallet.json

Expand Down
59 changes: 23 additions & 36 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@govtechsg/oa-verify": "^7.11.0",
"@govtechsg/open-attestation": "^6.4.1",
"@govtechsg/token-registry": "^2.5.3",
"@govtechsg/tradetrust-config": "^1.2.2",
"@govtechsg/tradetrust-config": "^1.2.3",
"ajv": "^8.4.0",
"ajv-formats": "^2.1.0",
"chalk": "^4.1.2",
Expand Down
17 changes: 13 additions & 4 deletions src/commands/networks.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { providers } from "ethers";

export type networkCurrency = "ETH" | "MATIC";

type SupportedNetwork = {
explorer: string;
provider: () => providers.Provider;
networkId: number;
networkName: string;
currency: networkCurrency;
};

export enum NetworkCmdName {
Local = "local",
Mainnet = "mainnet",
Goerli = "goerli",
Sepolia = "sepolia",
Polygon = "polygon",
Mumbai = "mumbai",
Matic = "matic",
Maticmum = "maticmum",
}

const defaultInfuraProvider =
Expand All @@ -34,36 +37,42 @@ export const supportedNetwork: {
provider: jsonRpcProvider("http://127.0.0.1:8545"),
networkId: 1337,
networkName: "local",
currency: "ETH",
},
[NetworkCmdName.Mainnet]: {
explorer: "https://etherscan.io",
provider: defaultInfuraProvider("homestead"),
networkId: 1,
networkName: "homestead",
currency: "ETH",
},
[NetworkCmdName.Goerli]: {
explorer: "https://goerli.etherscan.io",
provider: defaultInfuraProvider("goerli"),
networkId: 5,
networkName: "goerli",
currency: "ETH",
},
[NetworkCmdName.Sepolia]: {
explorer: "https://sepolia.etherscan.io",
provider: jsonRpcProvider("https://rpc.sepolia.org"),
networkId: 11155111,
networkName: "sepolia",
currency: "ETH",
},
[NetworkCmdName.Polygon]: {
[NetworkCmdName.Matic]: {
explorer: "https://polygonscan.com",
provider: defaultInfuraProvider("matic"),
networkId: 137,
networkName: "matic",
currency: "MATIC",
},
[NetworkCmdName.Mumbai]: {
[NetworkCmdName.Maticmum]: {
explorer: "https://mumbai.polygonscan.com",
provider: defaultInfuraProvider("maticmum"),
networkId: 80001,
networkName: "maticmum",
currency: "MATIC",
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/implementations/config/__tests__/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NetworkCmdName } from "../../../commands/networks";
import { deployDocumentStore } from "../../deploy/document-store/document-store";
import { deployTokenRegistry } from "../../deploy/token-registry/token-registry";
import { create as createConfig } from "../create";
import expectedConfigFileOutput from "./expected-config-file-output.json";
import expectedConfigFileOutput from "./expected-config-file-output-v2.json";
import inputConfigFile from "./input-config-file.json";

const mockInputConfigFile = inputConfigFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
"name": "DEMO TOKEN REGISTRY",
"tokenRegistry": "0x620c1DC991E3E2585aFbaA61c762C0369D70C89D"
}
]
],
"network": {
"chainId": "5",
"chain": "ETH"
}
}
},
{
Expand All @@ -38,7 +42,11 @@
"location": "alert-cyan-stoat.sandbox.openattestation.com"
}
}
]
],
"network": {
"chainId": "5",
"chain": "ETH"
}
}
},
{
Expand All @@ -58,7 +66,11 @@
"key": "did:ethr:0x709731d94d65b078496937655582401157c8a640#controller"
}
}
]
],
"network": {
"chainId": "5",
"chain": "ETH"
}
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"id": "https://example.com",
"name": "DEMO TOKEN REGISTRY",
"type": "OpenAttestationIssuer"
},
"network": {
"chainId": "5",
"chain": "ETH"
}
},
"schema": {
Expand Down Expand Up @@ -180,6 +184,10 @@
"id": "https://example.com",
"name": "DEMO DOCUMENT STORE",
"type": "OpenAttestationIssuer"
},
"network": {
"chainId": "5",
"chain": "ETH"
}
},
"schema": {
Expand Down Expand Up @@ -645,6 +653,10 @@
"id": "https://example.com",
"name": "DEMO DNS-DID",
"type": "OpenAttestationIssuer"
},
"network": {
"chainId": "5",
"chain": "ETH"
}
},
"schema": {
Expand Down Expand Up @@ -819,6 +831,10 @@
"id": "https://example.com",
"name": "DEMO DOCUMENT STORE",
"type": "OpenAttestationIssuer"
},
"network": {
"chainId": "5",
"chain": "ETH"
}
},
"schema": {
Expand Down
58 changes: 10 additions & 48 deletions src/implementations/config/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import { NetworkCmdName } from "../../../commands/networks";
import {
getConfigFile,
getConfigWithUpdatedDocumentStorage,
getConfigWithUpdatedForms,
getConfigWithUpdatedNetwork,
getConfigWithUpdatedWallet,
} from "../helpers";
import { ConfigFile } from "../types";
import ConfigFileV3 from "./config-reference-v3.json";
import expectedConfigFileOutputV3 from "./expected-config-file-output-v3.json";
import expectedConfigFileOutputV2 from "./expected-config-file-output.json";
import expectedConfigFileOutputV2 from "./expected-config-file-output-v2.json";
import ConfigFileV2 from "./input-config-file.json";
import wallet from "./wallet.json";

describe("getConfigFile", () => {
it("should return the config file when given a configTemplateUrl", async () => {
const config = await getConfigFile(
"",
"https://raw.githubusercontent.com/TradeTrust/tradetrust-config/master/build/config-reference-v3.json"
"https://raw.githubusercontent.com/TradeTrust/tradetrust-config/master/build/reference/config-v3.json"
);

expect(config).toStrictEqual(ConfigFileV3);
Expand All @@ -41,51 +40,6 @@ describe("getConfigWithUpdatedNetwork", () => {
});
});

describe("getConfigWithUpdatedDocumentStorage", () => {
it("should remove document storage in the config file if network is not 'goerli' for V2", () => {
const config = { ...ConfigFileV2 };
expect(
getConfigWithUpdatedDocumentStorage({ configFile: config as ConfigFile, network: NetworkCmdName.Sepolia })
.documentStorage
).toBeUndefined();
});

it("should remove document storage in the config file if network is not 'goerli' for V3", () => {
const config = { ...ConfigFileV3 };
expect(
getConfigWithUpdatedDocumentStorage({
configFile: config as ConfigFile,
network: NetworkCmdName.Sepolia,
}).documentStorage
).toBeUndefined();
});

it("should not remove document storage in the config file if network is 'goerli' for V2", () => {
const config = { ...ConfigFileV2 };
expect(
getConfigWithUpdatedDocumentStorage({
configFile: config as ConfigFile,
network: NetworkCmdName.Goerli,
}).documentStorage
).toStrictEqual({
apiKey: "randomKey",
url: "https://tradetrust-functions.netlify.app/.netlify/functions/storage",
});
});
it("should not remove document storage in the config file if network is 'goerli' for V3", () => {
const config = { ...ConfigFileV3 };
expect(
getConfigWithUpdatedDocumentStorage({
configFile: config as ConfigFile,
network: NetworkCmdName.Goerli,
}).documentStorage
).toStrictEqual({
apiKey: "randomKey",
url: "https://tradetrust-functions.netlify.app/.netlify/functions/storage",
});
});
});

describe("getConfigWithUpdatedWallet", () => {
it("should update config file with wallet string for V2", () => {
expect(
Expand All @@ -109,6 +63,10 @@ describe("getConfigWithUpdatedForms", () => {
});
const config = getConfigWithUpdatedForms({
configFile: configWithWallet as ConfigFile,
chain: {
id: "5",
currency: "ETH",
},
documentStoreAddress: "0xC378aBE13cf18a64fB2f913647bd4Fe054C9eaEd",
tokenRegistryAddress: "0x620c1DC991E3E2585aFbaA61c762C0369D70C89D",
dnsVerifiable: "alert-cyan-stoat.sandbox.openattestation.com",
Expand All @@ -125,6 +83,10 @@ describe("getConfigWithUpdatedForms", () => {
});
const config = getConfigWithUpdatedForms({
configFile: configWithWallet as ConfigFile,
chain: {
id: "5",
currency: "ETH",
},
documentStoreAddress: "0xC378aBE13cf18a64fB2f913647bd4Fe054C9eaEd",
tokenRegistryAddress: "0x620c1DC991E3E2585aFbaA61c762C0369D70C89D",
dnsVerifiable: "alert-cyan-stoat.sandbox.openattestation.com",
Expand Down
Loading

0 comments on commit 6b1c6b9

Please sign in to comment.