Skip to content

Commit

Permalink
csc version support (#35)
Browse files Browse the repository at this point in the history
csc version support
  • Loading branch information
GalaxySciTech authored Jan 15, 2024
1 parent 25df2be commit 22c2c59
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit 22c2c59

Please sign in to comment.