Skip to content

Commit

Permalink
update bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cherry-yl-sh committed Jun 17, 2024
1 parent e339f15 commit 9af37d8
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
10 changes: 8 additions & 2 deletions common/model/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ import (
const EnvKey = "Env"
const ProdEnv = "prod"
const DevEnv = "dev"
const UnitEnv = "unit"

type Env struct {
Name string // env Name, like `prod`, `dev` and etc.,
Debugger bool // whether to use debugger
}

func (env *Env) IsDevelopment() bool {
return strings.EqualFold(DevEnv, env.Name)
return strings.EqualFold(DevEnv, env.Name) || strings.EqualFold(UnitEnv, env.Name)
}
func (env *Env) IsUnit() bool {
return strings.EqualFold(UnitEnv, env.Name)
}

func (env *Env) IsProduction() bool {
return strings.EqualFold(ProdEnv, env.Name)
}

func (env *Env) GetEnvName() *string {
return &env.Name
}
func (env *Env) SetUnitEnv() {
env.Name = UnitEnv
}
45 changes: 26 additions & 19 deletions common/network/ethereum_adaptable_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"AAStarCommunity/EthPaymaster_BackService/common/user_op"
"AAStarCommunity/EthPaymaster_BackService/common/utils"
"AAStarCommunity/EthPaymaster_BackService/config"
"AAStarCommunity/EthPaymaster_BackService/envirment"
"AAStarCommunity/EthPaymaster_BackService/schedulor"
"context"
"crypto/ecdsa"
Expand Down Expand Up @@ -96,29 +97,35 @@ func GetEthereumExecutor(network global_const.Network) *EthereumExecutor {
if !success {
panic(xerrors.Errorf("chainId %s is invalid", config.GetChainId(network)))
}
wsUrl := config.GetNewWorkClientURl(network)
wsUrl = strings.Replace(wsUrl, "https", "wss", 1)
logrus.Debugf("wsUrl: %s", wsUrl)
webSocketClient, err := ethclient.Dial(wsUrl)
if err != nil {
panic(err)
}

eventListener, err := schedulor.NewEventListener(webSocketClient, network)
if err != nil {
panic(err)
}
go eventListener.Listen()
logrus.Debugf("after Lesten network :[%s]", network)
geth := gethclient.New(client.Client())
executorMap[network] = &EthereumExecutor{
network: network,
Client: client,
ChainId: chainId,
GethClient: geth,
eventListener: eventListener,
webSocketClient: webSocketClient,
ethExecutor := &EthereumExecutor{
network: network,
Client: client,
ChainId: chainId,
GethClient: geth,
}

if !envirment.Environment.IsUnit() {
logrus.Infof("Init EventListener network :[%s]", network)
wsUrl := config.GetNewWorkClientURl(network)
wsUrl = strings.Replace(wsUrl, "https", "wss", 1)
logrus.Debugf("wsUrl: %s", wsUrl)
webSocketClient, err := ethclient.Dial(wsUrl)
if err != nil {
panic(err)
}

eventListener, err := schedulor.NewEventListener(webSocketClient, network)
if err != nil {
panic(err)
}
go eventListener.Listen()
ethExecutor.eventListener = eventListener
ethExecutor.webSocketClient = webSocketClient
}
executorMap[network] = ethExecutor

return executorMap[network]
}
Expand Down
2 changes: 0 additions & 2 deletions config/secret_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ func secretConfigInit(secretConfigPath string) {
}

func IsSponsorWhitelist(senderAddress string) bool {
logrus.Debugf("IsSponsorWhitelist [%s]", senderAddress)
logrus.Debugf("IsSponsorWhitelist [%v]", sponsorWhitelist)
return sponsorWhitelist.Contains(senderAddress)
}
func GetNetworkSecretConfig(network global_const.Network) model.NetWorkSecretConfig {
Expand Down
1 change: 0 additions & 1 deletion rpc_server/api/v1/paymaster.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,5 @@ func validateUserOpRequest(request *model.UserOpRequest) error {
if request.Network == "" {
return xerrors.Errorf("ForceNetwork is empty")
}

return nil
}
17 changes: 14 additions & 3 deletions service/operator/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"AAStarCommunity/EthPaymaster_BackService/common/user_op"
"AAStarCommunity/EthPaymaster_BackService/common/utils"
"AAStarCommunity/EthPaymaster_BackService/config"
"AAStarCommunity/EthPaymaster_BackService/envirment"
"AAStarCommunity/EthPaymaster_BackService/service/dashboard_service"
"AAStarCommunity/EthPaymaster_BackService/sponsor_manager"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/sirupsen/logrus"
"os"
"testing"
)

Expand All @@ -26,6 +29,8 @@ func TestOperator(t *testing.T) {
mockRequestNotSupport1559 := getMockTryPayUserOpRequest()
mockRequestNotSupport1559.UserOp["maxPriorityFeePerGas"] = mockRequestNotSupport1559.UserOp["maxFeePerGas"]
sponsor_manager.Init()
dashboard_service.Init()
envirment.Environment.SetUnitEnv()
tests := []struct {
name string
test func(t *testing.T)
Expand Down Expand Up @@ -129,8 +134,9 @@ func TestOperator(t *testing.T) {
"Test_NoSpectCode_TryPayUserOpExecute",
func(t *testing.T) {
request := model.UserOpRequest{
Network: global_const.EthereumSepolia,
UserOp: *utils.GenerateMockUservOperation(),
StrategyCode: "3123124__7dtFu",
Network: global_const.EthereumSepolia,
UserOp: *utils.GenerateMockUservOperation(),
}
testTryPayUserOpExecute(t, &request)
},
Expand Down Expand Up @@ -169,7 +175,9 @@ func testGetSupportEntrypointExecute(t *testing.T) {
t.Log(res)
}
func testTryPayUserOpExecute(t *testing.T, request *model.UserOpRequest) {
result, err := TryPayUserOpExecute(&model.ApiKeyModel{}, request)
result, err := TryPayUserOpExecute(&model.ApiKeyModel{
UserId: 5,
}, request)
if err != nil {
t.Fatal(err)
return
Expand Down Expand Up @@ -224,6 +232,9 @@ func getMockTryPayUserOpRequest() *model.UserOpRequest {
}

func TestWSclient(t *testing.T) {
os.Setenv("Env", "unit")

t.Logf("Env: %v", os.Getenv("Env"))
//TODO
url := "wss://eth-sepolia.g.alchemy.com/v2/wKeLycGxgYRykgf0aGfcpEkUtqyLQg4v"
wsClient, err := ethclient.Dial(url)
Expand Down
4 changes: 2 additions & 2 deletions service/validator_service/basic_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ func ValidateStrategy(strategy *model.Strategy, request *model.UserOpRequest) er
curTime := time.Now().Unix()
//check Time
if strategy.ExecuteRestriction.EffectiveStartTime != nil {
if curTime < strategy.ExecuteRestriction.EffectiveStartTime.Int64() {
if curTime < strategy.ExecuteRestriction.EffectiveStartTime.Int64() && strategy.ExecuteRestriction.EffectiveEndTime.Sign() > 0 {
return xerrors.Errorf("curTime [%s] is OutOff EffectiveStartTime [%s]", curTime, strategy.ExecuteRestriction.EffectiveStartTime.Int64())
}
}
if strategy.ExecuteRestriction.EffectiveEndTime != nil {
if strategy.ExecuteRestriction.EffectiveEndTime != nil && strategy.ExecuteRestriction.EffectiveEndTime.Sign() > 0 {
if curTime > strategy.ExecuteRestriction.EffectiveEndTime.Int64() {
return xerrors.Errorf("curTime [%s] is OutOff EffectiveEndTime [%s]", curTime, strategy.ExecuteRestriction.EffectiveEndTime.Int64())
}
Expand Down

0 comments on commit 9af37d8

Please sign in to comment.