From b9f4e33bb9218301c702269c1104a0527eed213c Mon Sep 17 00:00:00 2001 From: Aashutosh Rathi Date: Tue, 2 Jul 2024 23:06:27 +0530 Subject: [PATCH] feat: addPlayer (closes #27) --- deployment.json | 6 +++--- src/index.ts | 11 +++++++++-- src/stackr/actions.ts | 7 +++++++ src/stackr/transitions.ts | 18 ++++++++++++++++-- tests/mru-4.test.ts | 2 +- tests/mru-6.test.ts | 2 +- 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/deployment.json b/deployment.json index 6bad6ac..8653899 100644 --- a/deployment.json +++ b/deployment.json @@ -1,5 +1,5 @@ { - "appId": 8, - "appInbox": "0xa2a5d72B29C9Ccdc2c6594Bf9eD92cBd5A3bAf58", + "appId": 128, + "appInbox": "0x31240E2114f87AFA66dD270F414F838b36785B7d", "chainId": 69420 -} +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 72ed995..a0c104e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,12 +33,13 @@ export const stfSchemaMap = { logGoal: schemas.logGoal, logFoul: schemas.logGoal, logBlock: schemas.logGoal, - startPenaltyShootout: schemas.startMatch, + penaltyShootout: schemas.startMatch, logPenaltyHit: schemas.logGoal, logPenaltyMiss: schemas.logGoal, - removeGoal: schemas.logGoal, endMatch: schemas.endMatch, logByes: schemas.logByes, + addPlayer: schemas.addPlayer, + removeGoal: schemas.logGoal, }; const main = async () => { @@ -191,6 +192,12 @@ const main = async () => { }); }); + if (process.env.NODE_ENV === "sandbox") { + app.get("/restart", () => { + process.exit(1); + }); + } + // TODO: Break this route into a separate routes and handle validation pre-STF only app.post("/:reducerName", async (req: Request, res: Response) => { const { reducerName } = req.params; diff --git a/src/stackr/actions.ts b/src/stackr/actions.ts index ad11b17..54cd706 100644 --- a/src/stackr/actions.ts +++ b/src/stackr/actions.ts @@ -24,10 +24,17 @@ const teamActionSchema = new ActionSchema("teamAction", { ...baseTimeStamp, }); +const addPlayerSchema = new ActionSchema("addPlayer", { + teamId: SolidityType.UINT, + playerName: SolidityType.STRING, + ...baseTimeStamp, +}); + export const schemas = { startMatch: matchAction, endMatch: matchAction, logGoal: matchPlayerAction, startTournament: startTournamentSchema, logByes: teamActionSchema, + addPlayer: addPlayerSchema, }; diff --git a/src/stackr/transitions.ts b/src/stackr/transitions.ts index 324c5e0..6349f03 100644 --- a/src/stackr/transitions.ts +++ b/src/stackr/transitions.ts @@ -274,7 +274,7 @@ const startMatch: STF = { }, }; -const startPenaltyShootout: STF = { +const penaltyShootout: STF = { handler: ({ state, inputs, block }) => { if (hasTournamentEnded(state)) { throw new Error("TOURNAMENT_ENDED"); @@ -440,9 +440,22 @@ const logByes: STF = { }, }; +const addPlayer: STF = { + handler: ({ state, inputs }) => { + const { teamId, playerName } = inputs; + state.players.push({ + id: state.players.length + 1, + name: playerName, + teamId, + }); + + return state; + }, +}; + export const transitions: Transitions = { startMatch, - startPenaltyShootout, + penaltyShootout, endMatch, logGoal, removeGoal, @@ -452,4 +465,5 @@ export const transitions: Transitions = { logFoul, logPenaltyHit, logPenaltyMiss, + addPlayer, }; diff --git a/tests/mru-4.test.ts b/tests/mru-4.test.ts index ed6235e..242df4f 100644 --- a/tests/mru-4.test.ts +++ b/tests/mru-4.test.ts @@ -267,7 +267,7 @@ describe("League with 4 teams", async () => { ); // start a penalty shootout - await performAction("startPenaltyShootout", { + await performAction("penaltyShootout", { matchId, }); diff --git a/tests/mru-6.test.ts b/tests/mru-6.test.ts index bf8214b..4d7fabb 100644 --- a/tests/mru-6.test.ts +++ b/tests/mru-6.test.ts @@ -350,7 +350,7 @@ describe("League with 6 teams", async () => { ); // start a penalty shootout - await performAction("startPenaltyShootout", { + await performAction("penaltyShootout", { matchId, });