Skip to content

Commit

Permalink
apply code suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
EasterTheBunny committed Sep 13, 2023
1 parent 02d9a11 commit b99cb4a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ func TestPacker_UnpackGetUpkeepPrivilegeConfig(t *testing.T) {
err = json.Unmarshal(b, &data)

assert.NoError(t, err, "packed data should unmarshal using json encoding")
assert.Equal(t, []byte(`{"mercuryEnabled":true}`), b)
} else {
assert.NotNil(t, err, "error expected from unpack function")
}
Expand Down
14 changes: 7 additions & 7 deletions core/services/ocr2/plugins/ocr2keeper/evm21/streams_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,19 @@ func (r *EvmRegistry) allowedToUseMercury(opts *bind.CallOpts, upkeepId *big.Int
return encoding.PackUnpackDecodeFailed, encoding.UpkeepFailureReasonNone, false, false, fmt.Errorf("failed to pack upkeepId: %w", err)
}

var b hexutil.Bytes
var resultBytes hexutil.Bytes
args := map[string]interface{}{
"to": r.addr.Hex(),
"data": hexutil.Bytes(payload),
}

// call checkCallback function at the block which OCR3 has agreed upon
err = r.client.CallContext(opts.Context, &b, "eth_call", args, opts.BlockNumber)
err = r.client.CallContext(opts.Context, &resultBytes, "eth_call", args, opts.BlockNumber)
if err != nil {
return encoding.RpcFlakyFailure, encoding.UpkeepFailureReasonNone, true, false, fmt.Errorf("failed to get upkeep privilege config: %v", err)
}

cfg, err := r.packer.UnpackGetUpkeepPrivilegeConfig(b)
cfg, err := r.packer.UnpackGetUpkeepPrivilegeConfig(resultBytes)
if err != nil {
return encoding.PackUnpackDecodeFailed, encoding.UpkeepFailureReasonNone, false, false, fmt.Errorf("failed to get upkeep privilege config: %v", err)
}
Expand All @@ -250,14 +250,14 @@ func (r *EvmRegistry) allowedToUseMercury(opts *bind.CallOpts, upkeepId *big.Int
return encoding.NoPipelineError, encoding.UpkeepFailureReasonMercuryAccessNotAllowed, false, false, fmt.Errorf("upkeep privilege config is empty")
}

var a UpkeepPrivilegeConfig
if err := json.Unmarshal(cfg, &a); err != nil {
var privilegeConfig UpkeepPrivilegeConfig
if err := json.Unmarshal(cfg, &privilegeConfig); err != nil {
return encoding.MercuryUnmarshalError, encoding.UpkeepFailureReasonNone, false, false, fmt.Errorf("failed to unmarshal privilege config: %v", err)
}

r.mercury.allowListCache.Set(upkeepId.String(), a.MercuryEnabled, cache.DefaultExpiration)
r.mercury.allowListCache.Set(upkeepId.String(), privilegeConfig.MercuryEnabled, cache.DefaultExpiration)

return encoding.NoPipelineError, encoding.UpkeepFailureReasonNone, false, a.MercuryEnabled, nil
return encoding.NoPipelineError, encoding.UpkeepFailureReasonNone, false, privilegeConfig.MercuryEnabled, nil
}

// decodeStreamsLookup decodes the revert error StreamsLookup(string feedParamKey, string[] feeds, string feedParamKey, uint256 time, byte[] extraData)
Expand Down
15 changes: 8 additions & 7 deletions core/services/ocr2/plugins/ocr2keeper/integration_21_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,14 +352,10 @@ func TestIntegration_KeeperPluginLogUpkeep_Retry(t *testing.T) {
// deploy multiple upkeeps that listen to a log emitter and need to be
// performed for each log event
_ = feeds.DeployUpkeeps(t, backend, upkeepOwner, upkeepCount)
_ = feeds.RegisterAndFund(t, registerAndFund(registry, registryOwner, backend, linkToken))
_ = feeds.RegisterAndFund(t, registry, registryOwner, backend, linkToken)
_ = feeds.EnableMercury(t, backend, registry, registryOwner)
_ = feeds.VerifyEnv(t, backend, registry, registryOwner)

// using sleep here is not the right way to go, but it currently work on
// a local machine. this does have issues in CI
time.Sleep(10 * time.Second)

// start emitting events in a separate go-routine
// feed lookup relies on a single contract event log to perform multiple
// listener contracts
Expand Down Expand Up @@ -847,7 +843,10 @@ func (c *feedLookupUpkeepController) DeployUpkeeps(

func (c *feedLookupUpkeepController) RegisterAndFund(
t *testing.T,
f registerAndFundFunc,
registry *iregistry21.IKeeperRegistryMaster,
registryOwner *bind.TransactOpts,
backend *backends.SimulatedBackend,
linkToken *link_token_interface.LinkToken,
) error {
ids := make([]*big.Int, len(c.contracts))

Expand All @@ -865,8 +864,10 @@ func (c *feedLookupUpkeepController) RegisterAndFund(

require.NoError(t, err)

registerFunc := registerAndFund(registry, registryOwner, backend, linkToken)

for x := range c.contracts {
ids[x] = f(t, c.addresses[x], c.contractsOwner, 1, config)
ids[x] = registerFunc(t, c.addresses[x], c.contractsOwner, 1, config)
}

c.upkeepIds = ids
Expand Down

0 comments on commit b99cb4a

Please sign in to comment.