Skip to content

Commit

Permalink
[TT-681] Remove usages of github.com/pkg/errors (#11213)
Browse files Browse the repository at this point in the history
  • Loading branch information
tateexon authored Nov 7, 2023
1 parent e4b50ff commit f5d6797
Show file tree
Hide file tree
Showing 25 changed files with 189 additions and 231 deletions.
18 changes: 9 additions & 9 deletions integration-tests/actions/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (
"crypto/ecdsa"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"math/big"
"strings"
"testing"

"github.com/ethereum/go-ethereum/crypto"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -262,7 +262,7 @@ func TeardownSuite(
) error {
l := logging.GetTestLogger(t)
if err := testreporters.WriteTeardownLogs(t, env, optionalTestReporter, failingLogLevel); err != nil {
return errors.Wrap(err, "Error dumping environment logs, leaving environment running for manual retrieval")
return fmt.Errorf("Error dumping environment logs, leaving environment running for manual retrieval, err: %w", err)
}
// Delete all jobs to stop depleting the funds
err := DeleteAllJobs(chainlinkNodes)
Expand Down Expand Up @@ -330,16 +330,16 @@ func DeleteAllJobs(chainlinkNodes []*client.ChainlinkK8sClient) error {
}
jobs, _, err := node.ReadJobs()
if err != nil {
return errors.Wrap(err, "error reading jobs from chainlink node")
return fmt.Errorf("error reading jobs from chainlink node, err: %w", err)
}
for _, maps := range jobs.Data {
if _, ok := maps["id"]; !ok {
return errors.Errorf("error reading job id from chainlink node's jobs %+v", jobs.Data)
return fmt.Errorf("error reading job id from chainlink node's jobs %+v", jobs.Data)
}
id := maps["id"].(string)
_, err := node.DeleteJob(id)
if err != nil {
return errors.Wrap(err, "error deleting job from chainlink node")
return fmt.Errorf("error deleting job from chainlink node, err: %w", err)
}
}
}
Expand All @@ -350,7 +350,7 @@ func DeleteAllJobs(chainlinkNodes []*client.ChainlinkK8sClient) error {
// all from a remote, k8s style environment
func ReturnFunds(chainlinkNodes []*client.ChainlinkK8sClient, blockchainClient blockchain.EVMClient) error {
if blockchainClient == nil {
return errors.New("blockchain client is nil, unable to return funds from chainlink nodes")
return fmt.Errorf("blockchain client is nil, unable to return funds from chainlink nodes")
}
log.Info().Msg("Attempting to return Chainlink node funds to default network wallets")
if blockchainClient.NetworkSimulated() {
Expand Down Expand Up @@ -416,7 +416,7 @@ func UpgradeChainlinkNodeVersions(
nodes ...*client.ChainlinkK8sClient,
) error {
if newImage == "" && newVersion == "" {
return errors.New("unable to upgrade node version, found empty image and version, must provide either a new image or a new version")
return fmt.Errorf("unable to upgrade node version, found empty image and version, must provide either a new image or a new version")
}
for _, node := range nodes {
if err := node.UpgradeVersion(testEnvironment, newImage, newVersion); err != nil {
Expand Down Expand Up @@ -455,7 +455,7 @@ func GenerateWallet() (common.Address, error) {
publicKey := privateKey.Public()
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
if !ok {
return common.Address{}, errors.New("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
return common.Address{}, fmt.Errorf("cannot assert type: publicKey is not of type *ecdsa.PublicKey")
}
return crypto.PubkeyToAddress(*publicKeyECDSA), nil
}
5 changes: 3 additions & 2 deletions integration-tests/actions/actions_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
package actions

import (
"github.com/pkg/errors"
"fmt"

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

Expand All @@ -13,7 +14,7 @@ func UpgradeChainlinkNodeVersionsLocal(
nodes ...*test_env.ClNode,
) error {
if newImage == "" && newVersion == "" {
return errors.New("unable to upgrade node version, found empty image and version, must provide either a new image or a new version")
return fmt.Errorf("unable to upgrade node version, found empty image and version, must provide either a new image or a new version")
}
for _, node := range nodes {
if err := node.UpgradeVersion(node.NodeConfig, newImage, newVersion); err != nil {
Expand Down
3 changes: 1 addition & 2 deletions integration-tests/actions/automation_ocr_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/lib/pq"
"github.com/pkg/errors"
"github.com/rs/zerolog"
ocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"
Expand Down Expand Up @@ -187,7 +186,7 @@ func CreateOCRKeeperJobsLocal(
} else if registryVersion == ethereum.RegistryVersion_2_0 {
contractVersion = "v2.0"
} else {
return errors.New("v2.0 and v2.1 are the only supported versions")
return fmt.Errorf("v2.0 and v2.1 are the only supported versions")
}

bootstrapSpec := &client.OCR2TaskJobSpec{
Expand Down
9 changes: 4 additions & 5 deletions integration-tests/actions/ocr_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
Expand Down Expand Up @@ -280,7 +279,7 @@ func TrackForwarderLocal(
chainID := chainClient.GetChainID()
_, _, err := node.TrackForwarder(chainID, authorizedForwarder)
if err != nil {
return errors.Wrap(err, "failed to track forwarder")
return fmt.Errorf("failed to track forwarder, err: %w", err)
}
logger.Info().Str("NodeURL", node.Config.URL).
Str("ForwarderAddress", authorizedForwarder.Hex()).
Expand All @@ -305,7 +304,7 @@ func DeployOCRContractsForwarderFlowLocal(
contracts.DefaultOffChainAggregatorOptions(),
)
if err != nil {
return nil, errors.Wrap(err, "failed to deploy offchain aggregator")
return nil, fmt.Errorf("failed to deploy offchain aggregator, err: %w", err)
}
ocrInstances = append(ocrInstances, ocrInstance)
err = client.WaitForEvents()
Expand All @@ -329,7 +328,7 @@ func DeployOCRContractsForwarderFlowLocal(
for _, ocrInstance := range ocrInstances {
err := ocrInstance.SetPayees(transmitters, payees)
if err != nil {
return nil, errors.Wrap(err, "failed to set OCR payees")
return nil, fmt.Errorf("failed to set OCR payees, err: %w", err)
}
if err := client.WaitForEvents(); err != nil {
return nil, err
Expand All @@ -348,7 +347,7 @@ func DeployOCRContractsForwarderFlowLocal(
forwarderAddresses,
)
if err != nil {
return nil, errors.Wrap(err, "failed to set on-chain config")
return nil, fmt.Errorf("failed to set on-chain config, err: %w", err)
}
if err = client.WaitForEvents(); err != nil {
return nil, err
Expand Down
9 changes: 5 additions & 4 deletions integration-tests/actions/vrfv1/actions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package vrfv1

import (
"github.com/pkg/errors"
"fmt"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
)
Expand All @@ -21,15 +22,15 @@ type Contracts struct {
func DeployVRFContracts(cd contracts.ContractDeployer, bc blockchain.EVMClient, lt contracts.LinkToken) (*Contracts, error) {
bhs, err := cd.DeployBlockhashStore()
if err != nil {
return nil, errors.Wrap(err, ErrDeployBHSV1)
return nil, fmt.Errorf("%s, err %w", ErrDeployBHSV1, err)
}
coordinator, err := cd.DeployVRFCoordinator(lt.Address(), bhs.Address())
if err != nil {
return nil, errors.Wrap(err, ErrDeployVRFCootrinatorV1)
return nil, fmt.Errorf("%s, err %w", ErrDeployVRFCootrinatorV1, err)
}
consumer, err := cd.DeployVRFConsumer(lt.Address(), coordinator.Address())
if err != nil {
return nil, errors.Wrap(err, ErrDeployVRFConsumerV1)
return nil, fmt.Errorf("%s, err %w", ErrDeployVRFConsumerV1, err)
}
if err := bc.WaitForEvents(); err != nil {
return nil, err
Expand Down
27 changes: 13 additions & 14 deletions integration-tests/actions/vrfv2_actions/vrfv2_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/big"

"github.com/google/uuid"
"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
chainlinkutils "github.com/smartcontractkit/chainlink/v2/core/utils"
Expand Down Expand Up @@ -43,15 +42,15 @@ func DeployVRFV2Contracts(
) (*VRFV2Contracts, error) {
bhs, err := contractDeployer.DeployBlockhashStore()
if err != nil {
return nil, errors.Wrap(err, ErrDeployBlockHashStore)
return nil, fmt.Errorf("%s, err %w", ErrDeployBlockHashStore, err)
}
coordinator, err := contractDeployer.DeployVRFCoordinatorV2(linkTokenContract.Address(), bhs.Address(), linkEthFeedContract.Address())
if err != nil {
return nil, errors.Wrap(err, ErrDeployCoordinator)
return nil, fmt.Errorf("%s, err %w", ErrDeployCoordinator, err)
}
loadTestConsumer, err := contractDeployer.DeployVRFv2LoadTestConsumer(coordinator.Address())
if err != nil {
return nil, errors.Wrap(err, ErrAdvancedConsumer)
return nil, fmt.Errorf("%s, err %w", ErrAdvancedConsumer, err)
}
err = chainClient.WaitForEvents()
if err != nil {
Expand All @@ -70,7 +69,7 @@ func CreateVRFV2Jobs(
for _, chainlinkNode := range chainlinkNodes {
vrfKey, err := chainlinkNode.MustCreateVRFKey()
if err != nil {
return nil, errors.Wrap(err, ErrCreatingVRFv2Key)
return nil, fmt.Errorf("%s, err %w", ErrCreatingVRFv2Key, err)
}
pubKeyCompressed := vrfKey.Data.ID
jobUUID := uuid.New()
Expand All @@ -79,11 +78,11 @@ func CreateVRFV2Jobs(
}
ost, err := os.String()
if err != nil {
return nil, errors.Wrap(err, ErrParseJob)
return nil, fmt.Errorf("%s, err %w", ErrParseJob, err)
}
nativeTokenPrimaryKeyAddress, err := chainlinkNode.PrimaryEthAddress()
if err != nil {
return nil, errors.Wrap(err, ErrNodePrimaryKey)
return nil, fmt.Errorf("%s, err %w", ErrNodePrimaryKey, err)
}
job, err := chainlinkNode.MustCreateJob(&client.VRFV2JobSpec{
Name: fmt.Sprintf("vrf-%s", jobUUID),
Expand All @@ -97,15 +96,15 @@ func CreateVRFV2Jobs(
BatchFulfillmentEnabled: false,
})
if err != nil {
return nil, errors.Wrap(err, ErrCreatingVRFv2Job)
return nil, fmt.Errorf("%s, err %w", ErrCreatingVRFv2Job, err)
}
provingKey, err := VRFV2RegisterProvingKey(vrfKey, nativeTokenPrimaryKeyAddress, coordinator)
if err != nil {
return nil, errors.Wrap(err, ErrCreatingProvingKey)
return nil, fmt.Errorf("%s, err %w", ErrCreatingProvingKey, err)
}
keyHash, err := coordinator.HashOfKey(context.Background(), provingKey)
if err != nil {
return nil, errors.Wrap(err, ErrCreatingProvingKeyHash)
return nil, fmt.Errorf("%s, err %w", ErrCreatingProvingKeyHash, err)
}
ji := VRFV2JobInfo{
Job: job,
Expand All @@ -125,26 +124,26 @@ func VRFV2RegisterProvingKey(
) (VRFV2EncodedProvingKey, error) {
provingKey, err := actions.EncodeOnChainVRFProvingKey(*vrfKey)
if err != nil {
return VRFV2EncodedProvingKey{}, errors.Wrap(err, ErrEncodingProvingKey)
return VRFV2EncodedProvingKey{}, fmt.Errorf("%s, err %w", ErrEncodingProvingKey, err)
}
err = coordinator.RegisterProvingKey(
oracleAddress,
provingKey,
)
if err != nil {
return VRFV2EncodedProvingKey{}, errors.Wrap(err, ErrRegisterProvingKey)
return VRFV2EncodedProvingKey{}, fmt.Errorf("%s, err %w", ErrRegisterProvingKey, err)
}
return provingKey, nil
}

func FundVRFCoordinatorV2Subscription(linkToken contracts.LinkToken, coordinator contracts.VRFCoordinatorV2, chainClient blockchain.EVMClient, subscriptionID uint64, linkFundingAmount *big.Int) error {
encodedSubId, err := chainlinkutils.ABIEncode(`[{"type":"uint64"}]`, subscriptionID)
if err != nil {
return errors.Wrap(err, ErrABIEncodingFunding)
return fmt.Errorf("%s, err %w", ErrABIEncodingFunding, err)
}
_, err = linkToken.TransferAndCall(coordinator.Address(), big.NewInt(0).Mul(linkFundingAmount, big.NewInt(1e18)), encodedSubId)
if err != nil {
return errors.Wrap(err, ErrSendingLinkToken)
return fmt.Errorf("%s, err %w", ErrSendingLinkToken, err)
}
return chainClient.WaitForEvents()
}
Expand Down
Loading

0 comments on commit f5d6797

Please sign in to comment.