-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto 4601/add log retry integration test #10355
Changes from all commits
e6e3e32
2bbfc70
32021ce
12c046d
2841753
743afae
8b07fcd
02d9a11
b99cb4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package encoding | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
"strings" | ||
|
@@ -355,6 +356,97 @@ func TestPacker_PackReport_UnpackReport(t *testing.T) { | |
assert.Equal(t, hexutil.Encode(res), expected) | ||
} | ||
|
||
func TestPacker_PackGetUpkeepPrivilegeConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
upkeepId *big.Int | ||
raw []byte | ||
errored bool | ||
}{ | ||
{ | ||
name: "happy path", | ||
upkeepId: func() *big.Int { | ||
id, _ := new(big.Int).SetString("52236098515066839510538748191966098678939830769967377496848891145101407612976", 10) | ||
|
||
return id | ||
}(), | ||
raw: func() []byte { | ||
b, _ := hexutil.Decode("0x19d97a94737c9583000000000000000000000001ea8ed6d0617dd5b3b87374020efaf030") | ||
|
||
return b | ||
}(), | ||
errored: false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
packer, err := newPacker() | ||
require.NoError(t, err, "valid packer required for test") | ||
|
||
b, err := packer.PackGetUpkeepPrivilegeConfig(test.upkeepId) | ||
|
||
if !test.errored { | ||
require.NoError(t, err, "no error expected from packing") | ||
|
||
assert.Equal(t, test.raw, b, "raw bytes for output should match expected") | ||
} else { | ||
assert.NotNil(t, err, "error expected from packing function") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestPacker_UnpackGetUpkeepPrivilegeConfig(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
raw []byte | ||
errored bool | ||
}{ | ||
{ | ||
name: "happy path", | ||
raw: func() []byte { | ||
b, _ := hexutil.Decode("0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000177b226d657263757279456e61626c6564223a747275657d000000000000000000") | ||
|
||
return b | ||
}(), | ||
errored: false, | ||
}, | ||
{ | ||
name: "error empty config", | ||
raw: func() []byte { | ||
b, _ := hexutil.Decode("0x") | ||
|
||
return b | ||
}(), | ||
errored: true, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
packer, err := newPacker() | ||
require.NoError(t, err, "valid packer required for test") | ||
|
||
b, err := packer.UnpackGetUpkeepPrivilegeConfig(test.raw) | ||
|
||
if !test.errored { | ||
require.NoError(t, err, "should unpack bytes from abi encoded value") | ||
|
||
// the actual struct to unmarshal into is not available to this | ||
// package so basic json encoding is the limit of the following test | ||
var data map[string]interface{} | ||
err = json.Unmarshal(b, &data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it make sense to compare the output bytes of unpack() and our expected bytes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can add a test that |
||
|
||
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") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func newPacker() (*abiPacker, error) { | ||
keepersABI, err := abi.JSON(strings.NewReader(iregistry21.IKeeperRegistryMasterABI)) | ||
if err != nil { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,22 +220,44 @@ func (r *EvmRegistry) allowedToUseMercury(opts *bind.CallOpts, upkeepId *big.Int | |
return encoding.NoPipelineError, encoding.UpkeepFailureReasonNone, false, allowed.(bool), nil | ||
} | ||
|
||
cfg, err := r.registry.GetUpkeepPrivilegeConfig(opts, upkeepId) | ||
payload, err := r.packer.PackGetUpkeepPrivilegeConfig(upkeepId) | ||
if err != nil { | ||
// pack error, no retryable | ||
r.lggr.Warnf("failed to pack getUpkeepPrivilegeConfig data for upkeepId %s: %s", upkeepId, err) | ||
|
||
return encoding.PackUnpackDecodeFailed, encoding.UpkeepFailureReasonNone, false, false, fmt.Errorf("failed to pack upkeepId: %w", err) | ||
} | ||
|
||
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, &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(resultBytes) | ||
if err != nil { | ||
return encoding.PackUnpackDecodeFailed, encoding.UpkeepFailureReasonNone, false, false, fmt.Errorf("failed to get upkeep privilege config: %v", err) | ||
} | ||
|
||
if len(cfg) == 0 { | ||
r.mercury.allowListCache.Set(upkeepId.String(), false, cache.DefaultExpiration) | ||
return encoding.NoPipelineError, encoding.UpkeepFailureReasonMercuryAccessNotAllowed, false, false, fmt.Errorf("upkeep privilege config is empty") | ||
} | ||
|
||
var a UpkeepPrivilegeConfig | ||
err = json.Unmarshal(cfg, &a) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto, how about something like privilegeConfig? |
||
if 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) | ||
return encoding.NoPipelineError, encoding.UpkeepFailureReasonNone, false, a.MercuryEnabled, nil | ||
|
||
r.mercury.allowListCache.Set(upkeepId.String(), privilegeConfig.MercuryEnabled, cache.DefaultExpiration) | ||
|
||
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test