diff --git a/api/v1_developer_apps.go b/api/v1_developer_apps.go index 1df54b6e..ac0252b2 100644 --- a/api/v1_developer_apps.go +++ b/api/v1_developer_apps.go @@ -18,6 +18,10 @@ func (app *ApiServer) v1DeveloperApps(c *fiber.Ctx) error { address = "0x" + address } + // Normalize address to lowercase to ensure case-insensitive matching + // (addresses in the DB are stored as lowercase) + address = strings.ToLower(address) + developerApps, err := app.queries.GetDeveloperApps(c.Context(), dbv1.GetDeveloperAppsParams{ Address: address, }) diff --git a/api/v1_developer_apps_test.go b/api/v1_developer_apps_test.go index 53cd622e..8573f8ac 100644 --- a/api/v1_developer_apps_test.go +++ b/api/v1_developer_apps_test.go @@ -8,6 +8,8 @@ import ( "github.com/stretchr/testify/assert" ) +const testDeveloperAppAddress = "0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6" + func TestGetDeveloperAppsQueries(t *testing.T) { app := testAppWithFixtures(t) developerApps, err := app.queries.GetDeveloperApps(t.Context(), dbv1.GetDeveloperAppsParams{ @@ -15,7 +17,7 @@ func TestGetDeveloperAppsQueries(t *testing.T) { }) assert.NoError(t, err) assert.Len(t, developerApps, 1) - assert.Equal(t, "0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6", developerApps[0].Address) + assert.Equal(t, testDeveloperAppAddress, developerApps[0].Address) // redirect_uris must be an empty slice (not nil) when no URIs are registered assert.Equal(t, []string{}, developerApps[0].RedirectUris) } @@ -26,7 +28,7 @@ func TestGetDeveloperApp(t *testing.T) { var resp struct { Data dbv1.GetDeveloperAppsRow } - status, body := testGet(t, app, "/v1/developer_apps/0x7d7b6b7a97d1deefe3a1ccc5a13c48e8f055e0b6", &resp) + status, body := testGet(t, app, "/v1/developer_apps/"+testDeveloperAppAddress, &resp) assert.Equal(t, 200, status) assert.True(t, strings.Contains(string(body), `"user_id":"7eP5n"`)) assert.True(t, strings.Contains(string(body), `"name":"cool app"`)) @@ -34,3 +36,39 @@ func TestGetDeveloperApp(t *testing.T) { // redirect_uris must be an empty slice (not nil) when no URIs are registered assert.Equal(t, []string{}, resp.Data.RedirectUris) } + +func TestGetDeveloperAppUppercaseAddress(t *testing.T) { + app := testAppWithFixtures(t) + + var resp struct { + Data dbv1.GetDeveloperAppsRow + } + // Uppercase address should still find the app (case-insensitive lookup) + status, _ := testGet(t, app, "/v1/developer_apps/0x7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp) + assert.Equal(t, 200, status) + assert.Equal(t, "cool app", resp.Data.Name) +} + +func TestGetDeveloperAppMixedCaseAddress(t *testing.T) { + app := testAppWithFixtures(t) + + var resp struct { + Data dbv1.GetDeveloperAppsRow + } + // Mixed-case address should still find the app (case-insensitive lookup) + status, _ := testGet(t, app, "/v1/developer_apps/0x7d7B6B7A97d1deEFe3A1ccc5A13c48E8F055e0B6", &resp) + assert.Equal(t, 200, status) + assert.Equal(t, "cool app", resp.Data.Name) +} + +func TestGetDeveloperAppWithoutHexPrefix(t *testing.T) { + app := testAppWithFixtures(t) + + var resp struct { + Data dbv1.GetDeveloperAppsRow + } + // Address without 0x prefix should still find the app + status, _ := testGet(t, app, "/v1/developer_apps/7D7B6B7A97D1DEEFE3A1CCC5A13C48E8F055E0B6", &resp) + assert.Equal(t, 200, status) + assert.Equal(t, "cool app", resp.Data.Name) +}