Skip to content

Commit

Permalink
Move oracletype into its own package
Browse files Browse the repository at this point in the history
  • Loading branch information
ogtownsend committed Oct 16, 2024
1 parent 275bcf0 commit 4a8cbf2
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/red-jobs-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": patch
---

Moves oracletype config into its own package #wip
3 changes: 2 additions & 1 deletion core/capabilities/ccip/ocrimpls/contract_transmitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ocrimpls"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
Expand Down Expand Up @@ -600,7 +601,7 @@ type TestDAOracleConfig struct {
evmconfig.DAOracle
}

func (d *TestDAOracleConfig) OracleType() toml.OracleType { return toml.OPStack }
func (d *TestDAOracleConfig) OracleType() toml.OracleType { return toml.DAOracleOPStack }
func (d *TestDAOracleConfig) OracleAddress() *types.EIP55Address {
a, err := types.NewEIP55Address("0x420000000000000000000000000000000000000F")
if err != nil {
Expand Down
14 changes: 11 additions & 3 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,11 +767,19 @@ type DAOracle struct {
type OracleType string

const (
OPStack = OracleType("opstack")
Arbitrum = OracleType("arbitrum")
ZKSync = OracleType("zksync")
DAOracleOPStack = OracleType("opstack")
DAOracleArbitrum = OracleType("arbitrum")
DAOracleZKSync = OracleType("zksync")
)

func (o OracleType) IsValid() bool {
switch o {
case "", DAOracleOPStack, DAOracleArbitrum, DAOracleZKSync:
return true
}
return false
}

func (d *DAOracle) setFrom(f *DAOracle) {
d.OracleType = f.OracleType
if v := f.OracleAddress; v != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/gas/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestWrappedEvmEstimator(t *testing.T) {
assert.Nil(t, l1Oracle)

// expect l1Oracle
daOracle := rollups.CreateTestDAOracle(t, toml.OPStack, "0x420000000000000000000000000000000000000F", "")
daOracle := rollups.CreateTestDAOracle(t, toml.DAOracleOPStack, "0x420000000000000000000000000000000000000F", "")
oracle, err := rollups.NewL1GasOracle(lggr, nil, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
// cast oracle to L1Oracle interface
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/gas/rollups/l1_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func NewL1GasOracle(lggr logger.Logger, ethClient l1OracleClient, chainType chai
var err error
if daOracle != nil {
switch daOracle.OracleType() {
case toml.OPStack:
case toml.DAOracleOPStack:
l1Oracle, err = NewOpStackL1GasOracle(lggr, ethClient, chainType, daOracle)
case toml.Arbitrum:
case toml.DAOracleArbitrum:
l1Oracle, err = NewArbitrumL1GasOracle(lggr, ethClient)
case toml.ZKSync:
case toml.DAOracleZKSync:
l1Oracle = NewZkSyncL1GasOracle(lggr, ethClient)
default:
err = fmt.Errorf("unsupported DA oracle type %s. Going forward all chain configs should specify an oracle type", daOracle.OracleType())
Expand Down
14 changes: 7 additions & 7 deletions core/chains/evm/gas/rollups/l1_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestL1Oracle(t *testing.T) {
t.Run("Unsupported ChainType returns nil", func(t *testing.T) {
ethClient := mocks.NewL1OracleClient(t)

daOracle := CreateTestDAOracle(t, toml.OPStack, utils.RandomAddress().String(), "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, utils.RandomAddress().String(), "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainCelo, daOracle)
require.NoError(t, err)
assert.Nil(t, oracle)
Expand All @@ -43,7 +43,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
t.Run("Calling GasPrice on unstarted L1Oracle returns error", func(t *testing.T) {
ethClient := mocks.NewL1OracleClient(t)

daOracle := CreateTestDAOracle(t, toml.OPStack, utils.RandomAddress().String(), "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, utils.RandomAddress().String(), "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)

Expand All @@ -67,7 +67,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.Arbitrum, "0x0000000000000000000000000000000000000000", "")
daOracle := CreateTestDAOracle(t, toml.DAOracleArbitrum, "0x0000000000000000000000000000000000000000", "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainArbitrum, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainKroma, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainScroll, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down Expand Up @@ -194,7 +194,7 @@ func TestL1Oracle_GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(gasPerPubByteL2).Bytes(), nil)

daOracle := CreateTestDAOracle(t, toml.ZKSync, "0x0000000000000000000000000000000000000000", "")
daOracle := CreateTestDAOracle(t, toml.DAOracleZKSync, "0x0000000000000000000000000000000000000000", "")
oracle, err := NewL1GasOracle(logger.Test(t), ethClient, chaintype.ChainZkSync, daOracle)
require.NoError(t, err)
servicetest.RunHealthy(t, oracle)
Expand Down
18 changes: 9 additions & 9 deletions core/chains/evm/gas/rollups/op_l1_oracle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestOPL1Oracle_ReadV1GasPrice(t *testing.T) {
assert.Nil(t, blockNumber)
}).Return(common.BigToHash(l1BaseFee).Bytes(), nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, "0x0000000000000000000000000000000000001234", "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, "0x0000000000000000000000000000000000001234", "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
gasPrice, err := oracle.GetDAGasPrice(tests.Context(t))
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestOPL1Oracle_CalculateEcotoneGasPrice(t *testing.T) {
ethClient := setupUpgradeCheck(t, oracleAddress, false, true)
mockBatchContractCall(t, ethClient, oracleAddress, baseFee, baseFeeScalar, blobBaseFee, blobBaseFeeScalar, decimals)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
gasPrice, err := oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -246,7 +246,7 @@ func TestOPL1Oracle_CalculateEcotoneGasPrice(t *testing.T) {
rpcElements[1].Result = &badData
}).Return(nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -257,7 +257,7 @@ func TestOPL1Oracle_CalculateEcotoneGasPrice(t *testing.T) {
ethClient := setupUpgradeCheck(t, oracleAddress, false, true)
ethClient.On("BatchCallContext", mock.Anything, mock.IsType([]rpc.BatchElem{})).Return(fmt.Errorf("revert")).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -273,7 +273,7 @@ func TestOPL1Oracle_CalculateEcotoneGasPrice(t *testing.T) {
rpcElements[1].Error = fmt.Errorf("revert")
}).Return(nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -295,7 +295,7 @@ func TestOPL1Oracle_CalculateFjordGasPrice(t *testing.T) {
ethClient := setupUpgradeCheck(t, oracleAddress, true, true)
mockBatchContractCall(t, ethClient, oracleAddress, baseFee, baseFeeScalar, blobBaseFee, blobBaseFeeScalar, decimals)

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
gasPrice, err := oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -315,7 +315,7 @@ func TestOPL1Oracle_CalculateFjordGasPrice(t *testing.T) {
rpcElements[1].Result = &badData
}).Return(nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -326,7 +326,7 @@ func TestOPL1Oracle_CalculateFjordGasPrice(t *testing.T) {
ethClient := setupUpgradeCheck(t, oracleAddress, true, true)
ethClient.On("BatchCallContext", mock.Anything, mock.IsType([]rpc.BatchElem{})).Return(fmt.Errorf("revert")).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand All @@ -342,7 +342,7 @@ func TestOPL1Oracle_CalculateFjordGasPrice(t *testing.T) {
rpcElements[1].Error = fmt.Errorf("revert")
}).Return(nil).Once()

daOracle := CreateTestDAOracle(t, toml.OPStack, oracleAddress, "")
daOracle := CreateTestDAOracle(t, toml.DAOracleOPStack, oracleAddress, "")
oracle, err := NewOpStackL1GasOracle(logger.Test(t), ethClient, chaintype.ChainOptimismBedrock, daOracle)
require.NoError(t, err)
_, err = oracle.GetDAGasPrice(tests.Context(t))
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type TestDAOracleConfig struct {
evmconfig.DAOracle
}

func (d *TestDAOracleConfig) OracleType() toml.OracleType { return toml.OPStack }
func (d *TestDAOracleConfig) OracleType() toml.OracleType { return toml.DAOracleOPStack }
func (d *TestDAOracleConfig) OracleAddress() *types.EIP55Address {
a, err := types.NewEIP55Address("0x420000000000000000000000000000000000000F")
if err != nil {
Expand Down

0 comments on commit 4a8cbf2

Please sign in to comment.