Skip to content

Commit

Permalink
fix(SPV-1294): fix local operator regression tests (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolt-4chain authored Dec 12, 2024
1 parent f6e7d83 commit 57d1951
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion actions/admin/paymail_addresses_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func paymailCreateAddressOld(c *gin.Context, _ *reqctx.AdminContext) {
paymailAddress, err := reqctx.Engine(c).NewPaymailAddress(
c.Request.Context(), requestBody.Key, requestBody.Address, requestBody.PublicName, requestBody.Avatar, opts...)
if err != nil {
spverrors.ErrorResponse(c, spverrors.ErrCreatePaymailAddress.WithTrace(err), logger)
spverrors.ErrorResponse(c, err, logger)
return
}

Expand Down
3 changes: 0 additions & 3 deletions engine/spverrors/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,6 @@ var ErrPaymailAddressIsInvalid = models.SPVError{Message: "paymail address is in
// ErrDeletePaymailAddress is when the paymail address could not be deleted
var ErrDeletePaymailAddress = models.SPVError{Message: "deleting paymail address failed", StatusCode: 400, Code: "error-deleting-paymail-address-failed"}

// ErrCreatePaymailAddress is when the paymail address could not be created
var ErrCreatePaymailAddress = models.SPVError{Message: "creating paymail address failed", StatusCode: 500, Code: "error-creating-paymail-address-failed"}

// ErrMissingPaymailID is when id is missing in paymail
var ErrMissingPaymailID = models.SPVError{Message: "missing id in paymail", StatusCode: 400, Code: "error-paymail-id-missing"}

Expand Down
7 changes: 5 additions & 2 deletions regression_tests/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func handleUserCreation(paymailAlias string, config *regressionTestConfig) (*reg

// handleCreateUserError handles the error when creating a user.
func handleCreateUserError(err error, paymailAlias string, config *regressionTestConfig) (*regressionTestUser, error) {
if err.Error() == spverrors.ErrPaymailAlreadyExists.Error() {
if errors.Is(err, spverrors.ErrPaymailAlreadyExists) {
return handleExistingPaymail(paymailAlias, config)
} else {
return nil, fmt.Errorf("error creating user: %w", err)
Expand Down Expand Up @@ -251,7 +251,10 @@ func takeMasterUrlAndXPriv(leaderPaymail *regressionTestUser) error {

// sendFundsWithGoClient sends funds using the Go client.
func sendFundsWithGoClient(instanceUrl string, istanceXPriv string, receiverPaymail string) error {
client := walletclient.NewWithXPriv(addPrefixIfNeeded(instanceUrl), istanceXPriv)
client, err := walletclient.NewWithXPriv(addPrefixIfNeeded(instanceUrl), istanceXPriv)
if err != nil {
return fmt.Errorf("error initalizing client: %w", err)
}
ctx := context.Background()

balance, err := checkBalance(instanceUrl, istanceXPriv)
Expand Down
25 changes: 20 additions & 5 deletions regression_tests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,11 @@ func addPrefixIfNeeded(url string) string {

// getSharedConfig retrieves the shared configuration from the SPV Wallet.
func getSharedConfig(ctx context.Context) (*models.SharedConfig, error) {
wc := walletclient.NewWithXPriv(addPrefixIfNeeded(domainLocalHost), adminXPriv)
wc, err := walletclient.NewWithXPriv(addPrefixIfNeeded(domainLocalHost), adminXPriv)
if err != nil {
return nil, err
}

sharedConfig, err := wc.GetSharedConfig(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -192,7 +196,10 @@ func createUser(paymail string, config *regressionTestConfig) (*regressionTestUs
Paymail: preparePaymail(leaderPaymailAlias, paymail),
}

adminClient := walletclient.NewWithAdminKey(config.ClientOneURL, adminXPriv)
adminClient, err := walletclient.NewWithAdminKey(config.ClientOneURL, adminXPriv)
if err != nil {
return nil, err
}
ctx := context.Background()

if err := adminClient.AdminNewXpub(ctx, user.XPub, map[string]any{"purpose": "regression-tests"}); err != nil {
Expand Down Expand Up @@ -229,12 +236,17 @@ func useUserFromEnv(paymailDomain string, config *regressionTestConfig) (*regres
// deleteUser soft deletes paymail address from the SPV Wallet.
func deleteUser(paymail string, config *regressionTestConfig) error {
paymail = preparePaymail(leaderPaymailAlias, paymail)
adminClient := walletclient.NewWithAdminKey(addPrefixIfNeeded(config.ClientOneURL), adminXPriv)
adminClient, err := walletclient.NewWithAdminKey(addPrefixIfNeeded(config.ClientOneURL), adminXPriv)
if err != nil {
return err
}

ctx := context.Background()
err := adminClient.AdminDeletePaymail(ctx, paymail)
err = adminClient.AdminDeletePaymail(ctx, paymail)
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -275,7 +287,10 @@ func isValidURL(rawURL string) bool {

// checkBalance checks the balance of the specified xpriv at the given domain with given xpriv.
func checkBalance(domain, xpriv string) (int, error) {
client := walletclient.NewWithXPriv(addPrefixIfNeeded(domain), xpriv)
client, err := walletclient.NewWithXPriv(addPrefixIfNeeded(domain), xpriv)
if err != nil {
return wrongInput, err
}
ctx := context.Background()

xpubInfo, err := client.GetXPub(ctx)
Expand Down

0 comments on commit 57d1951

Please sign in to comment.