Skip to content

Commit

Permalink
wip validate erc165 supportsInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
ernanirst committed Nov 13, 2023
1 parent 23d54b8 commit 65c5672
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 18 additions & 1 deletion test/SftRolesRegistry/SftRolesRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Check warning on line 8 in test/SftRolesRegistry/SftRolesRegistry.spec.ts

View workflow job for this annotation

GitHub Actions / build_test_deploy

'getInterfaceID' is defined but never used
import { RoleAssignment, RevokeRoleData } from './types'
import { generateRandomInt } from '../helpers'
import { IERCXXXX__factory } from '../../typechain-types'

Check warning on line 11 in test/SftRolesRegistry/SftRolesRegistry.spec.ts

View workflow job for this annotation

GitHub Actions / build_test_deploy

'IERCXXXX__factory' is defined but never used

const { AddressZero } = ethers.constants

Expand Down Expand Up @@ -603,4 +604,20 @@ describe('SftRolesRegistry', async () => {
).to.be.equal(RoleAssignment.tokenAmount)
})
})

describe('ERC-165 supportsInterface', async () => {

Check failure on line 609 in test/SftRolesRegistry/SftRolesRegistry.spec.ts

View workflow job for this annotation

GitHub Actions / build_test_deploy

Delete `⏎`
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
// })

Check failure on line 620 in test/SftRolesRegistry/SftRolesRegistry.spec.ts

View workflow job for this annotation

GitHub Actions / build_test_deploy

Replace `⏎··})⏎` with `··})`
})

})
10 changes: 10 additions & 0 deletions test/SftRolesRegistry/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')

Check failure on line 71 in test/SftRolesRegistry/helpers.ts

View workflow job for this annotation

GitHub Actions / build_test_deploy

Insert `·`
}

0 comments on commit 65c5672

Please sign in to comment.