Skip to content

Commit

Permalink
add Test
Browse files Browse the repository at this point in the history
change name
  • Loading branch information
cherry-yl-sh committed Mar 5, 2024
1 parent 03b4fe9 commit 19a5e24
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
12 changes: 3 additions & 9 deletions common/model/api_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,15 @@ type TryPayUserOpRequest struct {
ForceTokens string `json:"force_tokens"`
ForceEntryPointAddress string `json:"force_entry_point_address"`
UserOperation UserOperationItem `json:"user_operation"`
Apikey string `json:"apikey"`
Extra interface{} `json:"extra"`
}

func (sender *TryPayUserOpRequest) Validate() error {
if len(sender.Apikey) == 0 {
return errors.New("apikey mustn't empty")
}

if len(sender.ForceStrategyId) == 0 {
if len(sender.ForceNetWork) == 0 || len(sender.ForceTokens) == 0 || len(sender.ForceEntryPointAddress) == 0 {
func (request *TryPayUserOpRequest) Validate() error {
if len(request.ForceStrategyId) == 0 {
if len(request.ForceNetWork) == 0 || len(request.ForceTokens) == 0 || len(request.ForceEntryPointAddress) == 0 {
return errors.New("strategy configuration illegal")
}
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions common/model/user_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package model
type UserOperationItem struct {
Sender string `json:"sender" binding:"required"`
Nonce string `json:"nonce" binding:"required"`
InitCode string `json:"init_code" binding:"required"`
InitCode string `json:"init_code"`
CallGasLimit string `json:"call_gas_limit" binding:"required"`
VerificationGasList string `json:"verification_gas_list" binding:"required"`
PerVerificationGas string `json:"per_verification_gas" binding:"required"`
MaxFeePerGas string `json:"max_fee_per_gas" binding:"required"`
MaxPriorityFeePerGas string `json:"max_priority_fee_per_gas" binding:"required"`
Signature string `json:"signature" binding:"required"`
Signature string `json:"signature"`
//paymasterAndData string `json:"paymaster_and_data"`
}
11 changes: 10 additions & 1 deletion service/dashboard_service/dashboard_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ package dashboard_service

import "AAStarCommunity/EthPaymaster_BackService/common/model"

var mockStrategyMap = map[string]model.Strategy{}

func init() {
mockStrategyMap["1"] = model.Strategy{
Id: "1",
EntryPointAddress: "0x123",
PayMasterAddress: "0x123",
}
}
func GetStrategyById(strategyId string) model.Strategy {
return model.Strategy{}
return mockStrategyMap[strategyId]
}
1 change: 1 addition & 0 deletions service/operator/get_support_entry_point_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package operator
1 change: 1 addition & 0 deletions service/operator/get_support_strategy_text.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package operator
7 changes: 6 additions & 1 deletion service/operator/try_pay_user_op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ package operator

import (
"AAStarCommunity/EthPaymaster_BackService/common/model"
"fmt"

"testing"
)

func TestTryPayUserOpExecute(t *testing.T) {
request := getMockTryPayUserOpRequest()
TryPayUserOpExecute(request)
result, err := TryPayUserOpExecute(request)
if err != nil {
t.Errorf("Error: %v", err)
}
fmt.Printf("Result: %v", result)

}

Expand Down

0 comments on commit 19a5e24

Please sign in to comment.