Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
"\\[Error handling\\]",
"\\[Key\\]",
"\\[ICM\\]",
"\\[Relayer\\]",
"\\[Local Network\\]",
"\\[Network\\]",
"\\[Blockchain Configure\\]",
Expand Down
37 changes: 23 additions & 14 deletions cmd/interchaincmd/relayercmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func newDeployCmd() *cobra.Command {
cmd.Flags().Float64Var(&deployFlags.CChainAmount, "cchain-amount", 0, "automatically fund cchain fee payments with the given amount")
cmd.Flags().StringVar(&deployFlags.BlockchainFundingKey, "blockchain-funding-key", "", "key to be used to fund relayer account on all l1s")
cmd.Flags().StringVar(&deployFlags.CChainFundingKey, "cchain-funding-key", "", "key to be used to fund relayer account on cchain")
cmd.Flags().BoolVar(&deployFlags.AllowPrivateIPs, "allow-private-ips", true, "allow relayer to connec to private ips")
cmd.Flags().BoolVar(&deployFlags.AllowPrivateIPs, "allow-private-ips", true, "allow relayer to connect to private ips")
return cmd
}

Expand Down Expand Up @@ -134,25 +134,30 @@ func CallDeploy(_ []string, flags DeployFlags, network models.Network) error {
}
}

logLevelOptions := []string{
logging.Info.LowerString(),
logging.Warn.LowerString(),
logging.Error.LowerString(),
logging.Off.LowerString(),
logging.Fatal.LowerString(),
logging.Debug.LowerString(),
logging.Trace.LowerString(),
logging.Verbo.LowerString(),
}
if flags.LogLevel == "" {
prompt := "Which log level do you prefer for your relayer?"
options := []string{
logging.Info.LowerString(),
logging.Warn.LowerString(),
logging.Error.LowerString(),
logging.Off.LowerString(),
logging.Fatal.LowerString(),
logging.Debug.LowerString(),
logging.Trace.LowerString(),
logging.Verbo.LowerString(),
}

flags.LogLevel, err = app.Prompt.CaptureList(
prompt,
options,
logLevelOptions,
)
if err != nil {
return err
}
} else {
if _, err := logging.ToLevel(flags.LogLevel); err != nil {
return fmt.Errorf("invalid log level %s: %w", flags.LogLevel, err)
}
}

networkUP := true
Expand Down Expand Up @@ -375,7 +380,7 @@ func CallDeploy(_ []string, flags DeployFlags, network models.Network) error {
return err
}
if balance.Cmp(big.NewInt(0)) == 0 {
return fmt.Errorf("destination %s funding key as no balance", destination.blockchainDesc)
return fmt.Errorf("destination %s funding key has no balance", destination.blockchainDesc)
}
balanceBigFlt := new(big.Float).SetInt(balance)
balanceBigFlt = balanceBigFlt.Quo(balanceBigFlt, new(big.Float).SetInt(vm.OneAvax))
Expand Down Expand Up @@ -415,9 +420,13 @@ func CallDeploy(_ []string, flags DeployFlags, network models.Network) error {
amountBigFlt := new(big.Float).SetFloat64(amountFlt)
amountBigFlt = amountBigFlt.Mul(amountBigFlt, new(big.Float).SetInt(vm.OneAvax))
amount, _ := amountBigFlt.Int(nil)
if _, err := client.FundAddress(privateKey, addr.Hex(), amount); err != nil {
receipt, err := client.FundAddress(privateKey, addr.Hex(), amount)
if err != nil {
return err
}
ux.Logger.PrintToUser("%s Paid fee: %.9f AVAX",
destination.blockchainDesc,
utils.CalculateEvmFeeInAvax(receipt.GasUsed, receipt.EffectiveGasPrice))
}
}
}
Expand Down
16 changes: 3 additions & 13 deletions cmd/keycmd/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ func intraEvmSend(
}
ux.Logger.PrintToUser("%s Paid fee: %.9f AVAX",
chainName,
calculateEvmFeeInAvax(receipt.GasUsed, receipt.EffectiveGasPrice))
utils.CalculateEvmFeeInAvax(receipt.GasUsed, receipt.EffectiveGasPrice))
return err
}

Expand Down Expand Up @@ -597,7 +597,7 @@ func interEvmSend(
}
ux.Logger.PrintToUser("%s Paid fee: %.9f AVAX",
chainName,
calculateEvmFeeInAvax(receipt.GasUsed, receipt.EffectiveGasPrice))
utils.CalculateEvmFeeInAvax(receipt.GasUsed, receipt.EffectiveGasPrice))

if receipt2 != nil {
chainName, err := contract.GetBlockchainDesc(receiverChain)
Expand All @@ -606,7 +606,7 @@ func interEvmSend(
}
ux.Logger.PrintToUser("%s Paid fee: %.9f AVAX",
chainName,
calculateEvmFeeInAvax(receipt2.GasUsed, receipt2.EffectiveGasPrice))
utils.CalculateEvmFeeInAvax(receipt2.GasUsed, receipt2.EffectiveGasPrice))
}

return nil
Expand Down Expand Up @@ -1091,13 +1091,3 @@ func getBuilderContext(wallet *primary.Wallet) *builder.Context {
}
return wallet.P().Builder().Context()
}

func calculateEvmFeeInAvax(gasUsed uint64, gasPrice *big.Int) float64 {
gasUsedBig := new(big.Int).SetUint64(gasUsed)
totalCost := new(big.Int).Mul(gasUsedBig, gasPrice)

totalCostInNanoAvax := utils.ConvertToNanoAvax(totalCost)

result, _ := new(big.Float).SetInt(totalCostInNanoAvax).Float64()
return result / float64(units.Avax)
}
12 changes: 12 additions & 0 deletions pkg/utils/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
package utils

import (
"math/big"
"os"
"strings"

"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/units"
"github.com/ava-labs/avalanchego/vms/platformvm"
)

Expand Down Expand Up @@ -52,3 +54,13 @@ func GetNetworkBalance(addressList []ids.ShortID, networkEndpoint string) (uint6
}
return uint64(bal.Balance), nil
}

func CalculateEvmFeeInAvax(gasUsed uint64, gasPrice *big.Int) float64 {
gasUsedBig := new(big.Int).SetUint64(gasUsed)
totalCost := new(big.Int).Mul(gasUsedBig, gasPrice)

totalCostInNanoAvax := ConvertToNanoAvax(totalCost)

result, _ := new(big.Float).SetInt(totalCostInNanoAvax).Float64()
return result / float64(units.Avax)
}
2 changes: 1 addition & 1 deletion tests/e2e/commands/icm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (

/* #nosec G204 */
func SendICMMessage(args []string, testFlags utils.TestFlags) (string, error) {
return utils.TestCommand(utils.ICMCmd, "sendMsg", args, utils.GlobalFlags{
return utils.TestCommand(ICMCmd, "sendMsg", args, utils.GlobalFlags{
"local": true,
"skip-update-check": true,
}, testFlags)
Expand Down
19 changes: 19 additions & 0 deletions tests/e2e/commands/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os/exec"

"github.com/ava-labs/avalanche-cli/pkg/constants"
"github.com/ava-labs/avalanche-cli/tests/e2e/utils"
)

/* #nosec G204 */
Expand Down Expand Up @@ -159,3 +160,21 @@ func KeyTransferReceive(keyName string, amount string, recoveryStep string) (str
out, err := cmd.CombinedOutput()
return string(out), err
}

/* #nosec G204 */
func FundKeyOnCchain(senderKeyName, destinationKeyName string, amount int, testFlags utils.TestFlags) (string, error) {
// Create config
args := []string{
"--local",
"--c-chain-sender",
"--c-chain-receiver",
"--" + constants.SkipUpdateFlag,
}
return utils.TestCommand(KeyCmd, "transfer", args, utils.GlobalFlags{
"key": senderKeyName,
"destination-key": destinationKeyName,
"amount": amount,
"local": true,
"skip-update-check": true,
}, testFlags)
}
4 changes: 4 additions & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/node/devnet"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/node/monitoring"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/packageman"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/relayer/deploy"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/relayer/logs_cmd"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/relayer/start"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/relayer/stop"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/root"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/subnet"
_ "github.com/ava-labs/avalanche-cli/tests/e2e/testcases/subnet/non-sov/local"
Expand Down
Loading
Loading