-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support native token * split the tests and add mercury related tests
- Loading branch information
1 parent
3a96fa0
commit 4b19e37
Showing
13 changed files
with
245 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"chainlink": patch | ||
--- | ||
|
||
add native billing in smoke test #added |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"strconv" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/google/uuid" | ||
"github.com/pkg/errors" | ||
"github.com/smartcontractkit/seth" | ||
|
@@ -115,7 +116,7 @@ func DeployKeeperContracts( | |
} | ||
|
||
registrar := DeployKeeperRegistrar(t, client, registryVersion, linkToken, registrarSettings, registry) | ||
upkeeps, upkeepIds := DeployConsumers(t, client, registry, registrar, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep, upkeepGasLimit, false, false) | ||
upkeeps, upkeepIds := DeployConsumers(t, client, registry, registrar, linkToken, numberOfUpkeeps, linkFundsForEachUpkeep, upkeepGasLimit, false, false, false, nil) | ||
|
||
return registry, registrar, upkeeps, upkeepIds | ||
} | ||
|
@@ -178,7 +179,7 @@ func DeployPerformanceKeeperContracts( | |
upkeepsAddresses = append(upkeepsAddresses, upkeep.Address()) | ||
} | ||
|
||
upkeepIds := RegisterUpkeepContracts(t, chainClient, linkToken, linkFundsForEachUpkeep, upkeepGasLimit, registry, registrar, numberOfContracts, upkeepsAddresses, false, false) | ||
upkeepIds := RegisterUpkeepContracts(t, chainClient, linkToken, linkFundsForEachUpkeep, upkeepGasLimit, registry, registrar, numberOfContracts, upkeepsAddresses, false, false, false, nil) | ||
|
||
return registry, registrar, upkeeps, upkeepIds | ||
} | ||
|
@@ -236,7 +237,7 @@ func DeployPerformDataCheckerContracts( | |
upkeepsAddresses = append(upkeepsAddresses, upkeep.Address()) | ||
} | ||
|
||
upkeepIds := RegisterUpkeepContracts(t, chainClient, linkToken, linkFundsForEachUpkeep, upkeepGasLimit, registry, registrar, numberOfContracts, upkeepsAddresses, false, false) | ||
upkeepIds := RegisterUpkeepContracts(t, chainClient, linkToken, linkFundsForEachUpkeep, upkeepGasLimit, registry, registrar, numberOfContracts, upkeepsAddresses, false, false, false, nil) | ||
|
||
return registry, registrar, upkeeps, upkeepIds | ||
} | ||
|
@@ -259,14 +260,14 @@ func DeployKeeperRegistrar( | |
return registrar | ||
} | ||
|
||
func RegisterUpkeepContracts(t *testing.T, client *seth.Client, linkToken contracts.LinkToken, linkFunds *big.Int, upkeepGasLimit uint32, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, numberOfContracts int, upkeepAddresses []string, isLogTrigger bool, isMercury bool) []*big.Int { | ||
func RegisterUpkeepContracts(t *testing.T, client *seth.Client, linkToken contracts.LinkToken, fundsForEachUpkeep *big.Int, upkeepGasLimit uint32, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, numberOfContracts int, upkeepAddresses []string, isLogTrigger bool, isMercury bool, isBillingTokenNative bool, wethToken contracts.WETHToken) []*big.Int { | ||
checkData := make([][]byte, 0) | ||
for i := 0; i < numberOfContracts; i++ { | ||
checkData = append(checkData, []byte("0")) | ||
} | ||
return RegisterUpkeepContractsWithCheckData( | ||
t, client, linkToken, linkFunds, upkeepGasLimit, registry, registrar, | ||
numberOfContracts, upkeepAddresses, checkData, isLogTrigger, isMercury) | ||
t, client, linkToken, fundsForEachUpkeep, upkeepGasLimit, registry, registrar, | ||
numberOfContracts, upkeepAddresses, checkData, isLogTrigger, isMercury, isBillingTokenNative, wethToken) | ||
} | ||
|
||
type upkeepRegistrationResult struct { | ||
|
@@ -284,7 +285,7 @@ type upkeepConfig struct { | |
|
||
type UpkeepId = *big.Int | ||
|
||
func RegisterUpkeepContractsWithCheckData(t *testing.T, client *seth.Client, linkToken contracts.LinkToken, linkFunds *big.Int, upkeepGasLimit uint32, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, numberOfContracts int, upkeepAddresses []string, checkData [][]byte, isLogTrigger bool, isMercury bool) []*big.Int { | ||
func RegisterUpkeepContractsWithCheckData(t *testing.T, client *seth.Client, linkToken contracts.LinkToken, fundsForEachUpkeep *big.Int, upkeepGasLimit uint32, registry contracts.KeeperRegistry, registrar contracts.KeeperRegistrar, numberOfContracts int, upkeepAddresses []string, checkData [][]byte, isLogTrigger bool, isMercury bool, isBillingTokenNative bool, wethToken contracts.WETHToken) []*big.Int { | ||
l := logging.GetTestLogger(t) | ||
|
||
concurrency, err := GetAndAssertCorrectConcurrency(client, 1) | ||
|
@@ -300,45 +301,69 @@ func RegisterUpkeepContractsWithCheckData(t *testing.T, client *seth.Client, lin | |
var registerUpkeepFn = func(resultCh chan upkeepRegistrationResult, errorCh chan error, executorNum int, config upkeepConfig) { | ||
id := uuid.New().String() | ||
keyNum := executorNum + 1 // key 0 is the root key | ||
var tx *types.Transaction | ||
|
||
if isBillingTokenNative { | ||
// register upkeep with native token | ||
tx, err = registrar.RegisterUpkeepFromKey( | ||
keyNum, | ||
fmt.Sprintf("upkeep_%s", id), | ||
[]byte("[email protected]"), | ||
config.address, | ||
upkeepGasLimit, | ||
client.MustGetRootKeyAddress().Hex(), // upkeep Admin | ||
config.data, | ||
fundsForEachUpkeep, | ||
wethToken.Address(), | ||
isLogTrigger, | ||
isMercury, | ||
) | ||
if err != nil { | ||
errorCh <- errors.Wrapf(err, "[id: %s] Failed to register upkeep at %s", id, config.address) | ||
return | ||
} | ||
} else { | ||
// register upkeep with LINK | ||
req, err := registrar.EncodeRegisterRequest( | ||
fmt.Sprintf("upkeep_%s", id), | ||
[]byte("[email protected]"), | ||
config.address, | ||
upkeepGasLimit, | ||
client.MustGetRootKeyAddress().Hex(), // upkeep Admin | ||
config.data, | ||
fundsForEachUpkeep, | ||
0, | ||
client.Addresses[keyNum].Hex(), | ||
isLogTrigger, | ||
isMercury, | ||
linkToken.Address(), | ||
) | ||
|
||
if err != nil { | ||
errorCh <- errors.Wrapf(err, "[id: %s] Failed to encode register request for upkeep at %s", id, config.address) | ||
return | ||
} | ||
|
||
req, err := registrar.EncodeRegisterRequest( | ||
fmt.Sprintf("upkeep_%s", id), | ||
[]byte("[email protected]"), | ||
config.address, | ||
upkeepGasLimit, | ||
client.MustGetRootKeyAddress().Hex(), // upkeep Admin | ||
config.data, | ||
linkFunds, | ||
0, | ||
client.Addresses[keyNum].Hex(), | ||
isLogTrigger, | ||
isMercury, | ||
linkToken.Address(), | ||
) | ||
|
||
if err != nil { | ||
errorCh <- errors.Wrapf(err, "[id: %s] Failed to encode register request for upkeep at %s", id, config.address) | ||
return | ||
} | ||
|
||
balance, err := linkToken.BalanceOf(context.Background(), client.Addresses[keyNum].Hex()) | ||
if err != nil { | ||
errorCh <- errors.Wrapf(err, "[id: %s]Failed to get LINK balance of %s", id, client.Addresses[keyNum].Hex()) | ||
return | ||
} | ||
balance, err := linkToken.BalanceOf(context.Background(), client.Addresses[keyNum].Hex()) | ||
if err != nil { | ||
errorCh <- errors.Wrapf(err, "[id: %s]Failed to get LINK balance of %s", id, client.Addresses[keyNum].Hex()) | ||
return | ||
} | ||
|
||
// not stricly necessary, but helps us to avoid an errorless revert if there is not enough LINK | ||
if balance.Cmp(linkFunds) < 0 { | ||
errorCh <- fmt.Errorf("[id: %s] Not enough LINK balance for %s. Has: %s. Needs: %s", id, client.Addresses[keyNum].Hex(), balance.String(), linkFunds.String()) | ||
return | ||
} | ||
// not strictly necessary, but helps us to avoid an errorless revert if there is not enough LINK | ||
if balance.Cmp(fundsForEachUpkeep) < 0 { | ||
errorCh <- fmt.Errorf("[id: %s] Not enough LINK balance for %s. Has: %s. Needs: %s", id, client.Addresses[keyNum].Hex(), balance.String(), fundsForEachUpkeep.String()) | ||
return | ||
} | ||
|
||
tx, err := linkToken.TransferAndCallFromKey(registrar.Address(), linkFunds, req, keyNum) | ||
if err != nil { | ||
errorCh <- errors.Wrapf(err, "[id: %s] Failed to register upkeep at %s", id, config.address) | ||
return | ||
tx, err = linkToken.TransferAndCallFromKey(registrar.Address(), fundsForEachUpkeep, req, keyNum) | ||
if err != nil { | ||
errorCh <- errors.Wrapf(err, "[id: %s] Failed to register upkeep at %s", id, config.address) | ||
return | ||
} | ||
} | ||
|
||
// parse txn to get upkeep ID | ||
receipt, err := client.Client.TransactionReceipt(context.Background(), tx.Hash()) | ||
if err != nil { | ||
errorCh <- errors.Wrapf(err, "[id: %s] Failed to get receipt for upkeep at %s and tx hash %s", id, config.address, tx.Hash()) | ||
|
@@ -405,10 +430,10 @@ func DeployKeeperConsumers(t *testing.T, client *seth.Client, numberOfContracts | |
// v2.1 only: Conditional based contract with Mercury enabled | ||
keeperConsumerInstance, err = contracts.DeployAutomationStreamsLookupUpkeepConsumerFromKey(client, keyNum, big.NewInt(1000), big.NewInt(5), false, true, false) // 1000 block test range | ||
} else if isLogTrigger { | ||
// v2.1 only: Log triggered based contract without Mercury | ||
// v2.1+: Log triggered based contract without Mercury | ||
keeperConsumerInstance, err = contracts.DeployAutomationLogTriggerConsumerFromKey(client, keyNum, big.NewInt(1000)) // 1000 block test range | ||
} else { | ||
// v2.0 and v2.1: Conditional based contract without Mercury | ||
// v2.0+: Conditional based contract without Mercury | ||
keeperConsumerInstance, err = contracts.DeployUpkeepCounterFromKey(client, keyNum, big.NewInt(999999), big.NewInt(5)) | ||
} | ||
|
||
|
@@ -580,7 +605,7 @@ func RegisterNewUpkeeps( | |
err = SendLinkFundsToDeploymentAddresses(chainClient, concurrency, numberOfNewUpkeeps, operationsPerAddress, multicallAddress, linkFundsForEachUpkeep, linkToken) | ||
require.NoError(t, err, "Sending link funds to deployment addresses shouldn't fail") | ||
|
||
newUpkeepIDs := RegisterUpkeepContracts(t, chainClient, linkToken, linkFundsForEachUpkeep, upkeepGasLimit, registry, registrar, numberOfNewUpkeeps, addressesOfNewUpkeeps, false, false) | ||
newUpkeepIDs := RegisterUpkeepContracts(t, chainClient, linkToken, linkFundsForEachUpkeep, upkeepGasLimit, registry, registrar, numberOfNewUpkeeps, addressesOfNewUpkeeps, false, false, false, nil) | ||
|
||
return newlyDeployedUpkeeps, newUpkeepIDs | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.