-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(p2p/proxy_workshop): fix readme and contracts
- Loading branch information
Lucas Leclerc
committed
Sep 2, 2024
1 parent
ea0e944
commit 58f288b
Showing
9 changed files
with
280 additions
and
201 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
p2p/6.Create_a_proxy/utils/Counter_v1.sol → p2p/6.Create_a_proxy/utils/CounterV1.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
p2p/6.Create_a_proxy/utils/Counter_v2.sol → p2p/6.Create_a_proxy/utils/CounterV2.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../src/proxys/ProxyV1.sol"; | ||
import "../src/implementations/CounterV1.sol"; | ||
|
||
contract ProxyTest is Test { | ||
ProxyV1 public proxy_v1; | ||
CounterV1 public counter; | ||
|
||
function setUp() public { | ||
counter = new CounterV1(); | ||
proxy_v1 = new ProxyV1(address(counter)); | ||
} | ||
|
||
function testCounter() public { | ||
assertEq(counter.total(), 0, "Counter should be 0"); | ||
counter.add(); | ||
assertEq(counter.total(), 1, "Counter should be 1"); | ||
} | ||
|
||
function testProxy_v1() public { | ||
uint256 total = CounterV1(address(proxy_v1)).total(); | ||
assertEq(total, 0, "total should be 0"); | ||
CounterV1(address(proxy_v1)).add(); | ||
total = CounterV1(address(proxy_v1)).total(); | ||
assertEq(total, 1, "total should be 1"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../src/proxys/ProxyV2.sol"; | ||
import "../src/implementations/CounterV1.sol"; | ||
import "../src/implementations/CounterV2.sol"; | ||
|
||
contract ProxyTest is Test { | ||
ProxyV2 public proxy_v2; | ||
CounterV1 public counter; | ||
CounterV2 public counter_v2; | ||
|
||
function setUp() public { | ||
counter = new CounterV1(); | ||
counter_v2 = new CounterV2(); | ||
proxy_v2 = new ProxyV2(address(counter)); | ||
} | ||
|
||
function testProxy_v2() public { | ||
uint256 total = CounterV1(address(proxy_v2)).total(); | ||
assertEq(total, 0, "total should be 0"); | ||
CounterV1(address(proxy_v2)).add(); | ||
total = CounterV1(address(proxy_v2)).total(); | ||
assertEq(total, 1, "total should be 1"); | ||
// change implementation | ||
proxy_v2.setImplementation(address(counter_v2)); | ||
CounterV2(address(proxy_v2)).add(2); | ||
total = CounterV2(address(proxy_v2)).total(); | ||
assertEq(total, 3, "total should be 3"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.25; | ||
|
||
import "forge-std/Test.sol"; | ||
import "../src/proxys/ProxyV1.sol"; | ||
import "../src/proxys/ProxyV2.sol"; | ||
import "../src/proxys/ProxyOwnableUpgradable.sol"; | ||
import "../src/implementations/CounterV1.sol"; | ||
import "../src/implementations/CounterV2.sol"; | ||
|
||
contract ProxyTest is Test { | ||
CounterV1 public counter; | ||
CounterV2 public counter_v2; | ||
ProxyOwnableUpgradable public proxy_ownable_upgradable; | ||
address public nonOwner; | ||
|
||
function setUp() public { | ||
counter = new CounterV1(); | ||
counter_v2 = new CounterV2(); | ||
proxy_ownable_upgradable = new ProxyOwnableUpgradable(address(counter)); | ||
nonOwner = address(0x1234); | ||
} | ||
|
||
function testProxyUpgrade() public { | ||
CounterV1(address(proxy_ownable_upgradable)).add(); | ||
assertEq(CounterV1(address(proxy_ownable_upgradable)).total(), 1, "should be 1"); | ||
proxy_ownable_upgradable.upgradeTo(address(counter_v2)); | ||
assertEq(proxy_ownable_upgradable.getImplementation(), address(counter_v2), "implementation should be CounterV2"); | ||
assertEq(CounterV2(address(proxy_ownable_upgradable)).total(), 1, "total should be 1"); | ||
CounterV2(address(proxy_ownable_upgradable)).add(3); | ||
assertEq(CounterV2(address(proxy_ownable_upgradable)).total(), 4, "total should be 4"); | ||
} | ||
|
||
function testUpgradeToAsNonOwner() public { | ||
// Attempt to upgrade implementation with a non-owner account | ||
vm.prank(nonOwner); | ||
vm.expectRevert("Caller is not the owner"); | ||
proxy_ownable_upgradable.upgradeTo(address(counter_v2)); | ||
assertEq(proxy_ownable_upgradable.getImplementation(), address(counter), "Implementation should not change for non-owner"); | ||
} | ||
|
||
function testTransferProxyOwnership() public { | ||
// Transfer ownership to nonOwner | ||
proxy_ownable_upgradable.transferProxyOwnership(nonOwner); | ||
assertEq(proxy_ownable_upgradable.getOwner(), nonOwner, "Owner should be nonOwner"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.