From 5afd17f7025431e24922cfbfd884dd39469d9e4f Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 17:52:25 +0200 Subject: [PATCH 01/18] feat(SPV-896): adds test func template, adds functions to retrive os envs --- regression_tests/regression_test.go | 32 ++++++++++++++++++++ regression_tests/utils.go | 47 +++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 regression_tests/regression_test.go create mode 100644 regression_tests/utils.go diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go new file mode 100644 index 0000000..ceaee51 --- /dev/null +++ b/regression_tests/regression_test.go @@ -0,0 +1,32 @@ +package regressiontests + +import ( + "testing" +) + +const ( + fundsPerTest = 2 + adminXPriv = "xprv9s21ZrQH143K3CbJXirfrtpLvhT3Vgusdo8coBritQ3rcS7Jy7sxWhatuxG5h2y1Cqj8FKmPp69536gmjYRpfga2MJdsGyBsnB12E19CESK" + adminXPub = "xpub661MyMwAqRbcFgfmdkPgE2m5UjHXu9dj124DbaGLSjaqVESTWfCD4VuNmEbVPkbYLCkykwVZvmA8Pbf8884TQr1FgdG2nPoHR8aB36YdDQh" + errorWhileGettingTransaction = "error while getting transaction: %s" + errorWhileCreatingUser = "error while creating user: %s" + errorWhileGettingBalance = "error while getting transaction: %s" + errorWhileSendingFunds = "error while sending funds: %s" + errorWhileGettingSharedConfig = "error while getting shared config: %s" + errorWhileGettingEnvVariables = "error while getting env variables: %s" +) + +var ( + clientOneURL string + clientTwoURL string + clientOneLeaderXPriv string + clientTwoLeaderXPriv string +) + +func TestRegression(t *testing.T) { + rtConfig, err := getEnvVariables() + if err != nil { + t.Errorf(errorWhileGettingEnvVariables, err) + } + t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) {}) +} diff --git a/regression_tests/utils.go b/regression_tests/utils.go new file mode 100644 index 0000000..6afc2ba --- /dev/null +++ b/regression_tests/utils.go @@ -0,0 +1,47 @@ +package regressiontests + +import ( + "errors" + "os" + "regexp" +) + +const ( + domainPrefix = "https://" + + ClientOneURLEnvVar = "CLIENT_ONE_URL" + ClientTwoURLEnvVar = "CLIENT_TWO_URL" + ClientOneLeaderXPrivEnvVar = "CLIENT_ONE_LEADER_XPRIV" + ClientTwoLeaderXPrivEnvVar = "CLIENT_TWO_LEADER_XPRIV" +) + +var ( + explicitHTTPURLRegex = regexp.MustCompile(`^https?://`) + envVariableError = errors.New("missing xpriv variables") +) + +type regressionTestConfig struct { + ClientOneURL string + ClientTwoURL string + ClientOneLeaderXPriv string + ClientTwoLeaderXPriv string +} + +// getEnvVariables retrieves the environment variables needed for the regression tests. +func getEnvVariables() (*regressionTestConfig, error) { + rtConfig := regressionTestConfig{ + ClientOneURL: os.Getenv(ClientOneURLEnvVar), + ClientTwoURL: os.Getenv(ClientTwoURLEnvVar), + ClientOneLeaderXPriv: os.Getenv(ClientOneLeaderXPrivEnvVar), + ClientTwoLeaderXPriv: os.Getenv(ClientTwoLeaderXPrivEnvVar), + } + + if rtConfig.ClientOneLeaderXPriv == "" || rtConfig.ClientTwoLeaderXPriv == "" { + return nil, envVariableError + } + if rtConfig.ClientOneURL == "" || rtConfig.ClientTwoURL == "" { + rtConfig.ClientOneURL = "http://localhost:3003" + rtConfig.ClientTwoURL = "http://localhost:3003" + } + return &rtConfig, nil +} From 79155d07ca785bab0d4a78d0fd1a19814990a6c3 Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 17:54:22 +0200 Subject: [PATCH 02/18] feat(SPV-896): adds function to get shared config form instances --- regression_tests/regression_test.go | 10 +++++++ regression_tests/utils.go | 44 ++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index ceaee51..18f5f3d 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -28,5 +28,15 @@ func TestRegression(t *testing.T) { if err != nil { t.Errorf(errorWhileGettingEnvVariables, err) } + + sharedConfigInstanceOne, err := getSharedConfig(adminXPub, rtConfig.ClientOneURL) + if err != nil { + t.Errorf(errorWhileGettingSharedConfig, err) + } + sharedConfigInstanceTwo, err := getSharedConfig(adminXPub, rtConfig.ClientTwoURL) + if err != nil { + t.Errorf(errorWhileGettingSharedConfig, err) + } + t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) {}) } diff --git a/regression_tests/utils.go b/regression_tests/utils.go index 6afc2ba..119a1d0 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -1,13 +1,20 @@ package regressiontests import ( + "encoding/json" "errors" + "fmt" + "io" + "net/http" "os" "regexp" + + "github.com/bitcoin-sv/spv-wallet/models" ) const ( - domainPrefix = "https://" + domainPrefix = "https://" + domainSuffixSharedConfig = "/v1/shared-config" ClientOneURLEnvVar = "CLIENT_ONE_URL" ClientTwoURLEnvVar = "CLIENT_TWO_URL" @@ -45,3 +52,38 @@ func getEnvVariables() (*regressionTestConfig, error) { } return &rtConfig, nil } + +// getSharedConfig retrieves the shared configuration from the SPV Wallet. +func getSharedConfig(xpub string, clientUrl string) (*models.SharedConfig, error) { + req, err := http.NewRequest(http.MethodGet, clientUrl+domainSuffixSharedConfig, nil) + if err != nil { + return nil, err + } + + req.Header.Set(models.AuthHeader, xpub) + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return nil, fmt.Errorf("failed to get shared config: %s", resp.Status) + } + + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + + var configResponse models.SharedConfig + if err := json.Unmarshal(body, &configResponse); err != nil { + return nil, err + } + + if len(configResponse.PaymailDomains) != 1 { + return nil, fmt.Errorf("expected 1 paymail domain, got %d", len(configResponse.PaymailDomains)) + } + return &configResponse, nil +} From c72582a3daf9e00d5618ca554e66701758167bf2 Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 17:57:10 +0200 Subject: [PATCH 03/18] feat(SPV-896): adds user creation --- regression_tests/regression_test.go | 12 ++++++ regression_tests/utils.go | 62 +++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 18f5f3d..0af7ba1 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -38,5 +38,17 @@ func TestRegression(t *testing.T) { t.Errorf(errorWhileGettingSharedConfig, err) } + userName := "instanceOneUser1" + userOne, err := createUser(userName, sharedConfigInstanceOne.PaymailDomains[0], rtConfig.ClientOneURL, adminXPriv) + if err != nil { + t.Errorf(errorWhileCreatingUser, err) + } + + userName = "instanceTwoUser1" + userTwo, err := createUser(userName, sharedConfigInstanceTwo.PaymailDomains[0], rtConfig.ClientTwoURL, adminXPriv) + if err != nil { + t.Errorf(errorWhileCreatingUser, err) + } + t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) {}) } diff --git a/regression_tests/utils.go b/regression_tests/utils.go index 119a1d0..d328a1f 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -1,6 +1,7 @@ package regressiontests import ( + "context" "encoding/json" "errors" "fmt" @@ -8,11 +9,15 @@ import ( "net/http" "os" "regexp" + "strings" + walletclient "github.com/bitcoin-sv/spv-wallet-go-client" + "github.com/bitcoin-sv/spv-wallet-go-client/xpriv" "github.com/bitcoin-sv/spv-wallet/models" ) const ( + atSign = "@" domainPrefix = "https://" domainSuffixSharedConfig = "/v1/shared-config" @@ -27,6 +32,12 @@ var ( envVariableError = errors.New("missing xpriv variables") ) +type regressionTestUser struct { + XPriv string `json:"xpriv"` + XPub string `json:"xpub"` + Paymail string `json:"paymail"` +} + type regressionTestConfig struct { ClientOneURL string ClientTwoURL string @@ -87,3 +98,54 @@ func getSharedConfig(xpub string, clientUrl string) (*models.SharedConfig, error } return &configResponse, nil } + +// createUser creates a set of keys and new paymail in the SPV Wallet. +func createUser(paymail string, paymailDomain string, instanceUrl string, adminXPriv string) (*regressionTestUser, error) { + keys, err := xpriv.Generate() + if err != nil { + return nil, err + } + + user := ®ressionTestUser{ + XPriv: keys.XPriv(), + XPub: keys.XPub().String(), + Paymail: preparePaymail(paymail, paymailDomain), + } + + adminClient := walletclient.NewWithAdminKey(addPrefixIfNeeded(instanceUrl), adminXPriv) + ctx := context.Background() + + if err := adminClient.AdminNewXpub(ctx, user.XPub, map[string]any{"some_metadata": "remove"}); err != nil { + return nil, err + } + + _, err = adminClient.AdminCreatePaymail(ctx, user.XPub, user.Paymail, "Regression tests", "") + if err != nil { + return nil, err + } + + return user, nil +} + +// preparePaymail prepares the paymail address by combining the alias and domain. +func preparePaymail(paymailAlias string, domain string) string { + if isValidURL(domain) { + splitedDomain := strings.SplitAfter(domain, "//") + domain = splitedDomain[1] + } + url := paymailAlias + atSign + domain + return url +} + +// addPrefixIfNeeded adds the HTTPS prefix to the URL if it is missing. +func addPrefixIfNeeded(url string) string { + if !isValidURL(url) { + return domainPrefix + url + } + return url +} + +// isValidURL validates the URL if it has http or https prefix. +func isValidURL(rawURL string) bool { + return explicitHTTPURLRegex.MatchString(rawURL) +} From 63e05c654f49b765656deeb0b44fdc0ce7db2a4c Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 18:00:04 +0200 Subject: [PATCH 04/18] feat(SPV-896): adds user deletion --- regression_tests/regression_test.go | 2 ++ regression_tests/utils.go | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 0af7ba1..db0aa51 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -43,12 +43,14 @@ func TestRegression(t *testing.T) { if err != nil { t.Errorf(errorWhileCreatingUser, err) } + defer deleteUser(userOne.Paymail, rtConfig.ClientOneURL, adminXPriv) userName = "instanceTwoUser1" userTwo, err := createUser(userName, sharedConfigInstanceTwo.PaymailDomains[0], rtConfig.ClientTwoURL, adminXPriv) if err != nil { t.Errorf(errorWhileCreatingUser, err) } + defer deleteUser(userTwo.Paymail, rtConfig.ClientTwoURL, adminXPriv) t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) {}) } diff --git a/regression_tests/utils.go b/regression_tests/utils.go index d328a1f..2611ac0 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -127,6 +127,17 @@ func createUser(paymail string, paymailDomain string, instanceUrl string, adminX return user, nil } +// deleteUser soft deletes paymail from the SPV Wallet. +func deleteUser(paymail string, instanceURL string, adminXPriv string) error { + adminClient := walletclient.NewWithAdminKey(addPrefixIfNeeded(instanceURL), adminXPriv) + ctx := context.Background() + err := adminClient.AdminDeletePaymail(ctx, paymail) + if err != nil { + return err + } + return nil +} + // preparePaymail prepares the paymail address by combining the alias and domain. func preparePaymail(paymailAlias string, domain string) string { if isValidURL(domain) { From c3faafd2f2dd97816bcd8f6b1d2abb3b6c7eb0d1 Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 18:03:19 +0200 Subject: [PATCH 05/18] feat(SPV-896): adds balance checking --- regression_tests/regression_test.go | 19 ++++++++++++++++++- regression_tests/utils.go | 12 ++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index db0aa51..61766f3 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -2,6 +2,8 @@ package regressiontests import ( "testing" + + "gotest.tools/v3/assert" ) const ( @@ -52,5 +54,20 @@ func TestRegression(t *testing.T) { } defer deleteUser(userTwo.Paymail, rtConfig.ClientTwoURL, adminXPriv) - t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) {}) + t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) { + // Given + balance, err := getBalance(rtConfig.ClientOneURL, userOne.XPriv) + if err != nil { + t.Errorf(errorWhileGettingBalance, err) + } + assert.Equal(t, 0, balance) + + balance, err = getBalance(rtConfig.ClientTwoURL, userTwo.XPriv) + if err != nil { + t.Errorf(errorWhileGettingBalance, err) + } + assert.Equal(t, 0, balance) + // When + // Then + }) } diff --git a/regression_tests/utils.go b/regression_tests/utils.go index 2611ac0..febf992 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -138,6 +138,18 @@ func deleteUser(paymail string, instanceURL string, adminXPriv string) error { return nil } +// getBalance retrieves the balance from the SPV Wallet. +func getBalance(fromInstance string, fromXPriv string) (int, error) { + client := walletclient.NewWithXPriv(addPrefixIfNeeded(fromInstance), fromXPriv) + ctx := context.Background() + + xpubInfo, err := client.GetXPub(ctx) + if err != nil { + return -1, err + } + return int(xpubInfo.CurrentBalance), nil +} + // preparePaymail prepares the paymail address by combining the alias and domain. func preparePaymail(paymailAlias string, domain string) string { if isValidURL(domain) { From aeffe985168ef3eab35064bd55da67bd2c1662e0 Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 18:05:56 +0200 Subject: [PATCH 06/18] feat(SPV-896): adds function to get transactions --- regression_tests/regression_test.go | 12 +++++++++++- regression_tests/utils.go | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 61766f3..11c80ee 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -3,7 +3,7 @@ package regressiontests import ( "testing" - "gotest.tools/v3/assert" + "github.com/stretchr/testify/assert" ) const ( @@ -60,13 +60,23 @@ func TestRegression(t *testing.T) { if err != nil { t.Errorf(errorWhileGettingBalance, err) } + transactions, err := getTransactions(rtConfig.ClientOneURL, userOne.XPriv) + if err != nil { + t.Errorf(errorWhileGettingTransaction, err) + } assert.Equal(t, 0, balance) + assert.Equal(t, 0, len(transactions)) balance, err = getBalance(rtConfig.ClientTwoURL, userTwo.XPriv) if err != nil { t.Errorf(errorWhileGettingBalance, err) } + transactions, err = getTransactions(rtConfig.ClientTwoURL, userTwo.XPriv) + if err != nil { + t.Errorf(errorWhileGettingTransaction, err) + } assert.Equal(t, 0, balance) + assert.Equal(t, 0, len(transactions)) // When // Then }) diff --git a/regression_tests/utils.go b/regression_tests/utils.go index febf992..eceae7b 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -14,6 +14,7 @@ import ( walletclient "github.com/bitcoin-sv/spv-wallet-go-client" "github.com/bitcoin-sv/spv-wallet-go-client/xpriv" "github.com/bitcoin-sv/spv-wallet/models" + "github.com/bitcoin-sv/spv-wallet/models/filter" ) const ( @@ -150,6 +151,22 @@ func getBalance(fromInstance string, fromXPriv string) (int, error) { return int(xpubInfo.CurrentBalance), nil } +// getTransactions retrieves the transactions from the SPV Wallet. +func getTransactions(fromInstance string, fromXPriv string) ([]*models.Transaction, error) { + client := walletclient.NewWithXPriv(addPrefixIfNeeded(fromInstance), fromXPriv) + ctx := context.Background() + + metadata := map[string]any{} + conditions := filter.TransactionFilter{} + queryParams := filter.QueryParams{} + + txs, err := client.GetTransactions(ctx, &conditions, metadata, &queryParams) + if err != nil { + return nil, err + } + return txs, nil +} + // preparePaymail prepares the paymail address by combining the alias and domain. func preparePaymail(paymailAlias string, domain string) string { if isValidURL(domain) { From 083a57346cc3bd08a8999aef9b74d630e0f3b580 Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 18:09:57 +0200 Subject: [PATCH 07/18] feat(SPV-896): adds funds transfer --- regression_tests/regression_test.go | 13 +++++++++++++ regression_tests/utils.go | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 11c80ee..56689e1 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -77,7 +77,20 @@ func TestRegression(t *testing.T) { } assert.Equal(t, 0, balance) assert.Equal(t, 0, len(transactions)) + // When + transactionOne, err := sendFunds(rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, 2) + if err != nil { + t.Errorf(errorWhileSendingFunds, err) + } + assert.GreaterOrEqual(t, int64(-1), transactionOne.OutputValue) + + transactionTwo, err := sendFunds(rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, 2) + if err != nil { + t.Errorf(errorWhileSendingFunds, err) + } + assert.GreaterOrEqual(t, int64(-1), transactionTwo.OutputValue) + // Then }) } diff --git a/regression_tests/utils.go b/regression_tests/utils.go index eceae7b..83f4f7b 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -167,6 +167,32 @@ func getTransactions(fromInstance string, fromXPriv string) ([]*models.Transacti return txs, nil } +// sendFunds sends funds from one paymail to another. +func sendFunds(fromInstance string, fromXPriv string, toPamail string, howMuch int) (*models.Transaction, error) { + client := walletclient.NewWithXPriv(fromInstance, fromXPriv) + ctx := context.Background() + + balance, err := getBalance(fromInstance, fromXPriv) + if err != nil { + return nil, err + } + if balance < howMuch { + return nil, fmt.Errorf("insufficient funds: %d", balance) + } + + recipient := walletclient.Recipients{To: toPamail, Satoshis: uint64(howMuch)} + recipients := []*walletclient.Recipients{&recipient} + metadata := map[string]any{ + "description": "regression-test", + } + + transaction, err := client.SendToRecipients(ctx, recipients, metadata) + if err != nil { + return nil, err + } + return transaction, nil +} + // preparePaymail prepares the paymail address by combining the alias and domain. func preparePaymail(paymailAlias string, domain string) string { if isValidURL(domain) { From 385238715db8e432cead8807de95059e410a43b7 Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 18:11:43 +0200 Subject: [PATCH 08/18] feat(SPV-896): adds checks after funds transfer --- regression_tests/regression_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 56689e1..4f8a5fb 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -92,5 +92,26 @@ func TestRegression(t *testing.T) { assert.GreaterOrEqual(t, int64(-1), transactionTwo.OutputValue) // Then + balance, err = getBalance(rtConfig.ClientOneURL, userOne.XPriv) + if err != nil { + t.Errorf(errorWhileGettingBalance, err) + } + transactions, err = getTransactions(rtConfig.ClientOneURL, userOne.XPriv) + if err != nil { + t.Errorf(errorWhileGettingTransaction, err) + } + assert.GreaterOrEqual(t, balance, 1) + assert.GreaterOrEqual(t, len(transactions), 1) + + balance, err = getBalance(rtConfig.ClientTwoURL, userTwo.XPriv) + if err != nil { + t.Errorf(errorWhileGettingBalance, err) + } + transactions, err = getTransactions(rtConfig.ClientTwoURL, userTwo.XPriv) + if err != nil { + t.Errorf(errorWhileGettingTransaction, err) + } + assert.GreaterOrEqual(t, balance, 1) + assert.GreaterOrEqual(t, len(transactions), 1) }) } From f2d8ed9f19bd8bedf76a89d804a2bf7d41fd325d Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 18:30:58 +0200 Subject: [PATCH 09/18] feat(SPV-896): adds build flags --- regression_tests/regression_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 4f8a5fb..25bfd3e 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -1,3 +1,6 @@ +//go:build regression +// +build regression + package regressiontests import ( From 6bfcd9752609431c3ed5b04133d275086aaf706f Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Fri, 19 Jul 2024 18:47:53 +0200 Subject: [PATCH 10/18] feat(SPV-896): adds timeout to http client request --- regression_tests/utils.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/regression_tests/utils.go b/regression_tests/utils.go index 83f4f7b..fd8d472 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -10,6 +10,7 @@ import ( "os" "regexp" "strings" + "time" walletclient "github.com/bitcoin-sv/spv-wallet-go-client" "github.com/bitcoin-sv/spv-wallet-go-client/xpriv" @@ -26,6 +27,8 @@ const ( ClientTwoURLEnvVar = "CLIENT_TWO_URL" ClientOneLeaderXPrivEnvVar = "CLIENT_ONE_LEADER_XPRIV" ClientTwoLeaderXPrivEnvVar = "CLIENT_TWO_LEADER_XPRIV" + + timeoutDuration = 30 * time.Second ) var ( @@ -73,7 +76,9 @@ func getSharedConfig(xpub string, clientUrl string) (*models.SharedConfig, error } req.Header.Set(models.AuthHeader, xpub) - client := &http.Client{} + client := http.Client{ + Timeout: timeoutDuration, + } resp, err := client.Do(req) if err != nil { return nil, err From 319c09586b004cbd33f84d91e9f492c40d1143ac Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Mon, 22 Jul 2024 13:45:15 +0200 Subject: [PATCH 11/18] feat(SPV-896): adds taskfile for regression tests --- regression_tests/Taskfile.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 regression_tests/Taskfile.yml diff --git a/regression_tests/Taskfile.yml b/regression_tests/Taskfile.yml new file mode 100644 index 0000000..f3ca22c --- /dev/null +++ b/regression_tests/Taskfile.yml @@ -0,0 +1,18 @@ +version: "3" + +tasks: + default: + cmds: + - task -l + + run_regression_tests: + desc: "running regression tests" + cmds: + - echo "running regression tests..." + - go test -tags=regression ./... + dir: . + env: + CLIENT_ONE_URL: "{{.CLIENT_ONE_URL}}" + CLIENT_TWO_URL: "{{.CLIENT_TWO_URL}}" + CLIENT_ONE_LEADER_XPRIV: "{{.CLIENT_ONE_LEADER_XPRIV}}" + CLIENT_TWO_LEADER_XPRIV: "{{.CLIENT_TWO_LEADER_XPRIV}}" From a5f5fe2db8cc751506f58224d2f7474308bb9a35 Mon Sep 17 00:00:00 2001 From: jakubmkowalski Date: Mon, 22 Jul 2024 14:06:09 +0200 Subject: [PATCH 12/18] feat(SPV-896): moves context declarations to upper functions --- regression_tests/regression_test.go | 30 +++++++++++++++-------------- regression_tests/utils.go | 17 ++++++---------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 25bfd3e..7ed2a87 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -4,6 +4,7 @@ package regressiontests import ( + "context" "testing" "github.com/stretchr/testify/assert" @@ -29,6 +30,7 @@ var ( ) func TestRegression(t *testing.T) { + ctx := context.Background() rtConfig, err := getEnvVariables() if err != nil { t.Errorf(errorWhileGettingEnvVariables, err) @@ -44,37 +46,37 @@ func TestRegression(t *testing.T) { } userName := "instanceOneUser1" - userOne, err := createUser(userName, sharedConfigInstanceOne.PaymailDomains[0], rtConfig.ClientOneURL, adminXPriv) + userOne, err := createUser(ctx, userName, sharedConfigInstanceOne.PaymailDomains[0], rtConfig.ClientOneURL, adminXPriv) if err != nil { t.Errorf(errorWhileCreatingUser, err) } - defer deleteUser(userOne.Paymail, rtConfig.ClientOneURL, adminXPriv) + defer deleteUser(ctx, userOne.Paymail, rtConfig.ClientOneURL, adminXPriv) userName = "instanceTwoUser1" - userTwo, err := createUser(userName, sharedConfigInstanceTwo.PaymailDomains[0], rtConfig.ClientTwoURL, adminXPriv) + userTwo, err := createUser(ctx, userName, sharedConfigInstanceTwo.PaymailDomains[0], rtConfig.ClientTwoURL, adminXPriv) if err != nil { t.Errorf(errorWhileCreatingUser, err) } - defer deleteUser(userTwo.Paymail, rtConfig.ClientTwoURL, adminXPriv) + defer deleteUser(ctx, userTwo.Paymail, rtConfig.ClientTwoURL, adminXPriv) t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) { // Given - balance, err := getBalance(rtConfig.ClientOneURL, userOne.XPriv) + balance, err := getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) if err != nil { t.Errorf(errorWhileGettingBalance, err) } - transactions, err := getTransactions(rtConfig.ClientOneURL, userOne.XPriv) + transactions, err := getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) if err != nil { t.Errorf(errorWhileGettingTransaction, err) } assert.Equal(t, 0, balance) assert.Equal(t, 0, len(transactions)) - balance, err = getBalance(rtConfig.ClientTwoURL, userTwo.XPriv) + balance, err = getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) if err != nil { t.Errorf(errorWhileGettingBalance, err) } - transactions, err = getTransactions(rtConfig.ClientTwoURL, userTwo.XPriv) + transactions, err = getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) if err != nil { t.Errorf(errorWhileGettingTransaction, err) } @@ -82,35 +84,35 @@ func TestRegression(t *testing.T) { assert.Equal(t, 0, len(transactions)) // When - transactionOne, err := sendFunds(rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, 2) + transactionOne, err := sendFunds(ctx, rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, 2) if err != nil { t.Errorf(errorWhileSendingFunds, err) } assert.GreaterOrEqual(t, int64(-1), transactionOne.OutputValue) - transactionTwo, err := sendFunds(rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, 2) + transactionTwo, err := sendFunds(ctx, rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, 2) if err != nil { t.Errorf(errorWhileSendingFunds, err) } assert.GreaterOrEqual(t, int64(-1), transactionTwo.OutputValue) // Then - balance, err = getBalance(rtConfig.ClientOneURL, userOne.XPriv) + balance, err = getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) if err != nil { t.Errorf(errorWhileGettingBalance, err) } - transactions, err = getTransactions(rtConfig.ClientOneURL, userOne.XPriv) + transactions, err = getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) if err != nil { t.Errorf(errorWhileGettingTransaction, err) } assert.GreaterOrEqual(t, balance, 1) assert.GreaterOrEqual(t, len(transactions), 1) - balance, err = getBalance(rtConfig.ClientTwoURL, userTwo.XPriv) + balance, err = getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) if err != nil { t.Errorf(errorWhileGettingBalance, err) } - transactions, err = getTransactions(rtConfig.ClientTwoURL, userTwo.XPriv) + transactions, err = getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) if err != nil { t.Errorf(errorWhileGettingTransaction, err) } diff --git a/regression_tests/utils.go b/regression_tests/utils.go index fd8d472..88b0bf0 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -106,7 +106,7 @@ func getSharedConfig(xpub string, clientUrl string) (*models.SharedConfig, error } // createUser creates a set of keys and new paymail in the SPV Wallet. -func createUser(paymail string, paymailDomain string, instanceUrl string, adminXPriv string) (*regressionTestUser, error) { +func createUser(ctx context.Context, paymail string, paymailDomain string, instanceUrl string, adminXPriv string) (*regressionTestUser, error) { keys, err := xpriv.Generate() if err != nil { return nil, err @@ -119,7 +119,6 @@ func createUser(paymail string, paymailDomain string, instanceUrl string, adminX } adminClient := walletclient.NewWithAdminKey(addPrefixIfNeeded(instanceUrl), adminXPriv) - ctx := context.Background() if err := adminClient.AdminNewXpub(ctx, user.XPub, map[string]any{"some_metadata": "remove"}); err != nil { return nil, err @@ -134,9 +133,8 @@ func createUser(paymail string, paymailDomain string, instanceUrl string, adminX } // deleteUser soft deletes paymail from the SPV Wallet. -func deleteUser(paymail string, instanceURL string, adminXPriv string) error { +func deleteUser(ctx context.Context, paymail string, instanceURL string, adminXPriv string) error { adminClient := walletclient.NewWithAdminKey(addPrefixIfNeeded(instanceURL), adminXPriv) - ctx := context.Background() err := adminClient.AdminDeletePaymail(ctx, paymail) if err != nil { return err @@ -145,9 +143,8 @@ func deleteUser(paymail string, instanceURL string, adminXPriv string) error { } // getBalance retrieves the balance from the SPV Wallet. -func getBalance(fromInstance string, fromXPriv string) (int, error) { +func getBalance(ctx context.Context, fromInstance string, fromXPriv string) (int, error) { client := walletclient.NewWithXPriv(addPrefixIfNeeded(fromInstance), fromXPriv) - ctx := context.Background() xpubInfo, err := client.GetXPub(ctx) if err != nil { @@ -157,9 +154,8 @@ func getBalance(fromInstance string, fromXPriv string) (int, error) { } // getTransactions retrieves the transactions from the SPV Wallet. -func getTransactions(fromInstance string, fromXPriv string) ([]*models.Transaction, error) { +func getTransactions(ctx context.Context, fromInstance string, fromXPriv string) ([]*models.Transaction, error) { client := walletclient.NewWithXPriv(addPrefixIfNeeded(fromInstance), fromXPriv) - ctx := context.Background() metadata := map[string]any{} conditions := filter.TransactionFilter{} @@ -173,11 +169,10 @@ func getTransactions(fromInstance string, fromXPriv string) ([]*models.Transacti } // sendFunds sends funds from one paymail to another. -func sendFunds(fromInstance string, fromXPriv string, toPamail string, howMuch int) (*models.Transaction, error) { +func sendFunds(ctx context.Context, fromInstance string, fromXPriv string, toPamail string, howMuch int) (*models.Transaction, error) { client := walletclient.NewWithXPriv(fromInstance, fromXPriv) - ctx := context.Background() - balance, err := getBalance(fromInstance, fromXPriv) + balance, err := getBalance(ctx, fromInstance, fromXPriv) if err != nil { return nil, err } From a6bd4fc1ae652ec5886026497a9428dec86b6ae2 Mon Sep 17 00:00:00 2001 From: wregulski Date: Sun, 11 Aug 2024 14:08:56 +0200 Subject: [PATCH 13/18] fix(SPV-896): applies cr comment - move errors check to require NoError --- regression_tests/regression_test.go | 78 +++++++++++------------------ 1 file changed, 30 insertions(+), 48 deletions(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 7ed2a87..91c79b1 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -5,9 +5,11 @@ package regressiontests import ( "context" + "fmt" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) const ( @@ -32,90 +34,70 @@ var ( func TestRegression(t *testing.T) { ctx := context.Background() rtConfig, err := getEnvVariables() - if err != nil { - t.Errorf(errorWhileGettingEnvVariables, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingEnvVariables, err)) sharedConfigInstanceOne, err := getSharedConfig(adminXPub, rtConfig.ClientOneURL) - if err != nil { - t.Errorf(errorWhileGettingSharedConfig, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingSharedConfig, err)) + sharedConfigInstanceTwo, err := getSharedConfig(adminXPub, rtConfig.ClientTwoURL) - if err != nil { - t.Errorf(errorWhileGettingSharedConfig, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingSharedConfig, err)) userName := "instanceOneUser1" userOne, err := createUser(ctx, userName, sharedConfigInstanceOne.PaymailDomains[0], rtConfig.ClientOneURL, adminXPriv) - if err != nil { - t.Errorf(errorWhileCreatingUser, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileCreatingUser, err)) + defer deleteUser(ctx, userOne.Paymail, rtConfig.ClientOneURL, adminXPriv) userName = "instanceTwoUser1" userTwo, err := createUser(ctx, userName, sharedConfigInstanceTwo.PaymailDomains[0], rtConfig.ClientTwoURL, adminXPriv) - if err != nil { - t.Errorf(errorWhileCreatingUser, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileCreatingUser, err)) + defer deleteUser(ctx, userTwo.Paymail, rtConfig.ClientTwoURL, adminXPriv) t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) { - // Given + // given balance, err := getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) - if err != nil { - t.Errorf(errorWhileGettingBalance, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) + transactions, err := getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) - if err != nil { - t.Errorf(errorWhileGettingTransaction, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) + assert.Equal(t, 0, balance) assert.Equal(t, 0, len(transactions)) balance, err = getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) - if err != nil { - t.Errorf(errorWhileGettingBalance, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) + transactions, err = getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) - if err != nil { - t.Errorf(errorWhileGettingTransaction, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) + assert.Equal(t, 0, balance) assert.Equal(t, 0, len(transactions)) - // When + // when transactionOne, err := sendFunds(ctx, rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, 2) - if err != nil { - t.Errorf(errorWhileSendingFunds, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileSendingFunds, err)) assert.GreaterOrEqual(t, int64(-1), transactionOne.OutputValue) transactionTwo, err := sendFunds(ctx, rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, 2) - if err != nil { - t.Errorf(errorWhileSendingFunds, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileSendingFunds, err)) assert.GreaterOrEqual(t, int64(-1), transactionTwo.OutputValue) - // Then + // then balance, err = getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) - if err != nil { - t.Errorf(errorWhileGettingBalance, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) + transactions, err = getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) - if err != nil { - t.Errorf(errorWhileGettingTransaction, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) + assert.GreaterOrEqual(t, balance, 1) assert.GreaterOrEqual(t, len(transactions), 1) balance, err = getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) - if err != nil { - t.Errorf(errorWhileGettingBalance, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) + transactions, err = getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) - if err != nil { - t.Errorf(errorWhileGettingTransaction, err) - } + require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) assert.GreaterOrEqual(t, balance, 1) assert.GreaterOrEqual(t, len(transactions), 1) }) From 0dbe370de4eb334bbb695ea3094d8b26ad967e58 Mon Sep 17 00:00:00 2001 From: wregulski Date: Sun, 11 Aug 2024 14:10:38 +0200 Subject: [PATCH 14/18] fix(SPV-896): replace all asserts with require keeping same logic --- regression_tests/regression_test.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 91c79b1..6b764cf 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -8,7 +8,6 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -62,8 +61,8 @@ func TestRegression(t *testing.T) { transactions, err := getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) - assert.Equal(t, 0, balance) - assert.Equal(t, 0, len(transactions)) + require.Equal(t, 0, balance) + require.Equal(t, 0, len(transactions)) balance, err = getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) @@ -71,17 +70,17 @@ func TestRegression(t *testing.T) { transactions, err = getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) - assert.Equal(t, 0, balance) - assert.Equal(t, 0, len(transactions)) + require.Equal(t, 0, balance) + require.Equal(t, 0, len(transactions)) // when transactionOne, err := sendFunds(ctx, rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, 2) require.NoError(t, err, fmt.Sprintf(errorWhileSendingFunds, err)) - assert.GreaterOrEqual(t, int64(-1), transactionOne.OutputValue) + require.GreaterOrEqual(t, int64(-1), transactionOne.OutputValue) transactionTwo, err := sendFunds(ctx, rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, 2) require.NoError(t, err, fmt.Sprintf(errorWhileSendingFunds, err)) - assert.GreaterOrEqual(t, int64(-1), transactionTwo.OutputValue) + require.GreaterOrEqual(t, int64(-1), transactionTwo.OutputValue) // then balance, err = getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) @@ -90,15 +89,15 @@ func TestRegression(t *testing.T) { transactions, err = getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) - assert.GreaterOrEqual(t, balance, 1) - assert.GreaterOrEqual(t, len(transactions), 1) + require.GreaterOrEqual(t, balance, 1) + require.GreaterOrEqual(t, len(transactions), 1) balance, err = getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) transactions, err = getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) - assert.GreaterOrEqual(t, balance, 1) - assert.GreaterOrEqual(t, len(transactions), 1) + require.GreaterOrEqual(t, balance, 1) + require.GreaterOrEqual(t, len(transactions), 1) }) } From 2b19aa207180dc0d3fc2181c1864b1f01abd4d57 Mon Sep 17 00:00:00 2001 From: wregulski Date: Sun, 11 Aug 2024 16:12:48 +0200 Subject: [PATCH 15/18] feat(SPV-896): split tests into smaller ones --- regression_tests/regression_test.go | 184 ++++++++++++++++------------ regression_tests/utils.go | 4 +- 2 files changed, 109 insertions(+), 79 deletions(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 6b764cf..3e25688 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -8,96 +8,126 @@ import ( "fmt" "testing" + "github.com/bitcoin-sv/spv-wallet/models" "github.com/stretchr/testify/require" ) const ( - fundsPerTest = 2 - adminXPriv = "xprv9s21ZrQH143K3CbJXirfrtpLvhT3Vgusdo8coBritQ3rcS7Jy7sxWhatuxG5h2y1Cqj8FKmPp69536gmjYRpfga2MJdsGyBsnB12E19CESK" - adminXPub = "xpub661MyMwAqRbcFgfmdkPgE2m5UjHXu9dj124DbaGLSjaqVESTWfCD4VuNmEbVPkbYLCkykwVZvmA8Pbf8884TQr1FgdG2nPoHR8aB36YdDQh" - errorWhileGettingTransaction = "error while getting transaction: %s" - errorWhileCreatingUser = "error while creating user: %s" - errorWhileGettingBalance = "error while getting transaction: %s" - errorWhileSendingFunds = "error while sending funds: %s" - errorWhileGettingSharedConfig = "error while getting shared config: %s" - errorWhileGettingEnvVariables = "error while getting env variables: %s" -) - -var ( - clientOneURL string - clientTwoURL string - clientOneLeaderXPriv string - clientTwoLeaderXPriv string + fundsPerTest = 2 + + adminXPriv = "xprv9s21ZrQH143K3CbJXirfrtpLvhT3Vgusdo8coBritQ3rcS7Jy7sxWhatuxG5h2y1Cqj8FKmPp69536gmjYRpfga2MJdsGyBsnB12E19CESK" + adminXPub = "xpub661MyMwAqRbcFgfmdkPgE2m5UjHXu9dj124DbaGLSjaqVESTWfCD4VuNmEbVPkbYLCkykwVZvmA8Pbf8884TQr1FgdG2nPoHR8aB36YdDQh" + + errGettingEnvVariables = "failed to get environment variables: %s" + errGettingSharedConfig = "failed to get shared config: %s" + errCreatingUser = "failed to create user: %s" + errDeletingUserPaymail = "failed to delete user's paymail: %s" + errSendingFunds = "failed to send funds: %s" + errGettingBalance = "failed to get balance: %s" + errGettingTransactions = "failed to get transactions: %s" ) func TestRegression(t *testing.T) { ctx := context.Background() rtConfig, err := getEnvVariables() - require.NoError(t, err, fmt.Sprintf(errorWhileGettingEnvVariables, err)) - - sharedConfigInstanceOne, err := getSharedConfig(adminXPub, rtConfig.ClientOneURL) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingSharedConfig, err)) - - sharedConfigInstanceTwo, err := getSharedConfig(adminXPub, rtConfig.ClientTwoURL) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingSharedConfig, err)) - - userName := "instanceOneUser1" - userOne, err := createUser(ctx, userName, sharedConfigInstanceOne.PaymailDomains[0], rtConfig.ClientOneURL, adminXPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileCreatingUser, err)) - - defer deleteUser(ctx, userOne.Paymail, rtConfig.ClientOneURL, adminXPriv) - - userName = "instanceTwoUser1" - userTwo, err := createUser(ctx, userName, sharedConfigInstanceTwo.PaymailDomains[0], rtConfig.ClientTwoURL, adminXPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileCreatingUser, err)) - - defer deleteUser(ctx, userTwo.Paymail, rtConfig.ClientTwoURL, adminXPriv) - - t.Run("TestInitialBalancesAndTransactionsBeforeAndAfterFundTransfers", func(t *testing.T) { - // given - balance, err := getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) + require.NoError(t, err, fmt.Sprintf(errGettingEnvVariables, err)) - transactions, err := getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) + var sharedConfigInstanceOne, sharedConfigInstanceTwo *models.SharedConfig + var userOne, userTwo *regressionTestUser - require.Equal(t, 0, balance) - require.Equal(t, 0, len(transactions)) + t.Run("Initialize Shared Configurations", func(t *testing.T) { + t.Run("Should get sharedConfig for instance one", func(t *testing.T) { + sharedConfigInstanceOne, err = getSharedConfig(adminXPub, rtConfig.ClientOneURL) + require.NoError(t, err, fmt.Sprintf(errGettingSharedConfig, err)) + }) - balance, err = getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) - - transactions, err = getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) - - require.Equal(t, 0, balance) - require.Equal(t, 0, len(transactions)) - - // when - transactionOne, err := sendFunds(ctx, rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, 2) - require.NoError(t, err, fmt.Sprintf(errorWhileSendingFunds, err)) - require.GreaterOrEqual(t, int64(-1), transactionOne.OutputValue) - - transactionTwo, err := sendFunds(ctx, rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, 2) - require.NoError(t, err, fmt.Sprintf(errorWhileSendingFunds, err)) - require.GreaterOrEqual(t, int64(-1), transactionTwo.OutputValue) - - // then - balance, err = getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) - - transactions, err = getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) - - require.GreaterOrEqual(t, balance, 1) - require.GreaterOrEqual(t, len(transactions), 1) + t.Run("Should get shared config for instance two", func(t *testing.T) { + sharedConfigInstanceTwo, err = getSharedConfig(adminXPub, rtConfig.ClientTwoURL) + require.NoError(t, err, fmt.Sprintf(errGettingSharedConfig, err)) + }) + }) - balance, err = getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingBalance, err)) + t.Run("Create Users", func(t *testing.T) { + t.Run("Should create user for instance one", func(t *testing.T) { + userName := "instanceOneUser1" + userOne, err = createUser(ctx, userName, sharedConfigInstanceOne.PaymailDomains[0], rtConfig.ClientOneURL, adminXPriv) + require.NoError(t, err, fmt.Sprintf(errCreatingUser, err)) + }) + + t.Run("Should create user for instance two", func(t *testing.T) { + userName := "instanceTwoUser1" + userTwo, err = createUser(ctx, userName, sharedConfigInstanceTwo.PaymailDomains[0], rtConfig.ClientTwoURL, adminXPriv) + require.NoError(t, err, fmt.Sprintf(errCreatingUser, err)) + }) + }) - transactions, err = getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) - require.NoError(t, err, fmt.Sprintf(errorWhileGettingTransaction, err)) - require.GreaterOrEqual(t, balance, 1) - require.GreaterOrEqual(t, len(transactions), 1) + defer func() { + t.Run("Cleanup: Remove Paymails", func(t *testing.T) { + t.Run("Should remove user's paymail on first instance", func(t *testing.T) { + if userOne != nil { + err := removeRegisteredPaymail(ctx, userOne.Paymail, rtConfig.ClientOneURL, adminXPriv) + require.NoError(t, err, fmt.Sprintf(errDeletingUserPaymail, err)) + } + }) + + t.Run("Should remove user's paymail on second instance", func(t *testing.T) { + if userTwo != nil { + err := removeRegisteredPaymail(ctx, userTwo.Paymail, rtConfig.ClientTwoURL, adminXPriv) + require.NoError(t, err, fmt.Sprintf(errDeletingUserPaymail, err)) + } + }) + }) + }() + + t.Run("Perform Transactions", func(t *testing.T) { + t.Run("Send money to instance 1", func(t *testing.T) { + transaction, err := sendFunds(ctx, rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, fundsPerTest) + require.NoError(t, err, fmt.Sprintf(errSendingFunds, err)) + require.GreaterOrEqual(t, int64(-1), transaction.OutputValue) + + balance, err := getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) + require.NoError(t, err, fmt.Sprintf(errGettingBalance, err)) + require.GreaterOrEqual(t, balance, 1) + + transactions, err := getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) + require.NoError(t, err, fmt.Sprintf(errGettingTransactions, err)) + require.GreaterOrEqual(t, len(transactions), 1) + }) + + t.Run("Send money to instance 2", func(t *testing.T) { + transaction, err := sendFunds(ctx, rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, fundsPerTest) + require.NoError(t, err, fmt.Sprintf(errSendingFunds, err)) + require.GreaterOrEqual(t, int64(-1), transaction.OutputValue) + + balance, err := getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) + require.NoError(t, err, fmt.Sprintf(errGettingBalance, err)) + require.GreaterOrEqual(t, balance, 1) + + transactions, err := getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) + require.NoError(t, err, fmt.Sprintf(errGettingTransactions, err)) + require.GreaterOrEqual(t, len(transactions), 1) + }) + + t.Run("Send money from instance 1 to instance 2", func(t *testing.T) { + transaction, err := sendFunds(ctx, rtConfig.ClientOneURL, userOne.XPriv, userTwo.Paymail, fundsPerTest) + require.NoError(t, err, fmt.Sprintf(errSendingFunds, err)) + require.GreaterOrEqual(t, int64(-1), transaction.OutputValue) + + balance, err := getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) + require.NoError(t, err, fmt.Sprintf(errGettingBalance, err)) + require.GreaterOrEqual(t, balance, 1) + + transactions, err := getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) + require.NoError(t, err, fmt.Sprintf(errGettingTransactions, err)) + require.GreaterOrEqual(t, len(transactions), 1) + + balance, err = getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) + require.NoError(t, err, fmt.Sprintf(errGettingBalance, err)) + require.GreaterOrEqual(t, balance, 1) + + transactions, err = getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) + require.NoError(t, err, fmt.Sprintf(errGettingTransactions, err)) + require.GreaterOrEqual(t, len(transactions), 1) + }) }) } diff --git a/regression_tests/utils.go b/regression_tests/utils.go index 88b0bf0..5e4c56a 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -132,8 +132,8 @@ func createUser(ctx context.Context, paymail string, paymailDomain string, insta return user, nil } -// deleteUser soft deletes paymail from the SPV Wallet. -func deleteUser(ctx context.Context, paymail string, instanceURL string, adminXPriv string) error { +// removeRegisteredPaymail soft deletes paymail from the SPV Wallet. +func removeRegisteredPaymail(ctx context.Context, paymail string, instanceURL string, adminXPriv string) error { adminClient := walletclient.NewWithAdminKey(addPrefixIfNeeded(instanceURL), adminXPriv) err := adminClient.AdminDeletePaymail(ctx, paymail) if err != nil { From 4aad98dbaad79180153d36db0be93c644c236ce7 Mon Sep 17 00:00:00 2001 From: wregulski Date: Sun, 11 Aug 2024 16:20:26 +0200 Subject: [PATCH 16/18] fix(SPV-896): simplify utils methods to limit outer methods calls --- regression_tests/regression_test.go | 11 +++++----- regression_tests/utils.go | 31 +++++++++++++++++------------ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 3e25688..53ab42f 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -8,7 +8,6 @@ import ( "fmt" "testing" - "github.com/bitcoin-sv/spv-wallet/models" "github.com/stretchr/testify/require" ) @@ -32,17 +31,17 @@ func TestRegression(t *testing.T) { rtConfig, err := getEnvVariables() require.NoError(t, err, fmt.Sprintf(errGettingEnvVariables, err)) - var sharedConfigInstanceOne, sharedConfigInstanceTwo *models.SharedConfig + var paymailDomainInstanceOne, paymailDomainInstanceTwo string var userOne, userTwo *regressionTestUser t.Run("Initialize Shared Configurations", func(t *testing.T) { t.Run("Should get sharedConfig for instance one", func(t *testing.T) { - sharedConfigInstanceOne, err = getSharedConfig(adminXPub, rtConfig.ClientOneURL) + paymailDomainInstanceOne, err = getPaymailDomain(adminXPub, rtConfig.ClientOneURL) require.NoError(t, err, fmt.Sprintf(errGettingSharedConfig, err)) }) t.Run("Should get shared config for instance two", func(t *testing.T) { - sharedConfigInstanceTwo, err = getSharedConfig(adminXPub, rtConfig.ClientTwoURL) + paymailDomainInstanceTwo, err = getPaymailDomain(adminXPub, rtConfig.ClientTwoURL) require.NoError(t, err, fmt.Sprintf(errGettingSharedConfig, err)) }) }) @@ -50,13 +49,13 @@ func TestRegression(t *testing.T) { t.Run("Create Users", func(t *testing.T) { t.Run("Should create user for instance one", func(t *testing.T) { userName := "instanceOneUser1" - userOne, err = createUser(ctx, userName, sharedConfigInstanceOne.PaymailDomains[0], rtConfig.ClientOneURL, adminXPriv) + userOne, err = createUser(ctx, userName, paymailDomainInstanceOne, rtConfig.ClientOneURL, adminXPriv) require.NoError(t, err, fmt.Sprintf(errCreatingUser, err)) }) t.Run("Should create user for instance two", func(t *testing.T) { userName := "instanceTwoUser1" - userTwo, err = createUser(ctx, userName, sharedConfigInstanceTwo.PaymailDomains[0], rtConfig.ClientTwoURL, adminXPriv) + userTwo, err = createUser(ctx, userName, paymailDomainInstanceTwo, rtConfig.ClientTwoURL, adminXPriv) require.NoError(t, err, fmt.Sprintf(errCreatingUser, err)) }) }) diff --git a/regression_tests/utils.go b/regression_tests/utils.go index 5e4c56a..3094a81 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -65,14 +65,18 @@ func getEnvVariables() (*regressionTestConfig, error) { rtConfig.ClientOneURL = "http://localhost:3003" rtConfig.ClientTwoURL = "http://localhost:3003" } + + rtConfig.ClientOneURL = addPrefixIfNeeded(rtConfig.ClientOneURL) + rtConfig.ClientTwoURL = addPrefixIfNeeded(rtConfig.ClientTwoURL) + return &rtConfig, nil } -// getSharedConfig retrieves the shared configuration from the SPV Wallet. -func getSharedConfig(xpub string, clientUrl string) (*models.SharedConfig, error) { +// getPaymailDomain retrieves the shared configuration from the SPV Wallet. +func getPaymailDomain(xpub string, clientUrl string) (string, error) { req, err := http.NewRequest(http.MethodGet, clientUrl+domainSuffixSharedConfig, nil) if err != nil { - return nil, err + return "", err } req.Header.Set(models.AuthHeader, xpub) @@ -81,28 +85,29 @@ func getSharedConfig(xpub string, clientUrl string) (*models.SharedConfig, error } resp, err := client.Do(req) if err != nil { - return nil, err + return "", err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("failed to get shared config: %s", resp.Status) + return "", fmt.Errorf("failed to get shared config: %s", resp.Status) } body, err := io.ReadAll(resp.Body) if err != nil { - return nil, err + return "", err } var configResponse models.SharedConfig if err := json.Unmarshal(body, &configResponse); err != nil { - return nil, err + return "", err } if len(configResponse.PaymailDomains) != 1 { - return nil, fmt.Errorf("expected 1 paymail domain, got %d", len(configResponse.PaymailDomains)) + return "", fmt.Errorf("expected 1 paymail domain, got %d", len(configResponse.PaymailDomains)) } - return &configResponse, nil + + return configResponse.PaymailDomains[0], nil } // createUser creates a set of keys and new paymail in the SPV Wallet. @@ -118,7 +123,7 @@ func createUser(ctx context.Context, paymail string, paymailDomain string, insta Paymail: preparePaymail(paymail, paymailDomain), } - adminClient := walletclient.NewWithAdminKey(addPrefixIfNeeded(instanceUrl), adminXPriv) + adminClient := walletclient.NewWithAdminKey(instanceUrl, adminXPriv) if err := adminClient.AdminNewXpub(ctx, user.XPub, map[string]any{"some_metadata": "remove"}); err != nil { return nil, err @@ -134,7 +139,7 @@ func createUser(ctx context.Context, paymail string, paymailDomain string, insta // removeRegisteredPaymail soft deletes paymail from the SPV Wallet. func removeRegisteredPaymail(ctx context.Context, paymail string, instanceURL string, adminXPriv string) error { - adminClient := walletclient.NewWithAdminKey(addPrefixIfNeeded(instanceURL), adminXPriv) + adminClient := walletclient.NewWithAdminKey(instanceURL, adminXPriv) err := adminClient.AdminDeletePaymail(ctx, paymail) if err != nil { return err @@ -144,7 +149,7 @@ func removeRegisteredPaymail(ctx context.Context, paymail string, instanceURL st // getBalance retrieves the balance from the SPV Wallet. func getBalance(ctx context.Context, fromInstance string, fromXPriv string) (int, error) { - client := walletclient.NewWithXPriv(addPrefixIfNeeded(fromInstance), fromXPriv) + client := walletclient.NewWithXPriv(fromInstance, fromXPriv) xpubInfo, err := client.GetXPub(ctx) if err != nil { @@ -155,7 +160,7 @@ func getBalance(ctx context.Context, fromInstance string, fromXPriv string) (int // getTransactions retrieves the transactions from the SPV Wallet. func getTransactions(ctx context.Context, fromInstance string, fromXPriv string) ([]*models.Transaction, error) { - client := walletclient.NewWithXPriv(addPrefixIfNeeded(fromInstance), fromXPriv) + client := walletclient.NewWithXPriv(fromInstance, fromXPriv) metadata := map[string]any{} conditions := filter.TransactionFilter{} From 6150f46d4b6234cc7acab69c558257114d9c726e Mon Sep 17 00:00:00 2001 From: Jakub Kowalski <155538368+jakubmkowalski@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:24:02 +0200 Subject: [PATCH 17/18] feat(SPV-896): switches to GetSharedConfig method to get paymail domain --- regression_tests/regression_test.go | 4 +-- regression_tests/utils.go | 49 ++++++----------------------- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index 53ab42f..c3817bd 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -36,12 +36,12 @@ func TestRegression(t *testing.T) { t.Run("Initialize Shared Configurations", func(t *testing.T) { t.Run("Should get sharedConfig for instance one", func(t *testing.T) { - paymailDomainInstanceOne, err = getPaymailDomain(adminXPub, rtConfig.ClientOneURL) + paymailDomainInstanceOne, err = getPaymailDomain(ctx, adminXPub, rtConfig.ClientOneURL) require.NoError(t, err, fmt.Sprintf(errGettingSharedConfig, err)) }) t.Run("Should get shared config for instance two", func(t *testing.T) { - paymailDomainInstanceTwo, err = getPaymailDomain(adminXPub, rtConfig.ClientTwoURL) + paymailDomainInstanceTwo, err = getPaymailDomain(ctx, adminXPub, rtConfig.ClientTwoURL) require.NoError(t, err, fmt.Sprintf(errGettingSharedConfig, err)) }) }) diff --git a/regression_tests/utils.go b/regression_tests/utils.go index 3094a81..b410c32 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -2,15 +2,11 @@ package regressiontests import ( "context" - "encoding/json" "errors" "fmt" - "io" - "net/http" "os" "regexp" "strings" - "time" walletclient "github.com/bitcoin-sv/spv-wallet-go-client" "github.com/bitcoin-sv/spv-wallet-go-client/xpriv" @@ -27,13 +23,11 @@ const ( ClientTwoURLEnvVar = "CLIENT_TWO_URL" ClientOneLeaderXPrivEnvVar = "CLIENT_ONE_LEADER_XPRIV" ClientTwoLeaderXPrivEnvVar = "CLIENT_TWO_LEADER_XPRIV" - - timeoutDuration = 30 * time.Second ) var ( - explicitHTTPURLRegex = regexp.MustCompile(`^https?://`) - envVariableError = errors.New("missing xpriv variables") + explicitHTTPURLRegex = regexp.MustCompile(`^https?://`) + errEmptyXPrivEnvVariables = errors.New("missing xpriv variables") ) type regressionTestUser struct { @@ -59,7 +53,7 @@ func getEnvVariables() (*regressionTestConfig, error) { } if rtConfig.ClientOneLeaderXPriv == "" || rtConfig.ClientTwoLeaderXPriv == "" { - return nil, envVariableError + return nil, errEmptyXPrivEnvVariables } if rtConfig.ClientOneURL == "" || rtConfig.ClientTwoURL == "" { rtConfig.ClientOneURL = "http://localhost:3003" @@ -73,41 +67,16 @@ func getEnvVariables() (*regressionTestConfig, error) { } // getPaymailDomain retrieves the shared configuration from the SPV Wallet. -func getPaymailDomain(xpub string, clientUrl string) (string, error) { - req, err := http.NewRequest(http.MethodGet, clientUrl+domainSuffixSharedConfig, nil) +func getPaymailDomain(ctx context.Context, xpub string, clientUrl string) (string, error) { + wc := walletclient.NewWithXPub(clientUrl, xpub) + sharedConfig, err := wc.GetSharedConfig(ctx) if err != nil { return "", err } - - req.Header.Set(models.AuthHeader, xpub) - client := http.Client{ - Timeout: timeoutDuration, - } - resp, err := client.Do(req) - if err != nil { - return "", err + if len(sharedConfig.PaymailDomains) != 1 { + return "", fmt.Errorf("expected 1 paymail domain, got %d", len(sharedConfig.PaymailDomains)) } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return "", fmt.Errorf("failed to get shared config: %s", resp.Status) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - return "", err - } - - var configResponse models.SharedConfig - if err := json.Unmarshal(body, &configResponse); err != nil { - return "", err - } - - if len(configResponse.PaymailDomains) != 1 { - return "", fmt.Errorf("expected 1 paymail domain, got %d", len(configResponse.PaymailDomains)) - } - - return configResponse.PaymailDomains[0], nil + return sharedConfig.PaymailDomains[0], nil } // createUser creates a set of keys and new paymail in the SPV Wallet. From ecab3fb549f00bd8f6ca20e2aef2553da79515a6 Mon Sep 17 00:00:00 2001 From: Jakub Kowalski <155538368+jakubmkowalski@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:11:20 +0200 Subject: [PATCH 18/18] feat(SPV-896): changes key to xpriv when requesting shared config, changes in transaction amounts --- regression_tests/regression_test.go | 21 +++++++++++---------- regression_tests/utils.go | 9 ++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/regression_tests/regression_test.go b/regression_tests/regression_test.go index c3817bd..ce2a573 100644 --- a/regression_tests/regression_test.go +++ b/regression_tests/regression_test.go @@ -12,7 +12,7 @@ import ( ) const ( - fundsPerTest = 2 + minimalFundsPerTransaction = 2 adminXPriv = "xprv9s21ZrQH143K3CbJXirfrtpLvhT3Vgusdo8coBritQ3rcS7Jy7sxWhatuxG5h2y1Cqj8FKmPp69536gmjYRpfga2MJdsGyBsnB12E19CESK" adminXPub = "xpub661MyMwAqRbcFgfmdkPgE2m5UjHXu9dj124DbaGLSjaqVESTWfCD4VuNmEbVPkbYLCkykwVZvmA8Pbf8884TQr1FgdG2nPoHR8aB36YdDQh" @@ -36,12 +36,12 @@ func TestRegression(t *testing.T) { t.Run("Initialize Shared Configurations", func(t *testing.T) { t.Run("Should get sharedConfig for instance one", func(t *testing.T) { - paymailDomainInstanceOne, err = getPaymailDomain(ctx, adminXPub, rtConfig.ClientOneURL) + paymailDomainInstanceOne, err = getPaymailDomain(ctx, adminXPriv, rtConfig.ClientOneURL) require.NoError(t, err, fmt.Sprintf(errGettingSharedConfig, err)) }) t.Run("Should get shared config for instance two", func(t *testing.T) { - paymailDomainInstanceTwo, err = getPaymailDomain(ctx, adminXPub, rtConfig.ClientTwoURL) + paymailDomainInstanceTwo, err = getPaymailDomain(ctx, adminXPriv, rtConfig.ClientTwoURL) require.NoError(t, err, fmt.Sprintf(errGettingSharedConfig, err)) }) }) @@ -80,7 +80,8 @@ func TestRegression(t *testing.T) { t.Run("Perform Transactions", func(t *testing.T) { t.Run("Send money to instance 1", func(t *testing.T) { - transaction, err := sendFunds(ctx, rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, fundsPerTest) + const amountToSend = 3 + transaction, err := sendFunds(ctx, rtConfig.ClientTwoURL, rtConfig.ClientTwoLeaderXPriv, userOne.Paymail, amountToSend) require.NoError(t, err, fmt.Sprintf(errSendingFunds, err)) require.GreaterOrEqual(t, int64(-1), transaction.OutputValue) @@ -94,7 +95,7 @@ func TestRegression(t *testing.T) { }) t.Run("Send money to instance 2", func(t *testing.T) { - transaction, err := sendFunds(ctx, rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, fundsPerTest) + transaction, err := sendFunds(ctx, rtConfig.ClientOneURL, rtConfig.ClientOneLeaderXPriv, userTwo.Paymail, minimalFundsPerTransaction) require.NoError(t, err, fmt.Sprintf(errSendingFunds, err)) require.GreaterOrEqual(t, int64(-1), transaction.OutputValue) @@ -108,25 +109,25 @@ func TestRegression(t *testing.T) { }) t.Run("Send money from instance 1 to instance 2", func(t *testing.T) { - transaction, err := sendFunds(ctx, rtConfig.ClientOneURL, userOne.XPriv, userTwo.Paymail, fundsPerTest) + transaction, err := sendFunds(ctx, rtConfig.ClientOneURL, userOne.XPriv, userTwo.Paymail, minimalFundsPerTransaction) require.NoError(t, err, fmt.Sprintf(errSendingFunds, err)) require.GreaterOrEqual(t, int64(-1), transaction.OutputValue) balance, err := getBalance(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) require.NoError(t, err, fmt.Sprintf(errGettingBalance, err)) - require.GreaterOrEqual(t, balance, 1) + require.GreaterOrEqual(t, balance, 2) transactions, err := getTransactions(ctx, rtConfig.ClientTwoURL, userTwo.XPriv) require.NoError(t, err, fmt.Sprintf(errGettingTransactions, err)) - require.GreaterOrEqual(t, len(transactions), 1) + require.GreaterOrEqual(t, len(transactions), 2) balance, err = getBalance(ctx, rtConfig.ClientOneURL, userOne.XPriv) require.NoError(t, err, fmt.Sprintf(errGettingBalance, err)) - require.GreaterOrEqual(t, balance, 1) + require.GreaterOrEqual(t, balance, 0) transactions, err = getTransactions(ctx, rtConfig.ClientOneURL, userOne.XPriv) require.NoError(t, err, fmt.Sprintf(errGettingTransactions, err)) - require.GreaterOrEqual(t, len(transactions), 1) + require.GreaterOrEqual(t, len(transactions), 2) }) }) } diff --git a/regression_tests/utils.go b/regression_tests/utils.go index b410c32..ba07616 100644 --- a/regression_tests/utils.go +++ b/regression_tests/utils.go @@ -15,9 +15,8 @@ import ( ) const ( - atSign = "@" - domainPrefix = "https://" - domainSuffixSharedConfig = "/v1/shared-config" + atSign = "@" + domainPrefix = "https://" ClientOneURLEnvVar = "CLIENT_ONE_URL" ClientTwoURLEnvVar = "CLIENT_TWO_URL" @@ -67,8 +66,8 @@ func getEnvVariables() (*regressionTestConfig, error) { } // getPaymailDomain retrieves the shared configuration from the SPV Wallet. -func getPaymailDomain(ctx context.Context, xpub string, clientUrl string) (string, error) { - wc := walletclient.NewWithXPub(clientUrl, xpub) +func getPaymailDomain(ctx context.Context, xpriv string, clientUrl string) (string, error) { + wc := walletclient.NewWithXPriv(clientUrl, xpriv) sharedConfig, err := wc.GetSharedConfig(ctx) if err != nil { return "", err