Skip to content

Commit

Permalink
Add comments and more test
Browse files Browse the repository at this point in the history
  • Loading branch information
makoto committed Oct 30, 2023
1 parent ed57aa8 commit 093fbd2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
9 changes: 7 additions & 2 deletions contracts/resolvers/DelegatableResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ contract DelegatableResolver is
//node => (delegate => isAuthorised)
mapping(bytes32 => mapping(address => bool)) operators;

/**
* @dev Check to see if the operator has been approved by the owner for the node.
/*
* Check to see if the operator has been approved by the owner for the node.
* @param name The ENS node to query
* @param offset The offset of the label to query recursively. Start from the 0 position and kepp adding the length of each label as it traverse. The function exits when len is 0.
* @param operator The address of the operator to query
* @return node The node of the name passed as an argument
* @return authorized The boolean state of whether the operator is approved to update record of the name
*/
function getAuthorizedNode(
bytes memory name,
Expand Down
46 changes: 46 additions & 0 deletions test/resolvers/TestDelegatableResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,37 @@ contract('DelegatableResolver', function (accounts) {
}),
)
})

it('forbids approving wrong node', async () => {
encodedname = encodeName('a.b.c.eth')
const wrongnode = namehash('d.b.c.eth')
await resolver.approve(encodedname, operator, true, { from: owner })
await exceptions.expectFailure(
resolver.methods['setAddr(bytes32,address)'](wrongnode, operator, {
from: operator,
}),
)
})
})

describe('authorisations', async () => {
it('owner is the owner', async () => {
assert.equal(await resolver.owner(), owner)
})

it('owner is ahtorised to update any names', async () => {
assert.equal(
(await resolver.getAuthorizedNode(encodeName('a.b.c'), 0, owner))
.authorized,
true,
)
assert.equal(
(await resolver.getAuthorizedNode(encodeName('x.y.z'), 0, owner))
.authorized,
true,
)
})

it('approves multiple users', async () => {
await resolver.approve(encodedname, operator, true, { from: owner })
await resolver.approve(encodedname, operator2, true, { from: owner })
Expand Down Expand Up @@ -94,6 +118,28 @@ contract('DelegatableResolver', function (accounts) {
)
})

it('only approves the subname and not its parent', async () => {
const subname = '1234.123'
const parentname = 'b.c.eth'
await resolver.approve(encodeName(subname), operator, true, {
from: owner,
})
const result = await resolver.getAuthorizedNode(
encodeName(subname),
0,
operator,
)
assert.equal(result.node, namehash(subname))
assert.equal(result.authorized, true)
const result2 = await resolver.getAuthorizedNode(
encodeName(parentname),
0,
operator,
)
assert.equal(result2.node, namehash(parentname))
assert.equal(result2.authorized, false)
})

it('approves users to make changes', async () => {
await resolver.approve(encodedname, operator, true, { from: owner })
await resolver.methods['setAddr(bytes32,address)'](node, operator, {
Expand Down

0 comments on commit 093fbd2

Please sign in to comment.