Skip to content

Commit

Permalink
comment fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dusannosovic-ethernal committed Dec 25, 2023
1 parent 12704d2 commit 3396f7e
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 63 deletions.
4 changes: 2 additions & 2 deletions command/genesis/predeploy/genesis_predeploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func setFlags(cmd *cobra.Command) {
&params.artifactsName,
artifactsNameFlag,
"",
"the path to the contract artifacts JSON",
"the built-in contract artifact name",
)

cmd.Flags().StringVar(
Expand All @@ -54,7 +54,7 @@ func setFlags(cmd *cobra.Command) {

cmd.Flags().StringArrayVar(
&params.constructorArgs,
constructorArgsPathFlag,
constructorArgsFlag,
[]string{},
"the constructor arguments, if any",
)
Expand Down
35 changes: 10 additions & 25 deletions command/genesis/predeploy/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
)

const (
chainFlag = "chain"
predeployAddressFlag = "predeploy-address"
artifactsNameFlag = "artifacts-name"
artifactsPathFlag = "artifacts-path"
constructorArgsPathFlag = "constructor-args"
deployerAddrFlag = "deployer-address"
chainFlag = "chain"
predeployAddressFlag = "predeploy-address"
artifactsNameFlag = "artifacts-name"
artifactsPathFlag = "artifacts-path"
constructorArgsFlag = "constructor-args"
deployerAddrFlag = "deployer-address"
)

var (
Expand Down Expand Up @@ -55,7 +55,6 @@ type predeployParams struct {
func (p *predeployParams) getRequiredFlags() []string {
return []string{
predeployAddressFlag,
artifactsNameFlag,
}
}

Expand All @@ -64,11 +63,13 @@ func (p *predeployParams) initRawParams() (err error) {
return errArtifactPathAndNameMissing
}

if err := p.initPredeployAddress(); err != nil {
p.address, err = types.IsValidAddress(p.addressRaw, false)
if err != nil {
return err
}

if err := p.initDeployerAddress(); err != nil {
p.deployerAddr, err = types.IsValidAddress(p.deployerAddrRaw, false)
if err != nil {
return err
}

Expand All @@ -87,22 +88,6 @@ func (p *predeployParams) initRawParams() (err error) {
return nil
}

func (p *predeployParams) initPredeployAddress() error {
if p.addressRaw == "" {
return errInvalidPredeployAddress
}

p.address = types.StringToAddress(p.addressRaw)

return nil
}

func (p *predeployParams) initDeployerAddress() error {
p.deployerAddr = types.StringToAddress(p.deployerAddrRaw)

return nil
}

func (p *predeployParams) verifyMinAddress() error {
address, err := hex.DecodeHexToBig(p.address.String())
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions consensus/polybft/contracts_initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ func initStakeManager(polyBFTConfig PolyBFTConfig, transition *state.Transition)

input, err := approveFn.EncodeAbi()
if err != nil {
return fmt.Errorf("NativeERC20.approve params encoding failed: %w", err)
return fmt.Errorf("Staking ERC20.approve params encoding failed: %w", err)

Check failure on line 48 in consensus/polybft/contracts_initializer.go

View workflow job for this annotation

GitHub Actions / Linter

ST1005: error strings should not be capitalized (stylecheck)

Check failure on line 48 in consensus/polybft/contracts_initializer.go

View workflow job for this annotation

GitHub Actions / Linter

ST1005: error strings should not be capitalized (stylecheck)
}

err = callContract(validator.Address, polyBFTConfig.StakeTokenAddr, input, "StakeToken.approve", transition)
err = callContract(validator.Address, polyBFTConfig.StakeTokenAddr, input, "Staking ERC20.approve", transition)
if err != nil {
return fmt.Errorf("Error while calling contract %w", err)
}
Expand Down Expand Up @@ -381,11 +381,11 @@ func mintStakeToken(polyBFTConfig PolyBFTConfig, transition *state.Transition) e

input, err := mintFn.EncodeAbi()
if err != nil {
return fmt.Errorf("StakeToken.mint params encoding failed: %w", err)
return fmt.Errorf("Staking ERC20.mint params encoding failed: %w", err)

Check failure on line 384 in consensus/polybft/contracts_initializer.go

View workflow job for this annotation

GitHub Actions / Linter

ST1005: error strings should not be capitalized (stylecheck)

Check failure on line 384 in consensus/polybft/contracts_initializer.go

View workflow job for this annotation

GitHub Actions / Linter

ST1005: error strings should not be capitalized (stylecheck)
}

if err := callContract(polyBFTConfig.BladeAdmin, polyBFTConfig.StakeTokenAddr,
input, "StakeToken.mint", transition); err != nil {
input, "Staking ERC20.mint", transition); err != nil {
return err
}
}
Expand Down
40 changes: 23 additions & 17 deletions e2e-polybft/e2e/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ func TestE2E_Bridge_NonMintableERC20Token_WithPremine(t *testing.T) {
})
}

func TestE2E_Bridge_NonNative(t *testing.T) {
func TestE2E_Bridge_NonNativeStakingToken(t *testing.T) {
const (
transfersCount = 5
amount = 100
Expand All @@ -1453,7 +1453,9 @@ func TestE2E_Bridge_NonNative(t *testing.T) {
)

var (
stakeAmount = ethgo.Ether(500)
stakeAmount = ethgo.Ether(500)
addedStakeAmount = ethgo.Gwei(1)
mintAmount = ethgo.Gwei(10)
)

minter, err := wallet.GenerateKey()
Expand All @@ -1469,23 +1471,30 @@ func TestE2E_Bridge_NonNative(t *testing.T) {
tcc.StakeAmounts = append(tcc.StakeAmounts, stakeAmount)
}
}),
framework.WithPredeploy(),
framework.WithPredeploy(fmt.Sprintf("%s:%s", contracts.ERC20Contract, "RootERC20")),
)
defer cluster.Stop()

cluster.WaitForReady(t)

polybftCfg, err := polybft.LoadPolyBFTConfig(path.Join(cluster.Config.TmpDir, chainConfigFileName))
require.NoError(t, err)

//first validator server(minter)
firstValidator := cluster.Servers[0]
//second validator server
secondValidator := cluster.Servers[1]

validatorAcc, err := validatorHelper.GetAccountFromDir(firstValidator.DataDir())
//validator account from second validator
validatorAccTwo, err := validatorHelper.GetAccountFromDir(secondValidator.DataDir())
require.NoError(t, err)

relayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(firstValidator.JSONRPCAddr()))
require.NoError(t, err)

mintFn := &contractsapi.MintRootERC20Fn{
To: validatorAcc.Address(),
Amount: big.NewInt(100000),
To: validatorAccTwo.Address(),
Amount: mintAmount,
}

mintInput, err := mintFn.EncodeAbi()
Expand All @@ -1502,30 +1511,27 @@ func TestE2E_Bridge_NonNative(t *testing.T) {
require.NoError(t, err)
require.Equal(t, uint64(types.ReceiptSuccess), receipt.Status)

polybftCfg, err := polybft.LoadPolyBFTConfig(path.Join(cluster.Config.TmpDir, chainConfigFileName))
require.NoError(t, err)

firstValidatorInfo, err := validatorHelper.GetValidatorInfo(validatorAcc.Ecdsa.Address(), relayer)
secondValidatorInfo, err := validatorHelper.GetValidatorInfo(validatorAccTwo.Ecdsa.Address(), relayer)
require.NoError(t, err)
require.True(t, firstValidatorInfo.Stake.Cmp(stakeAmount) == 0)
require.True(t, secondValidatorInfo.Stake.Cmp(stakeAmount) == 0)

require.NoError(t, cluster.WaitForBlock(epochSize*1, 1*time.Minute))

require.NoError(t, firstValidator.Stake(polybftCfg.StakeTokenAddr, big.NewInt(1000)))
require.NoError(t, firstValidator.Stake(polybftCfg.StakeTokenAddr, addedStakeAmount))

require.NoError(t, cluster.WaitForBlock(epochSize*3, 90*time.Second))

updatedStakeAmount := big.NewInt(0)

firstValidatorInfo, err = validatorHelper.GetValidatorInfo(validatorAcc.Ecdsa.Address(), relayer)
secondValidatorInfo, err = validatorHelper.GetValidatorInfo(validatorAccTwo.Ecdsa.Address(), relayer)
require.NoError(t, err)
require.True(t, firstValidatorInfo.Stake.Cmp(updatedStakeAmount.Add(stakeAmount, big.NewInt(1000))) == 0)
require.True(t, secondValidatorInfo.Stake.Cmp(updatedStakeAmount.Add(stakeAmount, addedStakeAmount)) == 0)

require.NoError(t, firstValidator.Unstake(big.NewInt(1000)))
require.NoError(t, secondValidator.Unstake(addedStakeAmount))

require.NoError(t, cluster.WaitForBlock(epochSize*4, 30*time.Second))

firstValidatorInfo, err = validatorHelper.GetValidatorInfo(validatorAcc.Ecdsa.Address(), relayer)
secondValidatorInfo, err = validatorHelper.GetValidatorInfo(validatorAccTwo.Ecdsa.Address(), relayer)
require.NoError(t, err)
require.True(t, firstValidatorInfo.Stake.Cmp(stakeAmount) == 0)
require.True(t, secondValidatorInfo.Stake.Cmp(stakeAmount) == 0)
}
4 changes: 2 additions & 2 deletions e2e-polybft/e2e/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ func TestE2E_Consensus_RegisterValidator(t *testing.T) {
initialBalance := ethgo.Ether(1000)

// mint tokens to new validators
require.NoError(t, owner.MintNativeERC20Token([]string{firstValidatorAddr.String(), secondValidatorAddr.String()},
[]*big.Int{initialBalance, initialBalance}))
require.NoError(t, owner.MintERC20Token([]string{firstValidatorAddr.String(), secondValidatorAddr.String()},
[]*big.Int{initialBalance, initialBalance}, polybftConfig.StakeTokenAddr))

// first validator's balance to be received
firstBalance, err := relayer.Client().Eth().GetBalance(firstValidatorAddr, ethgo.Latest)
Expand Down
22 changes: 13 additions & 9 deletions e2e-polybft/framework/test-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/0xPolygon/polygon-edge/command/genesis"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/helper/common"
"github.com/0xPolygon/polygon-edge/txrelayer"
"github.com/0xPolygon/polygon-edge/types"
Expand Down Expand Up @@ -116,7 +115,7 @@ type TestClusterConfig struct {
SecretsCallback func([]types.Address, *TestClusterConfig)
BladeAdmin string
RewardWallet string
PredeployNonNative bool
PredeployContract string

ContractDeployerAllowListAdmin []types.Address
ContractDeployerAllowListEnabled []types.Address
Expand Down Expand Up @@ -458,9 +457,9 @@ func WithRewardWallet(rewardWallet string) ClusterOption {
}
}

func WithPredeploy() ClusterOption {
func WithPredeploy(predeployString string) ClusterOption {
return func(h *TestClusterConfig) {
h.PredeployNonNative = true
h.PredeployContract = predeployString
}
}

Expand Down Expand Up @@ -707,21 +706,26 @@ func NewTestCluster(t *testing.T, validatorsCount int, opts ...ClusterOption) *T
}
args = append(args, "--proxy-contracts-admin", proxyAdminAddr)

if config.PredeployNonNative {
args = append(args, "--stake-token", contracts.ERC20Contract.String())
if config.PredeployContract != "" {
parts := strings.Split(config.PredeployContract, ":")
require.Equal(t, 2, len(parts))
args = append(args, "--stake-token", parts[0])
}

// run genesis command with all the arguments
err = cluster.cmdRun(args...)
require.NoError(t, err)
}

if config.PredeployNonNative {
if config.PredeployContract != "" {

Check failure on line 720 in e2e-polybft/framework/test-cluster.go

View workflow job for this annotation

GitHub Actions / Linter

unnecessary leading newline (whitespace)

Check failure on line 720 in e2e-polybft/framework/test-cluster.go

View workflow job for this annotation

GitHub Actions / Linter

unnecessary leading newline (whitespace)

parts := strings.Split(config.PredeployContract, ":")
require.Equal(t, 2, len(parts))
// run predeploy genesis population
args := []string{
"genesis", "predeploy",
"--predeploy-address", contracts.ERC20Contract.String(),
"--artifacts-name", "RootERC20",
"--predeploy-address", parts[0],
"--artifacts-name", parts[1],
"--chain", genesisPath,
"--deployer-address", config.BladeAdmin}

Expand Down
7 changes: 3 additions & 4 deletions e2e-polybft/framework/test-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
"github.com/0xPolygon/polygon-edge/contracts"
"github.com/0xPolygon/polygon-edge/server/proto"
txpoolProto "github.com/0xPolygon/polygon-edge/txpool/proto"
"github.com/0xPolygon/polygon-edge/types"
Expand Down Expand Up @@ -289,8 +288,8 @@ func (t *TestServer) WhitelistValidators(addresses []string) error {
return runCommand(t.clusterConfig.Binary, args, t.clusterConfig.GetStdout("validator"))
}

// MintNativeERC20Token mints given amounts of native erc20 token on blade to given addresses
func (t *TestServer) MintNativeERC20Token(addresses []string, amounts []*big.Int) error {
// MintERC20Token mints given amounts of native erc20 token on blade to given addresses
func (t *TestServer) MintERC20Token(addresses []string, amounts []*big.Int, stakeToken types.Address) error {
acc, err := validatorHelper.GetAccountFromDir(t.DataDir())
if err != nil {
return err
Expand All @@ -304,7 +303,7 @@ func (t *TestServer) MintNativeERC20Token(addresses []string, amounts []*big.Int
args := []string{
"mint-erc20",
"--jsonrpc", t.JSONRPCAddr(),
"--erc20-token", contracts.NativeERC20TokenContract.String(),
"--erc20-token", stakeToken.String(),
"--private-key", hex.EncodeToString(rawKey),
}

Expand Down

0 comments on commit 3396f7e

Please sign in to comment.