Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed May 7, 2024
1 parent 3f78f47 commit c495bb2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/server/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func APITestCall(engine *gin.Engine, method, url string, body any, response any,
}

func TestAPI(t *testing.T) {
Init("../../config/basic_strategy_dev_config.json", "../../config/business_dev_config.json")
initEngine("../../config/basic_strategy_dev_config.json", "../../config/business_dev_config.json")
tests := []struct {
name string
test func(t *testing.T)
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func main() {
strategyPath := fmt.Sprintf("./config/basic_strategy_%s_config.json", strings.ToLower(envirment.Environment.Name))
businessConfigPath := fmt.Sprintf("./config/business_%s_config.json", strings.ToLower(envirment.Environment.Name))

Init(strategyPath, businessConfigPath)
initEngine(strategyPath, businessConfigPath)
port := runMode()
_ = Engine.Run(port)
}

func Init(strategyPath string, businessConfigPath string) {
func initEngine(strategyPath string, businessConfigPath string) {
config.BasicStrategyInit(strategyPath)
config.BusinessConfigInit(businessConfigPath)
if envirment.Environment.IsDevelopment() {
Expand Down
1 change: 1 addition & 0 deletions common/network/ethereum_adaptable_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type EthereumExecutor struct {
func GetEthereumExecutor(network global_const.Network) *EthereumExecutor {

if executorMap[network] == nil {
// TODO need to check Out Client Connection Always Open
client, err := ethclient.Dial(config.GetEthereumRpcUrl(network))
if err != nil {
panic(err)
Expand Down
3 changes: 2 additions & 1 deletion common/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ func PackIntTo32Bytes(left *big.Int, right *big.Int) [32]byte {
return result
}

func GetGasEntryPointGasGrace(maxFeePerGas *big.Int, maxPriorityFeePerGas *big.Int, baseFee *big.Int) *big.Int {
func GetGasEntryPointGasPrice(maxFeePerGas *big.Int, maxPriorityFeePerGas *big.Int, baseFee *big.Int) *big.Int {
if maxFeePerGas == maxPriorityFeePerGas {
// is 1559 not support
return maxFeePerGas
}
combineFee := new(big.Int).Add(baseFee, maxPriorityFeePerGas)
Expand Down
12 changes: 10 additions & 2 deletions gas_executor/gas_computor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func ComputeGas(userOp *user_op.UserOpInput, strategy *model.Strategy, paymaster
updateUserOp := getNewUserOpAfterCompute(userOp, opEstimateGas, strategy.GetStrategyEntrypointVersion())
var erc20TokenCost *big.Float
if !userOp.ComputeGasOnly {
// NetworkCall 1
erc20TokenCost, err = getErc20TokenCost(strategy, totalGasDetail.MaxTxGasCostInEther)
if err != nil {
return nil, nil, xerrors.Errorf("getErc20TokenCost error: %v", err)
Expand Down Expand Up @@ -107,21 +108,27 @@ func getUserOpEstimateGas(userOp *user_op.UserOpInput, strategy *model.Strategy,
}
logrus.Debugf("userOpInputForSimulate: %v", userOpInputForSimulate)
logrus.Debugf("getUserOpEstimateGas gasPriceResult: %v", gasPriceResult)
simulateGasPrice := utils.GetGasEntryPointGasGrace(gasPriceResult.MaxFeePerGas, gasPriceResult.MaxPriorityFeePerGas, gasPriceResult.BaseFee)

// get EntryPoint GasPrice
// NetworkCall 1
simulateGasPrice := utils.GetGasEntryPointGasPrice(gasPriceResult.MaxFeePerGas, gasPriceResult.MaxPriorityFeePerGas, gasPriceResult.BaseFee)
// NetworkCall 1
simulateResult, err := chain_service.SimulateHandleOp(userOpInputForSimulate, strategy)
if err != nil {
return nil, xerrors.Errorf("SimulateHandleOp error: %v", err)
}
// NetworkCall 1
preVerificationGas, err := GetPreVerificationGas(userOp, strategy, gasPriceResult, simulateResult)
if err != nil {
return nil, xerrors.Errorf("GetPreVerificationGas error: %v", err)
}

// TODO verificationGasLimit and callGasLimit parell
verificationGasLimit, err := estimateVerificationGasLimit(simulateResult, preVerificationGas)
if err != nil {
return nil, xerrors.Errorf("estimateVerificationGasLimit error: %v", err)
}

// NetworkCall 1
callGasLimit, err := EstimateCallGasLimit(strategy, simulateResult, userOp, simulateGasPrice)
if err != nil {
return nil, xerrors.Errorf("EstimateCallGasLimit error: %v", err)
Expand Down Expand Up @@ -194,6 +201,7 @@ func EstimateCallGasLimit(strategy *model.Strategy, simulateOpResult *model.Simu
}
}

// ratio need cache
func getErc20TokenCost(strategy *model.Strategy, tokenCount *big.Float) (*big.Float, error) {
if strategy.GetPayType() == global_const.PayTypeERC20 {
if strategy.Erc20TokenType == "" {
Expand Down
2 changes: 1 addition & 1 deletion service/chain_service/chain_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func CheckContractAddressAccess(contract *common.Address, chain global_const.Network) (bool, error) {
//todo needCache
//todo DB Cache needCache
executor := network.GetEthereumExecutor(chain)
return executor.CheckContractAddressAccess(contract)
}
Expand Down

0 comments on commit c495bb2

Please sign in to comment.