Skip to content

Commit

Permalink
fixed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
satyajeetkolhapure committed Nov 15, 2024
1 parent 8061fb7 commit 556c026
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 141 deletions.
2 changes: 1 addition & 1 deletion contracts/src/ModuleRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract ModuleRegistry is OwnableUpgradeable {
IRouter public router;
/// @dev The list of Modules, accessed by their address
mapping(address id => Module module) public modules;
/// @dev The list of Module addresses
/// @dev Deprecated: The `moduleAddresses` variable is no longer used. It was used to store the modules addresses.
address[] public moduleAddresses;

/// @notice Error thrown when an invalid Router address is given
Expand Down
1 change: 1 addition & 0 deletions contracts/src/PortalRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contract PortalRegistry is OwnableUpgradeable {

mapping(address issuerAddress => bool isIssuer) private issuers;

/// @dev Deprecated: The `portalAddresses` variable is no longer used. It was used to store the portals addresses.
address[] private portalAddresses;

bool private isTestnet;
Expand Down
2 changes: 1 addition & 1 deletion contracts/src/SchemaRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract SchemaRegistry is OwnableUpgradeable {
IRouter public router;
/// @dev The list of Schemas, accessed by their ID
mapping(bytes32 id => Schema schema) private schemas;
/// @dev The list of Schema IDs
/// @dev Deprecated: The `schemaIds` variable is no longer used. It was used to store the ids of schemas.
bytes32[] public schemaIds;
/// @dev Associates a Schema ID with the address of the Issuer who created it
mapping(bytes32 id => address issuer) private schemasIssuers;
Expand Down
4 changes: 0 additions & 4 deletions sdk/doc/cli-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@

pnpm module isRegistered "0x8DcC1F7e746D6071Eb3ee9012aFB6c707bFf82a5"

pnpm module getModuleAddress 0

pnpm module getModule "0x8DcC1F7e746D6071Eb3ee9012aFB6c707bFf82a5"
```

Expand Down Expand Up @@ -151,8 +149,6 @@
pnpm schema getSchemasNumber

pnpm schema isRegistered "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738"

pnpm schema getSchemaIds 0
```

</details>
5 changes: 0 additions & 5 deletions sdk/examples/module/moduleExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ export default class ModuleExamples {
console.log(await this.veraxSdk.module.isRegistered(moduleAddress));
}

if (methodName.toLowerCase() == "getModuleAddress".toLowerCase() || methodName == "") {
const index: number = argv === "" ? 0 : (argv as unknown as number);
console.log(await this.veraxSdk.module.getModuleAddress(index));
}

if (methodName.toLowerCase() == "getModule".toLowerCase() || methodName == "") {
const moduleAddress: Address = argv === "" ? "0x8DcC1F7e746D6071Eb3ee9012aFB6c707bFf82a5" : (argv as Address);
console.log(await this.veraxSdk.module.getModule(moduleAddress));
Expand Down
5 changes: 0 additions & 5 deletions sdk/examples/schema/schemaExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,5 @@ export default class SchemaExamples {
argv === "" ? "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738" : argv;
console.log(await this.veraxSdk.schema.isRegistered(schemaId));
}

if (methodName.toLowerCase() == "getSchemaIds".toLowerCase() || methodName == "") {
const index: number = argv === "" ? 0 : (argv as unknown as number);
console.log(await this.veraxSdk.schema.getSchemaIds(index));
}
}
}
24 changes: 8 additions & 16 deletions sdk/src/dataMapper/ModuleDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ModuleDataMapper extends BaseDataMapper<Module, Module_filt
}`;

async simulateUpdateRouter(routerAddress: Address) {
return await this.simulateContract("updateRouter", [routerAddress]);
return this.simulateContract("updateRouter", [routerAddress]);
}

async updateRouter(routerAddress: Address, waitForConfirmation: boolean = false) {
Expand All @@ -27,7 +27,7 @@ export default class ModuleDataMapper extends BaseDataMapper<Module, Module_filt
}

async simulateRegister(name: string, description: string, moduleAddress: Address) {
return await this.simulateContract("register", [name, description, moduleAddress]);
return this.simulateContract("register", [name, description, moduleAddress]);
}

async register(name: string, description: string, moduleAddress: Address, waitForConfirmation: boolean = false) {
Expand Down Expand Up @@ -85,11 +85,7 @@ export default class ModuleDataMapper extends BaseDataMapper<Module, Module_filt
attestationData,
]);
}
return await this.simulateContract("bulkRunModules", [
modulesAddresses,
attestationPayloadsArg,
validationPayloads,
]);
return this.simulateContract("bulkRunModules", [modulesAddresses, attestationPayloadsArg, validationPayloads]);
}

async bulkRunModules(
Expand All @@ -103,27 +99,23 @@ export default class ModuleDataMapper extends BaseDataMapper<Module, Module_filt
}

async isContractAddress(contractAddress: Address) {
return await this.executeReadMethod("isContractAddress", [contractAddress]);
return this.executeReadMethod("isContractAddress", [contractAddress]);
}

async getModulesNumber() {
return await super.findTotalCount();
return super.findTotalCount();
}

async isRegistered(moduleAddress: Address) {
return await this.executeReadMethod("isRegistered", [moduleAddress]);
}

async getModuleAddress(index: number) {
return await this.executeReadMethod("moduleAddresses", [index]);
return this.executeReadMethod("isRegistered", [moduleAddress]);
}

async getModule(moduleAddress: Address) {
return await this.executeReadMethod("modules", [moduleAddress]);
return this.executeReadMethod("modules", [moduleAddress]);
}

private async executeReadMethod(functionName: string, args: unknown[]) {
return await this.web3Client.readContract({
return this.web3Client.readContract({
abi: abiModuleRegistry,
address: this.conf.moduleRegistryAddress,
functionName,
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/dataMapper/PortalDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ export default class PortalDataMapper extends BaseDataMapper<Portal, Portal_filt
return this.executePortalRegistryReadMethod("getPortalByAddress", [id]);
}

async getPortalsNumber() {
return super.findTotalCount();
}

async isPortalRegistered(id: Address) {
return this.executePortalRegistryReadMethod("isRegistered", [id]);
}
Expand Down
6 changes: 1 addition & 5 deletions sdk/src/dataMapper/SchemaDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,13 @@ export default class SchemaDataMapper extends BaseDataMapper<Schema, Schema_filt
}

async getSchemasNumber() {
return await super.findTotalCount();
return super.findTotalCount();
}

async isRegistered(schemaId: string) {
return this.executeReadMethod("isRegistered", [schemaId]);
}

async getSchemaIds(index: number) {
return this.executeReadMethod("schemaIds", [index]);
}

private async executeReadMethod(functionName: string, args: unknown[]) {
return this.web3Client.readContract({
abi: abiSchemaRegistry,
Expand Down
71 changes: 0 additions & 71 deletions sdk/src/dataMapper/UtilsDataMapper.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import UtilsDataMapper from "./UtilsDataMapper";
import { abiAttestationRegistry } from "../abi/AttestationRegistry";
import { encode, decode } from "../utils/abiCoder";
import { subgraphCall } from "../utils/graphClientHelper";
import { PublicClient, WalletClient } from "viem";
import { lineaSepolia } from "viem/chains";
import { Conf } from "../types";
Expand All @@ -12,10 +11,6 @@ jest.mock("../utils/abiCoder", () => ({
decode: jest.fn(),
}));

jest.mock("../utils/graphClientHelper", () => ({
subgraphCall: jest.fn(),
}));

describe("UtilsDataMapper", () => {
let utilsDataMapper: UtilsDataMapper;
const mockConf: Conf = {
Expand All @@ -35,57 +30,6 @@ describe("UtilsDataMapper", () => {
utilsDataMapper = new UtilsDataMapper(mockConf, mockWeb3Client, mockVeraxSdk, mockWalletClient);
});

describe("getModulesNumber", () => {
it("should return the modules counter from subgraph", async () => {
const mockModulesCount = 10;
(subgraphCall as jest.Mock).mockResolvedValue({
data: { data: { counters: [{ modules: mockModulesCount }] } },
status: 200,
});

const result = await utilsDataMapper.getModulesNumber();
expect(result).toBe(mockModulesCount);
expect(subgraphCall).toHaveBeenCalledWith(
`query get_module_counter { counters { modules } }`,
mockConf.subgraphUrl,
);
});
});

describe("getPortalsCount", () => {
it("should return the portals counter from subgraph", async () => {
const mockPortalsCount = 5;
(subgraphCall as jest.Mock).mockResolvedValue({
data: { data: { counters: [{ portals: mockPortalsCount }] } },
status: 200,
});

const result = await utilsDataMapper.getPortalsCount();
expect(result).toBe(mockPortalsCount);
expect(subgraphCall).toHaveBeenCalledWith(
`query get_portal_counter { counters { portals } }`,
mockConf.subgraphUrl,
);
});
});

describe("getSchemasNumber", () => {
it("should return the schemas counter from subgraph", async () => {
const mockSchemasCount = 7;
(subgraphCall as jest.Mock).mockResolvedValue({
data: { data: { counters: [{ schemas: mockSchemasCount }] } },
status: 200,
});

const result = await utilsDataMapper.getSchemasNumber();
expect(result).toBe(mockSchemasCount);
expect(subgraphCall).toHaveBeenCalledWith(
`query get_schema_counter { counters { schemas } }`,
mockConf.subgraphUrl,
);
});
});

describe("getVersionNumber", () => {
it("should call web3Client to get the version number", async () => {
const mockVersion = "1.0.0";
Expand All @@ -101,21 +45,6 @@ describe("UtilsDataMapper", () => {
});
});

describe("getAttestationIdCounter", () => {
it("should call web3Client to get the attestation ID counter", async () => {
const mockCounter = 100;
(mockWeb3Client.readContract as jest.Mock).mockResolvedValue(mockCounter);

const result = await utilsDataMapper.getAttestationIdCounter();
expect(result).toBe(mockCounter);
expect(mockWeb3Client.readContract).toHaveBeenCalledWith({
abi: abiAttestationRegistry,
address: mockConf.attestationRegistryAddress,
functionName: "getAttestationIdCounter",
});
});
});

describe("encode", () => {
it("should call encode with correct arguments", () => {
const schema = "schema";
Expand Down
33 changes: 0 additions & 33 deletions sdk/src/dataMapper/UtilsDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import BaseDataMapper from "./BaseDataMapper";
import { abiAttestationRegistry } from "../abi/AttestationRegistry";
import { decode, encode } from "../utils/abiCoder";
import { Hex } from "viem";
import { subgraphCall } from "../utils/graphClientHelper";

export default class UtilsDataMapper extends BaseDataMapper<object, unknown, unknown> {
typeName = "counter";
Expand All @@ -13,18 +12,6 @@ export default class UtilsDataMapper extends BaseDataMapper<object, unknown, unk
schemas
}`;

async getModulesNumber() {
return await this.getCounterForType("module");
}

async getPortalsCount() {
return await this.getCounterForType("portal");
}

async getSchemasNumber() {
return await this.getCounterForType("schema");
}

async getVersionNumber() {
return this.web3Client.readContract({
abi: abiAttestationRegistry,
Expand All @@ -33,31 +20,11 @@ export default class UtilsDataMapper extends BaseDataMapper<object, unknown, unk
});
}

async getAttestationIdCounter() {
return this.web3Client.readContract({
abi: abiAttestationRegistry,
address: this.conf.attestationRegistryAddress,
functionName: "getAttestationIdCounter",
});
}

encode(schema: string, values: unknown[]): Hex {
return encode(schema, values);
}

decode(schema: string, attestationData: Hex): readonly unknown[] {
return decode(schema, attestationData);
}

private async getCounterForType(type: string) {
const query = `query get_${type}_counter { counters { ${type}s } }`;

const { data, status } = await subgraphCall(query, this.conf.subgraphUrl);

if (status != 200) {
throw new Error(`Error(s) while fetching total count of ${type}s`);
}

return data?.data ? data.data["counters"][0][`${type}s`] : 0;
}
}

0 comments on commit 556c026

Please sign in to comment.