Skip to content

Commit 50ab84c

Browse files
committed
Fixed tests
1 parent 582799e commit 50ab84c

File tree

1 file changed

+58
-58
lines changed

1 file changed

+58
-58
lines changed

test/ServerAllocator.t.sol

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ abstract contract CreateHash is Test {
4949
// stringified types
5050
string EIP712_DOMAIN_TYPE = "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"; // Hashed inside the funcion
5151
// string ALLOCATOR_TYPE = "Allocator(bytes32 hash)"; // Hashed inside the funcion
52-
string REGISTER_ATTEST_TYPE = "RegisterAttest(address signer,bytes32 attestHash,uint256 expiration,uint256 nonce)"; // Hashed inside the funcion
53-
string NONCE_CONSUMPTION_TYPE = "NonceConsumption(address signer,uint256[] nonces,bytes32[] attests)"; // Hashed inside the funcion
52+
string REGISTER_ATTESTATION_TYPE = "RegisterAttestation(address signer,bytes32 attestationHash,uint256 expiration,uint256 nonce)"; // Hashed inside the funcion
53+
string NONCE_CONSUMPTION_TYPE = "NonceConsumption(address signer,uint256[] nonces,bytes32[] attestations)"; // Hashed inside the funcion
5454
// EIP712 domain type
5555
string name = "Allocator";
5656
string version = "1";
@@ -77,12 +77,12 @@ abstract contract CreateHash is Test {
7777
);
7878
}
7979

80-
function _hashRegisterAttest(ServerAllocator.RegisterAttest memory data, address verifyingContract) internal view returns (bytes32) {
80+
function _hashRegisterAttest(ServerAllocator.RegisterAttestation memory data, address verifyingContract) internal view returns (bytes32) {
8181
return keccak256(
8282
abi.encodePacked(
8383
"\x19\x01", // backslash is needed to escape the character
8484
_domainSeperator(verifyingContract),
85-
keccak256(abi.encode(keccak256(bytes(REGISTER_ATTEST_TYPE)), data.signer, data.attestHash, data.expiration, data.nonce))
85+
keccak256(abi.encode(keccak256(bytes(REGISTER_ATTESTATION_TYPE)), data.signer, data.attestationHash, data.expiration, data.nonce))
8686
)
8787
);
8888
}
@@ -93,7 +93,7 @@ abstract contract CreateHash is Test {
9393
abi.encodePacked(
9494
"\x19\x01", // backslash is needed to escape the character
9595
_domainSeperator(verifyingContract),
96-
keccak256(abi.encode(keccak256(bytes(NONCE_CONSUMPTION_TYPE)), data.signer, data.nonces, data.attests))
96+
keccak256(abi.encode(keccak256(bytes(NONCE_CONSUMPTION_TYPE)), data.signer, data.nonces, data.attestations))
9797
)
9898
);
9999
}
@@ -205,71 +205,71 @@ contract ServerAllocator_Attest is SignerSet {
205205

206206
vm.prank(attacker_);
207207
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.InvalidSigner.selector, attacker_));
208-
serverAllocator.registerAttest(createAttest(attacker_, usdcId, 100), vm.getBlockTimestamp() + 1 days);
208+
serverAllocator.registerAttestation(createAttest(attacker_, usdcId, 100), vm.getBlockTimestamp() + 1 days);
209209
}
210210

211211
function test_fuzz_registerAttest_attestExpired(uint256 expiration_) public {
212212
vm.assume(expiration_ < vm.getBlockTimestamp());
213213

214214
vm.prank(signer);
215215
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.Expired.selector, expiration_, vm.getBlockTimestamp()));
216-
serverAllocator.registerAttest(createAttest(signer, usdcId, 100), expiration_);
216+
serverAllocator.registerAttestation(createAttest(signer, usdcId, 100), expiration_);
217217
}
218218

219219
function test_registerAttest_successful() public {
220220
vm.prank(signer);
221221
bytes32 attest = createAttest(signer, usdcId, 100);
222222
uint256 expiration = vm.getBlockTimestamp() + 1 days;
223223
vm.expectEmit(address(serverAllocator));
224-
emit IServerAllocator.AttestRegistered(attest, expiration);
225-
serverAllocator.registerAttest(attest, expiration);
224+
emit IServerAllocator.AttestationRegistered(attest, expiration);
225+
serverAllocator.registerAttestation(attest, expiration);
226226

227-
assertEq(serverAllocator.checkAttestExpirations(attest)[0], expiration);
227+
assertEq(serverAllocator.checkAttestationExpirations(attest)[0], expiration);
228228
}
229229

230230
function test_registerAttestViaSignature_InvalidSignature() public {
231231
bytes32 attest = createAttest(signer, usdcId, 100);
232232
uint256 expiration = vm.getBlockTimestamp() + 1 days;
233233

234-
IServerAllocator.RegisterAttest memory attestData = IServerAllocator.RegisterAttest(signer, attest, expiration, 0);
234+
IServerAllocator.RegisterAttestation memory attestData = IServerAllocator.RegisterAttestation(signer, attest, expiration, 0);
235235
bytes32 message = _hashRegisterAttest(attestData, address(serverAllocator));
236236
bytes memory signature = _signMessage(message, attackerPK);
237237

238238
vm.prank(attacker);
239239
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.InvalidSignature.selector, signature, attacker));
240-
serverAllocator.registerAttestViaSignature(attestData, signature);
240+
serverAllocator.registerAttestationViaSignature(attestData, signature);
241241
}
242242

243243
function test_registerAttestViaSignature_successful() public {
244244
bytes32 attest = createAttest(signer, usdcId, 100);
245245
uint256 expiration = vm.getBlockTimestamp() + 1 days;
246246

247-
IServerAllocator.RegisterAttest memory attestData = IServerAllocator.RegisterAttest(signer, attest, expiration, 0);
247+
IServerAllocator.RegisterAttestation memory attestData = IServerAllocator.RegisterAttestation(signer, attest, expiration, 0);
248248
bytes32 message = _hashRegisterAttest(attestData, address(serverAllocator));
249249
bytes memory signature = _signMessage(message, signerPK);
250250

251251
vm.prank(attacker);
252252
vm.expectEmit(address(serverAllocator));
253-
emit IServerAllocator.AttestRegistered(attest, expiration);
254-
serverAllocator.registerAttestViaSignature(attestData, signature);
253+
emit IServerAllocator.AttestationRegistered(attest, expiration);
254+
serverAllocator.registerAttestationViaSignature(attestData, signature);
255255
}
256256

257257
function test_registerAttestViaSignature_AlreadyUsedSig() public {
258258
bytes32 attest = createAttest(signer, usdcId, 100);
259259
uint256 expiration = vm.getBlockTimestamp() + 1 days;
260260

261-
IServerAllocator.RegisterAttest memory attestData = IServerAllocator.RegisterAttest(signer, attest, expiration, 0);
261+
IServerAllocator.RegisterAttestation memory attestData = IServerAllocator.RegisterAttestation(signer, attest, expiration, 0);
262262
bytes32 message = _hashRegisterAttest(attestData, address(serverAllocator));
263263
bytes memory signature = _signMessage(message, signerPK);
264264

265265
vm.prank(attacker);
266266
vm.expectEmit(address(serverAllocator));
267-
emit IServerAllocator.AttestRegistered(attest, expiration);
268-
serverAllocator.registerAttestViaSignature(attestData, signature);
267+
emit IServerAllocator.AttestationRegistered(attest, expiration);
268+
serverAllocator.registerAttestationViaSignature(attestData, signature);
269269

270270
vm.prank(attacker);
271271
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.AlreadyUsedSig.selector, attest, 0));
272-
serverAllocator.registerAttestViaSignature(attestData, signature);
272+
serverAllocator.registerAttestationViaSignature(attestData, signature);
273273
}
274274

275275
function test_registerSameAttestTwice() public {
@@ -280,18 +280,18 @@ contract ServerAllocator_Attest is SignerSet {
280280

281281
// first attest
282282
vm.expectEmit(address(serverAllocator));
283-
emit IServerAllocator.AttestRegistered(attest, expiration1);
284-
serverAllocator.registerAttest(attest, expiration1);
283+
emit IServerAllocator.AttestationRegistered(attest, expiration1);
284+
serverAllocator.registerAttestation(attest, expiration1);
285285

286-
assertEq(serverAllocator.checkAttestExpirations(attest)[0], expiration1);
286+
assertEq(serverAllocator.checkAttestationExpirations(attest)[0], expiration1);
287287

288288
// second attest with different expiration
289289
vm.expectEmit(address(serverAllocator));
290-
emit IServerAllocator.AttestRegistered(attest, expiration2);
291-
serverAllocator.registerAttest(attest, expiration2);
290+
emit IServerAllocator.AttestationRegistered(attest, expiration2);
291+
serverAllocator.registerAttestation(attest, expiration2);
292292

293-
assertEq(serverAllocator.checkAttestExpirations(attest)[0], expiration1);
294-
assertEq(serverAllocator.checkAttestExpirations(attest)[1], expiration2);
293+
assertEq(serverAllocator.checkAttestationExpirations(attest)[0], expiration1);
294+
assertEq(serverAllocator.checkAttestationExpirations(attest)[1], expiration2);
295295
}
296296

297297
function test_fuzz_attest_callerMustBeCompact(address caller_) public {
@@ -304,7 +304,7 @@ contract ServerAllocator_Attest is SignerSet {
304304

305305
function test_fuzz_attest_notRegistered(address operator_, address from_, address to_, uint256 id_, uint256 amount_) public {
306306
vm.prank(address(compactContract));
307-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttest.selector, keccak256(abi.encode(from_, id_, amount_))));
307+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttestation.selector, keccak256(abi.encode(from_, id_, amount_))));
308308
serverAllocator.attest(operator_, from_, to_, id_, amount_);
309309
}
310310

@@ -315,14 +315,14 @@ contract ServerAllocator_Attest is SignerSet {
315315

316316
// register attest
317317
vm.prank(signer);
318-
serverAllocator.registerAttest(attest, expiration);
318+
serverAllocator.registerAttestation(attest, expiration);
319319

320320
// move time forward
321321
vm.warp(vm.getBlockTimestamp() + 1);
322322

323323
// check attest
324324
vm.prank(address(compactContract));
325-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.ExpiredAttests.selector, attest));
325+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.ExpiredAttestations.selector, attest));
326326
serverAllocator.attest(signer, attacker, makeAddr("to"), usdcId, amount_);
327327
}
328328

@@ -332,21 +332,21 @@ contract ServerAllocator_Attest is SignerSet {
332332

333333
// register attest
334334
vm.prank(signer);
335-
serverAllocator.registerAttest(attest, expiration);
335+
serverAllocator.registerAttestation(attest, expiration);
336336

337337
// check for attest
338-
assertEq(serverAllocator.checkAttestExpirations(attest)[0], expiration);
338+
assertEq(serverAllocator.checkAttestationExpirations(attest)[0], expiration);
339339

340340
// check attest
341341
vm.prank(address(compactContract));
342342
vm.expectEmit(address(serverAllocator));
343-
emit IServerAllocator.Attested(from_, id_, amount_);
343+
emit IServerAllocator.AttestationConsumed(from_, id_, amount_);
344344
bytes4 attestSelector = serverAllocator.attest(operator_, from_, to_, id_, amount_);
345345
assertEq(attestSelector, _ATTEST_SELECTOR);
346346

347347
// check attest was consumed
348-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttest.selector, attest));
349-
serverAllocator.checkAttestExpirations(attest);
348+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttestation.selector, attest));
349+
serverAllocator.checkAttestationExpirations(attest);
350350
}
351351
}
352352

@@ -395,13 +395,13 @@ contract ServerAllocator_Consume is SignerSet {
395395
attests[2] = createAttest(signer, usdcId, 300);
396396

397397
// register attests
398-
serverAllocator.registerAttest(attests[0], vm.getBlockTimestamp());
399-
serverAllocator.registerAttest(attests[1], vm.getBlockTimestamp());
400-
serverAllocator.registerAttest(attests[2], vm.getBlockTimestamp());
398+
serverAllocator.registerAttestation(attests[0], vm.getBlockTimestamp());
399+
serverAllocator.registerAttestation(attests[1], vm.getBlockTimestamp());
400+
serverAllocator.registerAttestation(attests[2], vm.getBlockTimestamp());
401401

402-
assertEq(serverAllocator.checkAttestExpirations(attests[0])[0], vm.getBlockTimestamp());
403-
assertEq(serverAllocator.checkAttestExpirations(attests[1])[0], vm.getBlockTimestamp());
404-
assertEq(serverAllocator.checkAttestExpirations(attests[2])[0], vm.getBlockTimestamp());
402+
assertEq(serverAllocator.checkAttestationExpirations(attests[0])[0], vm.getBlockTimestamp());
403+
assertEq(serverAllocator.checkAttestationExpirations(attests[1])[0], vm.getBlockTimestamp());
404+
assertEq(serverAllocator.checkAttestationExpirations(attests[2])[0], vm.getBlockTimestamp());
405405

406406
vm.expectEmit(address(serverAllocator));
407407
emit IServerAllocator.NoncesConsumed(nonces);
@@ -413,12 +413,12 @@ contract ServerAllocator_Consume is SignerSet {
413413
}
414414

415415
// check attests were consumed
416-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttest.selector, attests[0]));
417-
serverAllocator.checkAttestExpirations(attests[0]);
418-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttest.selector, attests[1]));
419-
serverAllocator.checkAttestExpirations(attests[1]);
420-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttest.selector, attests[2]));
421-
serverAllocator.checkAttestExpirations(attests[2]);
416+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttestation.selector, attests[0]));
417+
serverAllocator.checkAttestationExpirations(attests[0]);
418+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttestation.selector, attests[1]));
419+
serverAllocator.checkAttestationExpirations(attests[1]);
420+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttestation.selector, attests[2]));
421+
serverAllocator.checkAttestationExpirations(attests[2]);
422422
}
423423

424424
function test_consumeViaSignature_requiresNoncesAndAttestsToBeOfSameLength() public {
@@ -467,14 +467,14 @@ contract ServerAllocator_Consume is SignerSet {
467467

468468
vm.startPrank(signer);
469469
// register attests
470-
serverAllocator.registerAttest(attests[0], vm.getBlockTimestamp());
471-
serverAllocator.registerAttest(attests[1], vm.getBlockTimestamp());
472-
serverAllocator.registerAttest(attests[2], vm.getBlockTimestamp());
470+
serverAllocator.registerAttestation(attests[0], vm.getBlockTimestamp());
471+
serverAllocator.registerAttestation(attests[1], vm.getBlockTimestamp());
472+
serverAllocator.registerAttestation(attests[2], vm.getBlockTimestamp());
473473
vm.stopPrank();
474474

475-
assertEq(serverAllocator.checkAttestExpirations(attests[0])[0], vm.getBlockTimestamp());
476-
assertEq(serverAllocator.checkAttestExpirations(attests[1])[0], vm.getBlockTimestamp());
477-
assertEq(serverAllocator.checkAttestExpirations(attests[2])[0], vm.getBlockTimestamp());
475+
assertEq(serverAllocator.checkAttestationExpirations(attests[0])[0], vm.getBlockTimestamp());
476+
assertEq(serverAllocator.checkAttestationExpirations(attests[1])[0], vm.getBlockTimestamp());
477+
assertEq(serverAllocator.checkAttestationExpirations(attests[2])[0], vm.getBlockTimestamp());
478478

479479
bytes32 message = _hashNonceConsumption(IServerAllocator.NonceConsumption(signer, nonces, attests), address(serverAllocator));
480480
bytes memory signature = _signMessage(message, signerPK);
@@ -490,12 +490,12 @@ contract ServerAllocator_Consume is SignerSet {
490490
}
491491

492492
// check attests were consumed
493-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttest.selector, attests[0]));
494-
serverAllocator.checkAttestExpirations(attests[0]);
495-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttest.selector, attests[1]));
496-
serverAllocator.checkAttestExpirations(attests[1]);
497-
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttest.selector, attests[2]));
498-
serverAllocator.checkAttestExpirations(attests[2]);
493+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttestation.selector, attests[0]));
494+
serverAllocator.checkAttestationExpirations(attests[0]);
495+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttestation.selector, attests[1]));
496+
serverAllocator.checkAttestationExpirations(attests[1]);
497+
vm.expectRevert(abi.encodeWithSelector(IServerAllocator.UnregisteredAttestation.selector, attests[2]));
498+
serverAllocator.checkAttestationExpirations(attests[2]);
499499
}
500500
}
501501

0 commit comments

Comments
 (0)