From af154fafb548039cf316d3f213c7aabcafc19a2b Mon Sep 17 00:00:00 2001 From: Leonardo Massazza Date: Thu, 7 Dec 2023 13:44:26 -0300 Subject: [PATCH 1/2] Add mock and include in testable toml --- .../OpGasPriceOracle/cannonfile.test.toml | 40 ++++++++++- .../contracts/mocks/MockOVMGasPriceOracle.sol | 66 +++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 auxiliary/OpGasPriceOracle/contracts/mocks/MockOVMGasPriceOracle.sol diff --git a/auxiliary/OpGasPriceOracle/cannonfile.test.toml b/auxiliary/OpGasPriceOracle/cannonfile.test.toml index 7a0acdfaad..e9d5dda5e6 100644 --- a/auxiliary/OpGasPriceOracle/cannonfile.test.toml +++ b/auxiliary/OpGasPriceOracle/cannonfile.test.toml @@ -1,2 +1,40 @@ +name = "op-gas-price-oracle" version = "<%= package.version %>-testable" -include = ["cannonfile.toml"] + +[setting.baseFee] +defaultValue = "30000000" + +[setting.gasPrice] +defaultValue = "30000000" + +[setting.l1BaseFee] +defaultValue = "50000000000" + +[setting.overhead] +defaultValue = "200" + +[setting.scalar] +defaultValue = "684000" + +[setting.internall1GasUsed] +defaultValue = "10000" + +[setting.internall1Fee] +defaultValue = "1000" + +[contract.mockOVMGasPriceOracle] +artifact = "contracts/mocks/MockOVMGasPriceOracle.sol:MockOVMGasPriceOracle" +args = [ + "<%= settings.gasPrice %>", + "<%= settings.overhead %>", + "<%= settings.baseFee %>", + "<%= settings.l1BaseFee %>", + "<%= settings.scalar %>", + "<%= settings.internall1GasUsed %>", + "<%= settings.internall1Fee %>" +] + +[contract.OpGasPriceOracle] +artifact = "contracts/OpGasPriceOracle.sol:OpGasPriceOracle" +args = ["<%= contracts.mockOVMGasPriceOracle.address %>"] +create2 = true diff --git a/auxiliary/OpGasPriceOracle/contracts/mocks/MockOVMGasPriceOracle.sol b/auxiliary/OpGasPriceOracle/contracts/mocks/MockOVMGasPriceOracle.sol new file mode 100644 index 0000000000..b0a5acaa19 --- /dev/null +++ b/auxiliary/OpGasPriceOracle/contracts/mocks/MockOVMGasPriceOracle.sol @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +import "../interfaces/IOVM_GasPriceOracle.sol"; + +contract MockOVMGasPriceOracle is IOVM_GasPriceOracle { + uint256 public constant DECIMALS = 6; + + uint256 public gasPrice; + uint256 public overhead; + uint256 public baseFee; + uint256 public l1BaseFee; + uint256 public scalar; + uint256 public internall1GasUsed; + uint256 public internall1Fee; + + constructor( + uint256 _gasPrice, + uint256 _overhead, + uint256 _baseFee, + uint256 _l1BaseFee, + uint256 _scalar, + uint256 _internall1GasUsed, + uint256 _internall1Fee + ) { + gasPrice = _gasPrice; + overhead = _overhead; + baseFee = _baseFee; + l1BaseFee = _l1BaseFee; + scalar = _scalar; + internall1GasUsed = _internall1GasUsed; + internall1Fee = _internall1Fee; + } + + function setParams( + uint256 _gasPrice, + uint256 _overhead, + uint256 _baseFee, + uint256 _l1BaseFee, + uint256 _scalar, + uint256 _internall1GasUsed, + uint256 _internall1Fee + ) external { + gasPrice = _gasPrice; + overhead = _overhead; + baseFee = _baseFee; + l1BaseFee = _l1BaseFee; + scalar = _scalar; + internall1GasUsed = _internall1GasUsed; + internall1Fee = _internall1Fee; + } + + function decimals() external pure returns (uint256) { + return DECIMALS; + } + + function getL1Fee(bytes memory _data) external view returns (uint256) { + _data; + return internall1Fee; + } + + function getL1GasUsed(bytes memory _data) external view returns (uint256) { + _data; + return internall1GasUsed; + } +} From 46ea00ff6119b2e12e79bcc0b02522877cc9dc09 Mon Sep 17 00:00:00 2001 From: Leonardo Massazza Date: Thu, 7 Dec 2023 15:49:39 -0300 Subject: [PATCH 2/2] Use withMock toml --- .../OpGasPriceOracle/cannonfile.test.toml | 40 +------------------ .../OpGasPriceOracle/cannonfile.withMock.toml | 39 ++++++++++++++++++ auxiliary/OpGasPriceOracle/package.json | 1 + 3 files changed, 41 insertions(+), 39 deletions(-) create mode 100644 auxiliary/OpGasPriceOracle/cannonfile.withMock.toml diff --git a/auxiliary/OpGasPriceOracle/cannonfile.test.toml b/auxiliary/OpGasPriceOracle/cannonfile.test.toml index e9d5dda5e6..7a0acdfaad 100644 --- a/auxiliary/OpGasPriceOracle/cannonfile.test.toml +++ b/auxiliary/OpGasPriceOracle/cannonfile.test.toml @@ -1,40 +1,2 @@ -name = "op-gas-price-oracle" version = "<%= package.version %>-testable" - -[setting.baseFee] -defaultValue = "30000000" - -[setting.gasPrice] -defaultValue = "30000000" - -[setting.l1BaseFee] -defaultValue = "50000000000" - -[setting.overhead] -defaultValue = "200" - -[setting.scalar] -defaultValue = "684000" - -[setting.internall1GasUsed] -defaultValue = "10000" - -[setting.internall1Fee] -defaultValue = "1000" - -[contract.mockOVMGasPriceOracle] -artifact = "contracts/mocks/MockOVMGasPriceOracle.sol:MockOVMGasPriceOracle" -args = [ - "<%= settings.gasPrice %>", - "<%= settings.overhead %>", - "<%= settings.baseFee %>", - "<%= settings.l1BaseFee %>", - "<%= settings.scalar %>", - "<%= settings.internall1GasUsed %>", - "<%= settings.internall1Fee %>" -] - -[contract.OpGasPriceOracle] -artifact = "contracts/OpGasPriceOracle.sol:OpGasPriceOracle" -args = ["<%= contracts.mockOVMGasPriceOracle.address %>"] -create2 = true +include = ["cannonfile.toml"] diff --git a/auxiliary/OpGasPriceOracle/cannonfile.withMock.toml b/auxiliary/OpGasPriceOracle/cannonfile.withMock.toml new file mode 100644 index 0000000000..5c1ca82e5a --- /dev/null +++ b/auxiliary/OpGasPriceOracle/cannonfile.withMock.toml @@ -0,0 +1,39 @@ +name = "op-gas-price-oracle-mock" +version = "<%= package.version %>" + +[setting.baseFee] +defaultValue = "30000000" + +[setting.gasPrice] +defaultValue = "30000000" + +[setting.l1BaseFee] +defaultValue = "50000000000" + +[setting.overhead] +defaultValue = "200" + +[setting.scalar] +defaultValue = "684000" + +[setting.internall1GasUsed] +defaultValue = "10000" + +[setting.internall1Fee] +defaultValue = "1000" + +[contract.mockOVMGasPriceOracle] +artifact = "contracts/mocks/MockOVMGasPriceOracle.sol:MockOVMGasPriceOracle" +args = [ + "<%= settings.gasPrice %>", + "<%= settings.overhead %>", + "<%= settings.baseFee %>", + "<%= settings.l1BaseFee %>", + "<%= settings.scalar %>", + "<%= settings.internall1GasUsed %>", + "<%= settings.internall1Fee %>" +] + +[contract.OpGasPriceOracle] +artifact = "contracts/OpGasPriceOracle.sol:OpGasPriceOracle" +args = ["<%= contracts.mockOVMGasPriceOracle.address %>"] diff --git a/auxiliary/OpGasPriceOracle/package.json b/auxiliary/OpGasPriceOracle/package.json index 3f5bba9575..2ca214a595 100644 --- a/auxiliary/OpGasPriceOracle/package.json +++ b/auxiliary/OpGasPriceOracle/package.json @@ -12,6 +12,7 @@ "build": "yarn build:contracts", "build:contracts": "hardhat storage:verify && hardhat cannon:build", "build-testable": "CANNON_REGISTRY_PRIORITY=local hardhat cannon:build cannonfile.test.toml", + "build-mock": "CANNON_REGISTRY_PRIORITY=local hardhat cannon:build cannonfile.withMock.toml", "check:storage": "git diff --exit-code storage.dump.sol", "compile-contracts": "hardhat compile", "size-contracts": "hardhat compile && hardhat size-contracts",