Skip to content

Commit

Permalink
Added VRF v2 oracle withdraw smoke test (#11617)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkneisly authored Dec 19, 2023
1 parent 9ae0b9a commit b9b4068
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
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

0 comments on commit b9b4068

Please sign in to comment.