Skip to content

Commit

Permalink
Better error catching
Browse files Browse the repository at this point in the history
  • Loading branch information
chray-zhang committed Dec 4, 2024
1 parent 97aef91 commit c3d22e7
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 22 deletions.
2 changes: 1 addition & 1 deletion integration-tests/common/gauntlet_plus_plus_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"os"

"github.com/smartcontractkit/chainlink-starknet/integration-tests/utils"
)

Expand Down
5 changes: 2 additions & 3 deletions integration-tests/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ func (m *OCRv2TestState) DeployCluster() {
func (m *OCRv2TestState) StartGppWithoutNetwork() {
gpp := test_env_gauntlet.NewGauntletPlusPlus([]string{}, *m.Common.TestConfig.Common.GauntletPlusPlusImage)
url, err := gpp.StartContainer()
m.TestConfig.TestConfig.Common.GauntletPlusPlusUrl = url
m.TestConfig.TestConfig.Common.GauntletPlusPlusURL = url
require.NoError(m.TestConfig.T, err)
}

// Starts GauntletPP with a network
func (m *OCRv2TestState) StartGppWithNetwork(networkName string) {
gpp := test_env_gauntlet.NewGauntletPlusPlus([]string{networkName}, *m.Common.TestConfig.Common.GauntletPlusPlusImage)
url, err := gpp.StartContainer()
m.TestConfig.TestConfig.Common.GauntletPlusPlusUrl = url
m.TestConfig.TestConfig.Common.GauntletPlusPlusURL = url
require.NoError(m.TestConfig.T, err)
}

Expand Down Expand Up @@ -289,7 +289,6 @@ func (m *OCRv2TestState) LoadOCR2Config() (*ops.OCR2Config, error) {
func (m *OCRv2TestState) removeOCR2PrefixAndAddPrefix(k string, prefix string, newPrefix string) string {
// Print k for debugging before the modification
if strings.HasPrefix(k, prefix) {
fmt.Println("After:", newPrefix+k[len(prefix):])
return newPrefix + k[len(prefix):]
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/smoke/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestOCRBasic(t *testing.T) {
state.DeployCluster()
// Setting up G++ Client
rpcURL := state.Common.RPCDetails.RPCL2Internal
gppURL := state.TestConfig.TestConfig.Common.GauntletPlusPlusUrl
gppURL := state.TestConfig.TestConfig.Common.GauntletPlusPlusURL
state.Clients.GauntletPPClient, err = gauntlet.NewStarknetGauntletPlusPlus(gppURL, rpcURL, state.Account.Account, state.Account.PrivateKey)
require.NoError(t, err, "Setting up gauntlet++ should not fail")

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/soak/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func TestOCRBasicSoak(t *testing.T) {

// Setting up G++ Client
rpcURL := state.Common.RPCDetails.RPCL2Internal
gppURL := state.TestConfig.TestConfig.Common.GauntletPlusPlusUrl
gppURL := state.TestConfig.TestConfig.Common.GauntletPlusPlusURL
state.Clients.GauntletPPClient, err = gauntlet.NewStarknetGauntletPlusPlus(gppURL, rpcURL, state.Account.Account, state.Account.PrivateKey)
require.NoError(t, err, "Setting up gauntlet++ should not fail")

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ type Common struct {
DevnetImage *string `toml:"devnet_image"`
GauntletPlusPlusImage *string `toml:"gauntlet_plus_plus_image"`
PostgresVersion *string `toml:"postgres_version"`
GauntletPlusPlusUrl string
GauntletPlusPlusURL string
}

func (c *Common) Validate() error {
Expand Down
60 changes: 45 additions & 15 deletions ops/gauntlet/gauntlet_plus_plus_starknet.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,11 @@ func NewStarknetGauntletPlusPlus(gauntletPPEndpoint string, rpcURL string, addre
func (sgpp *StarknetGauntletPlusPlus) ExtractValueFromResponseBody(report g.Report, key string) (string, error) {
if report.Output != nil {
// Log the raw content of Output
outputJSON, err := json.Marshal(report.Output)
_, err := json.Marshal(report.Output)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal report.Output")
return "", err
}
log.Info().Str("Report.Output", string(outputJSON)).Msg("Gauntlet++")

// Attempt to assert the Output as a map
if outputMap, ok := (*report.Output).(map[string]interface{}); ok {
Expand All @@ -110,9 +109,10 @@ func (sgpp *StarknetGauntletPlusPlus) ExtractValueFromResponseBody(report g.Repo
// Assert value to a string
if strValue, ok := value.(string); ok {
return strValue, nil
}
} else {
err := fmt.Errorf("parsed Value is not of type string")
return "", err
}
}
} else {
// Log a message if it’s not a map
Expand Down Expand Up @@ -140,23 +140,48 @@ func (sgpp *StarknetGauntletPlusPlus) BuildRequestBody(request Request) *g.PostE
}

func (sgpp *StarknetGauntletPlusPlus) execute(request *Request) error {
body := sgpp.BuildRequestBody(*request)
report, err := sgpp.executeReturnsReport(request)

tmp, err := json.Marshal(body)
if err != nil {
return err // Handle marshaling error
}

// Show request body
log.Info().Str("Request Body: ", string(tmp)).Msg("Gauntlet++")
headers := &g.PostExecuteParams{}
response, err := sgpp.client.PostExecuteWithResponse(context.Background(), headers, *body)
if err != nil {
return err // Handle post execution error
}

// Show Response Status
log.Info().Str("Response Status:", response.Status()).Msg("Gauntlet++")
if report.Output != nil {
_, err := json.Marshal(report.Output)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal report.Output")
return err
}

// Attempt to assert the Output as a map
if outputMap, ok := (*report.Output).(map[string]interface{}); ok {
log.Info().Interface("Report Response: ", outputMap).Msg("Gauntlet++")

// Access the 'output' field and then the 'receipt' field
if output, exists := outputMap["receipt"]; exists {
if receiptMap, ok := output.(map[string]interface{}); ok {
log.Info().Interface("Receipt Map: ", receiptMap).Msg("Gauntlet++")
// Access 'execution_status' inside the 'receipt' field
if executionStatus, exists := receiptMap["execution_status"]; exists {

// Assert value to a string
if strExecutionStatus, ok := executionStatus.(string); ok {
if strExecutionStatus != "SUCCEEDED" {
err := fmt.Errorf("Op was not successful")
return err
}
} else {
err := fmt.Errorf("execution_status is not of type string")
return err
}
}
}
}
} else {
// Log a message if it’s not a map
log.Warn().Msg("Report.Output is not a map[string]interface{}")
}
}
return nil
}

Expand Down Expand Up @@ -208,6 +233,11 @@ func (sgpp *StarknetGauntletPlusPlus) executeDeploy(request *Request) (string, e
return "", err
}

if contractAddress == "" {
log.Err(err).Str("G++ Deploy Requets returned with empty contractAddress", err.Error()).Msg("Gauntlet++")
return "", err
}

log.Info().Str("Contract Address Response: ", contractAddress).Msg("Gauntlet++")
return contractAddress, nil
}
Expand Down

0 comments on commit c3d22e7

Please sign in to comment.