Skip to content

Commit

Permalink
Emit reverse claimed (#308)
Browse files Browse the repository at this point in the history
* Emit ReverseClaimed

* Remove console.log
  • Loading branch information
makoto authored Jan 15, 2024
1 parent a4c7597 commit c842f05
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ node_modules
artifacts
cache
gasreport-*
.env
.env*
*.DS_Store
node_modules
build
forge-cache
out
out
4 changes: 3 additions & 1 deletion contracts/reverseRegistrar/L2ReverseRegistrar.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ contract L2ReverseRegistrar is
returns (bytes32)
{
bytes32 node = _getNamehash(addr);

_setName(node, name, inceptionDate);
emit ReverseClaimed(addr, node);
return node;
}

Expand Down Expand Up @@ -216,6 +216,7 @@ contract L2ReverseRegistrar is
{
bytes32 node = _getNamehash(contractAddr);
_setName(node, name, inceptionDate);
emit ReverseClaimed(contractAddr, node);
}

/**
Expand All @@ -242,6 +243,7 @@ contract L2ReverseRegistrar is
) public authorised(addr) returns (bytes32) {
bytes32 node = _getNamehash(addr);
_setName(node, name, block.timestamp);
emit ReverseClaimed(addr, node);
return node;
}

Expand Down
91 changes: 70 additions & 21 deletions test/reverseRegistrar/TestL2ReverseRegistrar.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,50 +64,79 @@ describe('L2ReverseRegistrar', function () {
})

describe('setName', () => {
let name
let node
beforeEach(async () => {
name = 'myname.eth'
node = await L2ReverseRegistrar.node(
await ethers.provider.getSigner().getAddress(),
)
})

it('should set the name record for the calling account', async function () {
const name = 'myname.eth'
const tx = await L2ReverseRegistrar.setName(name)
await tx.wait()

const node = await L2ReverseRegistrar.node(
await ethers.provider.getSigner().getAddress(),
)
const actualName = await L2ReverseRegistrar.name(node)
expect(actualName).to.equal(name)
})

it('event ReverseClaimed is emitted', async () => {
await expect(L2ReverseRegistrar.setName(name))
.to.emit(L2ReverseRegistrar, 'ReverseClaimed')
.withArgs(account, node)
})
})

describe('setNameForAddrWithSignature', () => {
it('allows an account to sign a message to allow a relayer to claim the address', async () => {
let name
let node
let inceptionDate
let signature
beforeEach(async () => {
name = 'myname.eth'
node = await L2ReverseRegistrar.node(account)
const funcId = ethers.utils
.id(setNameForAddrWithSignatureFuncSig)
.substring(0, 10)

const block = await ethers.provider.getBlock('latest')
const inceptionDate = block.timestamp
const signature = await signers[0].signMessage(
inceptionDate = block.timestamp
signature = await signers[0].signMessage(
ethers.utils.arrayify(
keccak256(
['bytes32', 'address', 'uint256', 'uint256'],
[
keccak256(['bytes4', 'string'], [funcId, 'hello.eth']),
keccak256(['bytes4', 'string'], [funcId, name]),
account,
inceptionDate,
coinType,
],
),
),
)
})

it('allows an account to sign a message to allow a relayer to claim the address', async () => {
await L2ReverseRegistrarWithAccount2['setNameForAddrWithSignature'](
account,
'hello.eth',
name,
inceptionDate,
signature,
)
assert.equal(await L2ReverseRegistrar.name(node), name)
})

const node = await L2ReverseRegistrar.node(account)
assert.equal(await L2ReverseRegistrar.name(node), 'hello.eth')
it('event ReverseClaimed is emitted', async () => {
await expect(
L2ReverseRegistrarWithAccount2['setNameForAddrWithSignature'](
account,
name,
inceptionDate,
signature,
),
)
.to.emit(L2ReverseRegistrar, 'ReverseClaimed')
.withArgs(account, node)
})

it('reverts if signature parameters do not match', async () => {
Expand All @@ -122,7 +151,7 @@ describe('L2ReverseRegistrar', function () {
keccak256(
['bytes32', 'address', 'uint256'],
[
keccak256(['bytes4', 'string'], [funcId, 'hello.eth']),
keccak256(['bytes4', 'string'], [funcId, name]),
account,
inceptionDate,
],
Expand Down Expand Up @@ -197,22 +226,27 @@ describe('L2ReverseRegistrar', function () {
})
})

describe('setNameForAddrWithSignatureAndOwnable', () => {
it('allows an account to sign a message to allow a relayer to claim the address of a contract that is owned by another contract that the account is a signer of', async () => {
const node = await L2ReverseRegistrar.node(MockOwnable.address)
describe.only('setNameForAddrWithSignatureAndOwnable', () => {
let name
let node
let inceptionDate
let signature
beforeEach(async () => {
name = 'ownable.eth'
node = await L2ReverseRegistrar.node(MockOwnable.address)
assert.equal(await L2ReverseRegistrar.name(node), '')
const funcId = ethers.utils
.id(setNameForAddrWithSignatureAndOwnableFuncSig)
.substring(0, 10)

const block = await ethers.provider.getBlock('latest')
const inceptionDate = block.timestamp
const signature = await signers[0].signMessage(
inceptionDate = block.timestamp
signature = await signers[0].signMessage(
ethers.utils.arrayify(
keccak256(
['bytes32', 'address', 'address', 'uint256', 'uint256'],
[
keccak256(['bytes4', 'string'], [funcId, 'ownable.eth']),
keccak256(['bytes4', 'string'], [funcId, name]),
MockOwnable.address,
MockSmartContractWallet.address,
inceptionDate,
Expand All @@ -221,18 +255,33 @@ describe('L2ReverseRegistrar', function () {
),
),
)
})

it('allows an account to sign a message to allow a relayer to claim the address of a contract that is owned by another contract that the account is a signer of', async () => {
await L2ReverseRegistrarWithAccount2[
'setNameForAddrWithSignatureAndOwnable'
](
MockOwnable.address,
MockSmartContractWallet.address,
'ownable.eth',
name,
inceptionDate,
signature,
)

assert.equal(await L2ReverseRegistrar.name(node), 'ownable.eth')
assert.equal(await L2ReverseRegistrar.name(node), name)
})
it('event ReverseClaimed is emitted', async () => {
await expect(
L2ReverseRegistrarWithAccount2['setNameForAddrWithSignatureAndOwnable'](
MockOwnable.address,
MockSmartContractWallet.address,
name,
inceptionDate,
signature,
),
)
.to.emit(L2ReverseRegistrar, 'ReverseClaimed')
.withArgs(MockOwnable.address, node)
})
})

Expand Down

0 comments on commit c842f05

Please sign in to comment.