Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csc version support #35

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion contracts/proxy/ProxyGateway.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;

import {ProxyAdmin, TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {ProxyAdmin, TransparentUpgradeableProxy, ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {ICheckpoint} from "../interfaces/ICheckpoint.sol";

contract ProxyGateway is ProxyAdmin {
// 0 full | 1 lite
mapping(uint256 => TransparentUpgradeableProxy) public cscProxies;

//proxy => version
mapping(ITransparentUpgradeableProxy => uint256) public version;

event CreateProxy(TransparentUpgradeableProxy proxy);

function createProxy(
Expand Down Expand Up @@ -50,6 +53,7 @@ contract ProxyGateway is ProxyAdmin {
initEpoch
);
cscProxies[0] = createProxy(full, data);

return cscProxies[0];
}

Expand Down Expand Up @@ -77,6 +81,24 @@ contract ProxyGateway is ProxyAdmin {
initEpoch
);
cscProxies[1] = createProxy(lite, data);

return cscProxies[1];
}

function upgrade(
ITransparentUpgradeableProxy proxy,
address implementation
) public override {
super.upgrade(proxy, implementation);
version[proxy]++;
}

function upgradeAndCall(
ITransparentUpgradeableProxy proxy,
address implementation,
bytes memory data
) public payable override {
super.upgradeAndCall(proxy, implementation, data);
version[proxy]++;
}
}
7 changes: 7 additions & 0 deletions test/ProxyGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ describe("proxyGateway", () => {
900
);
const fullProxyAddress = await proxyGateway.cscProxies(0);
const fullVersion = await proxyGateway.version(fullProxyAddress);
const fullProxy = full.attach(fullProxyAddress);
const fullMode = await fullProxy.MODE();
const fullGap = await fullProxy.INIT_GAP();
const fullResult = await fullProxy.getHeaderByNumber(1);

expect(full.address).to.not.eq(fullProxy.address);
expect(fullVersion).to.eq(0);
expect(fullMode).to.eq("full");
expect(fullGap).to.eq(450);

Expand All @@ -105,10 +107,15 @@ describe("proxyGateway", () => {

await proxyGateway.upgrade(fullProxyAddress, proxyTest.address);
const afterUpgradeResult = await fullProxy.getHeaderByNumber(1);
const fullVersionAfterUpdate = await proxyGateway.version(
fullProxyAddress
);

expect(fullResult.hash).to.eq(
"0x684d18e0081cbe82cab66173647eaf2b078413da5f79a1082a5228314c23ae15"
);

expect(fullVersionAfterUpdate).to.eq(1);
expect(fullResult.number).to.eq(1);

expect(afterUpgradeResult.hash).to.eq(
Expand Down
Loading