mirror of
https://github.com/muun/recovery.git
synced 2025-11-12 23:01:40 -05:00
Update project structure and build process
This commit is contained in:
67
libwallet/newop/money_test.go
Normal file
67
libwallet/newop/money_test.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package newop
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
func TestMonetaryAmountString(t *testing.T) {
|
||||
|
||||
amount := NewMonetaryAmountFromFiat("10.54", "USD")
|
||||
if amount.ValueAsString() != "10.54" {
|
||||
t.Fatalf("expected value as string to match, got %v", amount.ValueAsString())
|
||||
}
|
||||
|
||||
if amount.String() != "10.54 USD" {
|
||||
t.Fatalf("expected value as string to match, got %v", amount.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMonetaryAmountToBitcoinAmount(t *testing.T) {
|
||||
|
||||
amount := NewMonetaryAmountFromSatoshis(100_000_000)
|
||||
|
||||
window := &ExchangeRateWindow{}
|
||||
window.AddRate("BTC", 1)
|
||||
window.AddRate("USD", 32_000)
|
||||
|
||||
bitcoinAmount := amount.toBitcoinAmount(window, "USD")
|
||||
|
||||
if bitcoinAmount.InSat != 100_000_000 {
|
||||
t.Fatalf("expected sats amount to be 100000000, got %v", bitcoinAmount.InSat)
|
||||
}
|
||||
|
||||
if bitcoinAmount.InPrimaryCurrency.Currency != "USD" {
|
||||
t.Fatalf("expected converted currency to be USD, got %v", bitcoinAmount.InPrimaryCurrency.Currency)
|
||||
}
|
||||
|
||||
if bitcoinAmount.InPrimaryCurrency.Value.Cmp(decimal.NewFromInt(32_000)) != 0 {
|
||||
t.Fatalf("expected converted amount to be 32000, got %v", bitcoinAmount.InInputCurrency.Value)
|
||||
}
|
||||
|
||||
if bitcoinAmount.InInputCurrency.Currency != "BTC" {
|
||||
t.Fatalf("expected intput currency to be BTC, got %v", bitcoinAmount.InInputCurrency.Currency)
|
||||
}
|
||||
|
||||
if bitcoinAmount.InInputCurrency.Value.Cmp(decimal.NewFromInt(1)) != 0 {
|
||||
t.Fatalf("expected converted amount to be 1, got %v", bitcoinAmount.InInputCurrency.Value)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestMonetaryAmountAdd(t *testing.T) {
|
||||
|
||||
a := NewMonetaryAmountFromFiat("10", "USD")
|
||||
b := NewMonetaryAmountFromFiat("20", "USD")
|
||||
|
||||
sum := a.add(b)
|
||||
|
||||
if sum.Currency != "USD" {
|
||||
t.Fatalf("expected converted currency to be USD, got %v", sum.Currency)
|
||||
}
|
||||
|
||||
if sum.Value.Cmp(decimal.NewFromInt(30)) != 0 {
|
||||
t.Fatalf("expected converted amount to be 30, got %v", sum.Value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user