mirror of
https://github.com/hanzo-fi/stack.git
synced 2026-10-30 20:34:43 +00:00
Co-authored-by: Antoine Wacheux <[email protected]> Co-authored-by: Maxence Maireaux <[email protected]> Co-authored-by: Brieuc Caillot <[email protected]>
67 lines
1.1 KiB
Go
67 lines
1.1 KiB
Go
package ledger
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestReverseMultiple(t *testing.T) {
|
|
p := Postings{
|
|
{
|
|
Source: "world",
|
|
Destination: "users:001",
|
|
Amount: big.NewInt(100),
|
|
Asset: "COIN",
|
|
},
|
|
{
|
|
Source: "users:001",
|
|
Destination: "payments:001",
|
|
Amount: big.NewInt(100),
|
|
Asset: "COIN",
|
|
},
|
|
}
|
|
|
|
expected := Postings{
|
|
{
|
|
Source: "payments:001",
|
|
Destination: "users:001",
|
|
Amount: big.NewInt(100),
|
|
Asset: "COIN",
|
|
},
|
|
{
|
|
Source: "users:001",
|
|
Destination: "world",
|
|
Amount: big.NewInt(100),
|
|
Asset: "COIN",
|
|
},
|
|
}
|
|
|
|
p.Reverse()
|
|
require.Equal(t, expected, p)
|
|
}
|
|
|
|
func TestReverseSingle(t *testing.T) {
|
|
p := Postings{
|
|
{
|
|
Source: "world",
|
|
Destination: "users:001",
|
|
Amount: big.NewInt(100),
|
|
Asset: "COIN",
|
|
},
|
|
}
|
|
|
|
expected := Postings{
|
|
{
|
|
Source: "users:001",
|
|
Destination: "world",
|
|
Amount: big.NewInt(100),
|
|
Asset: "COIN",
|
|
},
|
|
}
|
|
|
|
p.Reverse()
|
|
require.Equal(t, expected, p)
|
|
}
|