Skip to content

Commit

Permalink
refactor: zksync adapter params in base tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianflexa committed Nov 5, 2024
1 parent e70a9a2 commit 5287300
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
3 changes: 2 additions & 1 deletion how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Alter the appropriate deployment script:
- `snapshotTimestamp`: timestamp of the snapshot ratio
- `maxYearlyRatioGrowthPercent`: the maximum possible annual LST growth percentage

1.1 If the adapter is deployed on zkSync network, you'll need to create a function that only returns the encoded parameters above instead of returning the deployment code.

2. Add the deployment script and command to the Makefile.

## 3. Testing
Expand All @@ -68,7 +70,6 @@ To test the adapter:

2.1. If the adapter will be tested against the zksync network:

- It must also implement the `_capAdapterParams() ` with the corresponding adapter's parameters. Because the parameters cannot be obtained from the regular deterministic deployment ( `GovV3Helpers.deployDeterministic(deploymentCode)` ).
- add the `salt` parameter using the `new` keyword for deployment: e.g.: `new CLRatePriceCapAdapter{salt: 'test'}(capAdapterParams)`

3. Specify the following test parameters:
Expand Down
20 changes: 11 additions & 9 deletions tests/BaseStableTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,20 @@ abstract contract BaseStableTest is Test {

ForkParams public forkParams;
bytes public deploymentCode;
bytes public adapterParams;

constructor(
bytes memory _deploymentCode,
bytes memory _deploymentCodeOrParams,
uint8 _retrospectiveDays,
ForkParams memory _forkParams
) {
forkParams = _forkParams;
deploymentCode = _deploymentCode;
RETROSPECTIVE_DAYS = _retrospectiveDays;
if (keccak256(bytes(_forkParams.network)) == keccak256(bytes('zksync'))) {
adapterParams = _deploymentCodeOrParams;
} else {
deploymentCode = _deploymentCodeOrParams;
}
}

function setUp() public {
Expand Down Expand Up @@ -82,14 +87,11 @@ abstract contract BaseStableTest is Test {

function _createAdapter() internal returns (IPriceCapAdapterStable) {
if (keccak256(bytes(forkParams.network)) == keccak256(bytes('zksync'))) {
return new PriceCapAdapterStable{salt: 'test'}(_capAdapterParams());
return
new PriceCapAdapterStable{salt: 'test'}(
abi.decode(adapterParams, (IPriceCapAdapterStable.CapAdapterStableParams))
);
}
return IPriceCapAdapterStable(GovV3Helpers.deployDeterministic(deploymentCode));
}

function _capAdapterParams()
internal
virtual
returns (IPriceCapAdapterStable.CapAdapterStableParams memory)
{}
}
19 changes: 9 additions & 10 deletions tests/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,24 @@ abstract contract BaseTest is Test {

ForkParams public forkParams;
bytes public deploymentCode;
bytes public adapterParams;
string public reportName;
PriceParams[] prices;

constructor(
bytes memory _deploymentCode,
bytes memory _deploymentCodeOrParams,
uint8 _retrospectiveDays,
ForkParams memory _forkParams,
string memory _reportName
) {
forkParams = _forkParams;
deploymentCode = _deploymentCode;
RETROSPECTIVE_DAYS = _retrospectiveDays;
reportName = _reportName;
if (keccak256(bytes(_forkParams.network)) == keccak256(bytes('zksync'))) {
adapterParams = _deploymentCodeOrParams;
} else {
deploymentCode = _deploymentCodeOrParams;
}
}

function setUp() public {
Expand Down Expand Up @@ -165,7 +170,7 @@ abstract contract BaseTest is Test {

function _getCapAdapterParams() internal returns (IPriceCapAdapter.CapAdapterParams memory) {
if (keccak256(bytes(forkParams.network)) == keccak256(bytes('zksync'))) {
return _capAdapterParams();
return abi.decode(adapterParams, (IPriceCapAdapter.CapAdapterParams));
}
IPriceCapAdapter adapter = _createAdapter();
return
Expand All @@ -187,15 +192,9 @@ abstract contract BaseTest is Test {
IPriceCapAdapter.CapAdapterParams memory capAdapterParams
) internal virtual returns (IPriceCapAdapter) {}

function _capAdapterParams()
internal
virtual
returns (IPriceCapAdapter.CapAdapterParams memory)
{}

function _createAdapter() internal returns (IPriceCapAdapter) {
if (keccak256(bytes(forkParams.network)) == keccak256(bytes('zksync'))) {
return _createAdapter(_capAdapterParams());
return _createAdapter(_getCapAdapterParams());
}
return IPriceCapAdapter(GovV3Helpers.deployDeterministic(deploymentCode));
}
Expand Down

0 comments on commit 5287300

Please sign in to comment.