Files
Maxence MaireauxandGitHub 22ebbe0a85 feat: CE/EE split architecture (#644)
* feat: Create EE architecture

* feat: Move Fireblocks to EE

* feat: Add dual CE/EE licensing model

Update root LICENSE to dual-license format distinguishing Community
Edition (MIT) from Enterprise Edition (ee/LICENSE), aligned with
the formancehq/stack licensing model.

* refactor: Rename main_ee.go to ee.go for cleaner build tag convention

* feat: Move Coinbase Prime to EE

* feat: just

* fix: tidy & package name
2026-02-24 15:26:29 +00:00

231 lines
5.5 KiB
Go

package coinbaseprime
import (
"errors"
"time"
"github.com/formancehq/go-libs/v3/logging"
"github.com/formancehq/payments/internal/connectors/plugins"
"github.com/formancehq/payments/ee/plugins/coinbaseprime/client"
"github.com/formancehq/payments/internal/models"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"go.uber.org/mock/gomock"
)
var _ = Describe("Coinbase Plugin Accounts", func() {
var (
ctrl *gomock.Controller
m *client.MockClient
plg *Plugin
)
BeforeEach(func() {
ctrl = gomock.NewController(GinkgoT())
m = client.NewMockClient(ctrl)
plg = &Plugin{
Plugin: plugins.NewBasePlugin(),
client: m,
logger: logging.NewDefaultLogger(GinkgoWriter, true, false, false),
currencies: map[string]int{
"USD": 2,
"EUR": 2,
"GBP": 2,
"BTC": 8,
"ETH": 18,
"USDC": 6,
},
}
})
AfterEach(func() {
ctrl.Finish()
})
Context("fetching next accounts", func() {
var (
now time.Time
sampleWallets []client.Wallet
)
BeforeEach(func() {
now = time.Now().UTC()
sampleWallets = []client.Wallet{
{
ID: "wallet1",
Name: "BTC Trading Wallet",
Symbol: "BTC",
Type: "TRADING",
CreatedAt: now.Add(-48 * time.Hour),
},
{
ID: "wallet2",
Name: "USD Wallet",
Symbol: "USD",
Type: "TRADING",
CreatedAt: now.Add(-24 * time.Hour),
},
{
ID: "wallet3",
Name: "ETH Vault",
Symbol: "ETH",
Type: "VAULT",
CreatedAt: now,
},
}
})
It("should return an error - get wallets error", func(ctx SpecContext) {
req := models.FetchNextAccountsRequest{
State: []byte(`{}`),
PageSize: 10,
}
m.EXPECT().GetWallets(gomock.Any(), "", 10).Return(
nil,
errors.New("test error"),
)
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).ToNot(BeNil())
Expect(err).To(MatchError("test error"))
Expect(resp).To(Equal(models.FetchNextAccountsResponse{}))
})
It("should fetch wallets successfully", func(ctx SpecContext) {
req := models.FetchNextAccountsRequest{
State: []byte(`{}`),
PageSize: 10,
}
m.EXPECT().GetWallets(gomock.Any(), "", 10).Return(
&client.WalletsResponse{
Wallets: sampleWallets,
Pagination: client.Pagination{
NextCursor: "cursor123",
HasNext: true,
},
},
nil,
)
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Accounts).To(HaveLen(3))
Expect(resp.HasMore).To(BeTrue())
// Verify BTC wallet
Expect(resp.Accounts[0].Reference).To(Equal("wallet1"))
Expect(resp.Accounts[0].CreatedAt).To(Equal(sampleWallets[0].CreatedAt))
Expect(*resp.Accounts[0].DefaultAsset).To(Equal("BTC/8"))
Expect(*resp.Accounts[0].Name).To(Equal("BTC Trading Wallet"))
Expect(resp.Accounts[0].Metadata["wallet_type"]).To(Equal("TRADING"))
// Verify USD wallet
Expect(resp.Accounts[1].Reference).To(Equal("wallet2"))
Expect(resp.Accounts[1].CreatedAt).To(Equal(sampleWallets[1].CreatedAt))
Expect(*resp.Accounts[1].DefaultAsset).To(Equal("USD/2"))
// Verify ETH wallet
Expect(resp.Accounts[2].Reference).To(Equal("wallet3"))
Expect(resp.Accounts[2].CreatedAt).To(Equal(sampleWallets[2].CreatedAt))
Expect(*resp.Accounts[2].DefaultAsset).To(Equal("ETH/18"))
Expect(resp.Accounts[2].Metadata["wallet_type"]).To(Equal("VAULT"))
})
It("should skip unsupported currencies", func(ctx SpecContext) {
req := models.FetchNextAccountsRequest{
State: []byte(`{}`),
PageSize: 10,
}
unsupportedWallets := []client.Wallet{
{
ID: "wallet1",
Name: "Unknown Wallet",
Symbol: "UNKNOWN_CURRENCY",
Type: "TRADING",
CreatedAt: now,
},
{
ID: "wallet2",
Name: "BTC Wallet",
Symbol: "BTC",
Type: "TRADING",
CreatedAt: now,
},
}
m.EXPECT().GetWallets(gomock.Any(), "", 10).Return(
&client.WalletsResponse{
Wallets: unsupportedWallets,
Pagination: client.Pagination{
HasNext: false,
},
},
nil,
)
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Accounts).To(HaveLen(1))
Expect(*resp.Accounts[0].DefaultAsset).To(Equal("BTC/8"))
})
It("should accept lowercase symbols", func(ctx SpecContext) {
req := models.FetchNextAccountsRequest{
State: []byte(`{}`),
PageSize: 10,
}
lowercaseWallets := []client.Wallet{
{
ID: "wallet1",
Name: "btc wallet",
Symbol: "btc",
Type: "TRADING",
CreatedAt: now,
},
}
m.EXPECT().GetWallets(gomock.Any(), "", 10).Return(
&client.WalletsResponse{
Wallets: lowercaseWallets,
Pagination: client.Pagination{
HasNext: false,
},
},
nil,
)
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Accounts).To(HaveLen(1))
Expect(*resp.Accounts[0].DefaultAsset).To(Equal("BTC/8"))
})
It("should use cursor for pagination", func(ctx SpecContext) {
req := models.FetchNextAccountsRequest{
State: []byte(`{"cursor": "existing-cursor"}`),
PageSize: 10,
}
m.EXPECT().GetWallets(gomock.Any(), "existing-cursor", 10).Return(
&client.WalletsResponse{
Wallets: []client.Wallet{},
Pagination: client.Pagination{
HasNext: false,
},
},
nil,
)
resp, err := plg.FetchNextAccounts(ctx, req)
Expect(err).To(BeNil())
Expect(resp.Accounts).To(HaveLen(0))
Expect(resp.HasMore).To(BeFalse())
})
})
})