Skip to content

Commit 3c93765

Browse files
committed
Add tests for inceptionDate
1 parent 4ab3a85 commit 3c93765

File tree

1 file changed

+134
-12
lines changed

1 file changed

+134
-12
lines changed

test/reverseRegistrar/TestL2ReverseRegistrar.js

Lines changed: 134 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,52 @@ describe('L2ReverseRegistrar', function () {
127127
),
128128
).to.be.revertedWith(`InvalidSignature()`)
129129
})
130+
131+
it('reverts if inception date is too low', async () => {
132+
const funcId = ethers.utils
133+
.id(setNameForAddrWithSignatureFuncSig)
134+
.substring(0, 10)
135+
136+
const block = await ethers.provider.getBlock('latest')
137+
const inceptionDate = block.timestamp
138+
const signature = await signers[0].signMessage(
139+
ethers.utils.arrayify(
140+
ethers.utils.solidityKeccak256(
141+
['bytes4', 'address', 'string', 'uint256'],
142+
[funcId, account, 'hello.eth', inceptionDate],
143+
),
144+
),
145+
)
146+
147+
await L2ReverseRegistrarWithAccount2['setNameForAddrWithSignature'](
148+
account,
149+
'hello.eth',
150+
inceptionDate,
151+
signature,
152+
)
153+
154+
const node = await L2ReverseRegistrar.node(account)
155+
assert.equal(await L2ReverseRegistrar.name(node), 'hello.eth')
156+
157+
const inceptionDate2 = 0
158+
const signature2 = await signers[0].signMessage(
159+
ethers.utils.arrayify(
160+
ethers.utils.solidityKeccak256(
161+
['bytes4', 'address', 'string', 'uint256'],
162+
[funcId, account, 'hello.eth', inceptionDate2],
163+
),
164+
),
165+
)
166+
167+
await expect(
168+
L2ReverseRegistrarWithAccount2['setNameForAddrWithSignature'](
169+
account,
170+
'hello.eth',
171+
inceptionDate2,
172+
signature2,
173+
),
174+
).to.be.revertedWith(`InvalidSignature()`)
175+
})
130176
})
131177

132178
describe('setNameForAddrWithSignatureAndOwnable', () => {
@@ -241,6 +287,57 @@ describe('L2ReverseRegistrar', function () {
241287
),
242288
).to.be.revertedWith(`InvalidSignature()`)
243289
})
290+
291+
it('reverts if inceptionDate is too low', async () => {
292+
const funcId = ethers.utils
293+
.id(setTextForAddrWithSignatureFuncSig)
294+
.substring(0, 10)
295+
296+
const block = await ethers.provider.getBlock('latest')
297+
const inceptionDate = block.timestamp
298+
const signature = await signers[0].signMessage(
299+
ethers.utils.arrayify(
300+
ethers.utils.solidityKeccak256(
301+
['bytes4', 'address', 'string', 'string', 'uint256'],
302+
[funcId, account, 'url', 'http://ens.domains', inceptionDate],
303+
),
304+
),
305+
)
306+
307+
await L2ReverseRegistrarWithAccount2['setTextForAddrWithSignature'](
308+
account,
309+
'url',
310+
'http://ens.domains',
311+
inceptionDate,
312+
signature,
313+
)
314+
315+
const node = await L2ReverseRegistrar.node(account)
316+
assert.equal(
317+
await L2ReverseRegistrar.text(node, 'url'),
318+
'http://ens.domains',
319+
)
320+
321+
const inceptionDate2 = 0
322+
const signature2 = await signers[0].signMessage(
323+
ethers.utils.arrayify(
324+
ethers.utils.solidityKeccak256(
325+
['bytes4', 'address', 'string', 'string', 'uint256'],
326+
[funcId, account, 'url', 'http://ens.domains', inceptionDate],
327+
),
328+
),
329+
)
330+
331+
await expect(
332+
L2ReverseRegistrarWithAccount2['setTextForAddrWithSignature'](
333+
account,
334+
'url',
335+
'http://ens.domains',
336+
inceptionDate2,
337+
signature2,
338+
),
339+
).to.be.revertedWith(`InvalidSignature()`)
340+
})
244341
})
245342

246343
describe('setTextForAddrWithSignatureAndOwnable', function () {
@@ -405,22 +502,47 @@ describe('L2ReverseRegistrar', function () {
405502
),
406503
)
407504

408-
keccak256(
409-
abi.encodePacked(
410-
IL2ReverseRegistrar.setNameForAddrWithSignature.selector,
411-
addr,
412-
name,
413-
inceptionDate,
505+
await L2ReverseRegistrarWithAccount2['clearRecordsWithSignature'](
506+
account,
507+
signatureExpiry,
508+
signature,
509+
)
510+
511+
assert.equal(await L2ReverseRegistrar.text(node, 'url'), '')
512+
assert.equal(await L2ReverseRegistrar.name(node), '')
513+
})
514+
515+
it('clearRecordsWithSignature() reverts when signature expiry is too low', async () => {
516+
const node = await L2ReverseRegistrar.node(account)
517+
await L2ReverseRegistrar.setText('url', 'http://ens.domains')
518+
await L2ReverseRegistrar.setName('hello.eth')
519+
assert.equal(
520+
await L2ReverseRegistrar.text(node, 'url'),
521+
'http://ens.domains',
522+
)
523+
assert.equal(await L2ReverseRegistrar.name(node), 'hello.eth')
524+
525+
const funcId = ethers.utils
526+
.id('clearRecordsWithSignature(address,uint256,bytes)')
527+
.substring(0, 10)
528+
529+
const signatureExpiry = 0
530+
const signature = await signers[0].signMessage(
531+
ethers.utils.arrayify(
532+
ethers.utils.solidityKeccak256(
533+
['bytes4', 'address', 'uint256'],
534+
[funcId, account, signatureExpiry],
535+
),
414536
),
415-
),
416-
await L2ReverseRegistrarWithAccount2['clearRecordsWithSignature'](
537+
)
538+
539+
await expect(
540+
L2ReverseRegistrarWithAccount2['clearRecordsWithSignature'](
417541
account,
418542
signatureExpiry,
419543
signature,
420-
)
421-
422-
assert.equal(await L2ReverseRegistrar.text(node, 'url'), '')
423-
assert.equal(await L2ReverseRegistrar.name(node), '')
544+
),
545+
).to.be.revertedWith(`InvalidSignature()`)
424546
})
425547
})
426548
})

0 commit comments

Comments
 (0)