Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit reverse claimed #308

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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