diff --git a/core/services/ocr2/plugins/ocr2keeper/evm21/feed_lookup.go b/core/services/ocr2/plugins/ocr2keeper/evm21/feed_lookup.go index 80528cdb94a..51de1d7ac04 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evm21/feed_lookup.go +++ b/core/services/ocr2/plugins/ocr2keeper/evm21/feed_lookup.go @@ -14,6 +14,7 @@ import ( "net/url" "strconv" "strings" + "sync" "time" "github.com/avast/retry-go/v4" @@ -25,8 +26,8 @@ import ( const ( BlockNumber = "blockNumber" // valid for v0.2 - FeedID = "feedID" // valid for v0.3 - FeedIDHex = "feedIDHex" // valid for v0.2 + FeedId = "feedId" // valid for v0.3 + FeedIdHex = "feedIdHex" // valid for v0.2 MercuryPathV2 = "/client?" MercuryPathV3 = "/v1/reports?" MercuryBatchPathV3 = "/v1/reports/bulk?" @@ -46,6 +47,8 @@ type FeedLookup struct { timeParamKey string time *big.Int extraData []byte + upkeepId *big.Int + block uint64 } // MercuryResponse is used in both single feed endpoint and bulk endpoint because bulk endpoint will return ONE @@ -69,7 +72,7 @@ type AdminOffchainConfig struct { // feedLookup looks through check upkeep results looking for any that need off chain lookup func (r *EvmRegistry) feedLookup(ctx context.Context, upkeepResults []EVMAutomationUpkeepResult21) ([]EVMAutomationUpkeepResult21, error) { - // TODO (AUTO-2862): parallelize the feed lookup work for all upkeeps + lookups := map[int]*FeedLookup{} for i := range upkeepResults { if upkeepResults[i].FailureReason != UPKEEP_FAILURE_REASON_TARGET_CHECK_REVERTED { continue @@ -84,7 +87,6 @@ func (r *EvmRegistry) feedLookup(ctx context.Context, upkeepResults []EVMAutomat } allowed, err := r.allowedToUseMercury(opts, upkeepId) - r.lggr.Info(allowed) if err != nil { r.lggr.Errorf("[FeedLookup] upkeep %s block %d failed to time mercury allow list: %v", upkeepId, block, err) continue @@ -96,52 +98,73 @@ func (r *EvmRegistry) feedLookup(ctx context.Context, upkeepResults []EVMAutomat continue } - feedLookup, err := r.decodeFeedLookup(upkeepResults[i].PerformData) + r.lggr.Infof("[FeedLookup] upkeep %s block %d decodeFeedLookup performData=%s", upkeepId, block, hexutil.Encode(upkeepResults[i].PerformData)) + lookup, err := r.decodeFeedLookup(upkeepResults[i].PerformData) if err != nil { r.lggr.Errorf("[FeedLookup] upkeep %s block %d decodeFeedLookup: %v", upkeepId, block, err) continue } - r.lggr.Infof("[FeedLookup] upkeep %s block %d feedLookup=%v", upkeepId, block, feedLookup) + lookup.upkeepId = upkeepId + // the block here is exclusively used to call checkCallback at this block, not to be confused with the block number + // in the revert for mercury v0.2, which is denoted by time in the struct bc starting from v0.3, only timestamp will be supported + lookup.block = uint64(block) + r.lggr.Infof("[FeedLookup] upkeep %s block %d decodeFeedLookup feedKey=%s timeKey=%s feeds=%v time=%s extraData=%s", upkeepId, block, lookup.feedParamKey, lookup.timeParamKey, lookup.feeds, lookup.time, hexutil.Encode(lookup.extraData)) + lookups[i] = lookup + } - values, retryable, err := r.doMercuryRequest(ctx, feedLookup, upkeepId) - if err != nil { - r.lggr.Errorf("[FeedLookup] upkeep %s block %d retryable %v doMercuryRequest: %v", upkeepId, block, retryable, err) - upkeepResults[i].Retryable = retryable - continue - } + var wg sync.WaitGroup + for i, lookup := range lookups { + wg.Add(1) + go r.doLookup(ctx, &wg, lookup, i, upkeepResults) + } + wg.Wait() - r.lggr.Debugf("[FeedLookup] upkeep %s block %d values: %v\nextraData: %v", upkeepId, block, values, feedLookup.extraData) - mercuryBytes, err := r.checkCallback(ctx, upkeepId, values, feedLookup.extraData, block) - if err != nil { - r.lggr.Errorf("[FeedLookup] upkeep %s block %d checkCallback err: %v", upkeepId, block, err) - continue - } + // don't surface error to plugin bc FeedLookup process should be self-contained. + return upkeepResults, nil +} - needed, performData, failureReason, _, err := r.packer.UnpackCheckCallbackResult(mercuryBytes) - if err != nil { - r.lggr.Errorf("[FeedLookup] upkeep %s block %d UnpackCheckCallbackResult err: %v", upkeepId, block, err) - continue - } +func (r *EvmRegistry) doLookup(ctx context.Context, wg *sync.WaitGroup, lookup *FeedLookup, i int, upkeepResults []EVMAutomationUpkeepResult21) { + defer wg.Done() - if int(failureReason) == UPKEEP_FAILURE_REASON_MERCURY_CALLBACK_REVERTED { - upkeepResults[i].FailureReason = UPKEEP_FAILURE_REASON_MERCURY_CALLBACK_REVERTED - r.lggr.Debugf("[FeedLookup] upkeep %s block %d mercury callback reverts", upkeepId, block) - continue - } + values, retryable, err := r.doMercuryRequest(ctx, lookup) + if err != nil { + r.lggr.Errorf("[FeedLookup] upkeep %s retryable %v doMercuryRequest: %v", lookup.upkeepId, retryable, err) + upkeepResults[i].Retryable = retryable + return + } + for j, v := range values { + r.lggr.Infof("[FeedLookup] checkCallback values[%d]=%s", j, hexutil.Encode(v)) + } - if !needed { - upkeepResults[i].FailureReason = UPKEEP_FAILURE_REASON_UPKEEP_NOT_NEEDED - r.lggr.Debugf("[FeedLookup] upkeep %s block %d callback reports upkeep not needed", upkeepId, block) - continue - } + mercuryBytes, err := r.checkCallback(ctx, values, lookup) + if err != nil { + r.lggr.Errorf("[FeedLookup] upkeep %s block %d checkCallback err: %v", lookup.upkeepId, lookup.block, err) + return + } + r.lggr.Infof("[FeedLookup] checkCallback mercuryBytes=%s", hexutil.Encode(mercuryBytes)) + + needed, performData, failureReason, _, err := r.packer.UnpackCheckCallbackResult(mercuryBytes) + if err != nil { + r.lggr.Errorf("[FeedLookup] upkeep %s block %d UnpackCheckCallbackResult err: %v", lookup.upkeepId, lookup.block, err) + return + } - upkeepResults[i].FailureReason = UPKEEP_FAILURE_REASON_NONE - upkeepResults[i].Eligible = true - upkeepResults[i].PerformData = performData - r.lggr.Infof("[FeedLookup] upkeep %s block %d successful with perform data: %+v", upkeepId, block, performData) + if int(failureReason) == UPKEEP_FAILURE_REASON_MERCURY_CALLBACK_REVERTED { + upkeepResults[i].FailureReason = UPKEEP_FAILURE_REASON_MERCURY_CALLBACK_REVERTED + r.lggr.Debugf("[FeedLookup] upkeep %s block %d mercury callback reverts", lookup.upkeepId, lookup.block) + return } - // don't surface error to plugin bc FeedLookup process should be self-contained. - return upkeepResults, nil + + if !needed { + upkeepResults[i].FailureReason = UPKEEP_FAILURE_REASON_UPKEEP_NOT_NEEDED + r.lggr.Debugf("[FeedLookup] upkeep %s block %d callback reports upkeep not needed", lookup.upkeepId, lookup.block) + return + } + + upkeepResults[i].FailureReason = UPKEEP_FAILURE_REASON_NONE + upkeepResults[i].Eligible = true + upkeepResults[i].PerformData = performData + r.lggr.Infof("[FeedLookup] upkeep %s block %d successful with perform data: %s", lookup.upkeepId, lookup.block, hexutil.Encode(performData)) } // allowedToUseMercury retrieves upkeep's administrative offchain config and decode a mercuryEnabled bool to indicate if @@ -184,8 +207,8 @@ func (r *EvmRegistry) decodeFeedLookup(data []byte) (*FeedLookup, error) { }, nil } -func (r *EvmRegistry) checkCallback(ctx context.Context, upkeepID *big.Int, values [][]byte, ed []byte, block uint32) (hexutil.Bytes, error) { - payload, err := r.abi.Pack("checkCallback", upkeepID, values, ed) +func (r *EvmRegistry) checkCallback(ctx context.Context, values [][]byte, lookup *FeedLookup) (hexutil.Bytes, error) { + payload, err := r.abi.Pack("checkCallback", lookup.upkeepId, values, lookup.extraData) if err != nil { return nil, err } @@ -196,7 +219,8 @@ func (r *EvmRegistry) checkCallback(ctx context.Context, upkeepID *big.Int, valu "data": hexutil.Bytes(payload), } - err = r.client.CallContext(ctx, &b, "eth_call", args, hexutil.EncodeUint64(uint64(block))) + // call checkCallback function at the block which OCR3 has agreed upon + err = r.client.CallContext(ctx, &b, "eth_call", args, hexutil.EncodeUint64(lookup.block)) if err != nil { return nil, err } @@ -204,24 +228,24 @@ func (r *EvmRegistry) checkCallback(ctx context.Context, upkeepID *big.Int, valu } // doMercuryRequest sends requests to Mercury API to retrieve ChainlinkBlob. -func (r *EvmRegistry) doMercuryRequest(ctx context.Context, ml *FeedLookup, upkeepId *big.Int) ([][]byte, bool, error) { +func (r *EvmRegistry) doMercuryRequest(ctx context.Context, ml *FeedLookup) ([][]byte, bool, error) { // TODO (AUTO-3253): if no feed labels are provided in v0.3, request for all feeds resultLen := len(ml.feeds) ch := make(chan MercuryBytes, resultLen) - if ml.feedParamKey == FeedIDHex && ml.timeParamKey == BlockNumber { + if ml.feedParamKey == FeedIdHex && ml.timeParamKey == BlockNumber { // only mercury v0.2 for i := range ml.feeds { - go r.singleFeedRequest(ctx, ch, upkeepId, i, ml, MercuryV02) + go r.singleFeedRequest(ctx, ch, i, ml, MercuryV02) } - } else if ml.feedParamKey == FeedID && ml.timeParamKey == Timestamp { + } else if ml.feedParamKey == FeedId && ml.timeParamKey == Timestamp { // only mercury v0.3 if resultLen == 1 { - go r.singleFeedRequest(ctx, ch, upkeepId, 0, ml, MercuryV03) + go r.singleFeedRequest(ctx, ch, 0, ml, MercuryV03) } else { // create a new channel with buffer size 1 since the batch endpoint will only return 1 blob resultLen = 1 ch = make(chan MercuryBytes, resultLen) - go r.multiFeedsRequest(ctx, ch, upkeepId, ml) + go r.multiFeedsRequest(ctx, ch, ml) } } else { return nil, false, fmt.Errorf("invalid label combination: feed param key %s and time param key %s", ml.feedParamKey, ml.timeParamKey) @@ -240,17 +264,17 @@ func (r *EvmRegistry) doMercuryRequest(ctx context.Context, ml *FeedLookup, upke } results[m.Index] = m.Bytes } - r.lggr.Debugf("FeedLookup upkeep %s retryable %s reqErr %w", upkeepId.String(), retryable && !allSuccess, reqErr) + r.lggr.Debugf("FeedLookup upkeep %s retryable %s reqErr %w", ml.upkeepId.String(), retryable && !allSuccess, reqErr) // only retry when not all successful AND none are not retryable return results, retryable && !allSuccess, reqErr } // singleFeedRequest sends a Mercury request for a single feed report. -func (r *EvmRegistry) singleFeedRequest(ctx context.Context, ch chan<- MercuryBytes, upkeepId *big.Int, index int, ml *FeedLookup, mv MercuryVersion) { +func (r *EvmRegistry) singleFeedRequest(ctx context.Context, ch chan<- MercuryBytes, index int, ml *FeedLookup, mv MercuryVersion) { q := url.Values{ ml.feedParamKey: {ml.feeds[index]}, ml.timeParamKey: {ml.time.String()}, - UserId: {upkeepId.String()}, + UserId: {ml.upkeepId.String()}, } mercuryURL := r.mercury.cred.URL path := MercuryPathV2 @@ -279,7 +303,7 @@ func (r *EvmRegistry) singleFeedRequest(ctx context.Context, ch chan<- MercuryBy retryable = false resp, err1 := r.hc.Do(req) if err1 != nil { - r.lggr.Errorf("FeedLookup upkeep %s block %s GET request fails for feed %s: %v", upkeepId.String(), ml.time.String(), ml.feeds[index], err1) + r.lggr.Errorf("FeedLookup upkeep %s block %s GET request fails for feed %s: %v", ml.upkeepId.String(), ml.time.String(), ml.feeds[index], err1) return err1 } defer resp.Body.Close() @@ -289,22 +313,22 @@ func (r *EvmRegistry) singleFeedRequest(ctx context.Context, ch chan<- MercuryBy } if resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusInternalServerError { - r.lggr.Errorf("FeedLookup upkeep %s block %s received status code %d for feed %s", upkeepId.String(), ml.time.String(), resp.StatusCode, ml.feeds[index]) + r.lggr.Errorf("FeedLookup upkeep %s block %s received status code %d for feed %s", ml.upkeepId.String(), ml.time.String(), resp.StatusCode, ml.feeds[index]) retryable = true return errors.New(strconv.FormatInt(int64(resp.StatusCode), 10)) } else if resp.StatusCode != http.StatusOK { - return fmt.Errorf("FeedLookup upkeep %s block %s received status code %d for feed %s", upkeepId.String(), ml.time.String(), resp.StatusCode, ml.feeds[index]) + return fmt.Errorf("FeedLookup upkeep %s block %s received status code %d for feed %s", ml.upkeepId.String(), ml.time.String(), resp.StatusCode, ml.feeds[index]) } var m MercuryResponse err1 = json.Unmarshal(body, &m) if err1 != nil { - r.lggr.Errorf("FeedLookup upkeep %s block %s failed to unmarshal body to MercuryResponse for feed %s: %v", upkeepId.String(), ml.time.String(), ml.feeds[index], err1) + r.lggr.Errorf("FeedLookup upkeep %s block %s failed to unmarshal body to MercuryResponse for feed %s: %v", ml.upkeepId.String(), ml.time.String(), ml.feeds[index], err1) return err1 } blobBytes, err1 := hexutil.Decode(m.ChainlinkBlob) if err1 != nil { - r.lggr.Errorf("FeedLookup upkeep %s block %s failed to decode chainlinkBlob %s for feed %s: %v", upkeepId.String(), ml.time.String(), m.ChainlinkBlob, ml.feeds[index], err1) + r.lggr.Errorf("FeedLookup upkeep %s block %s failed to decode chainlinkBlob %s for feed %s: %v", ml.upkeepId.String(), ml.time.String(), m.ChainlinkBlob, ml.feeds[index], err1) return err1 } ch <- MercuryBytes{Index: index, Bytes: blobBytes} @@ -330,11 +354,11 @@ func (r *EvmRegistry) singleFeedRequest(ctx context.Context, ch chan<- MercuryBy } // multiFeedsRequest sends a Mercury request for a multi-feed report -func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryBytes, upkeepId *big.Int, ml *FeedLookup) { +func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryBytes, ml *FeedLookup) { q := url.Values{ - FeedID: {strings.Join(ml.feeds, ",")}, + FeedId: {strings.Join(ml.feeds, ",")}, Timestamp: {ml.time.String()}, - UserId: {upkeepId.String()}, + UserId: {ml.upkeepId.String()}, } reqUrl := fmt.Sprintf("%s%s%s", r.mercury.cred.URL, MercuryBatchPathV3, q.Encode()) @@ -359,7 +383,7 @@ func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryBy retryable = false resp, err1 := r.hc.Do(req) if err1 != nil { - r.lggr.Errorf("FeedLookup upkeep %s block %s GET request fails for multi feed: %v", upkeepId.String(), ml.time.String(), err1) + r.lggr.Errorf("FeedLookup upkeep %s block %s GET request fails for multi feed: %v", ml.upkeepId.String(), ml.time.String(), err1) return err1 } defer resp.Body.Close() @@ -369,22 +393,22 @@ func (r *EvmRegistry) multiFeedsRequest(ctx context.Context, ch chan<- MercuryBy } if resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusInternalServerError { - r.lggr.Errorf("FeedLookup upkeep %s block %s received status code %d for multi feed", upkeepId.String(), ml.time.String(), resp.StatusCode) + r.lggr.Errorf("FeedLookup upkeep %s block %s received status code %d for multi feed", ml.upkeepId.String(), ml.time.String(), resp.StatusCode) retryable = true return errors.New(strconv.FormatInt(int64(resp.StatusCode), 10)) } else if resp.StatusCode != http.StatusOK { - return fmt.Errorf("FeedLookup upkeep %s block %s received status code %d for multi feed", upkeepId.String(), ml.time.String(), resp.StatusCode) + return fmt.Errorf("FeedLookup upkeep %s block %s received status code %d for multi feed", ml.upkeepId.String(), ml.time.String(), resp.StatusCode) } var m MercuryResponse err1 = json.Unmarshal(body, &m) if err1 != nil { - r.lggr.Errorf("FeedLookup upkeep %s block %s failed to unmarshal body to MercuryResponse for multi feed: %v", upkeepId.String(), ml.time.String(), err1) + r.lggr.Errorf("FeedLookup upkeep %s block %s failed to unmarshal body to MercuryResponse for multi feed: %v", ml.upkeepId.String(), ml.time.String(), err1) return err1 } blobBytes, err1 := hexutil.Decode(m.ChainlinkBlob) if err1 != nil { - r.lggr.Errorf("FeedLookup upkeep %s block %s failed to decode chainlinkBlob %s for multi feed: %v", upkeepId.String(), ml.time.String(), m.ChainlinkBlob, err1) + r.lggr.Errorf("FeedLookup upkeep %s block %s failed to decode chainlinkBlob %s for multi feed: %v", ml.upkeepId.String(), ml.time.String(), m.ChainlinkBlob, err1) return err1 } ch <- MercuryBytes{ diff --git a/core/services/ocr2/plugins/ocr2keeper/evm21/feed_lookup_test.go b/core/services/ocr2/plugins/ocr2keeper/evm21/feed_lookup_test.go index 8b9f256eead..f968280d8c8 100644 --- a/core/services/ocr2/plugins/ocr2keeper/evm21/feed_lookup_test.go +++ b/core/services/ocr2/plugins/ocr2keeper/evm21/feed_lookup_test.go @@ -107,7 +107,7 @@ func TestEvmRegistry_FeedLookup(t *testing.T) { Block: 26046145, FailureReason: UPKEEP_FAILURE_REASON_TARGET_CHECK_REVERTED, ID: upkeepId, - PerformData: []byte{125, 221, 147, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 102, 101, 101, 100, 73, 100, 72, 101, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 48, 120, 52, 53, 53, 52, 52, 56, 50, 100, 53, 53, 53, 51, 52, 52, 50, 100, 52, 49, 53, 50, 52, 50, 52, 57, 53, 52, 53, 50, 53, 53, 52, 100, 50, 100, 53, 52, 52, 53, 53, 51, 53, 52, 52, 101, 52, 53, 53, 52, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 98, 108, 111, 99, 107, 78, 117, 109, 98, 101, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, }, }, blob: "0x00066dfcd1ed2d95b18c948dbc5bd64c687afe93e4ca7d663ddec14c20090ad80000000000000000000000000000000000000000000000000000000000159761000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000280000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001204554482d5553442d415242495452554d2d544553544e4554000000000000000000000000000000000000000000000000000000000000000000000000648a1fbb000000000000000000000000000000000000000000000000000000274421041500000000000000000000000000000000000000000000000000000027437c6ecd0000000000000000000000000000000000000000000000000000002744c5995d00000000000000000000000000000000000000000000000000000000018d6ec108936dfe39c48715572a51ac868129958f937fb95ef5abdf73a239cf86a4fee700000000000000000000000000000000000000000000000000000000018d6ec100000000000000000000000000000000000000000000000000000000648a1fbb00000000000000000000000000000000000000000000000000000000000000028a26e557ee2feb91ccb116f3ab4eb1469afe5c3b012538cb151dbe3fbceaf6f117b24ac2a82cff25b286ae0a9b903dc6badaa16f6e67bf0983461b008574e30a00000000000000000000000000000000000000000000000000000000000000020db5c5924481061b98df59caefd9c4c1e72657c4976bf7c7568730fbdaf828080bff6b1edea2c8fed5e8bbac5574aa94cf809d898f5055cb1db14a16f1493726", @@ -236,11 +236,11 @@ func TestEvmRegistry_DecodeFeedLookup(t *testing.T) { }{ { name: "success - decode to feed lookup", - data: []byte{125, 221, 147, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 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, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 48, 120, 52, 50, 53, 52, 52, 51, 50, 100, 53, 53, 53, 51, 52, 52, 50, 100, 52, 49, 53, 50, 52, 50, 52, 57, 53, 52, 53, 50, 53, 53, 52, 100, 50, 100, 53, 52, 52, 53, 53, 51, 53, 52, 52, 101, 52, 53, 53, 52, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 98, 108, 111, 99, 107, 78, 117, 109, 98, 101, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + data: []byte{125, 221, 147, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 0, 0, 0, 0, 0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 53, 52, 53, 50, 53, 53, 52, 100, 50, 100, 53, 52, 52, 53, 53, 51, 53, 52, 52, 101, 52, 53, 53, 52, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 48, 120, 52, 50, 53, 52, 52, 51, 50, 100, 53, 53, 53, 51, 52, 52, 50, 100, 52, 49, 53, 50, 52, 50, 52, 57, 53, 52, 53, 50, 53, 53, 52, 100, 50, 100, 53, 52, 52, 53, 53, 51, 53, 52, 52, 101, 52, 53, 53, 52, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 98, 108, 111, 99, 107, 78, 117, 109, 98, 101, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, expected: &FeedLookup{ - feedParamKey: "feedIDHex", + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000", "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(25876477), extraData: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100}, }, @@ -338,7 +338,7 @@ func TestEvmRegistry_DoMercuryRequest(t *testing.T) { tests := []struct { name string - ml *FeedLookup + lookup *FeedLookup mockHttpStatusCode int mockChainlinkBlobs []string expectedValues [][]byte @@ -347,12 +347,13 @@ func TestEvmRegistry_DoMercuryRequest(t *testing.T) { }{ { name: "success", - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(25880526), extraData: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100}, + upkeepId: upkeepId, }, mockHttpStatusCode: http.StatusOK, mockChainlinkBlobs: []string{"0x00066dfcd1ed2d95b18c948dbc5bd64c687afe93e4ca7d663ddec14c20090ad80000000000000000000000000000000000000000000000000000000000081401000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000280000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001204554482d5553442d415242495452554d2d544553544e455400000000000000000000000000000000000000000000000000000000000000000000000064891c98000000000000000000000000000000000000000000000000000000289ad8d367000000000000000000000000000000000000000000000000000000289acf0b38000000000000000000000000000000000000000000000000000000289b3da40000000000000000000000000000000000000000000000000000000000018ae7ce74d9fa252a8983976eab600dc7590c778d04813430841bc6e765c34cd81a168d00000000000000000000000000000000000000000000000000000000018ae7cb0000000000000000000000000000000000000000000000000000000064891c98000000000000000000000000000000000000000000000000000000000000000260412b94e525ca6cedc9f544fd86f77606d52fe731a5d069dbe836a8bfc0fb8c911963b0ae7a14971f3b4621bffb802ef0605392b9a6c89c7fab1df8633a5ade00000000000000000000000000000000000000000000000000000000000000024500c2f521f83fba5efc2bf3effaaedde43d0a4adff785c1213b712a3aed0d8157642a84324db0cf9695ebd27708d4608eb0337e0dd87b0e43f0fa70c700d911"}, @@ -362,12 +363,13 @@ func TestEvmRegistry_DoMercuryRequest(t *testing.T) { }, { name: "failure - retryable", - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(25880526), extraData: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100}, + upkeepId: upkeepId, }, mockHttpStatusCode: http.StatusInternalServerError, mockChainlinkBlobs: []string{"0x00066dfcd1ed2d95b18c948dbc5bd64c687afe93e4ca7d663ddec14c20090ad80000000000000000000000000000000000000000000000000000000000081401000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000280000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001204554482d5553442d415242495452554d2d544553544e455400000000000000000000000000000000000000000000000000000000000000000000000064891c98000000000000000000000000000000000000000000000000000000289ad8d367000000000000000000000000000000000000000000000000000000289acf0b38000000000000000000000000000000000000000000000000000000289b3da40000000000000000000000000000000000000000000000000000000000018ae7ce74d9fa252a8983976eab600dc7590c778d04813430841bc6e765c34cd81a168d00000000000000000000000000000000000000000000000000000000018ae7cb0000000000000000000000000000000000000000000000000000000064891c98000000000000000000000000000000000000000000000000000000000000000260412b94e525ca6cedc9f544fd86f77606d52fe731a5d069dbe836a8bfc0fb8c911963b0ae7a14971f3b4621bffb802ef0605392b9a6c89c7fab1df8633a5ade00000000000000000000000000000000000000000000000000000000000000024500c2f521f83fba5efc2bf3effaaedde43d0a4adff785c1213b712a3aed0d8157642a84324db0cf9695ebd27708d4608eb0337e0dd87b0e43f0fa70c700d911"}, @@ -377,12 +379,13 @@ func TestEvmRegistry_DoMercuryRequest(t *testing.T) { }, { name: "failure - not retryable", - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(25880526), extraData: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100}, + upkeepId: upkeepId, }, mockHttpStatusCode: http.StatusBadGateway, mockChainlinkBlobs: []string{"0x00066dfcd1ed2d95b18c948dbc5bd64c687afe93e4ca7d663ddec14c20090ad80000000000000000000000000000000000000000000000000000000000081401000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000002200000000000000000000000000000000000000000000000000000000000000280000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001204554482d5553442d415242495452554d2d544553544e455400000000000000000000000000000000000000000000000000000000000000000000000064891c98000000000000000000000000000000000000000000000000000000289ad8d367000000000000000000000000000000000000000000000000000000289acf0b38000000000000000000000000000000000000000000000000000000289b3da40000000000000000000000000000000000000000000000000000000000018ae7ce74d9fa252a8983976eab600dc7590c778d04813430841bc6e765c34cd81a168d00000000000000000000000000000000000000000000000000000000018ae7cb0000000000000000000000000000000000000000000000000000000064891c98000000000000000000000000000000000000000000000000000000000000000260412b94e525ca6cedc9f544fd86f77606d52fe731a5d069dbe836a8bfc0fb8c911963b0ae7a14971f3b4621bffb802ef0605392b9a6c89c7fab1df8633a5ade00000000000000000000000000000000000000000000000000000000000000024500c2f521f83fba5efc2bf3effaaedde43d0a4adff785c1213b712a3aed0d8157642a84324db0cf9695ebd27708d4608eb0337e0dd87b0e43f0fa70c700d911"}, @@ -414,7 +417,7 @@ func TestEvmRegistry_DoMercuryRequest(t *testing.T) { } r.hc = hc - values, retryable, reqErr := r.doMercuryRequest(context.Background(), tt.ml, upkeepId) + values, retryable, reqErr := r.doMercuryRequest(context.Background(), tt.lookup) assert.Equal(t, tt.expectedValues, values) assert.Equal(t, tt.expectedRetryable, retryable) if tt.expectedError != nil { @@ -429,7 +432,7 @@ func TestEvmRegistry_SingleFeedRequest(t *testing.T) { tests := []struct { name string index int - ml *FeedLookup + lookup *FeedLookup mv MercuryVersion blob string statusCode int @@ -441,11 +444,12 @@ func TestEvmRegistry_SingleFeedRequest(t *testing.T) { { name: "success - mercury responds in the first try", index: 0, - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(123456), + upkeepId: upkeepId, }, mv: MercuryV02, blob: "0xab2123dc00000012", @@ -453,11 +457,12 @@ func TestEvmRegistry_SingleFeedRequest(t *testing.T) { { name: "success - retry for 404", index: 0, - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(123456), + upkeepId: upkeepId, }, mv: MercuryV02, blob: "0xab2123dcbabbad", @@ -468,11 +473,12 @@ func TestEvmRegistry_SingleFeedRequest(t *testing.T) { { name: "success - retry for 500", index: 0, - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(123456), + upkeepId: upkeepId, }, mv: MercuryV02, blob: "0xab2123dcbbabad", @@ -483,11 +489,12 @@ func TestEvmRegistry_SingleFeedRequest(t *testing.T) { { name: "failure - returns retryable", index: 0, - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(123456), + upkeepId: upkeepId, }, mv: MercuryV02, blob: "0xab2123dc", @@ -499,11 +506,12 @@ func TestEvmRegistry_SingleFeedRequest(t *testing.T) { { name: "failure - returns retryable and then non-retryable", index: 0, - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(123456), + upkeepId: upkeepId, }, mv: MercuryV02, blob: "0xab2123dc", @@ -515,11 +523,12 @@ func TestEvmRegistry_SingleFeedRequest(t *testing.T) { { name: "failure - returns not retryable", index: 0, - ml: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(123456), + upkeepId: upkeepId, }, mv: MercuryV02, blob: "0xab2123dc", @@ -573,7 +582,7 @@ func TestEvmRegistry_SingleFeedRequest(t *testing.T) { r.hc = hc ch := make(chan MercuryBytes, 1) - r.singleFeedRequest(context.Background(), ch, upkeepId, tt.index, tt.ml, tt.mv) + r.singleFeedRequest(context.Background(), ch, tt.index, tt.lookup, tt.mv) m := <-ch assert.Equal(t, tt.index, m.Index) @@ -595,7 +604,7 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) { upkeepId := big.NewInt(123456789) tests := []struct { name string - ml *FeedLookup + lookup *FeedLookup blob string statusCode int lastStatusCode int @@ -605,21 +614,23 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) { }{ { name: "success - mercury responds in the first try", - ml: &FeedLookup{ - feedParamKey: "feedID", + lookup: &FeedLookup{ + feedParamKey: FeedId, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000", "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "timestamp", + timeParamKey: Timestamp, time: big.NewInt(123456), + upkeepId: upkeepId, }, blob: "0xab2123dc00000012", }, { name: "success - retry for 404", - ml: &FeedLookup{ - feedParamKey: "feedID", + lookup: &FeedLookup{ + feedParamKey: FeedId, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000", "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "timestamp", + timeParamKey: Timestamp, time: big.NewInt(123456), + upkeepId: upkeepId, }, blob: "0xab2123dcbabbad", retryNumber: 1, @@ -628,11 +639,12 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) { }, { name: "success - retry for 500", - ml: &FeedLookup{ - feedParamKey: "feedID", + lookup: &FeedLookup{ + feedParamKey: FeedId, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000", "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "timestamp", + timeParamKey: Timestamp, time: big.NewInt(123456), + upkeepId: upkeepId, }, blob: "0xab2123dcbbabad", retryNumber: 2, @@ -641,11 +653,12 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) { }, { name: "failure - returns retryable", - ml: &FeedLookup{ - feedParamKey: "feedID", + lookup: &FeedLookup{ + feedParamKey: FeedId, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000", "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "timestamp", + timeParamKey: Timestamp, time: big.NewInt(123456), + upkeepId: upkeepId, }, blob: "0xab2123dc", retryNumber: TotalAttempt, @@ -655,11 +668,12 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) { }, { name: "failure - returns retryable and then non-retryable", - ml: &FeedLookup{ - feedParamKey: "feedID", + lookup: &FeedLookup{ + feedParamKey: FeedId, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000", "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "timestamp", + timeParamKey: Timestamp, time: big.NewInt(123456), + upkeepId: upkeepId, }, blob: "0xab2123dc", retryNumber: 1, @@ -669,11 +683,12 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) { }, { name: "failure - returns not retryable", - ml: &FeedLookup{ - feedParamKey: "feedID", + lookup: &FeedLookup{ + feedParamKey: FeedId, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "timestamp", + timeParamKey: Timestamp, time: big.NewInt(123456), + upkeepId: upkeepId, }, blob: "0xab2123dc", statusCode: http.StatusBadGateway, @@ -726,7 +741,7 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) { r.hc = hc ch := make(chan MercuryBytes, 1) - r.multiFeedsRequest(context.Background(), ch, upkeepId, tt.ml) + r.multiFeedsRequest(context.Background(), ch, tt.lookup) m := <-ch assert.Equal(t, 0, m.Index) @@ -745,15 +760,15 @@ func TestEvmRegistry_MultiFeedRequest(t *testing.T) { } func TestEvmRegistry_CheckCallback(t *testing.T) { + upkeepId := big.NewInt(123456789) + blockNumber := uint64(999) bs := []byte{183, 114, 215, 10, 0, 0, 0, 0, 0, 0} values := [][]byte{bs} tests := []struct { - name string - mercuryLookup *FeedLookup - values [][]byte - statusCode int - upkeepId *big.Int - blockNumber uint32 + name string + lookup *FeedLookup + values [][]byte + statusCode int callbackMsg ethereum.CallMsg callbackResp []byte @@ -765,17 +780,17 @@ func TestEvmRegistry_CheckCallback(t *testing.T) { }{ { name: "success - empty extra data", - mercuryLookup: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"ETD-USD", "BTC-ETH"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(100), extraData: []byte{48, 120, 48, 48}, + upkeepId: upkeepId, + block: blockNumber, }, values: values, statusCode: http.StatusOK, - upkeepId: big.NewInt(123456789), - blockNumber: 999, callbackResp: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 48, 120, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, upkeepNeeded: true, performData: []byte{48, 120, 48, 48}, @@ -783,18 +798,18 @@ func TestEvmRegistry_CheckCallback(t *testing.T) { }, { name: "success - with extra data", - mercuryLookup: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"0x4554482d5553442d415242495452554d2d544553544e45540000000000000000", "0x4254432d5553442d415242495452554d2d544553544e45540000000000000000"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(18952430), // this is the address of precompile contract ArbSys(0x0000000000000000000000000000000000000064) extraData: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100}, + upkeepId: upkeepId, + block: blockNumber, }, values: values, statusCode: http.StatusOK, - upkeepId: big.NewInt(123456789), - blockNumber: 999, callbackResp: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, upkeepNeeded: true, performData: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100}, @@ -802,17 +817,17 @@ func TestEvmRegistry_CheckCallback(t *testing.T) { }, { name: "failure - bad response", - mercuryLookup: &FeedLookup{ - feedParamKey: "feedIDHex", + lookup: &FeedLookup{ + feedParamKey: FeedIdHex, feeds: []string{"ETD-USD", "BTC-ETH"}, - timeParamKey: "blockNumber", + timeParamKey: BlockNumber, time: big.NewInt(100), extraData: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 48, 120, 48, 48, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, + upkeepId: upkeepId, + block: blockNumber, }, values: values, statusCode: http.StatusOK, - upkeepId: big.NewInt(123456789), - blockNumber: 999, callbackResp: []byte{}, callbackErr: errors.New("bad response"), wantErr: assert.Error, @@ -823,21 +838,20 @@ func TestEvmRegistry_CheckCallback(t *testing.T) { t.Run(tt.name, func(t *testing.T) { client := new(evmClientMocks.Client) r := setupEVMRegistry(t) - payload, err := r.abi.Pack("checkCallback", tt.upkeepId, values, tt.mercuryLookup.extraData) + payload, err := r.abi.Pack("checkCallback", tt.lookup.upkeepId, values, tt.lookup.extraData) require.Nil(t, err) args := map[string]interface{}{ "to": r.addr.Hex(), "data": hexutil.Bytes(payload), } - // if args don't match, just use mock.Anything - client.On("CallContext", mock.Anything, mock.AnythingOfType("*hexutil.Bytes"), "eth_call", args, hexutil.EncodeUint64(uint64(tt.blockNumber))).Return(tt.callbackErr). + client.On("CallContext", mock.Anything, mock.AnythingOfType("*hexutil.Bytes"), "eth_call", args, hexutil.EncodeUint64(tt.lookup.block)).Return(tt.callbackErr). Run(func(args mock.Arguments) { by := args.Get(1).(*hexutil.Bytes) *by = tt.callbackResp }).Once() r.client = client - _, err = r.checkCallback(context.Background(), tt.upkeepId, tt.values, tt.mercuryLookup.extraData, tt.blockNumber) + _, err = r.checkCallback(context.Background(), tt.values, tt.lookup) tt.wantErr(t, err, fmt.Sprintf("Error asserion failed: %v", tt.name)) }) }