Skip to content

Commit 5b720c8

Browse files
committed
SwanDebate.sol: Add named return/remove redundant parts
1 parent 618518e commit 5b720c8

File tree

2 files changed

+17
-43
lines changed

2 files changed

+17
-43
lines changed

src/SwanDebate.sol

+15-16
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ contract SwanDebate is Ownable, Pausable {
204204
CORE FUNCTIONS
205205
//////////////////////////////////////////////////////////////*/
206206
/// @notice Register a new agent with their system prompt
207-
/// @return The ID of the newly registered agent
208-
function registerAgent() external onlyOwner returns (uint256) {
207+
/// @return newAgentId The ID of the newly registered agent
208+
function registerAgent() external onlyOwner returns (uint256 newAgentId) {
209209
uint256 agentId = nextAgentId++;
210210
agents[agentId] = Agent({isRegistered: true, wins: 0});
211211

@@ -217,13 +217,13 @@ contract SwanDebate is Ownable, Pausable {
217217
/// @param _agent1Id ID of the first agent
218218
/// @param _agent2Id ID of the second agent
219219
/// @param _contest Address of the JokeRace contest
220-
/// @return The address of the initialized contest
220+
/// @return contestAddress The address of the initialized contest
221221
/// @dev Verifies agent registration and contest state before initialization
222222
function initializeDebate(uint256 _agent1Id, uint256 _agent2Id, address _contest)
223223
external
224224
onlyOwner
225225
whenNotPaused
226-
returns (address)
226+
returns (address contestAddress)
227227
{
228228
if (!agents[_agent1Id].isRegistered || !agents[_agent2Id].isRegistered) {
229229
revert AgentNotRegistered();
@@ -291,9 +291,8 @@ contract SwanDebate is Ownable, Pausable {
291291
/// @param _contest Address of the JokeRace contest
292292
/// @param _agentId ID of the agent providing output
293293
/// @param _taskId ID of the oracle task
294-
/// @param _output Output data from the oracle
295294
/// @dev Only owner can record outputs and both agents must provide output to complete a round
296-
function recordOracleOutput(address _contest, uint256 _agentId, uint256 _taskId, bytes calldata _output)
295+
function recordOracleOutput(address _contest, uint256 _agentId, uint256 _taskId)
297296
external
298297
onlyOwner
299298
whenNotPaused
@@ -309,10 +308,10 @@ contract SwanDebate is Ownable, Pausable {
309308
RoundData storage round = debate.rounds[debate.currentRound];
310309
if (_agentId == debate.agent1Id) {
311310
round.agent1TaskId = _taskId;
312-
round.agent1Output = _output;
311+
round.agent1Output = coordinator.getBestResponse(_taskId).output;
313312
} else if (_agentId == debate.agent2Id) {
314313
round.agent2TaskId = _taskId;
315-
round.agent2Output = _output;
314+
round.agent2Output = coordinator.getBestResponse(_taskId).output;
316315
} else {
317316
revert InvalidAgent(_agentId);
318317
}
@@ -370,23 +369,23 @@ contract SwanDebate is Ownable, Pausable {
370369
//////////////////////////////////////////////////////////////*/
371370
/// @notice Get an agent's information by their ID
372371
/// @param _agentId The ID of the agent to query
373-
/// @return The Agent struct containing the agent's information
374-
function getAgent(uint256 _agentId) external view returns (Agent memory) {
372+
/// @return agentInfo The Agent struct containing the agent's information
373+
function getAgent(uint256 _agentId) external view returns (Agent memory agentInfo) {
375374
return agents[_agentId];
376375
}
377376

378377
/// @notice Retrieves round data for a specific debate round
379378
/// @param _contest Address of the JokeRace contest
380379
/// @param _round Round number to query
381-
/// @return RoundData structure containing the round's information
382-
function getRoundForDebate(address _contest, uint256 _round) external view returns (RoundData memory) {
380+
/// @return roundData RoundData structure containing the round's information
381+
function getRoundForDebate(address _contest, uint256 _round) external view returns (RoundData memory roundData) {
383382
return debates[_contest].rounds[_round];
384383
}
385384

386385
/// @notice Gets the latest round data for a debate
387386
/// @param _contest Address of the JokeRace contest
388-
/// @return RoundData structure containing the current round's information
389-
function getLatestRoundForDebate(address _contest) external view returns (RoundData memory) {
387+
/// @return latestRound RoundData structure containing the current round's information
388+
function getLatestRoundForDebate(address _contest) external view returns (RoundData memory latestRound) {
390389
return debates[_contest].rounds[debates[_contest].currentRound];
391390
}
392391

@@ -407,8 +406,8 @@ contract SwanDebate is Ownable, Pausable {
407406

408407
/// @notice Gets all debates an agent has participated in
409408
/// @param _agentId ID of the agent
410-
/// @return Array of contest addresses the agent participated in
411-
function getAgentDebates(uint256 _agentId) external view returns (address[] memory) {
409+
/// @return agentContests Array of contest addresses the agent participated in
410+
function getAgentDebates(uint256 _agentId) external view returns (address[] memory agentContests) {
412411
return agentDebates[_agentId];
413412
}
414413

test/SwanDebateTest.t.sol

+2-27
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,7 @@ import {console} from "forge-std/Test.sol";
1313
import {MockJokeRaceContest} from "./mock/MockJokeRaceContest.sol";
1414
import {MockOracle} from "./mock/MockOracle.sol";
1515

16-
contract SwanDebateTest is Test {
17-
SwanDebate public debate;
18-
MockJokeRaceContest public jokeRace;
19-
MockOracle public oracle;
20-
LLMOracleCoordinator public coordinator;
21-
22-
address public owner;
23-
24-
event DebateInitialized(address indexed contest, uint256 indexed agent1Id, uint256 indexed agent2Id);
25-
event OracleOutputRecorded(
26-
address indexed contest, uint256 indexed round, uint256 indexed agentId, uint256 taskId, bytes output
27-
);
28-
event DebateTerminated(address indexed contest, uint256 winnerId, uint256 finalVotes);
29-
30-
function setUp() public {
31-
owner = address(this);
32-
33-
oracle = new MockOracle();
34-
jokeRace = new MockJokeRaceContest();
35-
coordinator = new LLMOracleCoordinator();
36-
37-
debate = new SwanDebate(address(coordinator));
38-
}
39-
}
40-
41-
contract SwanDebateIntegrationTest is Helper {
16+
contract SwanDebateTest is Helper {
4217
SwanDebate public debate;
4318
MockJokeRaceContest public jokeRace;
4419
LLMOracleCoordinator public coordinator;
@@ -160,7 +135,7 @@ contract SwanDebateIntegrationTest is Helper {
160135

161136
vm.warp(block.timestamp + 1);
162137

163-
debate.recordOracleOutput(contest, agentId, taskId, TEST_OUTPUT);
138+
debate.recordOracleOutput(contest, agentId, taskId);
164139
}
165140

166141
function test_CompleteDebateFlow() external fund addValidatorsToWhitelist registerOracles {

0 commit comments

Comments
 (0)