From 39aaf4e5fb83272f9cc9353fd1f332344b121acc Mon Sep 17 00:00:00 2001 From: Alonso Rodriguez Date: Mon, 27 Feb 2023 17:42:02 +0100 Subject: [PATCH] approve command with wei (#1703) * approve with wei * fix * comment consolidations --- cmd/approve.go | 15 ++++++--------- config/config_test.go | 4 ++-- config/default.go | 4 ++-- etherman/etherman.go | 2 +- test/Makefile | 1 + test/docker-compose.yml | 2 +- test/operations/manager.go | 11 ++++++----- test/scripts/sendForcedBatch/README.md | 2 +- 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/cmd/approve.go b/cmd/approve.go index c518285aa3..e335fa925a 100644 --- a/cmd/approve.go +++ b/cmd/approve.go @@ -6,15 +6,16 @@ import ( "strings" "github.com/0xPolygonHermez/zkevm-node/config" + "github.com/0xPolygonHermez/zkevm-node/encoding" "github.com/0xPolygonHermez/zkevm-node/log" "github.com/urfave/cli/v2" ) func approveTokens(ctx *cli.Context) error { amountArg := ctx.String(config.FlagAmount) - amount, _ := new(big.Float).SetString(amountArg) + amount, _ := new(big.Int).SetString(amountArg, encoding.Base10) if amount == nil { - fmt.Println("Please, introduce a valid amount. Use '.' instead of ',' if it is a decimal number") + fmt.Println("Please, introduce a valid amount in wei") return nil } @@ -27,8 +28,8 @@ func approveTokens(ctx *cli.Context) error { } if !ctx.Bool(config.FlagYes) { - fmt.Print("*WARNING* Are you sure you want to approve ", amount, - " tokens to be spent by the smc ? [y/N]: ") + fmt.Print("*WARNING* Are you sure you want to approve ", amount.String(), + " tokens (in wei) for the smc ? [y/N]: ") var input string if _, err := fmt.Scanln(&input); err != nil { return err @@ -55,11 +56,7 @@ func approveTokens(ctx *cli.Context) error { return err } - const decimals = 1000000000000000000 - amountInWei := new(big.Float).Mul(amount, big.NewFloat(decimals)) - amountB := new(big.Int) - amountInWei.Int(amountB) - tx, err := etherman.ApproveMatic(ctx.Context, auth.From, amountB, c.Etherman.PoEAddr) + tx, err := etherman.ApproveMatic(ctx.Context, auth.From, amount, c.Etherman.PoEAddr) if err != nil { return err } diff --git a/config/config_test.go b/config/config_test.go index 73ddd13a1d..10f9645d7e 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -164,7 +164,7 @@ func Test_Defaults(t *testing.T) { }, { path: "Etherman.PoEAddr", - expectedValue: common.HexToAddress("0x8A791620dd6260079BF849Dc5567aDC3F2FdC318"), + expectedValue: common.HexToAddress("0x610178dA211FEF7D417bC0e6FeD39F05609AD788"), }, { path: "Etherman.MaticAddr", @@ -172,7 +172,7 @@ func Test_Defaults(t *testing.T) { }, { path: "Etherman.GlobalExitRootManagerAddr", - expectedValue: common.HexToAddress("0xa513E6E4b8f2a923D98304ec87F64353C4D5C853"), + expectedValue: common.HexToAddress("0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6"), }, { path: "Etherman.MultiGasProvider", diff --git a/config/default.go b/config/default.go index efa83ea1e2..6eb76954b6 100644 --- a/config/default.go +++ b/config/default.go @@ -33,9 +33,9 @@ FreeClaimGasLimit = 150000 [Etherman] URL = "http://localhost:8545" L1ChainID = 1337 -PoEAddr = "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318" +PoEAddr = "0x610178dA211FEF7D417bC0e6FeD39F05609AD788" MaticAddr = "0x5FbDB2315678afecb367f032d93F642f64180aa3" -GlobalExitRootManagerAddr = "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853" +GlobalExitRootManagerAddr = "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6" MultiGasProvider = true [Etherman.Etherscan] ApiKey = "" diff --git a/etherman/etherman.go b/etherman/etherman.go index 5aa17cc094..9b693f5dee 100644 --- a/etherman/etherman.go +++ b/etherman/etherman.go @@ -464,7 +464,7 @@ func (etherMan *Client) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVe var newStateRoot [32]byte copy(newStateRoot[:], inputs.NewStateRoot) - log.Info("Proof before trim: %v", inputs.FinalProof.Proof) + log.Info("Proof before trim: ", inputs.FinalProof.Proof) proof, err := encoding.DecodeBytes(&inputs.FinalProof.Proof) if err != nil { return nil, nil, fmt.Errorf("failed to decode proof, err: %w", err) diff --git a/test/Makefile b/test/Makefile index f21f88e86a..d710009aef 100644 --- a/test/Makefile +++ b/test/Makefile @@ -346,6 +346,7 @@ run: ## Runs a full node $(RUNL1NETWORK) sleep 1 $(RUNZKPROVER) + $(RUNAPPROVE) sleep 3 $(RUNSYNC) sleep 2 diff --git a/test/docker-compose.yml b/test/docker-compose.yml index d312e0159a..178ab9c5e5 100644 --- a/test/docker-compose.yml +++ b/test/docker-compose.yml @@ -334,7 +334,7 @@ services: command: - "/bin/sh" - "-c" - - "/app/zkevm-node approve --key-store-path /pk/keystore --pw testonly --am 10000000000000000 -y --cfg /app/config.toml" + - "/app/zkevm-node approve --key-store-path /pk/keystore --pw testonly --am 115792089237316195423570985008687907853269984665640564039457584007913129639935 -y --cfg /app/config.toml" zkevm-permissionless-db: container_name: zkevm-permissionless-db diff --git a/test/operations/manager.go b/test/operations/manager.go index 3702c6ea8c..93bd0114cc 100644 --- a/test/operations/manager.go +++ b/test/operations/manager.go @@ -214,11 +214,12 @@ func ApplyL2Txs(ctx context.Context, txs []*types.Transaction, auth *bind.Transa } // wait for l2 block number to be consolidated - log.Infof("waiting for the block number %v to be consolidated", l2BlockNumber.String()) - err = WaitL2BlockToBeConsolidated(l2BlockNumber, 4*time.Minute) //nolint:gomnd - if err != nil { - return err - } + // TODO UNCOMMENT + // log.Infof("waiting for the block number %v to be consolidated", l2BlockNumber.String()) + // err = WaitL2BlockToBeConsolidated(l2BlockNumber, 4*time.Minute) //nolint:gomnd + // if err != nil { + // return err + // } return nil } diff --git a/test/scripts/sendForcedBatch/README.md b/test/scripts/sendForcedBatch/README.md index df4459907e..c12d1eaca4 100644 --- a/test/scripts/sendForcedBatch/README.md +++ b/test/scripts/sendForcedBatch/README.md @@ -1,5 +1,5 @@ Command: ``` -go run main.go send --url http://localhost:8545 --smc 0x8A791620dd6260079BF849Dc5567aDC3F2FdC318 +go run main.go send --url http://localhost:8545 --smc 0x610178dA211FEF7D417bC0e6FeD39F05609AD788 ``` \ No newline at end of file