mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-09 14:18:03 -05:00
Combine our HTTP RPC and Websocket services into a single HTTP server, eliminating the --ws-port flag to swapd and using --swapd-port flag for swapcli.
36 lines
938 B
Go
36 lines
938 B
Go
package common
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestMoneroAmount(t *testing.T) {
|
|
amount := float64(33.3)
|
|
piconero := MoneroToPiconero(amount)
|
|
require.Equal(t, fmt.Sprintf("%.11f", amount), fmt.Sprintf("%.11f", piconero.AsMonero()))
|
|
|
|
amountUint := piconero.Uint64()
|
|
amountUint2 := MoneroAmount(amountUint)
|
|
require.Equal(t, amountUint, amountUint2.Uint64())
|
|
}
|
|
|
|
func TestEtherAmount(t *testing.T) {
|
|
amount := float64(33.3)
|
|
wei := EtherToWei(amount)
|
|
require.Equal(t, fmt.Sprintf("%.18f", amount), fmt.Sprintf("%.18f", wei.AsEther()))
|
|
|
|
amountUint := int64(8181)
|
|
etherAmount := NewEtherAmount(amountUint)
|
|
require.Equal(t, amountUint, etherAmount.BigInt().Int64())
|
|
}
|
|
|
|
func TestToDecimals(t *testing.T) {
|
|
val := NewEtherAmount(123456)
|
|
require.Equal(t, "1.23456", FmtFloat(val.ToDecimals(5)))
|
|
val = NewEtherAmount(1234567890)
|
|
require.Equal(t, "1234.56789", FmtFloat(val.ToDecimals(6)))
|
|
}
|