Skip to content

Commit

Permalink
feat(ledger): add tests on big int support (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored and flemzord committed Dec 4, 2023
1 parent 4c43ac7 commit 88af7b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
6 changes: 4 additions & 2 deletions internal/storage/ledgerstore/accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,11 @@ func TestGetAccountWithVolumes(t *testing.T) {
t.Parallel()
store := newLedgerStore(t)

bigInt, _ := big.NewInt(0).SetString("999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", 10)

require.NoError(t, insertTransactions(context.Background(), store,
*ledger.NewTransaction().WithPostings(
ledger.NewPosting("world", "multi", "USD/2", big.NewInt(100)),
ledger.NewPosting("world", "multi", "USD/2", bigInt),
),
))

Expand All @@ -293,7 +295,7 @@ func TestGetAccountWithVolumes(t *testing.T) {
Metadata: metadata.Metadata{},
},
Volumes: map[string]*ledger.Volumes{
"USD/2": ledger.NewEmptyVolumes().WithInputInt64(100),
"USD/2": ledger.NewEmptyVolumes().WithInput(bigInt),
},
}, accountWithVolumes)
}
Expand Down
21 changes: 15 additions & 6 deletions internal/storage/ledgerstore/balances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ func TestGetBalancesAggregated(t *testing.T) {
store := newLedgerStore(t)
now := ledger.Now()

bigInt, _ := big.NewInt(0).SetString("999999999999999999999999999999999999999999999999999999999999999999999999999999999", 10)
smallInt := big.NewInt(199)

tx1 := ledger.NewTransaction().WithPostings(
ledger.NewPosting("world", "users:1", "USD", big.NewInt(1)),
ledger.NewPosting("world", "users:2", "USD", big.NewInt(199)),
ledger.NewPosting("world", "users:1", "USD", bigInt),
ledger.NewPosting("world", "users:2", "USD", smallInt),
).WithDate(now)

tx2 := ledger.NewTransaction().WithPostings(
ledger.NewPosting("world", "users:1", "USD", big.NewInt(1)),
ledger.NewPosting("world", "users:2", "USD", big.NewInt(199)),
ledger.NewPosting("world", "users:1", "USD", bigInt),
ledger.NewPosting("world", "users:2", "USD", smallInt),
).WithDate(now.Add(time.Minute)).WithIDUint64(1)

require.NoError(t, store.InsertLogs(context.Background(),
Expand All @@ -52,7 +55,10 @@ func TestGetBalancesAggregated(t *testing.T) {
))
require.NoError(t, err)
require.Equal(t, ledger.BalancesByAssets{
"USD": big.NewInt(400),
"USD": big.NewInt(0).Add(
big.NewInt(0).Mul(bigInt, big.NewInt(2)),
big.NewInt(0).Mul(smallInt, big.NewInt(2)),
),
}, ret)
})
t.Run("using pit", func(t *testing.T) {
Expand All @@ -64,7 +70,10 @@ func TestGetBalancesAggregated(t *testing.T) {
WithPageSize(10)))
require.NoError(t, err)
require.Equal(t, ledger.BalancesByAssets{
"USD": big.NewInt(200),
"USD": big.NewInt(0).Add(
bigInt,
smallInt,
),
}, ret)
})
}
18 changes: 17 additions & 1 deletion libs/pgtesting/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ func (s *pgServer) NewDatabase(t TestingT) *pgDatabase {
s.lock.Lock()
defer s.lock.Unlock()

_, _ = s.db.ExecContext(context.Background(), fmt.Sprintf(`DROP DATABASE "%s"`, databaseName))
_, err := s.db.ExecContext(context.Background(), fmt.Sprintf(`DROP DATABASE "%s"`, databaseName))
if err != nil {
panic(err)
}
})
}

Expand Down Expand Up @@ -224,6 +227,19 @@ func CreatePostgresServer(opts ...option) error {
return errors.Wrap(err, "unable to start postgres server container")
}

go func() {
if err := pool.Client.Logs(docker.LogsOptions{
Container: resource.Container.ID,
OutputStream: os.Stdout,
Stdout: true,
Stderr: true,
RawTerminal: true,
Timestamps: true,
}); err != nil {
fmt.Println(err)
}
}()

srv = &pgServer{
port: resource.GetPort("5432/tcp"),
destroy: func() error {
Expand Down

0 comments on commit 88af7b9

Please sign in to comment.