Skip to content

Commit

Permalink
(test): Amend TestCommitReportingPlugin_Report with pricegetter
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkaseman committed Apr 9, 2024
1 parent 8678eb1 commit a8992a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ telemetry-protobuf: $(telemetry-protobuf) ## Generate telemetry protocol buffers
config-docs: ## Generate core node configuration documentation
go run ./core/config/docs/cmd/generate -o ./docs/

.PHONY: golangci-lint
.PHONY: golintlangci-
golangci-lint: ## Run golangci-lint for all issues.
[ -d "./golangci-lint" ] || mkdir ./golangci-lint && \
docker run --rm -v $(shell pwd):/app -w /app golangci/golangci-lint:v1.56.2 golangci-lint run --max-issues-per-linter 0 --max-same-issues 0 > ./golangci-lint/$(shell date +%Y-%m-%d_%H:%M:%S).txt
Expand Down
26 changes: 21 additions & 5 deletions core/services/ocr2/plugins/ccip/ccipcommit/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
name string
observations []ccip.CommitObservation
f int
priceGetterConfTokens []cciptypes.Address
gasPriceUpdates []cciptypes.GasPriceUpdateWithTxMeta
tokenDecimals map[cciptypes.Address]uint8
tokenPriceUpdates []cciptypes.TokenPriceUpdateWithTxMeta
Expand All @@ -348,7 +349,8 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
expErr bool
}{
{
name: "base",
name: "base",
priceGetterConfTokens: []cciptypes.Address{},
observations: []ccip.CommitObservation{
{Interval: cciptypes.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: gasPrice},
{Interval: cciptypes.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: gasPrice},
Expand Down Expand Up @@ -383,6 +385,10 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
},
{
name: "multiple offRamps report with token prices",
priceGetterConfTokens: []cciptypes.Address{
ccipcalc.HexToAddress("2000"),
ccipcalc.HexToAddress("3000"),
},
observations: []ccip.CommitObservation{
{
Interval: cciptypes.CommitStoreInterval{Min: 1, Max: 1},
Expand Down Expand Up @@ -438,7 +444,8 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
expErr: false,
},
{
name: "empty",
name: "empty",
priceGetterConfTokens: []cciptypes.Address{},
observations: []ccip.CommitObservation{
{Interval: cciptypes.CommitStoreInterval{Min: 0, Max: 0}, SourceGasPriceUSD: big.NewInt(0)},
{Interval: cciptypes.CommitStoreInterval{Min: 0, Max: 0}, SourceGasPriceUSD: big.NewInt(0)},
Expand All @@ -458,7 +465,8 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
expErr: false,
},
{
name: "no leaves",
name: "no leaves",
priceGetterConfTokens: []cciptypes.Address{},
observations: []ccip.CommitObservation{
{Interval: cciptypes.CommitStoreInterval{Min: 2, Max: 2}, SourceGasPriceUSD: big.NewInt(0)},
{Interval: cciptypes.CommitStoreInterval{Min: 2, Max: 2}, SourceGasPriceUSD: big.NewInt(0)},
Expand All @@ -469,7 +477,8 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
expErr: true,
},
{
name: "price reporting disabled base case",
name: "price reporting disabled base case",
priceGetterConfTokens: []cciptypes.Address{},
observations: []ccip.CommitObservation{
{Interval: cciptypes.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: nil},
{Interval: cciptypes.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: nil},
Expand All @@ -493,7 +502,8 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
expErr: false,
},
{
name: "price reporting disabled with invalid observation",
name: "price reporting disabled with invalid observation",
priceGetterConfTokens: []cciptypes.Address{},
observations: []ccip.CommitObservation{
{Interval: cciptypes.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: big.NewInt(0)},
{Interval: cciptypes.CommitStoreInterval{Min: 1, Max: 1}, SourceGasPriceUSD: nil},
Expand Down Expand Up @@ -576,6 +586,11 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
healthCheck := ccipcachemocks.NewChainHealthcheck(t)
healthCheck.On("IsHealthy", ctx).Return(true, nil)

pricegetter := pricegetter.NewMockPriceGetter(t)
for _, confToken := range tc.priceGetterConfTokens {
pricegetter.On("IsTokenConfigured", mock.Anything, confToken).Return(true, nil)
}

p := &CommitReportingPlugin{}
p.lggr = logger.TestLogger(t)
p.destPriceRegistryReader = destPriceRegistryReader
Expand All @@ -586,6 +601,7 @@ func TestCommitReportingPlugin_Report(t *testing.T) {
p.offchainConfig.GasPriceHeartBeat = gasPriceHeartBeat.Duration()
p.commitStoreReader = commitStoreReader
p.F = tc.f
p.priceGetter = pricegetter
p.metricsCollector = ccip.NoopMetricsCollector
p.offchainConfig.PriceReportingDisabled = tc.priceReportingDisabled
p.chainHealthcheck = healthCheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ func TestDynamicPriceGetter(t *testing.T) {
for tk := range test.param.expectedTokenPrices {
tokenAddr := cciptypes.Address(tk.String())
tokens = append(tokens, tokenAddr)
// Expect that token is configured
isConfigured, err2 := pg.IsTokenConfigured(ctx, tokenAddr)
require.NoError(t, err2)
assert.True(t, isConfigured)
}
prices, err := pg.TokenPricesUSD(ctx, tokens)
if test.param.priceResolutionErrorExpected {
Expand Down

0 comments on commit a8992a5

Please sign in to comment.