forked from dragonfly-xyz/useful-solidity-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitializedProxyWallet.t.sol
61 lines (51 loc) · 1.79 KB
/
InitializedProxyWallet.t.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.23;
import "../patterns/initializing-upgradeable-contracts/InitializedProxyWallet.sol";
import "./TestUtils.sol";
contract InitializedProxyWalletTest is TestUtils {
Proxy proxy;
WalletLogic logic = new WalletLogic();
WalletLogic wallet;
address owner;
constructor() {
owner = _randomAddress();
proxy = new Proxy(
address(logic),
abi.encodeCall(WalletLogic.initialize, (owner))
);
wallet = WalletLogic(payable(proxy));
}
function test_hasOwner() external {
assertEq(wallet.owner(), owner);
}
function test_canReceiveEth() external {
_sendEth(payable(wallet), 1337);
assertEq(address(wallet).balance, 1337);
}
function test_ownerCanTransferEthOut() external {
_sendEth(payable(wallet), 1337);
vm.prank(owner);
address payable recipient = _randomAddress();
wallet.transferOut(recipient, 1337);
assertEq(recipient.balance, 1337);
}
function test_nonOwnerCannotTransferEthOut() external {
_sendEth(payable(wallet), 1337);
vm.prank(_randomAddress());
address payable recipient = _randomAddress();
vm.expectRevert('only owner');
wallet.transferOut(recipient, 1337);
}
function test_cannotInitializeAgain() external {
vm.expectRevert('not in constructor');
wallet.initialize(_randomAddress());
}
function test_cannotInitializeLogicContract() external {
vm.expectRevert('not in constructor');
logic.initialize(_randomAddress());
}
function _sendEth(address payable to, uint256 amount) private {
(bool s,) = to.call{value: amount}("");
require(s, 'ETH transfer failed');
}
}