diff --git a/api/dbv1/get_undisbursed_challenges.sql.go b/api/dbv1/get_undisbursed_challenges.sql.go index 931d4475..d40aacb2 100644 --- a/api/dbv1/get_undisbursed_challenges.sql.go +++ b/api/dbv1/get_undisbursed_challenges.sql.go @@ -19,12 +19,15 @@ SELECT user_challenges.specifier, user_challenges.amount FROM user_challenges +JOIN challenges ON challenges.id = user_challenges.challenge_id AND challenges.active JOIN users ON users.user_id = user_challenges.user_id LEFT JOIN sol_reward_disbursements AS challenge_disbursements ON challenge_disbursements.challenge_id = user_challenges.challenge_id AND challenge_disbursements.specifier = user_challenges.specifier WHERE challenge_disbursements.challenge_id IS NULL + AND user_challenges.challenge_id IN ('tt', 'tut') + AND users.is_current AND NOT users.is_deactivated AND user_challenges.is_complete AND user_challenges.user_id = $1 AND ($2::text = '' OR user_challenges.challenge_id = $2) diff --git a/api/dbv1/queries/get_undisbursed_challenges.sql b/api/dbv1/queries/get_undisbursed_challenges.sql index 5256b699..ccdf305b 100644 --- a/api/dbv1/queries/get_undisbursed_challenges.sql +++ b/api/dbv1/queries/get_undisbursed_challenges.sql @@ -6,6 +6,7 @@ SELECT user_challenges.specifier, user_challenges.amount FROM user_challenges +JOIN challenges ON challenges.id = user_challenges.challenge_id AND challenges.active JOIN users ON users.user_id = user_challenges.user_id -- Anti-join the raw table by (challenge_id, specifier); the v_challenge_disbursements -- view drops disbursements whose recipient wallet doesn't resolve to a user. @@ -14,6 +15,8 @@ LEFT JOIN sol_reward_disbursements AS challenge_disbursements AND challenge_disbursements.specifier = user_challenges.specifier WHERE challenge_disbursements.challenge_id IS NULL + AND user_challenges.challenge_id IN ('tt', 'tut') + AND users.is_current AND NOT users.is_deactivated AND user_challenges.is_complete AND user_challenges.user_id = @user_id AND (@challenge_id::text = '' OR user_challenges.challenge_id = @challenge_id) diff --git a/api/rewards_policy.go b/api/rewards_policy.go new file mode 100644 index 00000000..2b8fd8e6 --- /dev/null +++ b/api/rewards_policy.go @@ -0,0 +1,11 @@ +package api + +import "github.com/gofiber/fiber/v2" + +func isTrendingReward(id string) bool { return id == "tt" || id == "tut" } + +// Keep retired routes explicit for older clients, before any code consumption, +// pool creation, signing or Solana transaction submission. +func programmableRewardsDisabled(c *fiber.Ctx) error { + return fiber.NewError(fiber.StatusGone, "Programmable rewards are no longer supported") +} diff --git a/api/rewards_policy_test.go b/api/rewards_policy_test.go new file mode 100644 index 00000000..8b018ff1 --- /dev/null +++ b/api/rewards_policy_test.go @@ -0,0 +1,49 @@ +package api + +import ( + "bytes" + "context" + "github.com/gofiber/fiber/v2" + "github.com/stretchr/testify/require" + "net/http/httptest" + "os" + "testing" +) + +func TestRetiredRewardClaimsRejectBeforeDependencies(t *testing.T) { + server := &ApiServer{} // No database, key or Solana client may be needed. + app := fiber.New() + app.Post("/rewards/claim", server.v1ClaimRewards) + for _, id := range []string{"e", "tp", "dvl", "rbig1", "unknown"} { + req := httptest.NewRequest("POST", "/rewards/claim", bytes.NewBufferString(`{"userId":"L50xn","challengeId":"`+id+`"}`)) + req.Header.Set("Content-Type", "application/json") + res, err := app.Test(req) + require.NoError(t, err) + require.Equal(t, 410, res.StatusCode) + res.Body.Close() + } +} + +func TestProgrammableRewardRoutesRetired(t *testing.T) { + app := testAppWithFixtures(t) + for _, path := range []string{"/v1/rewards/code", "/v1/coins/mint/redeem", "/v1/coins/mint/redeem/code"} { + status, _ := testPost(t, app, path, []byte(`{}`), nil) + require.Equal(t, 410, status) + } +} + +func TestRetiredChallengeDoesNotGenerateNotification(t *testing.T) { + app := testAppWithFixtures(t) + ctx := context.Background() + function, err := os.ReadFile("../ddl/functions/handle_user_challenges.sql") + require.NoError(t, err) + _, err = app.pool.Exec(ctx, string(function)) + require.NoError(t, err) + _, err = app.pool.Exec(ctx, `INSERT INTO user_challenges (challenge_id,user_id,specifier,is_complete,current_step_count,amount,completed_at,completed_blocknumber) + VALUES ('e',402,'retirement-test',true,1,1,now(),200)`) + require.NoError(t, err) + var count int + err = app.pool.QueryRow(ctx, "SELECT COUNT(*) FROM notification WHERE data->>'specifier' = 'retirement-test'").Scan(&count) + require.NoError(t, err) + require.Zero(t, count) +} diff --git a/api/server.go b/api/server.go index 4a765dd4..8a82294a 100644 --- a/api/server.go +++ b/api/server.go @@ -682,7 +682,7 @@ func NewApiServer(config config.Config) *ApiServer { // Rewards g.Post("/rewards/claim", app.v1ClaimRewards) - g.Post("/rewards/code", app.v1CreateRewardCode) + g.Post("/rewards/code", programmableRewardsDisabled) // Prizes g.Get("/prizes", app.v1Prizes) @@ -753,10 +753,10 @@ func NewApiServer(config config.Config) *ApiServer { g.Get("/coins/:mint/insights", app.v1CoinInsights) g.Get("/coins/:mint/members", app.v1CoinsMembers) g.Get("/coins/:mint/members/count", app.v1CoinMembersCount) - g.Get("/coins/:mint/redeem", app.v1CoinsRedeem) - g.Get("/coins/:mint/redeem/:code", app.v1CoinsRedeemCode) - g.Post("/coins/:mint/redeem", app.requireAuthMiddleware, app.requireWriteScope, app.v1CoinsPostRedeem) - g.Post("/coins/:mint/redeem/:code", app.requireAuthMiddleware, app.requireWriteScope, app.v1CoinsPostRedeem) + g.Get("/coins/:mint/redeem", programmableRewardsDisabled) + g.Get("/coins/:mint/redeem/:code", programmableRewardsDisabled) + g.Post("/coins/:mint/redeem", programmableRewardsDisabled) + g.Post("/coins/:mint/redeem/:code", programmableRewardsDisabled) g.Post("/coins", app.v1CreateCoin) g.Post("/coins/:mint", app.v1UpdateCoin) diff --git a/api/v1_challenges_info.go b/api/v1_challenges_info.go index d093ba37..7c41c332 100644 --- a/api/v1_challenges_info.go +++ b/api/v1_challenges_info.go @@ -44,6 +44,9 @@ func weeklyPoolWindowStartAt(now time.Time) time.Time { } func (app *ApiServer) v1ChallengesInfo(c *fiber.Ctx) error { + if !isTrendingReward(c.Params("challengeId")) { + return fiber.NewError(fiber.StatusGone, "User challenges are no longer supported") + } params := GetChallengesInfoQueryParams{} if err := app.ParseAndValidateQueryParams(c, ¶ms); err != nil { return err diff --git a/api/v1_challenges_info_test.go b/api/v1_challenges_info_test.go index 0c991f0f..e1d29372 100644 --- a/api/v1_challenges_info_test.go +++ b/api/v1_challenges_info_test.go @@ -16,7 +16,7 @@ func TestV1ChallengesInfo(t *testing.T) { fixtures := database.FixtureMap{ "challenges": { { - "id": "challenge-aggregate", + "id": "tt", "type": "aggregate", "amount": "100000000", "active": true, @@ -31,7 +31,7 @@ func TestV1ChallengesInfo(t *testing.T) { }, "sol_reward_disbursements": { { - "challenge_id": "challenge-aggregate", + "challenge_id": "tt", "specifier": "spec-a", "signature": "sig-a", "instruction_index": 0, @@ -45,20 +45,20 @@ func TestV1ChallengesInfo(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) - status, body := testGet(t, app, "/v1/challenges/challenge-aggregate/info") + status, body := testGet(t, app, "/v1/challenges/tt/info") assert.Equal(t, 200, status) jsonAssert(t, body, map[string]any{ - "data.challenge_id": "challenge-aggregate", + "data.challenge_id": "tt", "data.type": "aggregate", "data.amount": "100000000", "data.weekly_pool": 100, "data.weekly_pool_remaining": 98, }) - status, body = testGet(t, app, "/v1/challenges/challenge-aggregate/info?weekly_pool_min_amount=99") + status, body = testGet(t, app, "/v1/challenges/tt/info?weekly_pool_min_amount=99") assert.Equal(t, 500, status) jsonAssert(t, body, map[string]any{ - "data.challenge_id": "challenge-aggregate", + "data.challenge_id": "tt", "data.weekly_pool_remaining": 98, }) } @@ -66,7 +66,7 @@ func TestV1ChallengesInfo(t *testing.T) { func TestV1ChallengesInfoInvalidWeeklyPoolMinAmount(t *testing.T) { app := emptyTestApp(t) - status, body := testGet(t, app, "/v1/challenges/any/info?weekly_pool_min_amount=-1") + status, body := testGet(t, app, "/v1/challenges/tt/info?weekly_pool_min_amount=-1") assert.Equal(t, 400, status) jsonAssert(t, body, map[string]any{ "error": "weekly_pool_min_amount is invalid", diff --git a/api/v1_challenges_undisbursed.go b/api/v1_challenges_undisbursed.go index 325f47f8..161c021e 100644 --- a/api/v1_challenges_undisbursed.go +++ b/api/v1_challenges_undisbursed.go @@ -1,8 +1,6 @@ package api import ( - "fmt" - "strings" "time" "api.audius.co/trashid" @@ -10,19 +8,6 @@ import ( "github.com/jackc/pgx/v5" ) -// openRewards are challenge IDs available to unverified users -var openRewards = []string{ - "dvl", // daily volume rewards - "t", // tastemaker - "tp", // trending playlists - "tt", // trending - "tut", // trending underground - "b", // audio match buy (from verified user) - "rd", // referred (by verified user) - "w", // remix contest winner (from verified user) - "cs", // cosign (from verified user) -} - type GetUndisbursedChallengesQueryParams struct { ChallengeID string `query:"challenge_id"` CompletedBlocknumber int `query:"completed_blocknumber"` @@ -41,13 +26,7 @@ func (app *ApiServer) v1ChallengesUndisbursed(c *fiber.Ctx) error { return err } - openRewardsPlaceholders := make([]string, len(openRewards)) - for i, reward := range openRewards { - openRewardsPlaceholders[i] = fmt.Sprintf("'%s'", reward) - } - openRewardsInClause := strings.Join(openRewardsPlaceholders, ", ") - - sql := fmt.Sprintf(` + sql := ` -- Get Undisbursed Challenges SELECT user_challenges.challenge_id, user_challenges.user_id, @@ -71,13 +50,12 @@ func (app *ApiServer) v1ChallengesUndisbursed(c *fiber.Ctx) error { WHERE challenge_disbursements.challenge_id IS NULL AND user_challenges.is_complete AND challenges.active + AND user_challenges.challenge_id IN ('tt', 'tut') AND users.is_current AND NOT users.is_deactivated AND (@user_id = 0 OR user_challenges.user_id = @user_id) AND (@completed_blocknumber = 0 OR user_challenges.completed_blocknumber > @completed_blocknumber) AND (@challenge_id = '' OR user_challenges.challenge_id = @challenge_id) - -- Filter by verification status: unverified users only see openRewards, verified users see all - AND (users.is_verified = true OR user_challenges.challenge_id IN (%s)) ORDER BY user_challenges.user_id ASC, user_challenges.challenge_id ASC, @@ -85,7 +63,7 @@ func (app *ApiServer) v1ChallengesUndisbursed(c *fiber.Ctx) error { LIMIT COALESCE(@limit, 100) OFFSET @offset ; - `, openRewardsInClause) + ` rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{ "user_id": userId, diff --git a/api/v1_challenges_undisbursed_test.go b/api/v1_challenges_undisbursed_test.go index 68b9186c..957985e8 100644 --- a/api/v1_challenges_undisbursed_test.go +++ b/api/v1_challenges_undisbursed_test.go @@ -1,72 +1,49 @@ package api import ( + "api.audius.co/api/dbv1" "context" + "github.com/stretchr/testify/require" "testing" - - "github.com/stretchr/testify/assert" ) -func TestGetUndisbursedChallenges(t *testing.T) { +func TestTrendingOnlyUndisbursed(t *testing.T) { app := testAppWithFixtures(t) - - // Set all users as verified so they can see all challenges ctx := context.Background() - _, err := app.pool.Exec(ctx, `UPDATE users SET is_verified = true WHERE is_current = true`) - assert.NoError(t, err) - - // Test basic functionality with no parameters - status, body := testGet(t, app, "/v1/challenges/undisbursed") - assert.Equal(t, 200, status) - jsonAssert(t, body, map[string]any{ - "data.0.challenge_id": "e", - "data.0.user_id": "eP7kD", - "data.0.specifier": "def", - "data.0.amount": "3", - "data.0.handle": "challenges_finished_streak", - "data.0.wallet": "0x001", - "data.0.cooldown_days": 0, - }) - - // Test filtering by user_id - status, body = testGetWithWallet(t, app, - "/v1/challenges/undisbursed?user_id=L50xn", - "0x8A2c4dcb2Eb9c2C5bc6E28310E4B07011D230C0A", - ) - assert.Equal(t, 200, status) - jsonAssert(t, body, map[string]any{ - "data.0.user_id": "L50xn", - }) - - // Test filtering by user_id with path parameter - status, body = testGet(t, app, "/v1/challenges/undisbursed/L50xn") - assert.Equal(t, 200, status) - jsonAssert(t, body, map[string]any{ - "data.0.user_id": "L50xn", - }) - - // Test filtering by challenge_id - status, body = testGet(t, app, "/v1/challenges/undisbursed?challenge_id=f") - assert.Equal(t, 200, status) - jsonAssert(t, body, map[string]any{ - "data.0.challenge_id": "f", - }) - - // Test pagination with limit and offset - status, body = testGet(t, app, "/v1/challenges/undisbursed?limit=1&offset=1") - assert.Equal(t, 200, status) - // Verify we get the second item - jsonAssert(t, body, map[string]any{ - "data.0.user_id": "L50xn", - }) - - // Test invalid parameters - status, _ = testGet(t, app, "/v1/challenges/undisbursed?limit=invalid") - assert.Equal(t, 400, status) - - status, _ = testGet(t, app, "/v1/challenges/undisbursed?offset=invalid") - assert.Equal(t, 400, status) - - status, _ = testGet(t, app, "/v1/challenges/undisbursed?completed_blocknumber=invalid") - assert.Equal(t, 400, status) + _, err := app.pool.Exec(ctx, ` + INSERT INTO challenges (id,type,amount,active,step_count,cooldown_days) VALUES + ('tt','trending','1000',true,1,0), ('tut','trending','1000',true,1,0) + ON CONFLICT (id) DO UPDATE SET active = true; + INSERT INTO user_challenges (challenge_id,user_id,specifier,is_complete,current_step_count,amount,completed_blocknumber,completed_at) + VALUES ('tt',402,'2026-11-13:1',true,1,1000,200,now()), ('tut',402,'2026-11-13:6',true,1,100,200,now()); + `) + require.NoError(t, err) + // Omitted IDs must not let a claim-all request pay old challenge fixtures. + rows, err := app.queries.GetUndisbursedChallenges(ctx, dbv1.GetUndisbursedChallengesParams{UserID: 402}) + require.NoError(t, err) + require.Len(t, rows, 2) + for _, row := range rows { + require.True(t, isTrendingReward(row.ChallengeID)) + } + // Explicit retired IDs are excluded at the SQL boundary as well. + rows, err = app.queries.GetUndisbursedChallenges(ctx, dbv1.GetUndisbursedChallengesParams{UserID: 402, ChallengeID: "e"}) + require.NoError(t, err) + require.Empty(t, rows) + status, body := testGet(t, app, "/v1/challenges/undisbursed?challenge_id=tt&completed_blocknumber=199") + require.Equal(t, 200, status) + jsonAssert(t, body, map[string]any{"data.#": float64(1), "data.0.specifier": "2026-11-13:1"}) + status, body = testGet(t, app, "/v1/challenges/undisbursed?challenge_id=e") + require.Equal(t, 200, status) + jsonAssert(t, body, map[string]any{"data.#": float64(0)}) + // Active flags and payments must apply to both listing and actual claiming. + _, err = app.pool.Exec(ctx, `UPDATE challenges SET active = false WHERE id = 'tt'; + INSERT INTO sol_reward_disbursements (signature,instruction_index,amount,slot,user_bank,challenge_id,specifier,recipient_eth_address) + VALUES ('paid-tut',0,10000000000,1,'test-bank','tut','2026-11-13:6','0x0000000000000000000000000000000000000001');`) + require.NoError(t, err) + rows, err = app.queries.GetUndisbursedChallenges(ctx, dbv1.GetUndisbursedChallengesParams{UserID: 402}) + require.NoError(t, err) + require.Empty(t, rows) + status, body = testGet(t, app, "/v1/challenges/undisbursed") + require.Equal(t, 200, status) + jsonAssert(t, body, map[string]any{"data.#": float64(0)}) } diff --git a/api/v1_claim_rewards.go b/api/v1_claim_rewards.go index 4d42f964..42db4d5b 100644 --- a/api/v1_claim_rewards.go +++ b/api/v1_claim_rewards.go @@ -830,6 +830,9 @@ func (app *ApiServer) v1ClaimRewards(c *fiber.Ctx) error { hashId := body.UserID challengeId := body.ChallengeID specifier := body.Specifier + if challengeId != "" && !isTrendingReward(challengeId) { + return fiber.NewError(fiber.StatusGone, "Only trending rewards can be claimed") + } if hashId == "" { return fiber.NewError(fiber.StatusBadRequest, "Missing user ID") diff --git a/api/v1_coins_redeem_test.go b/api/v1_coins_redeem_test.go index 6a794f8b..d8feed55 100644 --- a/api/v1_coins_redeem_test.go +++ b/api/v1_coins_redeem_test.go @@ -1,6 +1,7 @@ package api import ( + "context" "testing" "time" @@ -52,73 +53,14 @@ func TestV1CoinsRedeem(t *testing.T) { database.Seed(app.pool.Replicas[0], fixtures) - // Test /coins/:mint/redeem endpoint - should always return amount: 1 - t.Run("GET /coins/:mint/redeem returns amount 1", func(t *testing.T) { - status, body := testGet(t, app, "/v1/coins/TestMint123/redeem") - assert.Equal(t, 200, status) - - jsonAssert(t, body, map[string]any{ - "amount": 1, - }) - }) - - // Test /coins/:mint/redeem/:code endpoint with valid code - t.Run("GET /coins/:mint/redeem/:code with valid code", func(t *testing.T) { - status, body := testGet(t, app, "/v1/coins/TestMint123/redeem/CODE123") - assert.Equal(t, 200, status) - - jsonAssert(t, body, map[string]any{ - "code": "CODE123", - "amount": 100, - }) - }) - - // Test with another valid code - t.Run("GET /coins/:mint/redeem/:code with another valid code", func(t *testing.T) { - status, body := testGet(t, app, "/v1/coins/TestMint123/redeem/CODE456") - assert.Equal(t, 200, status) - - jsonAssert(t, body, map[string]any{ - "code": "CODE456", - "amount": 250, - }) - }) - - // Test with used code - t.Run("GET /coins/:mint/redeem/:code with used code returns 400 with error", func(t *testing.T) { - status, body := testGet(t, app, "/v1/coins/TestMint123/redeem/USEDCODE") - assert.Equal(t, 400, status) - - jsonAssert(t, body, map[string]any{ - "error": "used", - }) - }) - - // Test with non-existent code - t.Run("GET /coins/:mint/redeem/:code with non-existent code returns 400", func(t *testing.T) { - status, body := testGet(t, app, "/v1/coins/TestMint123/redeem/NONEXISTENT") - assert.Equal(t, 400, status) - jsonAssert(t, body, map[string]any{ - "error": "invalid", - }) - }) - - // Test with wrong mint for existing code - t.Run("GET /coins/:mint/redeem/:code with wrong mint returns 400", func(t *testing.T) { - status, body := testGet(t, app, "/v1/coins/WrongMint/redeem/CODE123") - assert.Equal(t, 400, status) - jsonAssert(t, body, map[string]any{ - "error": "invalid", - }) - }) - - // Test redeem endpoint with different mint - t.Run("GET /coins/:mint/redeem works for any mint", func(t *testing.T) { - status, body := testGet(t, app, "/v1/coins/AnyMintAddress/redeem") - assert.Equal(t, 200, status) - - jsonAssert(t, body, map[string]any{ - "amount": 1, - }) - }) + for _, path := range []string{"/v1/coins/TestMint123/redeem", "/v1/coins/TestMint123/redeem/CODE123", "/v1/coins/TestMint123/redeem/USEDCODE"} { + status, _ := testGet(t, app, path) + assert.Equal(t, 410, status) + status, _ = testPost(t, app, path, []byte(`{}`), nil) + assert.Equal(t, 410, status) + } + var remaining int + err := app.pool.QueryRow(context.Background(), "SELECT remaining_uses FROM reward_codes WHERE code = 'CODE123'").Scan(&remaining) + assert.NoError(t, err) + assert.Equal(t, 1, remaining) } diff --git a/api/v1_create_reward_code_test.go b/api/v1_create_reward_code_test.go index 34ce46f2..c2990f68 100644 --- a/api/v1_create_reward_code_test.go +++ b/api/v1_create_reward_code_test.go @@ -1,14 +1,10 @@ package api import ( - "context" "crypto/rand" - "encoding/json" "fmt" "testing" - "time" - "api.audius.co/database" "github.com/gagliardetto/solana-go" "github.com/stretchr/testify/assert" ) @@ -52,188 +48,10 @@ func buildSignedMemoTx(t *testing.T, privKey solana.PrivateKey, timestamp int64) return encoded } -func TestV1CreateRewardCode(t *testing.T) { - app := emptyTestApp(t) - - fixtures := database.FixtureMap{ - "artist_coins": { - { - "ticker": "TEST", - "decimals": 8, - "user_id": 1, - "mint": "TestMint123", - "name": "Test Coin", - "created_at": time.Now().Add(-time.Second), - }, - }, - } - - database.Seed(app.pool.Replicas[0], fixtures) - - originalKeys := app.config.RewardCodeAuthorizedKeys - defer func() { - app.config.RewardCodeAuthorizedKeys = originalKeys - }() - - t.Run("Successfully creates a reward code", func(t *testing.T) { - privKey, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - app.config.RewardCodeAuthorizedKeys = []string{privKey.PublicKey().String()} - - signedTx := buildSignedMemoTx(t, privKey, time.Now().UnixMilli()) - - body, err := json.Marshal(CreateRewardCodeRequest{ - SignedTransaction: signedTx, - Mint: "TestMint123", - Amount: 500, - }) - assert.NoError(t, err) - - var resp CreateRewardCodeResponse - status, respBody := testPost(t, app, "/v1/rewards/code", body, map[string]string{ - "Content-Type": "application/json", - }, &resp) - assert.Equal(t, 201, status, "Response body: %s", string(respBody)) - assert.Equal(t, "TestMint123", resp.Mint) - assert.Equal(t, int64(500), resp.Amount) - assert.Len(t, resp.Code, codeLength) - - var dbCode string - var dbRemainingUses int - err = app.pool.QueryRow(context.Background(), - "SELECT code, remaining_uses FROM reward_codes WHERE code = $1", resp.Code). - Scan(&dbCode, &dbRemainingUses) - assert.NoError(t, err) - assert.Equal(t, 1, dbRemainingUses) - }) - - t.Run("Successfully creates a reward code with second authorized signer", func(t *testing.T) { - _, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - privKey2, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - other, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - app.config.RewardCodeAuthorizedKeys = []string{other.PublicKey().String(), privKey2.PublicKey().String()} - - signedTx := buildSignedMemoTx(t, privKey2, time.Now().UnixMilli()) - - body, err := json.Marshal(CreateRewardCodeRequest{ - SignedTransaction: signedTx, - Mint: "TestMint123", - Amount: 500, - }) - assert.NoError(t, err) - - var resp CreateRewardCodeResponse - status, respBody := testPost(t, app, "/v1/rewards/code", body, map[string]string{ - "Content-Type": "application/json", - }, &resp) - assert.Equal(t, 201, status, "Response body: %s", string(respBody)) - }) - - t.Run("Unauthorized signer returns 403", func(t *testing.T) { - signerKey, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - otherKey, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - // Authorize a different key than the signer - app.config.RewardCodeAuthorizedKeys = []string{otherKey.PublicKey().String()} - - signedTx := buildSignedMemoTx(t, signerKey, time.Now().UnixMilli()) - - body, err := json.Marshal(CreateRewardCodeRequest{ - SignedTransaction: signedTx, - Mint: "TestMint123", - Amount: 100, - }) - assert.NoError(t, err) - - status, _ := testPost(t, app, "/v1/rewards/code", body, map[string]string{ - "Content-Type": "application/json", - }) - assert.Equal(t, 403, status) - }) - - t.Run("Missing signed_transaction returns 400", func(t *testing.T) { - body, err := json.Marshal(map[string]interface{}{ - "mint": "TestMint123", - "amount": 100, - }) - assert.NoError(t, err) - - status, _ := testPost(t, app, "/v1/rewards/code", body, map[string]string{ - "Content-Type": "application/json", - }) - assert.Equal(t, 400, status) - }) - - t.Run("Invalid base64 transaction returns 400", func(t *testing.T) { - privKey, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - app.config.RewardCodeAuthorizedKeys = []string{privKey.PublicKey().String()} - - body, err := json.Marshal(CreateRewardCodeRequest{ - SignedTransaction: "not-valid-base64!@#$", - Mint: "TestMint123", - Amount: 100, - }) - assert.NoError(t, err) - - status, _ := testPost(t, app, "/v1/rewards/code", body, map[string]string{ - "Content-Type": "application/json", - }) - assert.Equal(t, 400, status) - }) - - t.Run("Timestamp out of range returns 400", func(t *testing.T) { - privKey, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - app.config.RewardCodeAuthorizedKeys = []string{privKey.PublicKey().String()} - - // 24 hours in the past — outside the 12h drift window - staleTimestamp := time.Now().Add(-24 * time.Hour).UnixMilli() - signedTx := buildSignedMemoTx(t, privKey, staleTimestamp) - - body, err := json.Marshal(CreateRewardCodeRequest{ - SignedTransaction: signedTx, - Mint: "TestMint123", - Amount: 100, - }) - assert.NoError(t, err) - - status, _ := testPost(t, app, "/v1/rewards/code", body, map[string]string{ - "Content-Type": "application/json", - }) - assert.Equal(t, 400, status) - }) - - t.Run("Replay prevention: duplicate signature returns 400", func(t *testing.T) { - privKey, err := solana.NewRandomPrivateKey() - assert.NoError(t, err) - app.config.RewardCodeAuthorizedKeys = []string{privKey.PublicKey().String()} - - signedTx := buildSignedMemoTx(t, privKey, time.Now().UnixMilli()) - - body, err := json.Marshal(CreateRewardCodeRequest{ - SignedTransaction: signedTx, - Mint: "TestMint123", - Amount: 500, - }) - assert.NoError(t, err) - - // First request succeeds - status1, respBody1 := testPost(t, app, "/v1/rewards/code", body, map[string]string{ - "Content-Type": "application/json", - }) - assert.Equal(t, 201, status1, "First request should succeed. Body: %s", string(respBody1)) - - // Same transaction again should be rejected as a duplicate signature - status2, _ := testPost(t, app, "/v1/rewards/code", body, map[string]string{ - "Content-Type": "application/json", - }) - assert.Equal(t, 400, status2) - }) +func TestV1CreateRewardCodeRetired(t *testing.T) { + app := testAppWithFixtures(t) + status, _ := testPost(t, app, "/v1/rewards/code", []byte(`{}`), nil) + assert.Equal(t, 410, status) } func TestGenerateCode(t *testing.T) { diff --git a/api/v1_prizes_claim.go b/api/v1_prizes_claim.go index 52fe9860..e3cd6011 100644 --- a/api/v1_prizes_claim.go +++ b/api/v1_prizes_claim.go @@ -228,6 +228,7 @@ func (app *ApiServer) v1PrizesClaim(c *fiber.Ctx) error { SELECT prize_id, name, COALESCE(description, ''), weight, metadata FROM prizes WHERE is_active = true + AND COALESCE(metadata::jsonb->>'type', '') <> 'coin_airdrop' ORDER BY id `) if err != nil { @@ -479,6 +480,7 @@ func (app *ApiServer) v1Prizes(c *fiber.Ctx) error { SELECT prize_id, name, COALESCE(description, ''), weight, metadata FROM prizes WHERE is_active = true + AND COALESCE(metadata::jsonb->>'type', '') <> 'coin_airdrop' ORDER BY id `) if err != nil { diff --git a/api/v1_prizes_claim_test.go b/api/v1_prizes_claim_test.go index abe56928..a62b2f08 100644 --- a/api/v1_prizes_claim_test.go +++ b/api/v1_prizes_claim_test.go @@ -665,71 +665,24 @@ func TestV1PrizesClaim(t *testing.T) { "Content-Type": "application/json", }, &resp) - assert.Equal(t, 200, status, "Response body: %s", string(respBody)) - assert.Equal(t, prizeID, resp.PrizeID) - assert.Equal(t, prizeName, resp.PrizeName) - assert.Equal(t, validWallet, resp.Wallet) - assert.NotNil(t, resp.PrizeType, "Prize type should be set") - assert.Equal(t, "coin_airdrop", *resp.PrizeType) - assert.NotNil(t, resp.ActionData, "Action data should be set") - - // Parse action_data to verify it contains code and url - var actionData map[string]string - err = json.Unmarshal(resp.ActionData, &actionData) - assert.NoError(t, err, "Action data should be valid JSON") - assert.Contains(t, actionData, "code", "Action data should contain code") - assert.Contains(t, actionData, "url", "Action data should contain url") - assert.NotEmpty(t, actionData["code"], "Code should not be empty") - assert.NotEmpty(t, actionData["url"], "URL should not be empty") - assert.Contains(t, actionData["url"], "/coins/YAK/redeem/", "URL should contain redeem path") - assert.Contains(t, actionData["url"], actionData["code"], "URL should contain the code") - - // Verify it was saved to database with correct prize_type and action_data - var dbPrizeID, dbPrizeName, dbWallet, dbPrizeType string - var dbActionData json.RawMessage - err = app.writePool.QueryRow(ctx, ` - SELECT prize_id, prize_name, wallet, prize_type, action_data - FROM claimed_prizes - WHERE signature = $1 - `, signature).Scan(&dbPrizeID, &dbPrizeName, &dbWallet, &dbPrizeType, &dbActionData) - assert.NoError(t, err) - assert.Equal(t, prizeID, dbPrizeID) - assert.Equal(t, prizeName, dbPrizeName) - assert.Equal(t, validWallet, dbWallet) - assert.Equal(t, "coin_airdrop", dbPrizeType) - - // Verify action_data in database matches response - var dbActionDataMap map[string]string - err = json.Unmarshal(dbActionData, &dbActionDataMap) - assert.NoError(t, err) - assert.Equal(t, actionData["code"], dbActionDataMap["code"]) - assert.Equal(t, actionData["url"], dbActionDataMap["url"]) + assert.Equal(t, 500, status, "Response body: %s", string(respBody)) + assert.Contains(t, string(respBody), "No prizes available") + var claimed int + err = app.pool.QueryRow(ctx, "SELECT COUNT(*) FROM claimed_prizes WHERE signature = $1", signature).Scan(&claimed) + require.NoError(t, err) + assert.Zero(t, claimed, "An unavailable airdrop must not consume the prize claim") - // Verify reward code was created in reward_codes table with correct amount - var dbCode, dbMint string - var dbAmount int64 - var dbRemainingUses int - err = app.writePool.QueryRow(ctx, ` - SELECT code, mint, amount, remaining_uses - FROM reward_codes - WHERE code = $1 - `, actionData["code"]).Scan(&dbCode, &dbMint, &dbAmount, &dbRemainingUses) - assert.NoError(t, err, "Reward code should exist in database") - assert.Equal(t, actionData["code"], dbCode) - assert.Equal(t, yakMintAddress, dbMint) - assert.Equal(t, amount, dbAmount, "Reward code amount should match prize amount") - assert.Equal(t, 1, dbRemainingUses, "Remaining uses should be 1") } - t.Run("Success - 1 YAK coin airdrop prize with redeem code", func(t *testing.T) { + t.Run("Retired - 1 YAK coin airdrop", func(t *testing.T) { testCoinAirdropPrize(t, 1, "prize_1_yak", "1 YAK Airdrop", "airdrop_sig_1_yak") }) - t.Run("Success - 2 YAK coin airdrop prize with redeem code", func(t *testing.T) { + t.Run("Retired - 2 YAK coin airdrop", func(t *testing.T) { testCoinAirdropPrize(t, 2, "prize_2_yak", "2 YAK Airdrop", "airdrop_sig_2_yak") }) - t.Run("Success - 3 YAK coin airdrop prize with redeem code", func(t *testing.T) { + t.Run("Retired - 3 YAK coin airdrop", func(t *testing.T) { testCoinAirdropPrize(t, 3, "prize_3_yak", "3 YAK Airdrop", "airdrop_sig_3_yak") }) @@ -1106,7 +1059,7 @@ func TestV1PrizesClaim(t *testing.T) { status, body := testGet(t, app, "/v1/prizes", &response) assert.Equal(t, 200, status, "Response body: %s", string(body)) - assert.GreaterOrEqual(t, len(response.Data), 3, "Should return at least 3 prizes") + assert.GreaterOrEqual(t, len(response.Data), 2, "Non-coin prizes remain available") // Find the download prize var downloadPrize *PrizePublicResponse @@ -1152,17 +1105,7 @@ func TestV1PrizesClaim(t *testing.T) { break } } - require.NotNil(t, coinPrize, "Coin prize should be in response") - assert.Equal(t, "1 YAK", coinPrize.Name) - assert.Equal(t, "coin_airdrop", coinPrize.PublicMeta["type"]) - // Amount can be shown (it's just a number), but no redeem code/URL - if coinPrize.PublicMeta != nil { - assert.Equal(t, float64(1), coinPrize.PublicMeta["amount"]) - _, hasCode := coinPrize.PublicMeta["code"] - assert.False(t, hasCode, "code should not be in public metadata") - _, hasURL := coinPrize.PublicMeta["url"] - assert.False(t, hasURL, "url should not be in public metadata") - } + assert.Nil(t, coinPrize, "Retired coin airdrops must not be offered") }) t.Run("GET /v1/prizes - URLs not leaked in public endpoint", func(t *testing.T) { @@ -1196,7 +1139,7 @@ func TestV1PrizesClaim(t *testing.T) { } err = json.Unmarshal(body, &response) require.NoError(t, err) - assert.GreaterOrEqual(t, len(response.Data), 3, "Should return at least 3 prizes") + assert.GreaterOrEqual(t, len(response.Data), 2, "Non-coin prizes remain available") // Verify URLs are NOT in the response body assert.NotContains(t, string(body), downloadURL, "Download URL should not be leaked") @@ -1244,17 +1187,7 @@ func TestV1PrizesClaim(t *testing.T) { break } } - require.NotNil(t, coinPrize, "Coin prize should be in response") - assert.Equal(t, "1 YAK", coinPrize.Name) - if coinPrize.PublicMeta != nil { - assert.Equal(t, "coin_airdrop", coinPrize.PublicMeta["type"]) - // Amount can be shown (it's just a number), but no redeem code/URL - assert.Equal(t, float64(1), coinPrize.PublicMeta["amount"]) - _, hasCode := coinPrize.PublicMeta["code"] - assert.False(t, hasCode, "code should not be in public metadata") - _, hasURL := coinPrize.PublicMeta["url"] - assert.False(t, hasURL, "url should not be in public metadata") - } + assert.Nil(t, coinPrize, "Retired coin airdrops must not be offered") }) t.Run("GET /v1/wallet/:wallet/prizes - Success - returns claimed prizes (public, no auth required)", func(t *testing.T) { diff --git a/api/v1_users_challenges.go b/api/v1_users_challenges.go index 4b4e7a55..a14fee38 100644 --- a/api/v1_users_challenges.go +++ b/api/v1_users_challenges.go @@ -1,200 +1,9 @@ package api -import ( - "api.audius.co/trashid" - "github.com/gofiber/fiber/v2" - "github.com/jackc/pgx/v5" - "github.com/jackc/pgx/v5/pgtype" -) +import "github.com/gofiber/fiber/v2" +// User challenges are retired. Preserve the response shape for older clients. +// Weekly trending awards remain available through the restricted batch API. func (app *ApiServer) v1UsersChallenges(c *fiber.Ctx) error { - sql := ` - -- Start with the user ID and verification status - WITH user_row AS ( - SELECT - user_id, - is_verified - FROM users - WHERE users.is_current - AND users.user_id = @userId - ), - - -- Pre-filter to their user challenges - user_challenges_filtered AS ( - SELECT * FROM user_challenges JOIN user_row USING (user_id) - ), - - -- Start with the list of all active challenges, and then - -- apply the user's user challenges and disbursements. - -- verified-only challenges if not verified - -- and non-verified only challenges if verified. - all_user_challenges AS ( - SELECT challenges.id AS challenge_id, - user_row.user_id, - COALESCE(user_challenges_filtered.specifier, '') AS specifier, - COALESCE(user_challenges_filtered.is_complete, false) AS is_complete, - challenges.active AS is_active, - (reward_disbursements.slot IS NOT NULL) AS is_disbursed, - COALESCE(user_challenges_filtered.current_step_count, 0) AS current_step_count, - challenges.step_count AS max_steps, - challenges.type AS challenge_type, - COALESCE(challenges.amount::BIGINT, 0) AS amount, - COALESCE(user_challenges_filtered.amount, 0) AS user_amount, - COALESCE(reward_disbursements.amount, 0) / 100000000 AS disbursed_amount, - COALESCE(challenges.cooldown_days, 0) AS cooldown_days, - user_challenges_filtered.created_at - FROM challenges - LEFT JOIN user_challenges_filtered ON challenges.id = user_challenges_filtered.challenge_id - CROSS JOIN user_row - -- Match by (challenge_id, specifier), not user: a specifier is disbursed once - -- on-chain, so a paid reward is never shown claimable even if paid to another user. - LEFT JOIN sol_reward_disbursements AS reward_disbursements - ON user_challenges_filtered.challenge_id = reward_disbursements.challenge_id - AND user_challenges_filtered.specifier = reward_disbursements.specifier - WHERE challenges.active - AND NOT (challenges.id IN ('rv', 's') AND NOT user_row.is_verified) - AND NOT (challenges.id IN ('r') AND user_row.is_verified) - ), - - -- Get the most recent listen streak summary - current_listen_streak AS ( - SELECT - listen_streak, - last_listen_date - FROM challenge_listen_streak - JOIN user_row USING (user_id) - WHERE NOW() - last_listen_date < INTERVAL '16' HOUR - ) - - -- Non-aggregate challenges just use the values as-is - SELECT challenge_id, - user_id, - specifier, - is_complete, - is_active, - is_disbursed, - current_step_count, - max_steps, - challenge_type, - amount, - disbursed_amount, - cooldown_days - FROM all_user_challenges - WHERE challenge_type != 'aggregate' - - -- Aggregate challenges besides endless listen streak and oneshot need - -- to be rolled up. Sum the amounts, check for completion, etc. - UNION ALL ( - SELECT challenge_id, - user_id, - '' AS specifier, - COALESCE(SUM(user_amount) >= max_steps, false) AS is_complete, - is_active, - false AS is_disbursed, - SUM(user_amount) AS current_step_count, - max_steps, - challenge_type, - amount, - SUM(disbursed_amount) AS disbursed_amount, - cooldown_days - FROM all_user_challenges - WHERE challenge_type = 'aggregate' - AND challenge_id NOT IN ('e', 'o', 'dvl') - GROUP BY challenge_id, - user_id, - max_steps, - is_active, - challenge_type, - amount, - cooldown_days - ) - - -- Endless listen streak needs some custom logic to get step count, amount - UNION ALL ( - SELECT DISTINCT ON (challenge_id) - challenge_id, - user_id, - '' AS specifier, - COALESCE(COALESCE(current_listen_streak.listen_streak, 0) > 0 AND all_user_challenges.is_complete, false) AS is_complete, - is_active, - false AS is_disbursed, - COALESCE( - current_listen_streak.listen_streak, - 0 - ) AS current_step_count, - max_steps, - challenge_type, - all_user_challenges.amount, - (SELECT SUM(disbursed_amount) - FROM all_user_challenges - WHERE challenge_id = 'e' - ) AS disbursed_amount, - cooldown_days - FROM all_user_challenges - LEFT JOIN current_listen_streak ON 1=1 - WHERE all_user_challenges.challenge_id = 'e' - ORDER BY all_user_challenges.challenge_id, created_at DESC - ) - - -- Oneshot is unique per user, always complete, amount 1 if user challenge exists. - UNION ALL ( - SELECT challenge_id, - user_id, - '' AS specifier, - COALESCE(SUM(user_amount) > 0, false) AS is_complete, - is_active, - false AS is_disbursed, - SUM(user_amount) AS current_step_count, - CASE WHEN SUM(user_amount) = 0 - THEN max_steps - ELSE SUM(user_amount) - END AS max_steps, - challenge_type, - 1 AS amount, - SUM(disbursed_amount) AS disbursed_amount, - cooldown_days - FROM all_user_challenges - WHERE challenge_id = 'o' - GROUP BY challenge_id, - user_id, - max_steps, - is_active, - challenge_type, - amount, - cooldown_days - ) - ORDER BY challenge_id - ; - ` - - rows, err := app.pool.Query(c.Context(), sql, pgx.NamedArgs{ - "userId": app.getUserId(c), - }) - if err != nil { - return err - } - - type GetUserChallengesRow struct { - ChallengeID string `json:"challenge_id"` - UserID trashid.HashId `json:"user_id"` - Specifier string `json:"specifier"` - IsComplete bool `json:"is_complete"` - IsActive bool `json:"is_active"` - IsDisbursed bool `json:"is_disbursed"` - CurrentStepCount int32 `json:"current_step_count"` - MaxSteps pgtype.Int4 `json:"max_steps"` - ChallengeType string `json:"challenge_type"` - Amount string `json:"amount"` - DisbursedAmount uint64 `json:"disbursed_amount"` - CooldownDays int32 `json:"cooldown_days"` - } - - res, err := pgx.CollectRows(rows, pgx.RowToStructByName[GetUserChallengesRow]) - if err != nil { - return err - } - - return c.JSON(fiber.Map{ - "data": res, - }) + return c.JSON(fiber.Map{"data": []any{}}) } diff --git a/api/v1_users_challenges_test.go b/api/v1_users_challenges_test.go index e0355966..be857499 100644 --- a/api/v1_users_challenges_test.go +++ b/api/v1_users_challenges_test.go @@ -1,86 +1,15 @@ package api import ( - "context" - "testing" - "github.com/stretchr/testify/assert" + "testing" ) -func TestUserChallenges(t *testing.T) { +func TestUserChallengesRetired(t *testing.T) { app := testAppWithFixtures(t) - status, body := testGet(t, app, "/v1/users/eYVJn/challenges") - assert.Equal(t, 200, status) - jsonAssert(t, body, map[string]any{ - "data.0.challenge_id": "e", - "data.0.user_id": "eYVJn", - "data.0.amount": "1", - "data.0.current_step_count": "2", - "data.0.is_complete": false, - }) - - // Completed endless challenge - status, body = testGet(t, app, "/v1/users/eP7kD/challenges") - assert.Equal(t, 200, status) - jsonAssert(t, body, map[string]any{ - "data.0.challenge_id": "e", - "data.0.user_id": "eP7kD", - "data.0.amount": "1", - "data.0.current_step_count": "3", - "data.0.is_complete": true, - }) - - // Continued endless challenge - status, body = testGet(t, app, "/v1/users/L50xn/challenges") - assert.Equal(t, 200, status) - jsonAssert(t, body, map[string]any{ - "data.0.challenge_id": "e", - "data.0.user_id": "L50xn", - "data.0.amount": "1", - "data.0.current_step_count": "5", - "data.0.is_complete": true, - }) - - // Reset endless challenge - status, body = testGet(t, app, "/v1/users/eblKL/challenges") - assert.Equal(t, 200, status) - jsonAssert(t, body, map[string]any{ - "data.0.challenge_id": "e", - "data.0.user_id": "eblKL", - "data.0.amount": "1", - "data.0.current_step_count": "0", - "data.0.is_complete": false, - }) -} - -// A reward that has been disbursed for a (challenge_id, specifier) must show as -// disbursed to the user who completed that specifier, even when the on-chain -// recipient wallet resolves to a different user. Disbursements are deduped by -// (challenge_id, specifier) on-chain, so a paid specifier can never be claimed -// again — surfacing it as still-claimable produces a stuck reward that errors -// on claim. -func TestUserChallengesDisbursedToDifferentUser(t *testing.T) { - app := testAppWithFixtures(t) - ctx := context.Background() - - // User 402 (L50xn) completed boolean challenge "f" with specifier "fff". - // Record an on-chain disbursement for that specifier whose recipient wallet - // belongs to a different user (user 1, rayjacobson). - _, err := app.pool.Exec(ctx, ` - INSERT INTO sol_reward_disbursements - (signature, instruction_index, amount, slot, user_bank, challenge_id, specifier, recipient_eth_address) - VALUES - ('sig-fff', 0, 100000000, 1, 'user-bank-x', 'f', 'fff', '0x7d273271690538cf855e5b3002a0dd8c154bb060') - `) - assert.NoError(t, err) - - status, body := testGet(t, app, "/v1/users/L50xn/challenges") - assert.Equal(t, 200, status) - // Challenges are ordered by challenge_id, so "f" follows the rolled-up "e". - jsonAssert(t, body, map[string]any{ - "data.1.challenge_id": "f", - "data.1.is_complete": true, - "data.1.is_disbursed": true, - "data.1.disbursed_amount": float64(1), - }) + for _, user := range []string{"eYVJn", "eP7kD", "L50xn"} { + status, body := testGet(t, app, "/v1/users/"+user+"/challenges") + assert.Equal(t, 200, status) + jsonAssert(t, body, map[string]any{"data.#": float64(0)}) + } } diff --git a/ddl/functions/handle_user_challenges.sql b/ddl/functions/handle_user_challenges.sql index e95d4fb2..18f42a28 100644 --- a/ddl/functions/handle_user_challenges.sql +++ b/ddl/functions/handle_user_challenges.sql @@ -4,6 +4,11 @@ declare existing_notification bigint; listen_streak_value integer; begin + -- Retired challenges must not generate new claim prompts, including writes + -- from an older worker during a rolling deployment. + if new.challenge_id not in ('tt', 'tut') then + return new; + end if; if (new.is_complete = true) then -- attempt to insert a new notification, ignoring conflicts select challenges.cooldown_days into cooldown_days from challenges where id = new.challenge_id; diff --git a/ddl/migrations/0246_retire_user_challenges.sql b/ddl/migrations/0246_retire_user_challenges.sql new file mode 100644 index 00000000..098ab632 --- /dev/null +++ b/ddl/migrations/0246_retire_user_challenges.sql @@ -0,0 +1,2 @@ +-- Preserve award/payment history while retiring non-trending challenges. +UPDATE challenges SET active = false WHERE id NOT IN ('tt', 'tut'); diff --git a/jobs/index_challenges.go b/jobs/index_challenges.go index 677fcbda..e71e3861 100644 --- a/jobs/index_challenges.go +++ b/jobs/index_challenges.go @@ -42,28 +42,8 @@ func NewIndexChallengesJob(cfg config.Config, pool database.DbPool) *IndexChalle pool: pool, logger: logging.NewZapLogger(cfg).Named("IndexChallengesJob"), processors: []challenges.Processor{ - // Phase 1 - &challenges.TrackUploadProcessor{}, - &challenges.FirstPlaylistProcessor{}, - &challenges.ProfileCompletionProcessor{}, - &challenges.ProfileVerifiedProcessor{}, - &challenges.ListenStreakProcessor{}, - challenges.NewPlayCountMilestonesProcessor(), challenges.NewTrendingTrackProcessor(), challenges.NewTrendingUndergroundProcessor(), - // Phase 2 - &challenges.FirstWeeklyCommentProcessor{}, - &challenges.CommentPinProcessor{}, - &challenges.CosignProcessor{}, - &challenges.TastemakerProcessor{}, - &challenges.RemixContestWinnerProcessor{}, - challenges.NewAudioMatchingBuyerProcessor(), - challenges.NewAudioMatchingSellerProcessor(), - // Phase 3 (signal-driven) - &challenges.MobileInstallProcessor{}, - challenges.NewReferralProcessor(), - challenges.NewVerifiedReferralProcessor(), - &challenges.ReferredProcessor{}, }, } } diff --git a/jobs/index_challenges_test.go b/jobs/index_challenges_test.go new file mode 100644 index 00000000..c0089edf --- /dev/null +++ b/jobs/index_challenges_test.go @@ -0,0 +1,14 @@ +package jobs + +import ( + "api.audius.co/config" + "github.com/stretchr/testify/require" + "testing" +) + +func TestOnlyWeeklyTrendingProcessorsAreScheduled(t *testing.T) { + job := NewIndexChallengesJob(config.Config{LogLevel: "fatal"}, nil) + require.Len(t, job.processors, 2) + require.Equal(t, "tt", job.processors[0].ChallengeID()) + require.Equal(t, "tut", job.processors[1].ChallengeID()) +}