mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Move all public connectors to ce/plugins * Update tooling to account for new go modules under ce * Ensure we test all CE plugins in CI * Move Dummypay to ce/plugins for simplicity's sake in the generation scripts * Use versioned pkg/domain in plugins * Ensure that renovate updates all CE plugins in a single PR when pkg/domain tags are pushed to github * Ensure Justfile commands work over all CE plugins * Copy ce plugin go.mods in dev.Dockerfile * Only add a go.mod for new plugins if they are ce * Ensure generated generic client structs are named correctly for submodule * Add coverprofile for each ce plugin * Add set -e for Justfile for loops over plugins * Infer go version from flake.nix in connector template tool
57 lines
2.0 KiB
Go
57 lines
2.0 KiB
Go
package tink
|
|
|
|
import (
|
|
"math/big"
|
|
"strconv"
|
|
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("MapTinkAmount", func() {
|
|
Context("with GBP currency", func() {
|
|
DescribeTable("should map Tink amounts correctly",
|
|
func(unscaledValueStr string, scale int, currency string, expectedValue *big.Int, expectedAsset string) {
|
|
value, asset, err := MapTinkAmount(unscaledValueStr, strconv.Itoa(scale), currency)
|
|
Expect(err).To(BeNil())
|
|
Expect(value).To(Equal(expectedValue))
|
|
Expect(*asset).To(Equal(expectedAsset))
|
|
},
|
|
Entry("negative value with scale 2", "-399", 2, "GBP", big.NewInt(-399), "GBP/2"),
|
|
Entry("negative value with scale 1", "-99", 1, "GBP", big.NewInt(-990), "GBP/2"),
|
|
Entry("negative value with scale 1", "-390", 1, "GBP", big.NewInt(-3900), "GBP/2"),
|
|
Entry("positive value with scale 2", "389259", 2, "GBP", big.NewInt(389259), "GBP/2"),
|
|
Entry("positive value with scale 4", "3000", 4, "GBP", big.NewInt(30), "GBP/2"),
|
|
|
|
Entry("positive value with scale 0", "3384", 0, "GBP", big.NewInt(338400), "GBP/2"),
|
|
Entry("positive value with scale 2", "332635", 2, "GBP", big.NewInt(332635), "GBP/2"),
|
|
Entry("positive value with negative scale -2", "132", -2, "GBP", big.NewInt(1_320_000), "GBP/2"),
|
|
|
|
Entry("currency with precision of 3", "132", 2, "JOD", big.NewInt(1320), "JOD/3"),
|
|
)
|
|
})
|
|
|
|
Context("error cases", func() {
|
|
It("should return error for invalid unscaled value", func() {
|
|
value, asset, err := MapTinkAmount("not-a-number", "2", "GBP")
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(value).To(BeNil())
|
|
Expect(asset).To(BeNil())
|
|
})
|
|
|
|
It("should return error for invalid scale", func() {
|
|
value, asset, err := MapTinkAmount("100", "not-a-number", "GBP")
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(value).To(BeNil())
|
|
Expect(asset).To(BeNil())
|
|
})
|
|
|
|
It("should return error for invalid currency", func() {
|
|
value, asset, err := MapTinkAmount("100", "2", "INVALID")
|
|
Expect(err).ToNot(BeNil())
|
|
Expect(value).To(BeNil())
|
|
Expect(asset).To(BeNil())
|
|
})
|
|
})
|
|
})
|