Skip to content

Commit

Permalink
refactor unittest to remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
aditya1702 committed Oct 2, 2024
1 parent 3325577 commit 2c906e9
Showing 1 changed file with 6 additions and 31 deletions.
37 changes: 6 additions & 31 deletions cmd/soroban-rpc/internal/methods/get_ledgers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestGetLedgers_DefaultLimit(t *testing.T) {
}

func TestGetLedgers_CustomLimit(t *testing.T) {
testDB := setupTestDB(t, 50)
testDB := setupTestDB(t, 40)
handler := ledgersHandler{
ledgerReader: db.NewLedgerReader(testDB),
maxLimit: 100,
Expand All @@ -73,18 +73,18 @@ func TestGetLedgers_CustomLimit(t *testing.T) {
request := GetLedgersRequest{
StartLedger: 1,
Pagination: &LedgerPaginationOptions{
Limit: 41,
Limit: 50,
},
}

response, err := handler.getLedgers(context.TODO(), request)
require.NoError(t, err)

assert.Equal(t, uint32(50), response.LatestLedger)
assert.Equal(t, "41", response.Cursor)
assert.Len(t, response.Ledgers, 41)
assert.Equal(t, uint32(40), response.LatestLedger)
assert.Equal(t, "40", response.Cursor)
assert.Len(t, response.Ledgers, 40)
assert.Equal(t, uint32(1), response.Ledgers[0].Sequence)
assert.Equal(t, uint32(41), response.Ledgers[40].Sequence)
assert.Equal(t, uint32(40), response.Ledgers[39].Sequence)
}

func TestGetLedgers_WithCursor(t *testing.T) {
Expand Down Expand Up @@ -149,31 +149,6 @@ func TestGetLedgers_LimitExceedsMaxLimit(t *testing.T) {
assert.Contains(t, err.Error(), "limit must not exceed 100")
}

func TestGetLedgers_LimitExceedsLatestLedger(t *testing.T) {
testDB := setupTestDB(t, 10)
handler := ledgersHandler{
ledgerReader: db.NewLedgerReader(testDB),
maxLimit: 100,
defaultLimit: 5,
}

request := GetLedgersRequest{
StartLedger: 1,
Pagination: &LedgerPaginationOptions{
Limit: 50,
},
}

response, err := handler.getLedgers(context.TODO(), request)
require.NoError(t, err)

assert.Equal(t, uint32(10), response.LatestLedger)
assert.Equal(t, "10", response.Cursor)
assert.Len(t, response.Ledgers, 10)
assert.Equal(t, uint32(1), response.Ledgers[0].Sequence)
assert.Equal(t, uint32(10), response.Ledgers[9].Sequence)
}

func TestGetLedgers_InvalidCursor(t *testing.T) {
testDB := setupTestDB(t, 10)
handler := ledgersHandler{
Expand Down

0 comments on commit 2c906e9

Please sign in to comment.