diff --git a/test/SftRolesRegistry/SftRolesRegistry.spec.ts b/test/SftRolesRegistry/SftRolesRegistry.spec.ts index b57471f..a33bff2 100644 --- a/test/SftRolesRegistry/SftRolesRegistry.spec.ts +++ b/test/SftRolesRegistry/SftRolesRegistry.spec.ts @@ -5,9 +5,10 @@ import { expect } from 'chai' import { solidityKeccak256 } from 'ethers/lib/utils' import { loadFixture, time } from '@nomicfoundation/hardhat-network-helpers' import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' -import { buildRoleAssignment, ONE_DAY, generateRoleId, buildRevokeRoleData } from './helpers' +import { buildRoleAssignment, ONE_DAY, generateRoleId, buildRevokeRoleData, getInterfaceID } from './helpers' import { RoleAssignment, RevokeRoleData } from './types' import { generateRandomInt } from '../helpers' +import { IERCXXXX__factory } from '../../typechain-types' const { AddressZero } = ethers.constants @@ -603,4 +604,20 @@ describe('SftRolesRegistry', async () => { ).to.be.equal(RoleAssignment.tokenAmount) }) }) + + describe('ERC-165 supportsInterface', async () => { + + it('should return true if ERC1155Receiver interface id', async () => { + expect(await SftRolesRegistry.supportsInterface('0x4e2312e0')).to.be.true + }) + + // todo validate SftRolesRegistry is supported + // it('should return true if SftRolesRegistry interface id', async () => { + // const id = getInterfaceID(IERCXXXX__factory.createInterface()) + // console.log('id', id) + // expect(await SftRolesRegistry.supportsInterface(id)).to.be.true + // }) + + }) + }) diff --git a/test/SftRolesRegistry/helpers.ts b/test/SftRolesRegistry/helpers.ts index d1697d3..2fb848a 100644 --- a/test/SftRolesRegistry/helpers.ts +++ b/test/SftRolesRegistry/helpers.ts @@ -2,6 +2,7 @@ import { solidityKeccak256 } from 'ethers/lib/utils' import { RevokeRoleData, RoleAssignment } from './types' import { generateRandomInt } from '../helpers' import { ethers } from 'hardhat' +import { utils } from 'ethers' import { time } from '@nomicfoundation/hardhat-network-helpers' const { HashZero, AddressZero } = ethers.constants @@ -60,3 +61,12 @@ export function buildRevokeRoleData(roleAssignment: RoleAssignment): RevokeRoleD export function generateRoleId(role: string) { return solidityKeccak256(['string'], [role]) } + +export function getInterfaceID(contractInterface: utils.Interface) { + let interfaceID = ethers.constants.Zero + const functions: string[] = Object.keys(contractInterface.functions) + for (let i = 0; i < functions.length; i++) { + interfaceID = interfaceID.xor(contractInterface.getSighash(functions[i])) + } + return interfaceID//._hex.padEnd(10, '0') +}