Skip to content

Commit

Permalink
Return a clone from supported chains. Otherwise any operations on the…
Browse files Browse the repository at this point in the history
… returned set will affect the original set
  • Loading branch information
asoliman92 committed Dec 19, 2024
1 parent c50ac60 commit cf6c3dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
43 changes: 18 additions & 25 deletions commit/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,11 @@ func TestPlugin_E2E_AllNodesAgree_ChainFee(t *testing.T) {
nodes := make([]ocr3types.ReportingPlugin[[]byte], len(oracleIDs))

newFeeComponents, newNativePrice, packedGasPrice := newRandomFees()
expectedChainFeeOutcome := chainfee.Outcome{
expectedChain1FeeOutcome := chainfee.Outcome{
GasPrices: []ccipocr3.GasPriceChain{
{
GasPrice: packedGasPrice,
ChainSel: destChain,
ChainSel: sourceChain1,
},
},
}
Expand All @@ -464,10 +464,6 @@ func TestPlugin_E2E_AllNodesAgree_ChainFee(t *testing.T) {
MerkleRootOutcome: merkleOutcome,
ChainFeeOutcome: chainfee.Outcome{
GasPrices: []ccipocr3.GasPriceChain{
{
GasPrice: packedGasPrice,
ChainSel: destChain,
},
{
GasPrice: packedGasPrice,
ChainSel: sourceChain1,
Expand All @@ -485,15 +481,13 @@ func TestPlugin_E2E_AllNodesAgree_ChainFee(t *testing.T) {
GetChainsFeeComponents(params.ctx, mock.Anything).
Return(
map[ccipocr3.ChainSelector]types.ChainFeeComponents{
destChain: newFeeComponents,
sourceChain1: newFeeComponents,
sourceChain2: newFeeComponents,
})

m.EXPECT().
GetWrappedNativeTokenPriceUSD(params.ctx, mock.Anything).
Return(map[ccipocr3.ChainSelector]ccipocr3.BigInt{
destChain: newNativePrice,
sourceChain1: newNativePrice,
sourceChain2: newNativePrice,
})
Expand All @@ -504,21 +498,20 @@ func TestPlugin_E2E_AllNodesAgree_ChainFee(t *testing.T) {
prevOutcome: committypes.Outcome{},
expOutcome: committypes.Outcome{
MerkleRootOutcome: merkleOutcome,
ChainFeeOutcome: expectedChainFeeOutcome,
ChainFeeOutcome: expectedChain1FeeOutcome,
},
expTransmittedReportLen: 1,
mockCCIPReader: func(m *readerpkg_mock.MockCCIPReader) {
m.EXPECT().
GetChainsFeeComponents(params.ctx, mock.Anything).
Return(
map[ccipocr3.ChainSelector]types.ChainFeeComponents{
destChain: newFeeComponents,
sourceChain1: newFeeComponents,
})

m.EXPECT().
GetWrappedNativeTokenPriceUSD(params.ctx, mock.Anything).
Return(map[ccipocr3.ChainSelector]ccipocr3.BigInt{
destChain: newNativePrice,
sourceChain1: newNativePrice,
sourceChain2: newNativePrice,
})
Expand All @@ -528,41 +521,41 @@ func TestPlugin_E2E_AllNodesAgree_ChainFee(t *testing.T) {
name: "fee components should not be updated within deviation",
prevOutcome: committypes.Outcome{
MerkleRootOutcome: merkleOutcome,
ChainFeeOutcome: expectedChainFeeOutcome,
ChainFeeOutcome: expectedChain1FeeOutcome,
},
expOutcome: committypes.Outcome{
MerkleRootOutcome: noReportMerkleOutcome(params.rmnReportCfg),
ChainFeeOutcome: expectedChainFeeOutcome,
ChainFeeOutcome: expectedChain1FeeOutcome,
},
expTransmittedReportLen: 1,
mockCCIPReader: func(m *readerpkg_mock.MockCCIPReader) {
m.EXPECT().
GetChainsFeeComponents(params.ctx, mock.Anything).
Return(
map[ccipocr3.ChainSelector]types.ChainFeeComponents{
destChain: newFeeComponents,
sourceChain1: newFeeComponents,
})

m.EXPECT().
GetWrappedNativeTokenPriceUSD(params.ctx, mock.Anything).
Return(map[ccipocr3.ChainSelector]ccipocr3.BigInt{
destChain: newNativePrice,
sourceChain1: newNativePrice,
})
},
},
{
name: "fresh fees (timestamped) should not be updated, even outside of deviation",
prevOutcome: committypes.Outcome{
MerkleRootOutcome: merkleOutcome,
ChainFeeOutcome: expectedChainFeeOutcome,
ChainFeeOutcome: expectedChain1FeeOutcome,
},
expOutcome: committypes.Outcome{
MerkleRootOutcome: noReportMerkleOutcome(params.rmnReportCfg),
ChainFeeOutcome: chainfee.Outcome{
GasPrices: []ccipocr3.GasPriceChain{
{
GasPrice: newPackedGasPrice2,
ChainSel: destChain,
ChainSel: sourceChain1,
},
},
},
Expand All @@ -573,29 +566,29 @@ func TestPlugin_E2E_AllNodesAgree_ChainFee(t *testing.T) {
GetChainsFeeComponents(params.ctx, mock.Anything).
Return(
map[ccipocr3.ChainSelector]types.ChainFeeComponents{
destChain: newFeeComponents2,
sourceChain1: newFeeComponents2,
})

m.EXPECT().
GetWrappedNativeTokenPriceUSD(params.ctx, mock.Anything).
Return(map[ccipocr3.ChainSelector]ccipocr3.BigInt{
destChain: newNativePrice2,
sourceChain1: newNativePrice2,
})
},
},
{
name: "stale fees should be updated",
prevOutcome: committypes.Outcome{
MerkleRootOutcome: merkleOutcome,
ChainFeeOutcome: expectedChainFeeOutcome,
ChainFeeOutcome: expectedChain1FeeOutcome,
},
expOutcome: committypes.Outcome{
MerkleRootOutcome: noReportMerkleOutcome(params.rmnReportCfg),
ChainFeeOutcome: chainfee.Outcome{
GasPrices: []ccipocr3.GasPriceChain{
{
GasPrice: newPackedGasPrice2,
ChainSel: destChain,
ChainSel: sourceChain1,
},
},
},
Expand All @@ -606,12 +599,12 @@ func TestPlugin_E2E_AllNodesAgree_ChainFee(t *testing.T) {
GetChainsFeeComponents(params.ctx, mock.Anything).
Return(
map[ccipocr3.ChainSelector]types.ChainFeeComponents{
destChain: newFeeComponents2,
sourceChain1: newFeeComponents2,
})
m.EXPECT().
GetWrappedNativeTokenPriceUSD(params.ctx, mock.Anything).
Return(map[ccipocr3.ChainSelector]ccipocr3.BigInt{
destChain: newNativePrice2,
sourceChain1: newNativePrice2,
})

m.EXPECT().GetChainFeePriceUpdate(params.ctx, mock.Anything).Unset()
Expand All @@ -621,9 +614,9 @@ func TestPlugin_E2E_AllNodesAgree_ChainFee(t *testing.T) {
m.EXPECT().
GetChainFeePriceUpdate(params.ctx, mock.Anything).
Return(map[ccipocr3.ChainSelector]plugintypes.TimestampedBig{
destChain: {
sourceChain1: {
Timestamp: t,
Value: expectedChainFeeOutcome.GasPrices[0].GasPrice,
Value: expectedChain1FeeOutcome.GasPrices[0].GasPrice,
},
})
},
Expand Down
2 changes: 1 addition & 1 deletion internal/plugincommon/chain_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (c ccipChainSupport) SupportedChains(oracleID commontypes.OracleID) (mapset
return mapset.NewSet[cciptypes.ChainSelector](), fmt.Errorf("error getting supported chains: %w", err)
}

return supportedChains, nil
return supportedChains.Clone(), nil
}

// SupportsDestChain returns true if the given oracle supports the dest chain, returns false otherwise
Expand Down

0 comments on commit cf6c3dc

Please sign in to comment.