Skip to content

Commit df426e1

Browse files
committed
Add stateful property-based tests using rapid
Introduces two property-based tests using rapid's state machine support: TestLedgerStateMachine generates random sequences of actions (create account, create transfer, batch transfers, constrained accounts, expected-failure transfers) and checks five invariants after every step: - Entry chain consistency (prev + amount = curr for each entry) - Zero-sum balance (sum of all balances per currency is zero) - Version tracking (account version matches entry count) - Two entries per transfer (debit + credit summing to zero) - Entry version monotonicity (strictly increasing, no gaps) TestLedgerConcurrentStateMachine runs parallel goroutines performing transfers against shared accounts, then verifies the same invariants hold — stress-testing the sorted-ID locking strategy.
1 parent df0b95b commit df426e1

6 files changed

Lines changed: 442 additions & 2 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ jobs:
4545
env:
4646
POSTGRES_VERSION: ${{ matrix.postgres_version }}
4747

48+
- name: Upload rapid failure reproductions
49+
if: failure()
50+
uses: actions/upload-artifact@v6
51+
with:
52+
name: rapid-testdata-pg${{ matrix.postgres_version }}
53+
path: go/test/testdata/rapid/
54+
4855
all-tests-passed:
4956
if: ${{ always() }}
5057
needs: test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.aider*
1+
/.claude/settings.local.json
2+
/go/test/testdata/rapid/

go/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.26.1
55
require (
66
github.com/jackc/pgx/v5 v5.9.1
77
github.com/stretchr/testify v1.11.1
8+
pgregory.net/rapid v1.2.0
89
)
910

1011
require (

go/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
4343
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4444
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4545
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
46+
pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
47+
pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=

0 commit comments

Comments
 (0)