Skip to content

Commit

Permalink
Upgrade package suite & bump go version (#561)
Browse files Browse the repository at this point in the history
* Upgrade fastrlp

* Rename go-web3 to ethgo

* Bumped go version to 1.17

* bumped linter go version
* bumped tests go version
* set go version in go.mod
* ran go mod vendor

* Bump package versions

Co-authored-by: ZeljkoBenovic <[email protected]>
  • Loading branch information
zivkovicmilos and ZeljkoBenovic committed Jun 2, 2022
1 parent f73da20 commit 6bb316b
Show file tree
Hide file tree
Showing 1,151 changed files with 385,362 additions and 103,968 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.16.x
go-version: 1.17.x

- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.16.x
go-version: 1.17.x

- name: Checkout code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@master
with:
go-version: 1.16.x
go-version: 1.17.x

- name: Prepare
id: prepare
Expand Down
2 changes: 1 addition & 1 deletion command/loadbot/deploy_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
txpoolOp "github.com/0xPolygon/polygon-edge/txpool/proto"
"github.com/0xPolygon/polygon-edge/types"

"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/ethgo/jsonrpc"
)

func (l *Loadbot) deployContract(
Expand Down
4 changes: 2 additions & 2 deletions command/loadbot/duration.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package loadbot

import (
"github.com/umbracle/go-web3"
"github.com/umbracle/ethgo"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -88,7 +88,7 @@ func (ed *ExecDuration) calcTurnAroundMetrics() {
// reportTurnAroundTime reports the turn around time for a transaction
// for a single loadbot run
func (ed *ExecDuration) reportTurnAroundTime(
txHash web3.Hash,
txHash ethgo.Hash,
data *metadata,
) {
ed.turnAroundMap.Store(txHash, data)
Expand Down
14 changes: 7 additions & 7 deletions command/loadbot/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"crypto/ecdsa"
"fmt"
"github.com/umbracle/ethgo"
"math/big"
"sync"
"sync/atomic"
Expand All @@ -13,10 +14,9 @@ import (
"github.com/0xPolygon/polygon-edge/helper/tests"
txpoolOp "github.com/0xPolygon/polygon-edge/txpool/proto"
"github.com/golang/protobuf/ptypes/any"
"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/ethgo/jsonrpc"

"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/go-web3"
)

const (
Expand Down Expand Up @@ -92,7 +92,7 @@ func (b *BlockGasMetrics) AddBlockMetric(blockNum uint64, gasMetric GasMetrics)
type ContractMetricsData struct {
FailedContractTransactionsCount uint64
ContractDeploymentDuration ExecDuration
ContractAddress web3.Address
ContractAddress ethgo.Address
ContractGasMetrics *BlockGasMetrics
}

Expand Down Expand Up @@ -358,10 +358,10 @@ func (l *Loadbot) Run() error {

func (l *Loadbot) executeTxn(
client txpoolOp.TxnPoolOperatorClient,
) (web3.Hash, error) {
) (ethgo.Hash, error) {
txn, err := l.generator.GenerateTransaction()
if err != nil {
return web3.Hash{}, err
return ethgo.Hash{}, err
}

addReq := &txpoolOp.AddTxnReq{
Expand All @@ -373,8 +373,8 @@ func (l *Loadbot) executeTxn(

addRes, addErr := client.AddTxn(context.Background(), addReq)
if addErr != nil {
return web3.Hash{}, fmt.Errorf("unable to add transaction, %w", addErr)
return ethgo.Hash{}, fmt.Errorf("unable to add transaction, %w", addErr)
}

return web3.Hash(types.StringToHash(addRes.TxHash)), nil
return ethgo.Hash(types.StringToHash(addRes.TxHash)), nil
}
6 changes: 3 additions & 3 deletions command/loadbot/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package generator
import (
"crypto/ecdsa"
"encoding/json"
"github.com/umbracle/ethgo"
"io/ioutil"
"math/big"

"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/abi"
"github.com/umbracle/ethgo/abi"
)

type TransactionGenerator interface {
Expand Down Expand Up @@ -69,7 +69,7 @@ type GeneratorParams struct {
GasPrice *big.Int
ContractArtifact *ContractArtifact
ConstructorArgs []byte // smart contract constructor arguments
ContractAddress web3.Address
ContractAddress ethgo.Address
}

// ReadContractArtifact reads the contract bytecode from the specified path
Expand Down
2 changes: 1 addition & 1 deletion command/loadbot/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/0xPolygon/polygon-edge/crypto"
txpoolOp "github.com/0xPolygon/polygon-edge/txpool/proto"
"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/ethgo/jsonrpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
Expand Down
14 changes: 7 additions & 7 deletions command/loadbot/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ package loadbot

import (
"fmt"
"github.com/umbracle/ethgo"
"math/big"
"sync"
"time"

"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/ethgo/jsonrpc"
)

// getInitialSenderNonce queries the sender account nonce before starting the loadbot run.
// The nonce used for transactions is incremented by the loadbot during runtime
func getInitialSenderNonce(client *jsonrpc.Client, address types.Address) (uint64, error) {
nonce, err := client.Eth().GetNonce(web3.Address(address), web3.Latest)
nonce, err := client.Eth().GetNonce(ethgo.Address(address), ethgo.Latest)
if err != nil {
return 0, fmt.Errorf("failed to query initial sender nonce: %w", err)
}
Expand All @@ -36,9 +36,9 @@ func getAverageGasPrice(client *jsonrpc.Client) (uint64, error) {
// estimateGas queries the network node for a gas estimation before starting
// the loadbot run
func estimateGas(client *jsonrpc.Client, txn *types.Transaction) (uint64, error) {
gasEstimate, err := client.Eth().EstimateGas(&web3.CallMsg{
From: web3.Address(txn.From),
To: (*web3.Address)(txn.To),
gasEstimate, err := client.Eth().EstimateGas(&ethgo.CallMsg{
From: ethgo.Address(txn.From),
To: (*ethgo.Address)(txn.To),
Data: txn.Input,
GasPrice: txn.GasPrice.Uint64(),
Value: txn.Value,
Expand Down Expand Up @@ -99,7 +99,7 @@ func getBlockGasMetrics(
) {
// Query node for block
blockInfo, err := jsonClient.Eth().GetBlockByNumber(
web3.BlockNumber(blockNum),
ethgo.BlockNumber(blockNum),
false,
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion command/loadbot/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/0xPolygon/polygon-edge/command/loadbot/generator"
"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/go-web3/abi"
"github.com/umbracle/ethgo/abi"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions command/loadbot/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package loadbot
import (
"bytes"
"fmt"
"github.com/umbracle/ethgo"
"math"
"sort"

"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/command/loadbot/generator"
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/umbracle/go-web3"
)

const (
Expand Down Expand Up @@ -52,7 +52,7 @@ type LoadbotResult struct {
BlockData TxnBlockData `json:"block_data"`
DetailedErrorData TxnDetailedErrorData `json:"detailed_error_data,omitempty"`
ApproxTPS uint64 `json:"approx_tps"`
ContractAddress web3.Address `json:"contract_address,omitempty"`
ContractAddress ethgo.Address `json:"contract_address,omitempty"`
ContractBlockData TxnBlockData `json:"contract_block_data,omitempty"`
}

Expand Down Expand Up @@ -185,7 +185,7 @@ func (lr *LoadbotResult) writeErrorData(buffer *bytes.Buffer) {
buffer.WriteString("\n\n[DETAILED ERRORS]\n")

addToBuffer := func(detailedError *generator.FailedTxnInfo) {
if detailedError.TxHash != web3.ZeroHash.String() {
if detailedError.TxHash != ethgo.ZeroHash.String() {
buffer.WriteString(fmt.Sprintf("\n\n[%s]\n", detailedError.TxHash))
} else {
buffer.WriteString("\n\n[Tx Hash Unavailable]\n")
Expand Down Expand Up @@ -275,7 +275,7 @@ func (lr *LoadbotResult) writeTurnAroundData(buffer *bytes.Buffer) {

func (lr *LoadbotResult) writeContractDeploymentData(buffer *bytes.Buffer) {
// skip if contract was not deployed
if lr.ContractAddress == web3.ZeroAddress {
if lr.ContractAddress == ethgo.ZeroAddress {
return
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/abis/abis.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package abis

import (
"github.com/umbracle/go-web3/abi"
"github.com/umbracle/ethgo/abi"
)

var StakingABI = abi.MustNewABI(StakingJSONABI)
Expand Down
8 changes: 4 additions & 4 deletions contracts/staking/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package staking

import (
"errors"
"github.com/umbracle/ethgo"
"math/big"

"github.com/0xPolygon/polygon-edge/contracts/abis"
"github.com/0xPolygon/polygon-edge/state/runtime"
"github.com/0xPolygon/polygon-edge/types"
"github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/abi"
"github.com/umbracle/ethgo/abi"
)

var (
Expand All @@ -30,10 +30,10 @@ func DecodeValidators(method *abi.Method, returnValue []byte) ([]types.Address,
return nil, errors.New("failed type assertion from decodedResults to map")
}

web3Addresses, ok := results["0"].([]web3.Address)
web3Addresses, ok := results["0"].([]ethgo.Address)

if !ok {
return nil, errors.New("failed type assertion from results[0] to []web3.Address")
return nil, errors.New("failed type assertion from results[0] to []ethgo.Address")
}

addresses := make([]types.Address, len(web3Addresses))
Expand Down
26 changes: 13 additions & 13 deletions e2e/framework/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"github.com/umbracle/ethgo"
"io/ioutil"
"math/big"
"net"
Expand All @@ -23,8 +24,7 @@ import (
txpoolProto "github.com/0xPolygon/polygon-edge/txpool/proto"
"github.com/0xPolygon/polygon-edge/types"
"github.com/stretchr/testify/assert"
"github.com/umbracle/go-web3"
"github.com/umbracle/go-web3/jsonrpc"
"github.com/umbracle/ethgo/jsonrpc"
"golang.org/x/crypto/sha3"
empty "google.golang.org/protobuf/types/known/emptypb"
)
Expand Down Expand Up @@ -73,8 +73,8 @@ func GetAccountBalance(t *testing.T, address types.Address, rpcClient *jsonrpc.C
t.Helper()

accountBalance, err := rpcClient.Eth().GetBalance(
web3.Address(address),
web3.Latest,
ethgo.Address(address),
ethgo.Latest,
)

assert.NoError(t, err)
Expand All @@ -89,17 +89,17 @@ func GetValidatorSet(from types.Address, rpcClient *jsonrpc.Client) ([]types.Add
return nil, errors.New("validators method doesn't exist in Staking contract ABI")
}

toAddress := web3.Address(staking.AddrStakingContract)
toAddress := ethgo.Address(staking.AddrStakingContract)
selector := validatorsMethod.ID()
response, err := rpcClient.Eth().Call(
&web3.CallMsg{
From: web3.Address(from),
&ethgo.CallMsg{
From: ethgo.Address(from),
To: &toAddress,
Data: selector,
GasPrice: 100000000,
Value: big.NewInt(0),
},
web3.Latest,
ethgo.Latest,
)

if err != nil {
Expand Down Expand Up @@ -148,7 +148,7 @@ func UnstakeAmount(
from types.Address,
senderKey *ecdsa.PrivateKey,
srv *TestServer,
) (*web3.Receipt, error) {
) (*ethgo.Receipt, error) {
// Stake Balance
txn := &PreparedTransaction{
From: from,
Expand Down Expand Up @@ -178,17 +178,17 @@ func GetStakedAmount(from types.Address, rpcClient *jsonrpc.Client) (*big.Int, e
return nil, errors.New("stakedAmount method doesn't exist in Staking contract ABI")
}

toAddress := web3.Address(staking.AddrStakingContract)
toAddress := ethgo.Address(staking.AddrStakingContract)
selector := stakedAmountMethod.ID()
response, err := rpcClient.Eth().Call(
&web3.CallMsg{
From: web3.Address(from),
&ethgo.CallMsg{
From: ethgo.Address(from),
To: &toAddress,
Data: selector,
GasPrice: 100000000,
Value: big.NewInt(0),
},
web3.Latest,
ethgo.Latest,
)

if err != nil {
Expand Down
Loading

0 comments on commit 6bb316b

Please sign in to comment.