Skip to content
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

Added VRF v2 oracle withdraw smoke test #11617

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions integration-tests/contracts/contract_vrf_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type VRFCoordinatorV2 interface {
WaitForRandomWordsFulfilledEvent(requestID []*big.Int, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2RandomWordsFulfilled, error)
WaitForRandomWordsRequestedEvent(keyHash [][32]byte, subID []uint64, sender []common.Address, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested, error)
WaitForSubscriptionCanceledEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error)
OracleWithdraw(recipient common.Address, amount *big.Int) error
}

type VRFCoordinatorV2_5 interface {
Expand Down
12 changes: 12 additions & 0 deletions integration-tests/contracts/ethereum_vrfv2_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ func (v *EthereumVRFCoordinatorV2) PendingRequestsExist(ctx context.Context, sub
return pendingRequestExists, nil
}

func (v *EthereumVRFCoordinatorV2) OracleWithdraw(recipient common.Address, amount *big.Int) error {
opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet())
if err != nil {
return err
}
tx, err := v.coordinator.OracleWithdraw(opts, recipient, amount)
if err != nil {
return err
}
return v.client.ProcessTransaction(tx)
}

// OwnerCancelSubscription cancels subscription,
// return funds to the subscription owner,
// down not check if pending requests for a sub exist,
Expand Down
60 changes: 56 additions & 4 deletions integration-tests/smoke/vrfv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/kelseyhightower/envconfig"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"
"github.com/smartcontractkit/chainlink/integration-tests/actions/vrfv2_actions"
"github.com/smartcontractkit/chainlink/integration-tests/actions/vrfv2_actions/vrfv2_config"

"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/actions/vrfv2_actions"
"github.com/smartcontractkit/chainlink/integration-tests/actions/vrfv2_actions/vrfv2_config"
"github.com/smartcontractkit/chainlink/integration-tests/docker/test_env"
)

Expand Down Expand Up @@ -116,6 +116,58 @@ func TestVRFv2Basic(t *testing.T) {
}
})

t.Run("Oracle Withdraw", func(t *testing.T) {
testConfig := vrfv2Config
subIDsForOracleWithDraw, err := vrfv2_actions.CreateFundSubsAndAddConsumers(
env,
testConfig,
linkToken,
vrfv2Contracts.Coordinator,
vrfv2Contracts.LoadTestConsumers,
1,
)
require.NoError(t, err)

subIDForOracleWithdraw := subIDsForOracleWithDraw[0]

fulfilledEventLink, err := vrfv2_actions.RequestRandomnessAndWaitForFulfillment(
vrfv2Contracts.LoadTestConsumers[0],
vrfv2Contracts.Coordinator,
vrfv2Data,
subIDForOracleWithdraw,
testConfig.RandomnessRequestCountPerRequest,
testConfig,
testConfig.RandomWordsFulfilledEventTimeout,
l,
)
require.NoError(t, err)

amountToWithdrawLink := fulfilledEventLink.Payment

defaultWalletBalanceLinkBeforeOracleWithdraw, err := linkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress)
require.NoError(t, err)

l.Info().
Str("Returning to", defaultWalletAddress).
Str("Amount", amountToWithdrawLink.String()).
Msg("Invoking Oracle Withdraw for LINK")

err = vrfv2Contracts.Coordinator.OracleWithdraw(common.HexToAddress(defaultWalletAddress), amountToWithdrawLink)
require.NoError(t, err, "Error withdrawing LINK from coordinator to default wallet")

err = env.EVMClient.WaitForEvents()
require.NoError(t, err, vrfv2_actions.ErrWaitTXsComplete)

defaultWalletBalanceLinkAfterOracleWithdraw, err := linkToken.BalanceOf(testcontext.Get(t), defaultWalletAddress)
require.NoError(t, err)

require.Equal(
t,
1,
defaultWalletBalanceLinkAfterOracleWithdraw.Cmp(defaultWalletBalanceLinkBeforeOracleWithdraw),
"LINK funds were not returned after oracle withdraw",
)
})
t.Run("Canceling Sub And Returning Funds", func(t *testing.T) {
testConfig := vrfv2Config
subIDsForCancelling, err := vrfv2_actions.CreateFundSubsAndAddConsumers(
Expand Down
Loading