Skip to content

Commit

Permalink
use new client
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Mar 25, 2024
1 parent badef47 commit db96ab7
Show file tree
Hide file tree
Showing 38 changed files with 645 additions and 1,166 deletions.
16 changes: 8 additions & 8 deletions command/bridge/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"math/big"
"sync"

"github.com/0xPolygon/polygon-edge/jsonrpc"
"github.com/spf13/cobra"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/jsonrpc"
"golang.org/x/sync/errgroup"

"github.com/0xPolygon/polygon-edge/chain"
Expand Down Expand Up @@ -361,7 +361,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
return
}

client, err := jsonrpc.NewClient(params.jsonRPCAddress)
client, err := jsonrpc.NewEthClient(params.jsonRPCAddress)
if err != nil {
outputter.SetError(fmt.Errorf("failed to initialize JSON RPC client for provided IP address: %s: %w",
params.jsonRPCAddress, err))
Expand All @@ -370,7 +370,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
}

if consensusCfg.Bridge != nil {
code, err := client.Eth().GetCode(ethgo.Address(consensusCfg.Bridge.StateSenderAddr), ethgo.Latest)
code, err := client.GetCode(consensusCfg.Bridge.StateSenderAddr, jsonrpc.LatestBlockNumberOrHash)
if err != nil {
outputter.SetError(fmt.Errorf("failed to check if rootchain contracts are deployed: %w", err))

Expand All @@ -387,7 +387,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
// set event tracker start blocks for rootchain contract(s) of interest
// the block number should be queried before deploying contracts so that no events during deployment
// and initialization are missed
blockNum, err := client.Eth().BlockNumber()
blockNum, err := client.BlockNumber()
if err != nil {
outputter.SetError(fmt.Errorf("failed to query rootchain latest block number: %w", err))

Expand Down Expand Up @@ -427,7 +427,7 @@ func runCommand(cmd *cobra.Command, _ []string) {
}

// deployContracts deploys and initializes rootchain smart contracts
func deployContracts(outputter command.OutputFormatter, client *jsonrpc.Client, chainID int64,
func deployContracts(outputter command.OutputFormatter, client *jsonrpc.EthClient, chainID int64,
initialValidators []*validator.GenesisValidator, cmdCtx context.Context) (deploymentResultInfo, error) {
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithClient(client), txrelayer.WithWriter(outputter))
if err != nil {
Expand Down Expand Up @@ -465,7 +465,7 @@ func deployContracts(outputter command.OutputFormatter, client *jsonrpc.Client,
if !consensusCfg.NativeTokenConfig.IsMintable {
if params.rootERC20TokenAddr != "" {
// use existing root chain ERC20 token
if err := populateExistingTokenAddr(client.Eth(),
if err := populateExistingTokenAddr(client,
params.rootERC20TokenAddr, rootERC20Name, rootchainConfig); err != nil {
return deploymentResultInfo{RootchainCfg: nil, CommandResults: nil}, err
}
Expand Down Expand Up @@ -688,11 +688,11 @@ func deployContracts(outputter command.OutputFormatter, client *jsonrpc.Client,

// populateExistingTokenAddr checks whether given token is deployed on the provided address.
// If it is, then its address is set to the rootchain config, otherwise an error is returned
func populateExistingTokenAddr(eth *jsonrpc.Eth, tokenAddr, tokenName string,
func populateExistingTokenAddr(eth *jsonrpc.EthClient, tokenAddr, tokenName string,
rootchainCfg *polybft.RootchainConfig) error {
addr := types.StringToAddress(tokenAddr)

code, err := eth.GetCode(ethgo.Address(addr), ethgo.Latest)
code, err := eth.GetCode(addr, jsonrpc.LatestBlockNumberOrHash)
if err != nil {
return fmt.Errorf("failed to check is %s token deployed: %w", tokenName, err)
} else if code == "0x" {
Expand Down
4 changes: 2 additions & 2 deletions command/bridge/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"os"
"testing"

"github.com/0xPolygon/polygon-edge/jsonrpc"
"github.com/stretchr/testify/require"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/jsonrpc"
"github.com/umbracle/ethgo/testutil"

"github.com/0xPolygon/polygon-edge/command"
Expand All @@ -27,7 +27,7 @@ func TestDeployContracts_NoPanics(t *testing.T) {
}
})

client, err := jsonrpc.NewClient(server.HTTPAddr())
client, err := jsonrpc.NewEthClient(server.HTTPAddr())
require.NoError(t, err)

testKey, err := helper.DecodePrivateKey("")
Expand Down
2 changes: 1 addition & 1 deletion command/validator/registration/register_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
return err
}

rootChainID, err := txRelayer.Client().Eth().ChainID()
rootChainID, err := txRelayer.Client().ChainID()
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/polybft/checkpoint_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"testing"

"github.com/umbracle/ethgo/jsonrpc"
"github.com/0xPolygon/polygon-edge/jsonrpc"

"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/consensus/polybft/signer"
Expand Down Expand Up @@ -495,7 +495,7 @@ func (d *dummyTxRelayer) SendTransactionLocal(txn *types.Transaction) (*ethgo.Re
return args.Get(0).(*ethgo.Receipt), args.Error(1)
}

func (d *dummyTxRelayer) Client() *jsonrpc.Client {
func (d *dummyTxRelayer) Client() *jsonrpc.EthClient {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions consensus/polybft/stake_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/crypto"
"github.com/0xPolygon/polygon-edge/helper/hex"
"github.com/0xPolygon/polygon-edge/jsonrpc"
"github.com/0xPolygon/polygon-edge/txrelayer"
"github.com/0xPolygon/polygon-edge/types"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/umbracle/ethgo"
"github.com/umbracle/ethgo/abi"
"github.com/umbracle/ethgo/jsonrpc"
)

func TestStakeManager_PostBlock(t *testing.T) {
Expand Down Expand Up @@ -534,6 +534,6 @@ func (d *dummyStakeTxRelayer) SendTransactionLocal(txn *types.Transaction) (*eth
return args.Get(0).(*ethgo.Receipt), args.Error(1)
}

func (d *dummyStakeTxRelayer) Client() *jsonrpc.Client {
func (d *dummyStakeTxRelayer) Client() *jsonrpc.EthClient {
return nil
}
17 changes: 9 additions & 8 deletions e2e-polybft/e2e/acls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,18 @@ func TestE2E_AllowList_ContractDeployment(t *testing.T) {
deployTxn := cluster.Deploy(t, target, bytecode)
require.NoError(t, deployTxn.Wait())
require.True(t, deployTxn.Reverted())
require.False(t, cluster.ExistsCode(t, deployTxn.Receipt().ContractAddress))
require.False(t, cluster.ExistsCode(t, types.Address(deployTxn.Receipt().ContractAddress)))
}

{
// Step 3. 'adminAddr' can create contracts
deployTxn := cluster.Deploy(t, admin, bytecode)
require.NoError(t, deployTxn.Wait())
require.True(t, deployTxn.Succeed())
require.True(t, cluster.ExistsCode(t, deployTxn.Receipt().ContractAddress))

proxyContract = types.Address(deployTxn.Receipt().ContractAddress)

require.True(t, deployTxn.Succeed())
require.True(t, cluster.ExistsCode(t, proxyContract))
}

{
Expand All @@ -104,7 +105,7 @@ func TestE2E_AllowList_ContractDeployment(t *testing.T) {
deployTxn := cluster.Deploy(t, target, bytecode)
require.NoError(t, deployTxn.Wait())
require.True(t, deployTxn.Succeed())
require.True(t, cluster.ExistsCode(t, deployTxn.Receipt().ContractAddress))
require.True(t, cluster.ExistsCode(t, types.Address(deployTxn.Receipt().ContractAddress)))
}

{
Expand Down Expand Up @@ -168,15 +169,15 @@ func TestE2E_BlockList_ContractDeployment(t *testing.T) {
deployTxn := cluster.Deploy(t, target, bytecode)
require.NoError(t, deployTxn.Wait())
require.True(t, deployTxn.Succeed())
require.True(t, cluster.ExistsCode(t, deployTxn.Receipt().ContractAddress))
require.True(t, cluster.ExistsCode(t, types.Address(deployTxn.Receipt().ContractAddress)))
}

{
// Step 3. 'adminAddr' can create contracts
deployTxn := cluster.Deploy(t, admin, bytecode)
require.NoError(t, deployTxn.Wait())
require.True(t, deployTxn.Succeed())
require.True(t, cluster.ExistsCode(t, deployTxn.Receipt().ContractAddress))
require.True(t, cluster.ExistsCode(t, types.Address(deployTxn.Receipt().ContractAddress)))
}

{
Expand All @@ -193,7 +194,7 @@ func TestE2E_BlockList_ContractDeployment(t *testing.T) {
deployTxn := cluster.Deploy(t, target, bytecode)
require.NoError(t, deployTxn.Wait())
require.True(t, deployTxn.Reverted())
require.False(t, cluster.ExistsCode(t, deployTxn.Receipt().ContractAddress))
require.False(t, cluster.ExistsCode(t, types.Address(deployTxn.Receipt().ContractAddress)))
}

{
Expand Down Expand Up @@ -256,7 +257,7 @@ func TestE2E_AllowList_Transactions(t *testing.T) {
deployTxn := cluster.Deploy(t, target, bytecode)
require.NoError(t, deployTxn.Wait())
require.True(t, deployTxn.Reverted())
require.False(t, cluster.ExistsCode(t, deployTxn.Receipt().ContractAddress))
require.False(t, cluster.ExistsCode(t, types.Address(deployTxn.Receipt().ContractAddress)))
}

{
Expand Down
Loading

0 comments on commit db96ab7

Please sign in to comment.