diff --git a/tests/integration/suite/wallets-create.go b/tests/integration/suite/wallets-create.go deleted file mode 100644 index 2f698a7a59..0000000000 --- a/tests/integration/suite/wallets-create.go +++ /dev/null @@ -1,93 +0,0 @@ -package suite - -import ( - "fmt" - "github.com/formancehq/go-libs/pointer" - "math/big" - - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" - . "github.com/formancehq/stack/tests/integration/internal" - "github.com/formancehq/stack/tests/integration/internal/modules" - "github.com/google/uuid" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = WithModules([]*Module{modules.Auth, modules.Ledger, modules.Wallets}, func() { - const countWallets = 3 - When(fmt.Sprintf("creating %d wallets", countWallets), func() { - JustBeforeEach(func() { - for i := 0; i < countWallets; i++ { - name := uuid.NewString() - response, err := Client().Wallets.V1.CreateWallet( - TestContext(), - operations.CreateWalletRequest{ - CreateWalletRequest: &shared.CreateWalletRequest{ - Metadata: map[string]string{ - "wallets_number": fmt.Sprint(i), - }, - Name: name, - }, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(response.StatusCode).To(Equal(201)) - - _, err = Client().Wallets.V1.CreditWallet(TestContext(), operations.CreditWalletRequest{ - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(100), - Asset: "USD", - }, - }, - ID: response.CreateWalletResponse.Data.ID, - }) - Expect(err).ToNot(HaveOccurred()) - } - }) - Then("listing them", func() { - var ( - request operations.ListWalletsRequest - response *operations.ListWalletsResponse - err error - ) - BeforeEach(func() { - // reset between each test - request = operations.ListWalletsRequest{} - }) - JustBeforeEach(func() { - Eventually(func(g Gomega) bool { - response, err = Client().Wallets.V1.ListWallets(TestContext(), request) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(response.StatusCode).To(Equal(200)) - return true - }).Should(BeTrue()) - }) - It(fmt.Sprintf("should return %d items", countWallets), func() { - Expect(response.ListWalletsResponse.Cursor.Data).To(HaveLen(countWallets)) - }) - Context("using a metadata filter", func() { - BeforeEach(func() { - request.Metadata = map[string]string{ - "wallets_number": "0", - } - }) - It("should return only one item", func() { - Expect(response.ListWalletsResponse.Cursor.Data).To(HaveLen(1)) - }) - }) - Context("expanding balances", func() { - BeforeEach(func() { - request.Expand = pointer.For("balances") - }) - It("should return all items with volumes and balances", func() { - Expect(response.ListWalletsResponse.Cursor.Data).To(HaveLen(3)) - for _, wallet := range response.ListWalletsResponse.Cursor.Data { - Expect(wallet.Balances.Main.Assets["USD"]).To(Equal(big.NewInt(100))) - } - }) - }) - }) - }) -}) diff --git a/tests/integration/suite/wallets-credit.go b/tests/integration/suite/wallets-credit.go deleted file mode 100644 index 15ee8e7ca7..0000000000 --- a/tests/integration/suite/wallets-credit.go +++ /dev/null @@ -1,167 +0,0 @@ -package suite - -import ( - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/sdkerrors" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" - "github.com/formancehq/go-libs/pointer" - . "github.com/formancehq/stack/tests/integration/internal" - "github.com/formancehq/stack/tests/integration/internal/modules" - "github.com/google/uuid" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/pkg/errors" - "math/big" - "time" -) - -var _ = WithModules([]*Module{modules.Auth, modules.Ledger, modules.Wallets}, func() { - - When("creating a wallet", func() { - var ( - response *operations.CreateWalletResponse - err error - ) - BeforeEach(func() { - response, err = Client().Wallets.V1.CreateWallet( - TestContext(), - operations.CreateWalletRequest{ - CreateWalletRequest: &shared.CreateWalletRequest{ - Name: uuid.NewString(), - Metadata: map[string]string{}, - }, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(response.StatusCode).To(Equal(201)) - }) - Then("crediting it", func() { - BeforeEach(func() { - _, err := Client().Wallets.V1.CreditWallet(TestContext(), operations.CreditWalletRequest{ - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(1000), - Asset: "USD/2", - }, - Sources: []shared.Subject{}, - Metadata: map[string]string{}, - }, - ID: response.CreateWalletResponse.Data.ID, - IdempotencyKey: pointer.For("foo"), - }) - Expect(err).To(Succeed()) - }) - It("should be ok", func() {}) - Then("crediting again with the same ik", func() { - BeforeEach(func() { - _, err := Client().Wallets.V1.CreditWallet(TestContext(), operations.CreditWalletRequest{ - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(1000), - Asset: "USD/2", - }, - Sources: []shared.Subject{}, - Metadata: map[string]string{}, - }, - ID: response.CreateWalletResponse.Data.ID, - IdempotencyKey: pointer.For("foo"), - }) - Expect(err).To(Succeed()) - }) - It("Should not trigger any movements", func() { - balance, err := Client().Wallets.V1.GetBalance(TestContext(), operations.GetBalanceRequest{ - BalanceName: "main", - ID: response.CreateWalletResponse.Data.ID, - }) - Expect(err).To(Succeed()) - Expect(balance.GetBalanceResponse.Data.Assets["USD/2"]).To(Equal(big.NewInt(1000))) - }) - }) - }) - Then("crediting it with specified timestamp", func() { - now := time.Now().Round(time.Microsecond).UTC() - BeforeEach(func() { - _, err := Client().Wallets.V1.CreditWallet(TestContext(), operations.CreditWalletRequest{ - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(1000), - Asset: "USD/2", - }, - Sources: []shared.Subject{}, - Metadata: map[string]string{}, - Timestamp: &now, - }, - ID: response.CreateWalletResponse.Data.ID, - }) - Expect(err).To(Succeed()) - }) - It("should create the transaction at the specified date", func() { - tx, err := Client().Ledger.V2.GetTransaction(TestContext(), operations.V2GetTransactionRequest{ - ID: big.NewInt(0), - Ledger: "wallets-002", - }) - Expect(err).To(Succeed()) - Expect(tx.V2GetTransactionResponse.Data.Timestamp).To(Equal(now)) - }) - }) - Then("crediting it with invalid source", func() { - It("should fail", func() { - _, err := Client().Wallets.V1.CreditWallet(TestContext(), operations.CreditWalletRequest{ - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(1000), - Asset: "USD/2", - }, - Sources: []shared.Subject{shared.CreateSubjectAccount(shared.LedgerAccountSubject{ - Identifier: "@xxx", - })}, - Metadata: map[string]string{}, - }, - ID: response.CreateWalletResponse.Data.ID, - }) - Expect(err).NotTo(Succeed()) - sdkError := &sdkerrors.WalletsErrorResponse{} - Expect(errors.As(err, &sdkError)).To(BeTrue()) - Expect(sdkError.ErrorCode).To(Equal(sdkerrors.SchemasWalletsErrorResponseErrorCodeValidation)) - }) - }) - Then("crediting it with negative amount", func() { - It("should fail", func() { - _, err := Client().Wallets.V1.CreditWallet(TestContext(), operations.CreditWalletRequest{ - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(-1000), - Asset: "USD/2", - }, - Sources: []shared.Subject{}, - Metadata: map[string]string{}, - }, - ID: response.CreateWalletResponse.Data.ID, - }) - Expect(err).NotTo(Succeed()) - sdkError := &sdkerrors.WalletsErrorResponse{} - Expect(errors.As(err, &sdkError)).To(BeTrue()) - Expect(sdkError.ErrorCode).To(Equal(sdkerrors.SchemasWalletsErrorResponseErrorCodeValidation)) - }) - }) - Then("crediting it with invalid asset name", func() { - It("should fail", func() { - _, err := Client().Wallets.V1.CreditWallet(TestContext(), operations.CreditWalletRequest{ - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(1000), - Asset: "test", - }, - Sources: []shared.Subject{}, - Metadata: map[string]string{}, - }, - ID: response.CreateWalletResponse.Data.ID, - }) - Expect(err).NotTo(Succeed()) - sdkError := &sdkerrors.WalletsErrorResponse{} - Expect(errors.As(err, &sdkError)).To(BeTrue()) - Expect(sdkError.ErrorCode).To(Equal(sdkerrors.SchemasWalletsErrorResponseErrorCodeValidation)) - }) - }) - }) -}) diff --git a/tests/integration/suite/wallets-debit.go b/tests/integration/suite/wallets-debit.go deleted file mode 100644 index 73dbb3e4b5..0000000000 --- a/tests/integration/suite/wallets-debit.go +++ /dev/null @@ -1,192 +0,0 @@ -package suite - -import ( - "github.com/formancehq/formance-sdk-go/v3/pkg/models/operations" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/sdkerrors" - "github.com/formancehq/formance-sdk-go/v3/pkg/models/shared" - "github.com/formancehq/go-libs/pointer" - . "github.com/formancehq/stack/tests/integration/internal" - "github.com/formancehq/stack/tests/integration/internal/modules" - "github.com/google/uuid" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/pkg/errors" - "math/big" - "time" -) - -var _ = WithModules([]*Module{modules.Auth, modules.Ledger, modules.Wallets}, func() { - When("creating a wallet", func() { - var ( - createWalletResponse *operations.CreateWalletResponse - err error - ) - BeforeEach(func() { - createWalletResponse, err = Client().Wallets.V1.CreateWallet( - TestContext(), - operations.CreateWalletRequest{ - CreateWalletRequest: &shared.CreateWalletRequest{ - Name: uuid.NewString(), - Metadata: map[string]string{}, - }, - }, - ) - Expect(err).ToNot(HaveOccurred()) - Expect(createWalletResponse.StatusCode).To(Equal(201)) - }) - Then("crediting it", func() { - BeforeEach(func() { - _, err := Client().Wallets.V1.CreditWallet(TestContext(), operations.CreditWalletRequest{ - CreditWalletRequest: &shared.CreditWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(1000), - Asset: "USD/2", - }, - Sources: []shared.Subject{}, - Metadata: map[string]string{}, - }, - ID: createWalletResponse.CreateWalletResponse.Data.ID, - }) - Expect(err).To(Succeed()) - }) - Then("debiting it", func() { - BeforeEach(func() { - _, err := Client().Wallets.V1.DebitWallet(TestContext(), operations.DebitWalletRequest{ - DebitWalletRequest: &shared.DebitWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(100), - Asset: "USD/2", - }, - Metadata: map[string]string{}, - }, - ID: createWalletResponse.CreateWalletResponse.Data.ID, - }) - Expect(err).To(Succeed()) - }) - It("should be ok", func() {}) - }) - Then("debiting it using timestamp", func() { - now := time.Now().Round(time.Microsecond).UTC() - BeforeEach(func() { - _, err := Client().Wallets.V1.DebitWallet(TestContext(), operations.DebitWalletRequest{ - DebitWalletRequest: &shared.DebitWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(100), - Asset: "USD/2", - }, - Metadata: map[string]string{}, - Timestamp: &now, - }, - ID: createWalletResponse.CreateWalletResponse.Data.ID, - }) - Expect(err).To(Succeed()) - }) - It("should create the transaction at the specified timestamp", func() { - tx, err := Client().Ledger.V2.GetTransaction(TestContext(), operations.V2GetTransactionRequest{ - ID: big.NewInt(1), - Ledger: "wallets-002", - }) - Expect(err).To(Succeed()) - Expect(tx.V2GetTransactionResponse.Data.Timestamp).To(Equal(now)) - }) - }) - Then("debiting it using a hold", func() { - var ( - debitWalletResponse *operations.DebitWalletResponse - ts *time.Time - ) - JustBeforeEach(func() { - debitWalletResponse, err = Client().Wallets.V1.DebitWallet(TestContext(), operations.DebitWalletRequest{ - DebitWalletRequest: &shared.DebitWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(100), - Asset: "USD/2", - }, - Pending: pointer.For(true), - Metadata: map[string]string{}, - Timestamp: ts, - }, - ID: createWalletResponse.CreateWalletResponse.Data.ID, - }) - Expect(err).To(Succeed()) - }) - It("should be ok", func() {}) - Then("confirm the hold", func() { - JustBeforeEach(func() { - _, err := Client().Wallets.V1.ConfirmHold(TestContext(), operations.ConfirmHoldRequest{ - HoldID: debitWalletResponse.DebitWalletResponse.Data.ID, - }) - Expect(err).To(Succeed()) - }) - It("should be ok", func() {}) - }) - Then("void the hold", func() { - JustBeforeEach(func() { - _, err := Client().Wallets.V1.VoidHold(TestContext(), operations.VoidHoldRequest{ - HoldID: debitWalletResponse.DebitWalletResponse.Data.ID, - }) - Expect(err).To(Succeed()) - }) - It("should be ok", func() {}) - }) - }) - Then("debiting it using invalid destination", func() { - It("should fail", func() { - _, err := Client().Wallets.V1.DebitWallet(TestContext(), operations.DebitWalletRequest{ - DebitWalletRequest: &shared.DebitWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(100), - Asset: "USD/2", - }, - Metadata: map[string]string{}, - Destination: pointer.For(shared.CreateSubjectAccount(shared.LedgerAccountSubject{ - Identifier: "@xxx", - })), - }, - ID: createWalletResponse.CreateWalletResponse.Data.ID, - }) - Expect(err).NotTo(Succeed()) - sdkError := &sdkerrors.WalletsErrorResponse{} - Expect(errors.As(err, &sdkError)).To(BeTrue()) - Expect(sdkError.ErrorCode).To(Equal(sdkerrors.SchemasWalletsErrorResponseErrorCodeValidation)) - }) - }) - Then("debiting it using negative amount", func() { - It("should fail", func() { - _, err := Client().Wallets.V1.DebitWallet(TestContext(), operations.DebitWalletRequest{ - DebitWalletRequest: &shared.DebitWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(-100), - Asset: "USD/2", - }, - Metadata: map[string]string{}, - }, - ID: createWalletResponse.CreateWalletResponse.Data.ID, - }) - Expect(err).NotTo(Succeed()) - sdkError := &sdkerrors.WalletsErrorResponse{} - Expect(errors.As(err, &sdkError)).To(BeTrue()) - Expect(sdkError.ErrorCode).To(Equal(sdkerrors.SchemasWalletsErrorResponseErrorCodeValidation)) - }) - }) - Then("debiting it using invalid asset", func() { - It("should fail", func() { - _, err := Client().Wallets.V1.DebitWallet(TestContext(), operations.DebitWalletRequest{ - DebitWalletRequest: &shared.DebitWalletRequest{ - Amount: shared.Monetary{ - Amount: big.NewInt(100), - Asset: "test", - }, - Metadata: map[string]string{}, - }, - ID: createWalletResponse.CreateWalletResponse.Data.ID, - }) - Expect(err).NotTo(Succeed()) - sdkError := &sdkerrors.WalletsErrorResponse{} - Expect(errors.As(err, &sdkError)).To(BeTrue()) - Expect(sdkError.ErrorCode).To(Equal(sdkerrors.SchemasWalletsErrorResponseErrorCodeValidation)) - }) - }) - }) - }) -})