From c22f0bb9695a47ae360c186484a9fb15c94194d0 Mon Sep 17 00:00:00 2001 From: Satyajeet Kolhapure Date: Mon, 11 Nov 2024 22:09:07 +0000 Subject: [PATCH 1/4] used subgraph to get total count of entities instead of onchain function --- contracts/src/ModuleRegistry.sol | 10 ------- contracts/src/PortalRegistry.sol | 29 +------------------ contracts/src/SchemaRegistry.sol | 10 ------- contracts/test/ModuleRegistry.t.sol | 18 ------------ contracts/test/PortalRegistry.t.sol | 16 +++++------ contracts/test/SchemaRegistry.t.sol | 20 ------------- sdk/src/abi/ModuleRegistry.ts | 13 --------- sdk/src/abi/PortalRegistry.ts | 13 --------- sdk/src/abi/SchemaRegistry.ts | 13 --------- sdk/src/dataMapper/BaseDataMapper.test.ts | 31 +++++++++++++++++++++ sdk/src/dataMapper/BaseDataMapper.ts | 12 ++++++++ sdk/src/dataMapper/ModuleDataMapper.ts | 2 +- sdk/src/dataMapper/SchemaDataMapper.ts | 2 +- sdk/src/dataMapper/UtilsDataMapper.ts | 34 +++++++++++------------ 14 files changed, 70 insertions(+), 153 deletions(-) diff --git a/contracts/src/ModuleRegistry.sol b/contracts/src/ModuleRegistry.sol index f8c48b2a..f2ad6e1e 100644 --- a/contracts/src/ModuleRegistry.sol +++ b/contracts/src/ModuleRegistry.sol @@ -117,7 +117,6 @@ contract ModuleRegistry is OwnableUpgradeable { if (bytes(modules[moduleAddress].name).length > 0) revert ModuleAlreadyExists(); modules[moduleAddress] = Module(moduleAddress, name, description); - moduleAddresses.push(moduleAddress); emit ModuleRegistered(name, description, moduleAddress); } @@ -239,15 +238,6 @@ contract ModuleRegistry is OwnableUpgradeable { } } - /** - * @notice Get the number of Modules managed by the contract - * @return The number of Modules already registered - * @dev Returns the length of the `moduleAddresses` array - */ - function getModulesNumber() public view returns (uint256) { - return moduleAddresses.length; - } - /** * @notice Checks that a module is registered in the module registry * @param moduleAddress The address of the Module to check diff --git a/contracts/src/PortalRegistry.sol b/contracts/src/PortalRegistry.sol index e5c1091a..2f684173 100644 --- a/contracts/src/PortalRegistry.sol +++ b/contracts/src/PortalRegistry.sol @@ -170,7 +170,6 @@ contract PortalRegistry is OwnableUpgradeable { // Add portal to mapping Portal memory newPortal = Portal(id, msg.sender, modules, isRevocable, name, description, ownerName); portals[id] = newPortal; - portalAddresses.push(id); // Emit event emit PortalRegistered(name, description, id); @@ -184,24 +183,7 @@ contract PortalRegistry is OwnableUpgradeable { function revoke(address id) public onlyOwner { if (!isRegistered(id)) revert PortalNotRegistered(); - portals[id] = Portal(address(0), address(0), new address[](0), false, "", "", ""); - - bool found = false; - uint256 portalAddressIndex; - for (uint256 i = 0; i < portalAddresses.length; i = uncheckedInc256(i)) { - if (portalAddresses[i] == id) { - portalAddressIndex = i; - found = true; - break; - } - } - - if (!found) { - revert PortalNotRegistered(); - } - - portalAddresses[portalAddressIndex] = portalAddresses[portalAddresses.length - 1]; - portalAddresses.pop(); + delete portals[id]; emit PortalRevoked(id); } @@ -243,15 +225,6 @@ contract PortalRegistry is OwnableUpgradeable { return portals[id].id != address(0); } - /** - * @notice Get the number of Portals managed by the contract - * @return The number of Portals already registered - * @dev Returns the length of the `portalAddresses` array - */ - function getPortalsCount() public view returns (uint256) { - return portalAddresses.length; - } - /** * @notice Checks if the caller is allowlisted. * @return A flag indicating whether the Verax instance is running on testnet diff --git a/contracts/src/SchemaRegistry.sol b/contracts/src/SchemaRegistry.sol index 93c4a6d2..b077c9d3 100644 --- a/contracts/src/SchemaRegistry.sol +++ b/contracts/src/SchemaRegistry.sol @@ -155,7 +155,6 @@ contract SchemaRegistry is OwnableUpgradeable { } schemas[schemaId] = Schema(name, description, context, schemaString); - schemaIds.push(schemaId); schemasIssuers[schemaId] = msg.sender; emit SchemaCreated(schemaId, name, description, context, schemaString); } @@ -184,15 +183,6 @@ contract SchemaRegistry is OwnableUpgradeable { return schemas[schemaId]; } - /** - * @notice Get the number of Schemas managed by the contract - * @return The number of Schemas already registered - * @dev Returns the length of the `schemaIds` array - */ - function getSchemasNumber() public view returns (uint256) { - return schemaIds.length; - } - /** * @notice Check if a Schema is registered * @param schemaId The ID of the Schema diff --git a/contracts/test/ModuleRegistry.t.sol b/contracts/test/ModuleRegistry.t.sol index d925d220..e2e493cd 100644 --- a/contracts/test/ModuleRegistry.t.sol +++ b/contracts/test/ModuleRegistry.t.sol @@ -132,16 +132,6 @@ contract ModuleRegistryTest is Test { moduleRegistry.register(expectedName, expectedDescription, expectedAddress); } - function test_getModulesNumber() public { - uint256 modulesNumber = moduleRegistry.getModulesNumber(); - assertEq(modulesNumber, 0); - vm.prank(user); - moduleRegistry.register(expectedName, expectedDescription, expectedAddress); - - modulesNumber = moduleRegistry.getModulesNumber(); - assertEq(modulesNumber, 1); - } - function test_runModules() public { // Register 2 modules address[] memory moduleAddresses = new address[](2); @@ -343,14 +333,6 @@ contract ModuleRegistryTest is Test { vm.stopPrank(); } - function test_getModuleAddress() public { - vm.prank(user); - moduleRegistry.register(expectedName, expectedDescription, expectedAddress); - - address moduleAddress = moduleRegistry.moduleAddresses(0); - assertEq(moduleAddress, expectedAddress); - } - function test_isRegistered() public { bool isRegistered = moduleRegistry.isRegistered(expectedAddress); assertFalse(isRegistered); diff --git a/contracts/test/PortalRegistry.t.sol b/contracts/test/PortalRegistry.t.sol index f6cb5348..029e7b4f 100644 --- a/contracts/test/PortalRegistry.t.sol +++ b/contracts/test/PortalRegistry.t.sol @@ -179,8 +179,8 @@ contract PortalRegistryTest is Test { vm.prank(user); portalRegistry.register(address(validPortalMock), expectedName, expectedDescription, true, expectedOwnerName); - uint256 portalCount = portalRegistry.getPortalsCount(); - assertEq(portalCount, 1); + bool isRegistered = portalRegistry.isRegistered(address(validPortalMock)); + assertEq(isRegistered, true); // Register a portal implementing IPortal vm.expectEmit(); @@ -194,8 +194,8 @@ contract PortalRegistryTest is Test { expectedOwnerName ); - portalCount = portalRegistry.getPortalsCount(); - assertEq(portalCount, 2); + isRegistered = portalRegistry.isRegistered(address(iPortalImplementation)); + assertEq(isRegistered, true); Portal memory expectedPortal = Portal( address(validPortalMock), @@ -272,8 +272,8 @@ contract PortalRegistryTest is Test { expectedOwnerName ); - uint256 portalCount = portalRegistry.getPortalsCount(); - assertEq(portalCount, 1); + bool isRegistered = portalRegistry.isRegistered(portalAddress); + assertEq(isRegistered, true); Portal memory expectedPortal = Portal( portalAddress, @@ -292,8 +292,8 @@ contract PortalRegistryTest is Test { emit PortalRevoked(portalAddress); portalRegistry.revoke(portalAddress); - portalCount = portalRegistry.getPortalsCount(); - assertEq(portalCount, 0); + isRegistered = portalRegistry.isRegistered(portalAddress); + assertEq(isRegistered, false); vm.expectRevert(PortalRegistry.PortalNotRegistered.selector); portalRegistry.getPortalByAddress(portalAddress); diff --git a/contracts/test/SchemaRegistry.t.sol b/contracts/test/SchemaRegistry.t.sol index 195814e8..dd4f243d 100644 --- a/contracts/test/SchemaRegistry.t.sol +++ b/contracts/test/SchemaRegistry.t.sol @@ -220,26 +220,6 @@ contract SchemaRegistryTest is Test { schemaRegistry.getSchema(bytes32("not registered")); } - function test_getSchemasNumber() public { - uint256 schemasNumber = schemaRegistry.getSchemasNumber(); - assertEq(schemasNumber, 0); - vm.startPrank(user); - schemaRegistry.createSchema(expectedName, expectedDescription, expectedContext, expectedString); - - schemasNumber = schemaRegistry.getSchemasNumber(); - assertEq(schemasNumber, 1); - vm.stopPrank(); - } - - function test_getSchemaIds() public { - vm.startPrank(user); - schemaRegistry.createSchema(expectedName, expectedDescription, expectedContext, expectedString); - - bytes32 schemaId = schemaRegistry.schemaIds(0); - assertEq(schemaId, expectedId); - vm.stopPrank(); - } - function test_isRegistered() public { bool isRegistered = schemaRegistry.isRegistered(expectedId); assertFalse(isRegistered); diff --git a/sdk/src/abi/ModuleRegistry.ts b/sdk/src/abi/ModuleRegistry.ts index 6dcb5c18..b770cae2 100644 --- a/sdk/src/abi/ModuleRegistry.ts +++ b/sdk/src/abi/ModuleRegistry.ts @@ -151,19 +151,6 @@ export const abiModuleRegistry = [ stateMutability: "nonpayable", type: "function", }, - { - inputs: [], - name: "getModulesNumber", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, { inputs: [], name: "initialize", diff --git a/sdk/src/abi/PortalRegistry.ts b/sdk/src/abi/PortalRegistry.ts index 149789f6..13c29868 100644 --- a/sdk/src/abi/PortalRegistry.ts +++ b/sdk/src/abi/PortalRegistry.ts @@ -195,19 +195,6 @@ export const abiPortalRegistry = [ stateMutability: "view", type: "function", }, - { - inputs: [], - name: "getPortalsCount", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, { inputs: [], name: "initialize", diff --git a/sdk/src/abi/SchemaRegistry.ts b/sdk/src/abi/SchemaRegistry.ts index 91cfb2f6..f8608074 100644 --- a/sdk/src/abi/SchemaRegistry.ts +++ b/sdk/src/abi/SchemaRegistry.ts @@ -191,19 +191,6 @@ export const abiSchemaRegistry = [ stateMutability: "view", type: "function", }, - { - inputs: [], - name: "getSchemasNumber", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, { inputs: [], name: "initialize", diff --git a/sdk/src/dataMapper/BaseDataMapper.test.ts b/sdk/src/dataMapper/BaseDataMapper.test.ts index cf45f96a..c970a97e 100644 --- a/sdk/src/dataMapper/BaseDataMapper.test.ts +++ b/sdk/src/dataMapper/BaseDataMapper.test.ts @@ -141,4 +141,35 @@ describe("BaseDataMapper", () => { await expect(mockDataMapper.findBy()).rejects.toThrow("Error(s) while fetching TestTypes"); }); }); + + describe("findTotalCount", () => { + it("should call subgraphCall with the correct query and return the result", async () => { + const mockResponse = { data: { data: { counters: [{ TestTypes: 4 }] } }, status: 200 }; + (subgraphCall as jest.Mock).mockResolvedValueOnce(mockResponse); + + const result = await mockDataMapper.findTotalCount(); + + expect(subgraphCall).toHaveBeenCalledWith( + `query get_TestType_Counter { counters { TestTypes } }`, + mockConf.subgraphUrl, + ); + expect(result).toEqual(4); + }); + + it("should throw an error if the status is not 200", async () => { + const mockResponse = { status: 500 }; + (subgraphCall as jest.Mock).mockResolvedValueOnce(mockResponse); + + await expect(mockDataMapper.findTotalCount()).rejects.toThrow("Error(s) while fetching total count of TestTypes"); + }); + + it("should return 0 if no data is found", async () => { + const mockResponse = { data: null, status: 200 }; + (subgraphCall as jest.Mock).mockResolvedValueOnce(mockResponse); + + const result = await mockDataMapper.findTotalCount(); + + expect(result).toEqual(0); + }); + }); }); diff --git a/sdk/src/dataMapper/BaseDataMapper.ts b/sdk/src/dataMapper/BaseDataMapper.ts index eec22304..fe226d23 100644 --- a/sdk/src/dataMapper/BaseDataMapper.ts +++ b/sdk/src/dataMapper/BaseDataMapper.ts @@ -53,4 +53,16 @@ export default abstract class BaseDataMapper { return data?.data ? (data.data[`${this.typeName}s`] as T[]) : []; } + + async findTotalCount() { + const query = `query get_${this.typeName}_Counter { counters { ${this.typeName}s } }`; + + const { data, status } = await subgraphCall(query, this.conf.subgraphUrl); + + if (status != 200) { + throw new Error(`Error(s) while fetching total count of ${this.typeName}s`); + } + + return data?.data ? data.data["counters"][0][`${this.typeName}s`] : 0; + } } diff --git a/sdk/src/dataMapper/ModuleDataMapper.ts b/sdk/src/dataMapper/ModuleDataMapper.ts index a4943923..0e0bddd5 100644 --- a/sdk/src/dataMapper/ModuleDataMapper.ts +++ b/sdk/src/dataMapper/ModuleDataMapper.ts @@ -107,7 +107,7 @@ export default class ModuleDataMapper extends BaseDataMapper { typeName = "counter"; @@ -16,27 +14,15 @@ export default class UtilsDataMapper extends BaseDataMapper Date: Tue, 12 Nov 2024 10:57:45 +0000 Subject: [PATCH 2/4] added unit tests for UtilsDataMapper --- sdk/src/dataMapper/UtilsDataMapper.test.ts | 146 +++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 sdk/src/dataMapper/UtilsDataMapper.test.ts diff --git a/sdk/src/dataMapper/UtilsDataMapper.test.ts b/sdk/src/dataMapper/UtilsDataMapper.test.ts new file mode 100644 index 00000000..1aab3878 --- /dev/null +++ b/sdk/src/dataMapper/UtilsDataMapper.test.ts @@ -0,0 +1,146 @@ +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"; +import { SDKMode, VeraxSdk } from "../VeraxSdk"; + +jest.mock("../utils/abiCoder", () => ({ + encode: jest.fn(), + decode: jest.fn(), +})); + +jest.mock("../utils/graphClientHelper", () => ({ + subgraphCall: jest.fn(), +})); + +describe("UtilsDataMapper", () => { + let utilsDataMapper: UtilsDataMapper; + const mockConf: Conf = { + subgraphUrl: "http://mock-subgraph.com", + chain: lineaSepolia, + mode: SDKMode.BACKEND, + portalRegistryAddress: "0x1", + moduleRegistryAddress: "0x2", + schemaRegistryAddress: "0x3", + attestationRegistryAddress: "0x4", + }; + const mockWeb3Client = { readContract: jest.fn() } as unknown as PublicClient; + const mockWalletClient = {} as WalletClient; + const mockVeraxSdk = {} as VeraxSdk; + + beforeEach(() => { + 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"; + (mockWeb3Client.readContract as jest.Mock).mockResolvedValue(mockVersion); + + const result = await utilsDataMapper.getVersionNumber(); + expect(result).toBe(mockVersion); + expect(mockWeb3Client.readContract).toHaveBeenCalledWith({ + abi: abiAttestationRegistry, + address: mockConf.attestationRegistryAddress, + functionName: "getVersionNumber", + }); + }); + }); + + 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"; + const values = ["value1", "value2"]; + const mockEncoded = "0xencoded"; + + (encode as jest.Mock).mockReturnValue(mockEncoded); + + const result = utilsDataMapper.encode(schema, values); + expect(result).toBe(mockEncoded); + expect(encode).toHaveBeenCalledWith(schema, values); + }); + }); + + describe("decode", () => { + it("should call decode with correct arguments", () => { + const schema = "schema"; + const attestationData = "0xdata"; + const mockDecoded = ["value1", "value2"]; + + (decode as jest.Mock).mockReturnValue(mockDecoded); + + const result = utilsDataMapper.decode(schema, attestationData); + expect(result).toEqual(mockDecoded); + expect(decode).toHaveBeenCalledWith(schema, attestationData); + }); + }); +}); From c16d93da5adfc9162219cfa501774ae33c4ebf61 Mon Sep 17 00:00:00 2001 From: Satyajeet Kolhapure Date: Fri, 15 Nov 2024 11:07:22 +0000 Subject: [PATCH 3/4] fixed review comments --- contracts/src/ModuleRegistry.sol | 2 +- contracts/src/PortalRegistry.sol | 1 + contracts/src/SchemaRegistry.sol | 2 +- sdk/doc/cli-examples.md | 4 -- sdk/examples/module/moduleExamples.ts | 5 -- sdk/examples/schema/schemaExamples.ts | 5 -- sdk/src/dataMapper/ModuleDataMapper.ts | 24 +++----- sdk/src/dataMapper/PortalDataMapper.ts | 4 ++ sdk/src/dataMapper/SchemaDataMapper.ts | 6 +- sdk/src/dataMapper/UtilsDataMapper.test.ts | 71 ---------------------- sdk/src/dataMapper/UtilsDataMapper.ts | 33 ---------- 11 files changed, 16 insertions(+), 141 deletions(-) diff --git a/contracts/src/ModuleRegistry.sol b/contracts/src/ModuleRegistry.sol index f2ad6e1e..c0e2bcce 100644 --- a/contracts/src/ModuleRegistry.sol +++ b/contracts/src/ModuleRegistry.sol @@ -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 diff --git a/contracts/src/PortalRegistry.sol b/contracts/src/PortalRegistry.sol index 2f684173..c8da6fea 100644 --- a/contracts/src/PortalRegistry.sol +++ b/contracts/src/PortalRegistry.sol @@ -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; diff --git a/contracts/src/SchemaRegistry.sol b/contracts/src/SchemaRegistry.sol index b077c9d3..42d418dc 100644 --- a/contracts/src/SchemaRegistry.sol +++ b/contracts/src/SchemaRegistry.sol @@ -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; diff --git a/sdk/doc/cli-examples.md b/sdk/doc/cli-examples.md index 24a492f3..f89d5d6f 100644 --- a/sdk/doc/cli-examples.md +++ b/sdk/doc/cli-examples.md @@ -117,8 +117,6 @@ pnpm module isRegistered "0x8DcC1F7e746D6071Eb3ee9012aFB6c707bFf82a5" - pnpm module getModuleAddress 0 - pnpm module getModule "0x8DcC1F7e746D6071Eb3ee9012aFB6c707bFf82a5" ``` @@ -151,8 +149,6 @@ pnpm schema getSchemasNumber pnpm schema isRegistered "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738" - - pnpm schema getSchemaIds 0 ``` diff --git a/sdk/examples/module/moduleExamples.ts b/sdk/examples/module/moduleExamples.ts index 2bbe9ff6..1f1d99c5 100644 --- a/sdk/examples/module/moduleExamples.ts +++ b/sdk/examples/module/moduleExamples.ts @@ -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)); diff --git a/sdk/examples/schema/schemaExamples.ts b/sdk/examples/schema/schemaExamples.ts index af390758..7f001ddd 100644 --- a/sdk/examples/schema/schemaExamples.ts +++ b/sdk/examples/schema/schemaExamples.ts @@ -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)); - } } } diff --git a/sdk/src/dataMapper/ModuleDataMapper.ts b/sdk/src/dataMapper/ModuleDataMapper.ts index 0e0bddd5..a2f34187 100644 --- a/sdk/src/dataMapper/ModuleDataMapper.ts +++ b/sdk/src/dataMapper/ModuleDataMapper.ts @@ -18,7 +18,7 @@ export default class ModuleDataMapper extends BaseDataMapper ({ decode: jest.fn(), })); -jest.mock("../utils/graphClientHelper", () => ({ - subgraphCall: jest.fn(), -})); - describe("UtilsDataMapper", () => { let utilsDataMapper: UtilsDataMapper; const mockConf: Conf = { @@ -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"; @@ -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"; diff --git a/sdk/src/dataMapper/UtilsDataMapper.ts b/sdk/src/dataMapper/UtilsDataMapper.ts index 70b95146..5af46928 100644 --- a/sdk/src/dataMapper/UtilsDataMapper.ts +++ b/sdk/src/dataMapper/UtilsDataMapper.ts @@ -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 { typeName = "counter"; @@ -13,18 +12,6 @@ export default class UtilsDataMapper extends BaseDataMapper Date: Fri, 15 Nov 2024 11:30:22 +0000 Subject: [PATCH 4/4] fixed review comment --- sdk/doc/cli-examples.md | 2 +- sdk/examples/portal/portalExamples.ts | 4 ++++ sdk/examples/utils/countUniqueSubjects.ts | 2 +- sdk/examples/utils/getAllAttestations.ts | 2 +- sdk/examples/utils/getAttestationIdCounter.ts | 5 ----- sdk/examples/utils/getModulesNumber.ts | 5 ----- sdk/examples/utils/getPortalsCount.ts | 5 ----- sdk/examples/utils/getSchemasNumber.ts | 5 ----- subgraph/abis/ModuleRegistry.json | 13 ------------- subgraph/abis/PortalRegistry.json | 13 ------------- subgraph/abis/SchemaRegistry.json | 13 ------------- 11 files changed, 7 insertions(+), 62 deletions(-) delete mode 100644 sdk/examples/utils/getAttestationIdCounter.ts delete mode 100644 sdk/examples/utils/getModulesNumber.ts delete mode 100644 sdk/examples/utils/getPortalsCount.ts delete mode 100644 sdk/examples/utils/getSchemasNumber.ts diff --git a/sdk/doc/cli-examples.md b/sdk/doc/cli-examples.md index f89d5d6f..1da7d54f 100644 --- a/sdk/doc/cli-examples.md +++ b/sdk/doc/cli-examples.md @@ -43,7 +43,7 @@ pnpm portal isPortalRegistered '{\"portalAddress\":\"0x8b833796869b5debb9b06370d6d47016f0d7973b\"}' - pnpm portal getPortalsCount + pnpm portal getPortalsNumber ``` diff --git a/sdk/examples/portal/portalExamples.ts b/sdk/examples/portal/portalExamples.ts index 7653ca6b..3475a626 100644 --- a/sdk/examples/portal/portalExamples.ts +++ b/sdk/examples/portal/portalExamples.ts @@ -399,6 +399,10 @@ export default class PortalExamples { console.log(await this.veraxSdk.portal.getPortalByAddress(portalAddress)); } + if (methodName.toLowerCase() == "getPortalsNumber".toLowerCase() || methodName == "") { + console.log(await this.veraxSdk.portal.getPortalsNumber()); + } + if (methodName.toLowerCase() == "isPortalRegistered".toLowerCase() || methodName == "") { let params; if (argv !== "") params = JSON.parse(argv); diff --git a/sdk/examples/utils/countUniqueSubjects.ts b/sdk/examples/utils/countUniqueSubjects.ts index 1ccfaba3..9888384a 100644 --- a/sdk/examples/utils/countUniqueSubjects.ts +++ b/sdk/examples/utils/countUniqueSubjects.ts @@ -11,7 +11,7 @@ const fetchSubjectsFromFile = async (fileSuffix: number): Promise => { async function main() { const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_MAINNET); - const attestationNumber = await veraxSdk.utils.getAttestationIdCounter(); + const attestationNumber = await veraxSdk.attestation.getAttestationIdCounter(); const filesNumber = Math.ceil(Number(attestationNumber) / BATCH_SIZE); const allSubjects: string[][] = []; diff --git a/sdk/examples/utils/getAllAttestations.ts b/sdk/examples/utils/getAllAttestations.ts index 42871c1d..b686fa83 100644 --- a/sdk/examples/utils/getAllAttestations.ts +++ b/sdk/examples/utils/getAllAttestations.ts @@ -29,7 +29,7 @@ const fetchAllAttestations = async (batchNumber: number, veraxSdk: VeraxSdk) => async function main() { const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_MAINNET); - const attestationNumber = await veraxSdk.utils.getAttestationIdCounter(); + const attestationNumber = await veraxSdk.attestation.getAttestationIdCounter(); const batchesNumber = Math.ceil(Number(attestationNumber) / BATCH_SIZE); console.log(`Creating ${batchesNumber} batches of ${BATCH_SIZE} items to get all ${attestationNumber} attestations.`); diff --git a/sdk/examples/utils/getAttestationIdCounter.ts b/sdk/examples/utils/getAttestationIdCounter.ts deleted file mode 100644 index 78f6752d..00000000 --- a/sdk/examples/utils/getAttestationIdCounter.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { VeraxSdk } from "../../src/VeraxSdk"; - -const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_SEPOLIA); - -veraxSdk.utils.getAttestationIdCounter().then((res) => console.log(res)); diff --git a/sdk/examples/utils/getModulesNumber.ts b/sdk/examples/utils/getModulesNumber.ts deleted file mode 100644 index 747896a8..00000000 --- a/sdk/examples/utils/getModulesNumber.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { VeraxSdk } from "../../src/VeraxSdk"; - -const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_SEPOLIA); - -veraxSdk.utils.getModulesNumber().then((res) => console.log(res)); diff --git a/sdk/examples/utils/getPortalsCount.ts b/sdk/examples/utils/getPortalsCount.ts deleted file mode 100644 index 88f09904..00000000 --- a/sdk/examples/utils/getPortalsCount.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { VeraxSdk } from "../../src/VeraxSdk"; - -const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_SEPOLIA); - -veraxSdk.utils.getPortalsCount().then((res) => console.log(res)); diff --git a/sdk/examples/utils/getSchemasNumber.ts b/sdk/examples/utils/getSchemasNumber.ts deleted file mode 100644 index 12dd6ac2..00000000 --- a/sdk/examples/utils/getSchemasNumber.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { VeraxSdk } from "../../src/VeraxSdk"; - -const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_SEPOLIA); - -veraxSdk.utils.getSchemasNumber().then((res) => console.log(res)); diff --git a/subgraph/abis/ModuleRegistry.json b/subgraph/abis/ModuleRegistry.json index eec4a015..09d4f7d9 100644 --- a/subgraph/abis/ModuleRegistry.json +++ b/subgraph/abis/ModuleRegistry.json @@ -151,19 +151,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [], - "name": "getModulesNumber", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "initialize", diff --git a/subgraph/abis/PortalRegistry.json b/subgraph/abis/PortalRegistry.json index eca94eda..57765cb4 100644 --- a/subgraph/abis/PortalRegistry.json +++ b/subgraph/abis/PortalRegistry.json @@ -234,19 +234,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "getPortalsCount", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "initialize", diff --git a/subgraph/abis/SchemaRegistry.json b/subgraph/abis/SchemaRegistry.json index c8806b2f..c70e46fe 100644 --- a/subgraph/abis/SchemaRegistry.json +++ b/subgraph/abis/SchemaRegistry.json @@ -219,19 +219,6 @@ "stateMutability": "view", "type": "function" }, - { - "inputs": [], - "name": "getSchemasNumber", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "initialize",