Skip to content

Commit

Permalink
fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed May 13, 2024
1 parent 72e693b commit 2007438
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
12 changes: 5 additions & 7 deletions common/network/ethereum_adaptable_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,14 @@ func testSimulateHandleOp(t *testing.T, chain global_const.Network, strategy *mo
}
func parseOpToMapV7(input user_op.UserOpInput) map[string]string {
opMap := make(map[string]string)

opMap["sender"] = input.Sender.String()
opMap["Nonce"] = input.Nonce.String()
opMap["initCode"] = utils.EncodeToStringWithPrefix(input.InitCode[:])
opMap["accountGasLimits"] = utils.EncodeToStringWithPrefix(input.AccountGasLimits[:])
opMap["callGasLimit"] = input.CallGasLimit.String()
opMap["gasFees"] = utils.EncodeToStringWithPrefix(input.GasFees[:])
opMap["maxFeePerGas"] = input.MaxFeePerGas.String()
opMap["maxPriorityFeePerGas"] = input.MaxPriorityFeePerGas.String()
opMap["preVerificationGas"] = input.PreVerificationGas.String()
opMap["verificationGasLimit"] = input.VerificationGasLimit.String()
opMap["gasFees"] = utils.EncodeToStringWithPrefix(input.GasFees[:])
opMap["paymasterAndData"] = utils.EncodeToStringWithPrefix(input.PaymasterAndData[:])
opMap["Nonce"] = input.Nonce.String()
opMap["signature"] = utils.EncodeToStringWithPrefix(input.Signature[:])
return opMap
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package utils
package price_compoent

import (
"AAStarCommunity/EthPaymaster_BackService/common/global_const"
"AAStarCommunity/EthPaymaster_BackService/config"
"fmt"
"golang.org/x/xerrors"
"io"
Expand Down Expand Up @@ -42,7 +43,7 @@ func GetPriceUsd(tokenType global_const.TokenType) (float64, error) {
}
req, _ := http.NewRequest("GET", tokenUrl, nil)
//TODO remove APIKey
req.Header.Add("x-cg-demo-api-key", "CG-ioE6p8cmmSFBFwJnKECCbZ7U\t")
req.Header.Add("x-cg-demo-api-key", config.GetPriceOracleApiKey())

res, _ := http.DefaultClient.Do(req)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package utils
package price_compoent

import (
"AAStarCommunity/EthPaymaster_BackService/common/global_const"
"AAStarCommunity/EthPaymaster_BackService/config"
"fmt"
"strconv"
"testing"
)

func TestPriceUtilTest(t *testing.T) {
config.InitConfig("../../config/basic_strategy_config.json", "../../config/basic_config.json", "../../config/secret_config.json")
tests := []struct {
name string
test func(t *testing.T)
Expand Down Expand Up @@ -38,10 +40,6 @@ func testGetPriceUsd(t *testing.T, tokenType global_const.TokenType) {
t.Logf("price:%v", price)
}

func TestGetToken(t *testing.T) {
price, _ := GetToken(global_const.TokenTypeETH, global_const.TokenTypeUSDT)
fmt.Println(price)
}
func TestDemo(t *testing.T) {
str := "0000000000000000000000000000000000000000000000000000000000000002"
fmt.Printf(strconv.Itoa(len(str)))
Expand Down
11 changes: 3 additions & 8 deletions common/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,9 @@ func IsStringInUint64Range(s string) bool {
func PackIntTo32Bytes(left *big.Int, right *big.Int) [32]byte {
leftBytes := left.Bytes()
rightBytes := right.Bytes()

leftHex := fmt.Sprintf("%016x", leftBytes)
rightHex := fmt.Sprintf("%016x", rightBytes)

leftBytes, _ = hex.DecodeString(leftHex)
rightBytes, _ = hex.DecodeString(rightHex)

var result [32]byte
leftBytes = append(make([]byte, 16-len(leftBytes)), leftBytes...)
rightBytes = append(make([]byte, 16-len(rightBytes)), rightBytes...)
var result = [32]byte{}
copy(result[:16], leftBytes)
copy(result[16:], rightBytes)

Expand Down
8 changes: 8 additions & 0 deletions common/utils/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"fmt"
"github.com/ethereum/go-ethereum/crypto"
"math/big"
"testing"
)

Expand Down Expand Up @@ -36,6 +37,13 @@ func TestConvertStringToSet(t *testing.T) {
set := ConvertStringToSet(str, ",")
fmt.Printf("set: %v\n", set)
}
func TestPackIntTo32Bytes(t *testing.T) {

bytes := PackIntTo32Bytes(big.NewInt(2312), big.NewInt(2312))

resStr := EncodeToStringWithPrefix(bytes[:])
t.Logf("resStr: %s\n", resStr)
}

//func TestEthereumSign(t *testing.T) {
// messageStr := "hello world"
Expand Down
3 changes: 2 additions & 1 deletion gas_executor/gas_computor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"AAStarCommunity/EthPaymaster_BackService/common/model"
"AAStarCommunity/EthPaymaster_BackService/common/network"
"AAStarCommunity/EthPaymaster_BackService/common/paymaster_data"
"AAStarCommunity/EthPaymaster_BackService/common/price_compoent"
"AAStarCommunity/EthPaymaster_BackService/common/user_op"
"AAStarCommunity/EthPaymaster_BackService/common/utils"
"AAStarCommunity/EthPaymaster_BackService/config"
Expand Down Expand Up @@ -209,7 +210,7 @@ func getErc20TokenCost(strategy *model.Strategy, tokenCount *big.Float) (*big.Fl
}
formTokenType := config.GetGasToken(strategy.GetNewWork())
toTokenType := strategy.Erc20TokenType
toTokenPrice, err := utils.GetToken(formTokenType, toTokenType)
toTokenPrice, err := price_compoent.GetToken(formTokenType, toTokenType)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2007438

Please sign in to comment.