Skip to content

Commit 14a0c20

Browse files
committed
tests
1 parent fadd75b commit 14a0c20

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

Diff for: script/rescue/Rescuer.sol

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ contract Rescuer is Auth {
8181
}
8282

8383
/// @notice Rescues ETH from multiple ScribeOptimistic instances `opScribes`.
84+
///
85+
/// @dev Note that `opScribes` MUST be deactivated.
86+
/// @dev Note that validator key pair SHALL be only used once and generated
87+
/// via a CSPRNG.
88+
///
89+
/// @dev Only callable by auth'ed address.
8490
function suck(
8591
address[] memory opScribes,
8692
LibSecp256k1.Point memory pubKey,

Diff for: test/rescue/RescuerTest.sol

+19-9
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ contract RescuerTest is Test {
3434
scribe = new ScribeOptimistic(address(this), bytes32("TEST/TEST"));
3535
IScribeOptimistic(scribe).setMaxChallengeReward(type(uint).max);
3636
rescuer = new Rescuer(address(this));
37+
// Auth the recover contract on scribe
38+
IAuth(address(scribe)).rely(address(rescuer));
3739
}
3840

41+
// -- Test: Suck --
42+
3943
function testFuzz_suck(uint privKey) public {
4044
privKey = _bound(privKey, 1, LibSecp256k1.Q() - 1);
4145
// Auth the recover contract on scribe
@@ -65,12 +69,13 @@ contract RescuerTest is Test {
6569
emit Withdrawed(address(this), recipient, withdraw_amount);
6670
rescuer.withdraw(payable(recipient), withdraw_amount);
6771
assertEq(recipient.balance, withdraw_amount);
72+
assertEq(recipient.balance, 1 ether);
6873
}
6974

7075
function testFuzz_suckMultiple(uint privKey) public {
7176
privKey = _bound(privKey, 1, LibSecp256k1.Q() - 1);
7277
address[] memory scribes = new address[](10);
73-
for (uint i = 0; i < 10; i++) {
78+
for (uint i; i < scribes.len; i++) {
7479
scribes[i] = address(new ScribeOptimistic(address(this), bytes32("TEST/TEST")));
7580
IScribeOptimistic(scribes[i]).setMaxChallengeReward(type(uint).max);
7681
// Auth the recover contract on scribe
@@ -87,21 +92,24 @@ contract RescuerTest is Test {
8792
uint32 pokeDataAge = uint32(block.timestamp);
8893
IScribe.ECDSAData memory opPokeSig = _construct_opPokeSignature(feed, pokeDataAge);
8994
// Rescue ETH via rescuer contract.
90-
for (uint i = 0; i < 10; i++) {
95+
for (uint i; i < scribes.len; i++) {
9196
vm.expectEmit();
9297
emit Recovered(address(this), address(scribes[i]), 1 ether);
9398
}
9499
rescuer.suck(
95100
scribes, feed.pubKey, registrationSig, pokeDataAge, opPokeSig
96101
);
97102
// Withdraw the eth
98-
uint current_balance = address(this).balance;
99-
uint withdraw_amount = address(rescuer).balance;
100103
address recipient = address(0x1234567890123456789012345678901234567890);
101-
vm.expectEmit();
102-
emit Withdrawed(address(this), recipient, withdraw_amount);
103-
rescuer.withdraw(payable(recipient), withdraw_amount);
104-
assertEq(recipient.balance, withdraw_amount);
104+
for (uint i; i < scribes.len; i++){
105+
uint current_balance = address(this).balance;
106+
uint withdraw_amount = address(rescuer).balance;
107+
vm.expectEmit();
108+
emit Withdrawed(address(this), recipient, withdraw_amount);
109+
rescuer.withdraw(payable(recipient), withdraw_amount);
110+
assertEq(recipient.balance, withdraw_amount);
111+
}
112+
assertEq(recipient.balance, scribes.len * (1 ether));
105113

106114
}
107115

@@ -174,6 +182,7 @@ contract RescuerTest is Test {
174182
);
175183
}
176184

185+
// -- Test: Withdraw --
177186

178187
function testFuzz_withdraw(uint amount) public {
179188
amount = _bound(amount, 0, 1000 ether);
@@ -188,7 +197,7 @@ contract RescuerTest is Test {
188197
assertEq(withdraw_amount, amount);
189198
}
190199

191-
// ---------- Auth tests ----------
200+
// -- Test: Auth --
192201

193202
function test_suck_isAuthed() public {
194203
// Deauth this on the rescuer contract
@@ -225,6 +234,7 @@ contract RescuerTest is Test {
225234
rescuer.withdraw(payable(recipient), 0);
226235
}
227236

237+
// -- Helpers --
228238

229239
function _construct_opPokeSignature(LibFeed.Feed memory feed, uint32 pokeDataAge) private returns (IScribe.ECDSAData memory) {
230240
IScribe.PokeData memory pokeData = IScribe.PokeData(0, pokeDataAge);

0 commit comments

Comments
 (0)