Skip to content

Commit d014bc9

Browse files
committed
Add tests for renew
1 parent 5e7b143 commit d014bc9

File tree

2 files changed

+91
-7
lines changed

2 files changed

+91
-7
lines changed

contracts/subdomainregistrar/SubdomainRegistrar.sol

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ contract SubdomainRegistrar is ERC1155Holder {
2626
mapping(bytes32 => Name) public names;
2727
mapping(bytes32 => uint256) public expiries;
2828

29-
event NameRenewed(bytes32 node, uint256 duration);
29+
event NameRegistered(bytes32 node, uint256 expiry);
30+
event NameRenewed(bytes32 node, uint256 expiry);
3031

3132
constructor(INameWrapper _wrapper) {
3233
wrapper = _wrapper;
@@ -109,6 +110,8 @@ contract SubdomainRegistrar is ERC1155Holder {
109110
fuses | PARENT_CANNOT_CONTROL, // burn the ability for the parent to control
110111
uint64(block.timestamp + duration)
111112
);
113+
114+
emit NameRegistered(node, uint64(block.timestamp + duration));
112115
}
113116

114117
function renew(
@@ -124,16 +127,18 @@ contract SubdomainRegistrar is ERC1155Holder {
124127

125128
uint256 fee = duration * names[parentNode].registrationFee;
126129

130+
if (fee > 0) {
131+
IERC20(names[parentNode].token).transferFrom(
132+
msg.sender,
133+
address(names[parentNode].beneficiary),
134+
fee
135+
);
136+
}
137+
127138
newExpiry = expiry += duration;
128139

129140
wrapper.setChildFuses(parentNode, labelhash, 0, newExpiry);
130141

131-
IERC20(names[parentNode].token).transferFrom(
132-
msg.sender,
133-
address(names[parentNode].beneficiary),
134-
fee
135-
);
136-
137142
emit NameRenewed(node, newExpiry);
138143
}
139144

test/subdomainregistrar/TestSubdomainRegistrar.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,85 @@ describe('Subdomain registrar', () => {
212212
})
213213
})
214214

215+
describe('renew', () => {
216+
it('should allow subdomains to be renewed', async () => {
217+
await BaseRegistrar.register(labelhash('test'), account, 200000)
218+
await BaseRegistrar.setApprovalForAll(NameWrapper.address, true)
219+
await NameWrapper.wrapETH2LD(
220+
'test',
221+
account,
222+
0,
223+
MAX_EXPIRY,
224+
EMPTY_ADDRESS
225+
)
226+
expect(await NameWrapper.ownerOf(node)).to.equal(account)
227+
await SubdomainRegistrar.setupDomain(node, Erc20.address, 1, account)
228+
await NameWrapper.setApprovalForAll(SubdomainRegistrar.address, true)
229+
await Erc20WithAccount2.approve(
230+
SubdomainRegistrar.address,
231+
ethers.constants.MaxUint256
232+
)
233+
await SubdomainRegistrar2.register(
234+
node,
235+
'subname',
236+
account2,
237+
EMPTY_ADDRESS,
238+
0,
239+
86400,
240+
[]
241+
)
242+
243+
const [, expiry] = await NameWrapper.getFuses(
244+
namehash('subname.test.eth')
245+
)
246+
247+
expect(await NameWrapper.ownerOf(subNode)).to.equal(account2)
248+
249+
await SubdomainRegistrar2.renew(node, labelhash('subname'), 86400)
250+
const [, expiry2] = await NameWrapper.getFuses(
251+
namehash('subname.test.eth')
252+
)
253+
expect(expiry2.toNumber()).to.be.greaterThan(expiry.toNumber())
254+
})
255+
256+
it('should allow subdomains to be renewed even with 0 registration fee', async () => {
257+
await BaseRegistrar.register(labelhash('test'), account, 200000)
258+
await BaseRegistrar.setApprovalForAll(NameWrapper.address, true)
259+
await NameWrapper.wrapETH2LD(
260+
'test',
261+
account,
262+
0,
263+
MAX_EXPIRY,
264+
EMPTY_ADDRESS
265+
)
266+
expect(await NameWrapper.ownerOf(node)).to.equal(account)
267+
await SubdomainRegistrar.setupDomain(node, Erc20.address, 0, account)
268+
await NameWrapper.setApprovalForAll(SubdomainRegistrar.address, true)
269+
await SubdomainRegistrar2.register(
270+
node,
271+
'subname',
272+
account2,
273+
EMPTY_ADDRESS,
274+
0,
275+
86400,
276+
[]
277+
)
278+
279+
const [, expiry] = await NameWrapper.getFuses(
280+
namehash('subname.test.eth')
281+
)
282+
283+
expect(await NameWrapper.ownerOf(subNode)).to.equal(account2)
284+
285+
await SubdomainRegistrar2.renew(node, labelhash('subname'), 86400)
286+
const [, expiry2] = await NameWrapper.getFuses(
287+
namehash('subname.test.eth')
288+
)
289+
290+
expect(expiry2.toNumber()).to.be.greaterThan(expiry.toNumber())
291+
})
292+
})
293+
215294
describe('register Subnames with records', () => {
216295
it('should allow a subname to be registered with records', async () => {
217296
const node = namehash('test.eth')

0 commit comments

Comments
 (0)