Skip to content

Commit

Permalink
feat: use Chain enum from ew-did-reg/did
Browse files Browse the repository at this point in the history
Using in e2e tests and chain.config
Will make it easier to see where the chain name is referred to
Also helps with refactoring
  • Loading branch information
jrhender committed Dec 6, 2021
1 parent b98dbf8 commit 00aeab1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
12 changes: 6 additions & 6 deletions e2e/claims.service.e2e.ts
@@ -1,5 +1,5 @@
import { IRoleDefinition, PreconditionType } from "@energyweb/iam-contracts";
import { Methods } from "@ew-did-registry/did";
import { Methods, Chain } from "@ew-did-registry/did";
import { addressOf } from "@ew-did-registry/did-ethr-resolver";
import { KeyTags } from "@ew-did-registry/did-resolver-interface";
import { ethers, providers, utils, Wallet } from "ethers";
Expand All @@ -25,11 +25,11 @@ const { namehash } = utils;

const provider = new providers.JsonRpcProvider(rpcUrl);
const staticIssuer = Wallet.createRandom().connect(provider);
const staticIssuerDID = `did:${Methods.Erc1056}:volta:${staticIssuer.address}`;
const staticIssuerDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${staticIssuer.address}`;
const dynamicIssuer = Wallet.createRandom().connect(provider);
const dynamicIssuerDID = `did:${Methods.Erc1056}:volta:${dynamicIssuer.address}`;
const dynamicIssuerDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${dynamicIssuer.address}`;
const rootOwner = Wallet.createRandom().connect(provider);
const rootOwnerDID = `did:${Methods.Erc1056}:volta:${rootOwner.address}`;
const rootOwnerDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${rootOwner.address}`;
const roleName1 = "myrole1";
const roleName2 = "myrole2";
const roleName3 = "myrole3";
Expand Down Expand Up @@ -67,7 +67,7 @@ const mockGetRoleDefinition = jest.fn().mockImplementation((namespace: string) =
return roles[namespace];
});
const mockGetDidDocument = jest.fn().mockImplementation((did: string) => {
return { publicKey: [{ id: `did:ethr:volta:${did}-${KeyTags.OWNER}` }] }; // all documents are created
return { publicKey: [{ id: `did:${Methods.Erc1056}:${Chain.VOLTA}:${did}-${KeyTags.OWNER}` }] }; // all documents are created
});
const mockGetAssetById = jest.fn();
const mockGetClaimsBySubject = jest.fn();
Expand Down Expand Up @@ -212,7 +212,7 @@ describe("Enrollment claim tests", () => {
mockGetAssetById.mockImplementationOnce(({ id }: { id: string }) => ({ id }));
await signerService.connect(rootOwner, ProviderType.PrivateKey);
const assetAddress = await assetsService.registerAsset();
const assetDID = `did:${Methods.Erc1056}:volta:${assetAddress}`;
const assetDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${assetAddress}`;
await enrolAndIssue(rootOwner, staticIssuer, { subjectDID: assetDID, claimType: `${roleName1}.${root}` });

return expect(claimsService.hasOnChainRole(assetDID, `${roleName1}.${root}`, version)).resolves.toBe(true);
Expand Down
4 changes: 2 additions & 2 deletions e2e/domains.service.e2e.ts
@@ -1,6 +1,6 @@
import { utils, Wallet } from "ethers";
import { IRoleDefinition, PreconditionType } from "@energyweb/iam-contracts";
import { Methods } from "@ew-did-registry/did";
import { Methods, Chain } from "@ew-did-registry/did";
import {
DomainsService,
initWithPrivateKeySigner,
Expand Down Expand Up @@ -92,7 +92,7 @@ describe("Domains service", () => {
issuerFields: [],
issuer: {
issuerType: "DID",
did: [`did:${Methods.Erc1056}:volta:${rootOwner.address}`],
did: [`did:${Methods.Erc1056}:${Chain.VOLTA}:${rootOwner.address}`],
},
metadata: [],
roleName,
Expand Down
5 changes: 3 additions & 2 deletions e2e/staking-pool.e2e.ts
@@ -1,4 +1,5 @@
import { KeyTags } from "@ew-did-registry/did-resolver-interface";
import { Chain } from "@ew-did-registry/did";
import { BigNumber, providers, utils, Wallet } from "ethers";
import {
chainConfigs,
Expand Down Expand Up @@ -32,7 +33,7 @@ jest.mock("../src/modules/messaging/messaging.service", () => {

const mockGetRoleDefinition = jest.fn();
const mockGetDidDocument = jest.fn().mockImplementation(({ did }: { did: string }) => {
return { publicKey: [{ id: `did:ethr:volta:${did}-${KeyTags.OWNER}` }] };
return { publicKey: [{ id: `did:ethr:${Chain.VOLTA}:${did}-${KeyTags.OWNER}` }] };
});
const mockGetApplicationsByOrgNamespace = jest.fn();

Expand Down Expand Up @@ -83,7 +84,7 @@ export const setupStakingPoolFactory = async () => {
value: rewards,
});

setChainConfig(chainId, { stakingPoolFactoryAddress: stakingPoolFactory.address, chainName: "volta" });
setChainConfig(chainId, { stakingPoolFactoryAddress: stakingPoolFactory.address, chainName: Chain.VOLTA });
};

const putStake = async (pool: StakingPoolService, amount: number | BigNumber, withAmountCheck = true) => {
Expand Down
8 changes: 4 additions & 4 deletions e2e/staking.pool.e2e.ts
@@ -1,5 +1,5 @@
import { IRoleDefinition } from "@energyweb/iam-contracts";
import { Methods } from "@ew-did-registry/did";
import { Methods, Chain } from "@ew-did-registry/did";
import { KeyTags } from "@ew-did-registry/did-resolver-interface";

import { BigNumber, providers, utils, Wallet } from "ethers";
Expand Down Expand Up @@ -28,9 +28,9 @@ const patronRole = "patronrole";
const provider = new providers.JsonRpcProvider(rpcUrl);
const rootOwner = Wallet.createRandom().connect(provider);
const orgOwner = Wallet.createRandom().connect(provider);
const orgOwnerDid = `did:${Methods.Erc1056}:volta:${orgOwner.address}`;
const orgOwnerDid = `did:${Methods.Erc1056}:${Chain.VOLTA}:${orgOwner.address}`;
const patron = Wallet.createRandom().connect(provider);
const patronDID = `did:${Methods.Erc1056}:volta:${patron.address}`;
const patronDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${patron.address}`;
MessagingService.create = (signerService: SignerService) => Promise.resolve(new MessagingService(signerService));
const mockPublish = jest.fn();
jest.mock("../src/modules/messaging/messaging.service", () => {
Expand All @@ -43,7 +43,7 @@ jest.mock("../src/modules/messaging/messaging.service", () => {

const mockGetRoleDefinition = jest.fn();
const mockGetDidDocument = jest.fn().mockImplementation(({ did }: { did: string }) => {
return { publicKey: [{ id: `did:ethr:volta:${did}-${KeyTags.OWNER}` }] };
return { publicKey: [{ id: `did:${Methods.Erc1056}:${Chain.VOLTA}:${did}-${KeyTags.OWNER}` }] };
});
const mockGetApplicationsByOrgNamespace = jest.fn();
const mockRequestClaim = jest.fn();
Expand Down
8 changes: 4 additions & 4 deletions e2e/staking.service.e2e.ts
@@ -1,6 +1,6 @@
import { providers, Wallet } from "ethers";
import { IRoleDefinition } from "@energyweb/iam-contracts";
import { Methods } from "@ew-did-registry/did";
import { Methods, Chain } from "@ew-did-registry/did";
import { KeyTags } from "@ew-did-registry/did-resolver-interface";
import { StakingService } from "../src/modules/staking/staking.service";
import { ProviderType } from "../src/modules/signer/signer.types";
Expand All @@ -21,9 +21,9 @@ const domain = `${orgName}.${root}`;
const provider = new providers.JsonRpcProvider(rpcUrl);
const rootOwner = Wallet.createRandom().connect(provider);
const orgOwner = Wallet.createRandom().connect(provider);
const orgOwnerDid = `did:${Methods.Erc1056}:volta:${orgOwner.address}`;
const orgOwnerDid = `did:${Methods.Erc1056}:${Chain.VOLTA}:${orgOwner.address}`;
const patron = Wallet.createRandom().connect(provider);
const patronDID = `did:${Methods.Erc1056}:volta:${patron.address}`;
const patronDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${patron.address}`;

MessagingService.create = (signerService: SignerService) => Promise.resolve(new MessagingService(signerService));
const mockPublish = jest.fn();
Expand All @@ -37,7 +37,7 @@ jest.mock("../src/modules/messaging/messaging.service", () => {

const mockGetRoleDefinition = jest.fn();
const mockGetDidDocument = jest.fn().mockImplementation(({ did }: { did: string }) => {
return { publicKey: [{ id: `did:ethr:volta:${did}-${KeyTags.OWNER}` }] };
return { publicKey: [{ id: `did:${Methods.Erc1056}:${Chain.VOLTA}:${did}-${KeyTags.OWNER}` }] };
});
const mockGetApplicationsByOrgNamespace = jest.fn();
const mockRequestClaim = jest.fn();
Expand Down
3 changes: 2 additions & 1 deletion e2e/utils/setup_contracts.ts
@@ -1,5 +1,6 @@
import { ContractFactory, Contract, providers, utils, BigNumber } from "ethers";
import { ethrReg } from "@ew-did-registry/did-ethr-resolver";
import { Chain } from "@ew-did-registry/did";
import { DomainNotifier__factory } from "../../ethers/factories/DomainNotifier__factory";
import type { DomainNotifier } from "../../ethers/DomainNotifier";
import { RoleDefinitionResolver__factory } from "../../ethers/factories/RoleDefinitionResolver__factory";
Expand Down Expand Up @@ -79,7 +80,7 @@ export const setupENS = async (rootOwner: string) => {
const { chainId } = await provider.getNetwork();
setChainConfig(chainId, {
rpcUrl,
chainName: "volta",
chainName: Chain.VOLTA,
ensRegistryAddress: ensRegistry.address,
ensResolverAddress: ensResolver.address,
didRegistryAddress: didRegistry.address,
Expand Down
3 changes: 2 additions & 1 deletion e2e/utils/staking.ts
Expand Up @@ -2,6 +2,7 @@ import { BigNumber, utils } from "ethers";
import { deployer, replenish } from "./setup_contracts";
import { StakingPoolFactory__factory } from "../../ethers/factories/StakingPoolFactory__factory";
import { chainConfigs, setChainConfig } from "../../src/config/chain.config";
import { Chain } from "@ew-did-registry/did";

const { parseEther } = utils;

Expand All @@ -21,7 +22,7 @@ export async function setupStakingPoolFactory(withdrawDelay = defaultWithdrawDel
).deployed();
const rewardPoolAddress = await stakingPoolFactory.rewardPool();
await replenish(rewardPoolAddress);
setChainConfig(chainId, { stakingPoolFactoryAddress: stakingPoolFactory.address, chainName: "volta" });
setChainConfig(chainId, { stakingPoolFactoryAddress: stakingPoolFactory.address, chainName: Chain.VOLTA });
}

export const calculateReward = (
Expand Down
3 changes: 2 additions & 1 deletion src/config/chain.config.ts
@@ -1,4 +1,5 @@
import { VoltaAddress1056 } from "@ew-did-registry/did-ethr-resolver";
import { Chain } from "@ew-did-registry/did";
import {
VOLTA_DOMAIN_NOTIFER_ADDRESS,
VOLTA_ENS_REGISTRY_ADDRESS,
Expand Down Expand Up @@ -32,7 +33,7 @@ export type ChainId = number;
*/
const chainConfig: Record<number, ChainConfig> = {
[VOLTA_CHAIN_ID]: {
chainName: "volta",
chainName: Chain.VOLTA,
chainDisplayName: "Energy Web Volta Testnet",
rpcUrl: "https://volta-rpc.energyweb.org",
ensRegistryAddress: VOLTA_ENS_REGISTRY_ADDRESS,
Expand Down

0 comments on commit 00aeab1

Please sign in to comment.