Skip to content

Commit

Permalink
Merge branch 'develop' into ocrv2Soak
Browse files Browse the repository at this point in the history
  • Loading branch information
kalverra authored Dec 11, 2023
2 parents 7454343 + 1a45097 commit e8a2463
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 51 deletions.
12 changes: 6 additions & 6 deletions contracts/gas-snapshots/functions.gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ FunctionsSubscriptions_GetSubscriptionsInRange:test_GetSubscriptionsInRange_Reve
FunctionsSubscriptions_GetSubscriptionsInRange:test_GetSubscriptionsInRange_RevertIfStartIsAfterEnd() (gas: 13459)
FunctionsSubscriptions_GetSubscriptionsInRange:test_GetSubscriptionsInRange_Success() (gas: 59592)
FunctionsSubscriptions_GetTotalBalance:test_GetTotalBalance_Success() (gas: 15010)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfCallerIsNoCalldata(uint96) (runs: 256, μ: 43774, ~: 45548)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfCallerIsNoSubscription(uint96) (runs: 256, μ: 46286, ~: 48060)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfCallerIsNotLink(uint96) (runs: 256, μ: 14295, ~: 14295)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfPaused(uint96) (runs: 256, μ: 51443, ~: 53040)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_Success(uint96) (runs: 256, μ: 86057, ~: 89604)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfCallerIsNoCalldata() (gas: 39939)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfCallerIsNoSubscription() (gas: 42404)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfCallerIsNotLink() (gas: 13441)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_RevertIfPaused() (gas: 47347)
FunctionsSubscriptions_OnTokenTransfer:test_OnTokenTransfer_Success(uint96) (runs: 256, μ: 81598, ~: 81598)
FunctionsSubscriptions_OracleWithdraw:test_OracleWithdraw_RevertIfAmountMoreThanBalance() (gas: 20745)
FunctionsSubscriptions_OracleWithdraw:test_OracleWithdraw_RevertIfBalanceInvariant() (gas: 189)
FunctionsSubscriptions_OracleWithdraw:test_OracleWithdraw_RevertIfNoAmount() (gas: 15638)
Expand Down Expand Up @@ -177,7 +177,7 @@ FunctionsSubscriptions_ProposeSubscriptionOwnerTransfer:test_ProposeSubscription
FunctionsSubscriptions_ProposeSubscriptionOwnerTransfer:test_ProposeSubscriptionOwnerTransfer_Success() (gas: 68196)
FunctionsSubscriptions_ProposeSubscriptionOwnerTransfer:test_ProposeSubscriptionOwnerTransfer_SuccessChangeProposedOwner() (gas: 82749)
FunctionsSubscriptions_RecoverFunds:test_OwnerCancelSubscription_RevertIfNotOwner() (gas: 15554)
FunctionsSubscriptions_RecoverFunds:test_RecoverFunds_Success(uint64) (runs: 256, μ: 41717, ~: 41721)
FunctionsSubscriptions_RecoverFunds:test_RecoverFunds_Success() (gas: 41111)
FunctionsSubscriptions_RemoveConsumer:test_RemoveConsumer_RevertIfInvalidConsumer() (gas: 30260)
FunctionsSubscriptions_RemoveConsumer:test_RemoveConsumer_RevertIfNoSubscription() (gas: 15019)
FunctionsSubscriptions_RemoveConsumer:test_RemoveConsumer_RevertIfNotAllowedSender() (gas: 57800)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ contract FunctionsSubscriptions_OwnerCancelSubscription is FunctionsSubscription
contract FunctionsSubscriptions_RecoverFunds is FunctionsRouterSetup {
event FundsRecovered(address to, uint256 amount);

function test_RecoverFunds_Success(uint64 fundsTransferred) public {
//amount must be less than LINK total supply
vm.assume(fundsTransferred < 1_000_000_000 * 1e18);
vm.assume(fundsTransferred > 0);

// uint256 fundsTransferred = 1 * 1e18; // 1 LINK
function test_RecoverFunds_Success() public {
uint256 fundsTransferred = 1 * 1e18; // 1 LINK
s_linkToken.transfer(address(s_functionsRouter), fundsTransferred);

// topic0 (function signature, always checked), NOT topic1 (false), NOT topic2 (false), NOT topic3 (false), and data (true).
Expand Down Expand Up @@ -320,58 +316,43 @@ contract FunctionsSubscriptions_OnTokenTransfer is FunctionsClientSetup {
s_functionsRouter.addConsumer(s_subscriptionId, address(s_functionsClient));
}

function test_OnTokenTransfer_RevertIfPaused(uint96 fundingAmount) public {
// Funding amount must be less than LINK total supply
function test_OnTokenTransfer_RevertIfPaused() public {
// Funding amount must be less than or equal to LINK total supply
uint256 totalSupplyJuels = 1_000_000_000 * 1e18;
vm.assume(fundingAmount <= totalSupplyJuels);
vm.assume(fundingAmount >= 0);

s_functionsRouter.pause();
vm.expectRevert("Pausable: paused");
s_linkToken.transferAndCall(address(s_functionsRouter), fundingAmount, abi.encode(s_subscriptionId));
s_linkToken.transferAndCall(address(s_functionsRouter), totalSupplyJuels, abi.encode(s_subscriptionId));
}

function test_OnTokenTransfer_RevertIfCallerIsNotLink(uint96 fundingAmount) public {
// Funding amount must be less than LINK total supply
function test_OnTokenTransfer_RevertIfCallerIsNotLink() public {
// Funding amount must be less than or equal to LINK total supply
uint256 totalSupplyJuels = 1_000_000_000 * 1e18;
vm.assume(fundingAmount <= totalSupplyJuels);
vm.assume(fundingAmount >= 0);

vm.expectRevert(FunctionsSubscriptions.OnlyCallableFromLink.selector);
s_functionsRouter.onTokenTransfer(address(s_functionsRouter), fundingAmount, abi.encode(s_subscriptionId));
s_functionsRouter.onTokenTransfer(address(s_functionsRouter), totalSupplyJuels, abi.encode(s_subscriptionId));
}

function test_OnTokenTransfer_RevertIfCallerIsNoCalldata(uint96 fundingAmount) public {
// Funding amount must be less than LINK total supply
function test_OnTokenTransfer_RevertIfCallerIsNoCalldata() public {
// Funding amount must be less than or equal to LINK total supply
uint256 totalSupplyJuels = 1_000_000_000 * 1e18;
vm.assume(fundingAmount <= totalSupplyJuels);
vm.assume(fundingAmount >= 0);

vm.expectRevert(FunctionsSubscriptions.InvalidCalldata.selector);
s_linkToken.transferAndCall(address(s_functionsRouter), fundingAmount, new bytes(0));
s_linkToken.transferAndCall(address(s_functionsRouter), totalSupplyJuels, new bytes(0));
}

function test_OnTokenTransfer_RevertIfCallerIsNoSubscription(uint96 fundingAmount) public {
// Funding amount must be less than LINK total supply
function test_OnTokenTransfer_RevertIfCallerIsNoSubscription() public {
// Funding amount must be less than or equal to LINK total supply
uint256 totalSupplyJuels = 1_000_000_000 * 1e18;
vm.assume(fundingAmount <= totalSupplyJuels);
vm.assume(fundingAmount >= 0);

vm.expectRevert(FunctionsSubscriptions.InvalidSubscription.selector);
uint64 invalidSubscriptionId = 123456789;
s_linkToken.transferAndCall(address(s_functionsRouter), fundingAmount, abi.encode(invalidSubscriptionId));
s_linkToken.transferAndCall(address(s_functionsRouter), totalSupplyJuels, abi.encode(invalidSubscriptionId));
}

function test_OnTokenTransfer_Success(uint96 fundingAmount) public {
// Funding amount must be less than LINK total supply
uint256 totalSupplyJuels = 1_000_000_000 * 1e18;
// Some of the total supply is already in the subscription account
vm.assume(fundingAmount <= totalSupplyJuels);
vm.assume(fundingAmount >= 0);

s_linkToken.transferAndCall(address(s_functionsRouter), fundingAmount, abi.encode(s_subscriptionId));
s_linkToken.transferAndCall(address(s_functionsRouter), totalSupplyJuels, abi.encode(s_subscriptionId));
uint96 subscriptionBalanceAfter = s_functionsRouter.getSubscription(s_subscriptionId).balance;
assertEq(fundingAmount, subscriptionBalanceAfter);
assertEq(totalSupplyJuels, subscriptionBalanceAfter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ type StreamsLookup struct {
Block uint64
}

func (l *StreamsLookup) IsMercuryVersionUnkown() bool {
return l.FeedParamKey != FeedIDs
}

func (l *StreamsLookup) IsMercuryV02() bool {
return l.FeedParamKey == FeedIdHex && l.TimeParamKey == BlockNumber
}
Expand All @@ -117,6 +113,6 @@ func (l *StreamsLookup) IsMercuryV03() bool {
return l.FeedParamKey == FeedIDs
}

func (l *StreamsLookup) IsMercuryUsingBatchPathV03() bool {
func (l *StreamsLookup) IsMercuryV03UsingBlockNumber() bool {
return l.TimeParamKey == BlockNumber
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (s *streams) buildResult(ctx context.Context, i int, checkResult ocr2keeper
// tried to call mercury
lookupLggr.Infof("at block %d upkeep %s trying to DecodeStreamsLookupRequest performData=%s", block, upkeepId, hexutil.Encode(checkResults[i].PerformData))
streamsLookupErr, err := s.packer.DecodeStreamsLookupRequest(checkResult.PerformData)

if err != nil {
lookupLggr.Debugf("at block %d upkeep %s DecodeStreamsLookupRequest failed: %v", block, upkeepId, err)
// user contract did not revert with StreamsLookup error
Expand All @@ -144,7 +145,7 @@ func (s *streams) buildResult(ctx context.Context, i int, checkResult ocr2keeper
return
}

// mercury permission checking for v0.3 is done by mercury server
// mercury permission checking for v0.3 is done by mercury server, so no need to check here
if streamsLookupResponse.IsMercuryV02() {
// check permission on the registry for mercury v0.2
opts := s.buildCallOpts(ctx, block)
Expand All @@ -159,8 +160,8 @@ func (s *streams) buildResult(ctx context.Context, i int, checkResult ocr2keeper
checkResults[i].IneligibilityReason = uint8(mercury.MercuryUpkeepFailureReasonMercuryAccessNotAllowed)
return
}
} else if streamsLookupResponse.IsMercuryVersionUnkown() {
// if mercury version cannot be determined, set failure reason
} else if !streamsLookupResponse.IsMercuryV03() {
// if mercury version is not v02 or v03, set failure reason
lookupLggr.Debugf("at block %d upkeep %s NOT allowed to query Mercury server", block, upkeepId)
checkResults[i].IneligibilityReason = uint8(mercury.MercuryUpkeepFailureReasonInvalidRevertDataInput)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"testing"
"time"

"github.com/pkg/errors"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -619,6 +620,31 @@ func TestStreams_StreamsLookup(t *testing.T) {
},
hasError: true,
},
{
name: "failure - invalid mercury version",
input: []ocr2keepers.CheckResult{
{
// This Perform data contains invalid FeedParamKey: {feedIdHex:RandomString [ETD-USD BTC-ETH] blockNumber 100 [48 120 48 48]}
PerformData: hexutil.MustDecode("0xf055e4a200000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000166665656449644865783a52616e646f6d537472696e670000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000074554442d5553440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074254432d45544800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b626c6f636b4e756d62657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000043078303000000000000000000000000000000000000000000000000000000000"),
UpkeepID: upkeepIdentifier,
Trigger: ocr2keepers.Trigger{
BlockNumber: blockNum,
},
IneligibilityReason: uint8(encoding.UpkeepFailureReasonTargetCheckReverted),
},
},
expectedResults: []ocr2keepers.CheckResult{
{
PerformData: hexutil.MustDecode("0xf055e4a200000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000064000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000166665656449644865783a52616e646f6d537472696e670000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000074554442d5553440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074254432d45544800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b626c6f636b4e756d62657200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000043078303000000000000000000000000000000000000000000000000000000000"),
UpkeepID: upkeepIdentifier,
Trigger: ocr2keepers.Trigger{
BlockNumber: blockNum,
},
IneligibilityReason: uint8(mercury.MercuryUpkeepFailureReasonInvalidRevertDataInput),
},
},
hasError: true,
},
}

for _, tt := range tests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (c *client) multiFeedsRequest(ctx context.Context, ch chan<- mercury.Mercur

params := fmt.Sprintf("%s=%s&%s=%s", mercury.FeedIDs, strings.Join(sl.Feeds, ","), mercury.Timestamp, sl.Time.String())
batchPathV03 := mercuryBatchPathV03
if sl.IsMercuryUsingBatchPathV03() {
if sl.IsMercuryV03UsingBlockNumber() {
batchPathV03 = mercuryBatchPathV03BlockNumber
}
reqUrl := fmt.Sprintf("%s%s%s", c.mercuryConfig.Credentials().URL, batchPathV03, params)
Expand Down

0 comments on commit e8a2463

Please sign in to comment.