caelum0x 2b68bde5d5 Predikt: full Polymarket-style prediction market — web + mobile + on-chain + bots
Working tree is now the canonical repo. Off-chain play-money + trustless on-chain
(FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution,
mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-06 23:29:50 +03:00

74 lines
3.0 KiB
Solidity

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
import "./utils/SoladyTest.sol";
import {CallContextChecker, UUPSUpgradeable} from "../src/utils/UUPSUpgradeable.sol";
import {LibClone} from "../src/utils/LibClone.sol";
import {MockUUPSImplementation} from "../test/utils/mocks/MockUUPSImplementation.sol";
contract UUPSUpgradeableTest is SoladyTest {
MockUUPSImplementation impl1;
address proxy;
bytes32 internal constant _ERC1967_IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
event Upgraded(address indexed implementation);
function setUp() public {
impl1 = new MockUUPSImplementation();
proxy = LibClone.deployERC1967(address(impl1));
MockUUPSImplementation(proxy).initialize(address(this));
}
function testUpgradeTo() public {
MockUUPSImplementation impl2 = new MockUUPSImplementation();
vm.expectEmit(true, true, true, true);
emit Upgraded(address(impl2));
MockUUPSImplementation(proxy).upgradeToAndCall(address(impl2), bytes(""));
bytes32 v = vm.load(proxy, _ERC1967_IMPLEMENTATION_SLOT);
assertEq(address(uint160(uint256(v))), address(impl2));
}
function testUpgradeToRevertWithUnauthorized() public {
vm.prank(address(0xBEEF));
vm.expectRevert(MockUUPSImplementation.Unauthorized.selector);
MockUUPSImplementation(proxy).upgradeToAndCall(address(0xABCD), bytes(""));
}
function testUpgradeToRevertWithUpgradeFailed() public {
vm.expectRevert(UUPSUpgradeable.UpgradeFailed.selector);
MockUUPSImplementation(proxy).upgradeToAndCall(address(0xABCD), bytes(""));
}
function testUpgradeToAndCall() public {
MockUUPSImplementation impl2 = new MockUUPSImplementation();
bytes memory data = abi.encodeWithSignature("setValue(uint256)", 5);
MockUUPSImplementation(proxy).upgradeToAndCall(address(impl2), data);
bytes32 v = vm.load(proxy, _ERC1967_IMPLEMENTATION_SLOT);
assertEq(address(uint160(uint256(v))), address(impl2));
assertEq(MockUUPSImplementation(proxy).value(), 5);
}
function testUpgradeToAndCallRevertWithUpgradeFailed() public {
vm.expectRevert(UUPSUpgradeable.UpgradeFailed.selector);
MockUUPSImplementation(proxy).upgradeToAndCall(address(0xABCD), "");
}
function testUpgradeToAndCallRevertWithCustomError() public {
MockUUPSImplementation impl2 = new MockUUPSImplementation();
bytes memory data = abi.encodeWithSignature("revertWithError()");
vm.expectRevert(
abi.encodeWithSelector(MockUUPSImplementation.CustomError.selector, address(this))
);
MockUUPSImplementation(proxy).upgradeToAndCall(address(impl2), data);
}
function testUpgradeToAndCallRevertWithUnauthorized() public {
vm.prank(address(0xBEEF));
vm.expectRevert(MockUUPSImplementation.Unauthorized.selector);
MockUUPSImplementation(proxy).upgradeToAndCall(address(0xABCD), "");
}
}