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

Use Seth EVM client in E2E VRF tests #12964

Merged
merged 57 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
f605c01
WIP: smoke/vrfv2_test.go
lukaszcl Apr 24, 2024
c34385f
wip 2
lukaszcl Apr 24, 2024
3e48622
wip 3
lukaszcl Apr 24, 2024
874e0f0
wip 4
lukaszcl Apr 24, 2024
9a6a278
wip 5
lukaszcl Apr 24, 2024
3e5d2e3
wip 6
lukaszcl Apr 24, 2024
90fe936
wip 7
lukaszcl Apr 25, 2024
4afe6fe
wip 8
lukaszcl Apr 25, 2024
5fb6f53
fix
lukaszcl Apr 25, 2024
756fe82
wip 9
lukaszcl Apr 25, 2024
67d4c7f
wip 10
lukaszcl Apr 25, 2024
203d5f1
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl Apr 25, 2024
b735d32
fix
lukaszcl Apr 25, 2024
14092f4
fix go mod
lukaszcl Apr 25, 2024
c221218
fix
lukaszcl Apr 25, 2024
cc13fa2
fix lint
lukaszcl Apr 25, 2024
87d4400
fix
lukaszcl Apr 25, 2024
ea66dec
Fix
lukaszcl Apr 25, 2024
579280e
fix vrfv2plus
lukaszcl Apr 25, 2024
9f16f32
fix 2
lukaszcl Apr 25, 2024
cd25939
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl Apr 25, 2024
06bf8d2
fix
lukaszcl Apr 26, 2024
0febc2d
wip
lukaszcl Apr 26, 2024
f20fe27
bump gas limit for sending funds to EOA
lukaszcl Apr 26, 2024
08ce45a
check receipt when sending funds
lukaszcl Apr 26, 2024
57781c0
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl May 6, 2024
94b28d0
Merge branch 'TT-1057-Migrate-VRF-smoke-tests' of https://github.com/…
lukaszcl May 6, 2024
272c1d0
fix go mod
lukaszcl May 7, 2024
a4b0cca
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl May 8, 2024
65d3c78
Fix test context
lukaszcl May 10, 2024
89d8511
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
Tofel May 10, 2024
dbe63f8
use latest Seth that estimates gas for funds sending
Tofel May 10, 2024
702df4a
adding Polygon Amoy and Arb Sepolia with default config; small refact…
iljapavlovs May 12, 2024
b365b88
Merge remote-tracking branch 'origin/TT-1057-Migrate-VRF-smoke-tests'…
iljapavlovs May 12, 2024
1c438e0
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
iljapavlovs May 12, 2024
3703d86
Fix passing wrapped contract backend
lukaszcl May 13, 2024
340ddac
Use MustGetRootKeyAddress()
lukaszcl May 13, 2024
355aa34
Show funding amount in ETH
lukaszcl May 13, 2024
212c2a3
Remove legacy vrf code
lukaszcl May 13, 2024
c13e930
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl May 13, 2024
3ea165d
Fix lint
lukaszcl May 13, 2024
37c25fc
Fix lint 2
lukaszcl May 13, 2024
62f0bc7
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl May 13, 2024
f2ae505
Use AnySyncedKey in wasp guns
lukaszcl May 13, 2024
161eb7b
Log key num
lukaszcl May 13, 2024
d3eb868
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl May 13, 2024
771b7da
Merge branch 'TT-1057-Migrate-VRF-smoke-tests' of https://github.com/…
lukaszcl May 13, 2024
8e2a981
Add RequestRandomnessFromKey and use GetChainClientWithConfigFunction…
lukaszcl May 13, 2024
bd68776
Extract events from tx logs
lukaszcl May 14, 2024
25aa355
Use SethRootKeyIndex
lukaszcl May 14, 2024
3a1640f
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl May 14, 2024
f2b51bf
Fix getting event data
lukaszcl May 14, 2024
ab04fe4
Fix parsing events
lukaszcl May 15, 2024
1baec5a
Merge branch 'develop' into TT-1057-Migrate-VRF-smoke-tests
lukaszcl May 15, 2024
59e49d3
Fix load tests
lukaszcl May 15, 2024
d7ada9b
Do not use AnySyncedKey
lukaszcl May 15, 2024
ef712a0
Support multiple keys with AvailableSethKeyNum
lukaszcl May 15, 2024
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
2 changes: 1 addition & 1 deletion integration-tests/actions/vrf/vrfv2/contract_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ func CancelSubsAndReturnFunds(ctx context.Context, vrfContracts *vrfcommon.VRFCo
l.Error().Err(err).Msg("Error checking if pending requests exist")
}
if !pendingRequestsExist {
_, err := vrfContracts.CoordinatorV2.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
_, _, err := vrfContracts.CoordinatorV2.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
if err != nil {
l.Error().Err(err).Msg("Error canceling subscription")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func CancelSubsAndReturnFunds(ctx context.Context, vrfContracts *vrfcommon.VRFCo
l.Error().Err(err).Msg("Error checking if pending requests exist")
}
if !pendingRequestsExist {
_, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
_, _, err := vrfContracts.CoordinatorV2Plus.CancelSubscription(subID, common.HexToAddress(eoaWalletAddress))
if err != nil {
l.Error().Err(err).Msg("Error canceling subscription")
}
Expand Down
22 changes: 7 additions & 15 deletions integration-tests/contracts/contract_vrf_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"

"github.com/smartcontractkit/seth"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_coordinator_v2_5"
Expand Down Expand Up @@ -63,20 +65,14 @@ type VRFCoordinatorV2 interface {
GetSubscription(ctx context.Context, subID uint64) (Subscription, error)
GetOwner(ctx context.Context) (common.Address, error)
PendingRequestsExist(ctx context.Context, subID uint64) (bool, error)
OwnerCancelSubscription(subID uint64) (*types.Transaction, error)
OwnerCancelSubscription(subID uint64) (*seth.DecodedTransaction, *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error)
CancelSubscription(subID uint64, to common.Address) (*seth.DecodedTransaction, *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error)
ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error)
ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error)
ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error)
ParseLog(log types.Log) (generated.AbigenLog, error)
CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error)
FindSubscriptionID(subID uint64) (uint64, error)
WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, 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)
WaitForSubscriptionConsumerAdded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerAdded, error)
WaitForSubscriptionConsumerRemoved(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerRemoved, error)
WaitForSubscriptionCreatedEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCreated, error)
WaitForSubscriptionFunded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionFunded, error)
WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error)
OracleWithdraw(recipient common.Address, amount *big.Int) error
}
Expand Down Expand Up @@ -104,24 +100,21 @@ type VRFCoordinatorV2_5 interface {
HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error)
CreateSubscription() (*types.Transaction, error)
GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error)
Migrate(subId *big.Int, coordinatorAddress string) error
Migrate(subId *big.Int, coordinatorAddress string) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error)
RegisterMigratableCoordinator(migratableCoordinatorAddress string) error
AddConsumer(subId *big.Int, consumerAddress string) error
FundSubscriptionWithNative(subId *big.Int, nativeTokenAmount *big.Int) error
Address() string
PendingRequestsExist(ctx context.Context, subID *big.Int) (bool, error)
GetSubscription(ctx context.Context, subID *big.Int) (Subscription, error)
OwnerCancelSubscription(subID *big.Int) (*types.Transaction, error)
CancelSubscription(subID *big.Int, to common.Address) (*types.Transaction, error)
OwnerCancelSubscription(subID *big.Int) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error)
CancelSubscription(subID *big.Int, to common.Address) (*seth.DecodedTransaction, *vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error)
Withdraw(recipient common.Address) error
WithdrawNative(recipient common.Address) error
GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error)
GetLinkTotalBalance(ctx context.Context) (*big.Int, error)
FindSubscriptionID(subID *big.Int) (*big.Int, error)
WaitForSubscriptionCreatedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCreated, error)
WaitForSubscriptionCanceledEvent(subID *big.Int, timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCanceled, error)
WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error)
WaitForMigrationCompletedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25MigrationCompleted, error)
ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error)
ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error)
WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error)
Expand Down Expand Up @@ -160,7 +153,6 @@ type VRFCoordinatorV2PlusUpgradedVersion interface {
GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error)
FindSubscriptionID() (*big.Int, error)
WaitForRandomWordsFulfilledEvent(filter RandomWordsFulfilledEventFilter) (*CoordinatorRandomWordsFulfilled, error)
WaitForMigrationCompletedEvent(timeout time.Duration) (*vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionMigrationCompleted, error)
ParseRandomWordsRequested(log types.Log) (*CoordinatorRandomWordsRequested, error)
ParseRandomWordsFulfilled(log types.Log) (*CoordinatorRandomWordsFulfilled, error)
WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error)
Expand Down
172 changes: 44 additions & 128 deletions integration-tests/contracts/ethereum_vrfv2_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,12 +529,16 @@ func (v *EthereumVRFCoordinatorV2) OracleWithdraw(recipient common.Address, amou
// return funds to the subscription owner,
// down not check if pending requests for a sub exist,
// outstanding requests may fail onchain
func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*types.Transaction, error) {
// Do not wrap in Decode() to avoid waiting until the transaction is mined
return v.coordinator.OwnerCancelSubscription(
func (v *EthereumVRFCoordinatorV2) OwnerCancelSubscription(subID uint64) (*seth.DecodedTransaction, *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) {
tx, err := v.client.Decode(v.coordinator.OwnerCancelSubscription(
v.client.NewTXOpts(),
subID,
)
))
if err != nil {
return nil, nil, err
}
event, err := extractVRFCoordinatorV2SubscriptionCanceledEvent(tx.Events)
return tx, event, err
}

func (v *EthereumVRFCoordinatorV2) ParseSubscriptionCanceled(log types.Log) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) {
Expand Down Expand Up @@ -583,13 +587,17 @@ func (v *EthereumVRFCoordinatorV2) ParseLog(log types.Log) (generated.AbigenLog,
// CancelSubscription cancels subscription by Sub owner,
// return funds to specified address,
// checks if pending requests for a sub exist
func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*types.Transaction, error) {
// Do not wrap in Decode() to avoid waiting until the transaction is mined.
return v.coordinator.CancelSubscription(
func (v *EthereumVRFCoordinatorV2) CancelSubscription(subID uint64, to common.Address) (*seth.DecodedTransaction, *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) {
tx, err := v.client.Decode(v.coordinator.CancelSubscription(
v.client.NewTXOpts(),
subID,
to,
)
))
if err != nil {
return nil, nil, err
}
event, err := extractVRFCoordinatorV2SubscriptionCanceledEvent(tx.Events)
return tx, event, err
}

func (v *EthereumVRFCoordinatorV2) FindSubscriptionID(subID uint64) (uint64, error) {
Expand Down Expand Up @@ -635,126 +643,6 @@ func (v *EthereumVRFCoordinatorV2) WaitForRandomWordsFulfilledEvent(filter Rando
}
}

func (v *EthereumVRFCoordinatorV2) WaitForRandomWordsRequestedEvent(keyHash [][32]byte, subID []uint64, sender []common.Address, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested, error) {
eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2RandomWordsRequested)
subscription, err := v.coordinator.WatchRandomWordsRequested(nil, eventsChannel, keyHash, subID, sender)
if err != nil {
return nil, err
}
defer subscription.Unsubscribe()

for {
select {
case err := <-subscription.Err():
return nil, err
case <-time.After(timeout):
return nil, fmt.Errorf("timeout waiting for RandomWordsRequested event")
case event := <-eventsChannel:
return event, nil
}
}
}

func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionFunded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionFunded, error) {
eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionFunded)
subscription, err := v.coordinator.WatchSubscriptionFunded(nil, eventsChannel, subID)
if err != nil {
return nil, err
}
defer subscription.Unsubscribe()

for {
select {
case err := <-subscription.Err():
return nil, err
case <-time.After(timeout):
return nil, fmt.Errorf("timeout waiting for SubscriptionFunded event")
case event := <-eventsChannel:
return event, nil
}
}
}

func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionCanceledEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) {
eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled)
subscription, err := v.coordinator.WatchSubscriptionCanceled(nil, eventsChannel, subID)
if err != nil {
return nil, err
}
defer subscription.Unsubscribe()

for {
select {
case err := <-subscription.Err():
return nil, err
case <-time.After(timeout):
return nil, fmt.Errorf("timeout waiting for SubscriptionCanceled event")
case sub := <-eventsChannel:
return sub, nil
}
}
}

func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionCreatedEvent(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCreated, error) {
eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCreated)
subscription, err := v.coordinator.WatchSubscriptionCreated(nil, eventsChannel, subID)
if err != nil {
return nil, err
}
defer subscription.Unsubscribe()

for {
select {
case err := <-subscription.Err():
return nil, err
case <-time.After(timeout):
return nil, fmt.Errorf("timeout waiting for SubscriptionCreated event")
case event := <-eventsChannel:
return event, nil
}
}
}

func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionConsumerAdded(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerAdded, error) {
eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerAdded)
subscription, err := v.coordinator.WatchSubscriptionConsumerAdded(nil, eventsChannel, subID)
if err != nil {
return nil, err
}
defer subscription.Unsubscribe()

for {
select {
case err := <-subscription.Err():
return nil, err
case <-time.After(timeout):
return nil, fmt.Errorf("timeout waiting for SubscriptionConsumerAdded event")
case event := <-eventsChannel:
return event, nil
}
}
}

func (v *EthereumVRFCoordinatorV2) WaitForSubscriptionConsumerRemoved(subID []uint64, timeout time.Duration) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerRemoved, error) {
eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2SubscriptionConsumerRemoved)
subscription, err := v.coordinator.WatchSubscriptionConsumerRemoved(nil, eventsChannel, subID)
if err != nil {
return nil, err
}
defer subscription.Unsubscribe()

for {
select {
case err := <-subscription.Err():
return nil, err
case <-time.After(timeout):
return nil, fmt.Errorf("timeout waiting for SubscriptionConsumerRemoved event")
case event := <-eventsChannel:
return event, nil
}
}
}

func (v *EthereumVRFCoordinatorV2) WaitForConfigSetEvent(timeout time.Duration) (*CoordinatorConfigSet, error) {
eventsChannel := make(chan *vrf_coordinator_v2.VRFCoordinatorV2ConfigSet)
subscription, err := v.coordinator.WatchConfigSet(nil, eventsChannel)
Expand Down Expand Up @@ -1255,3 +1143,31 @@ func (v *EthereumVRFMockETHLINKFeed) SetBlockTimestampDeduction(blockTimestampDe
_, err := v.client.Decode(v.feed.SetBlockTimestampDeduction(v.client.NewTXOpts(), blockTimestampDeduction))
return err
}

func extractVRFCoordinatorV2SubscriptionCanceledEvent(events []seth.DecodedTransactionLog) (*vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled, error) {
var event vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled
for i, e := range events {
if len(e.Topics) == 0 {
return nil, fmt.Errorf("no topics in event %d", i)
}
switch e.Topics[0] {
case vrf_coordinator_v2.VRFCoordinatorV2SubscriptionCanceled{}.Topic().String():
if to, ok := e.EventData["to"].(common.Address); ok {
event.To = to
} else {
return nil, fmt.Errorf("'to' not found in the event")
}
if amount, ok := e.EventData["amount"].(*big.Int); ok {
event.Amount = amount
} else {
return nil, fmt.Errorf("'amount' not found in the event")
}
if subId, ok := e.EventData["subId"].(uint64); ok {
event.SubId = subId
} else {
return nil, fmt.Errorf("'subId' not found in the event")
}
}
}
return &event, nil
}
Loading
Loading