Skip to content

Commit

Permalink
Add rootHashes endpoint to oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
area authored and kronosapiens committed Nov 25, 2024
1 parent eabd5c1 commit 3f8df23
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/reputation-miner/ReputationMinerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class ReputationMinerClient {
return res.status(200).send({ active: activeAddr, inactive: inactiveAddr });
});

this._app.get("/rootHashes", async (req, res) => {
const currentRootHash = await this._miner.previousReputationTree.getRootHash();
const nextRootHash = await this._miner.reputationTree.getRootHash();
return res.status(200).send({ currentRootHash, nextRootHash });
});

// Query users who have given reputation in colony
this._app.get("/:rootHash/:colonyAddress/:skillId/", cache('1 hour'), async (req, res) => {
if (
Expand Down
16 changes: 15 additions & 1 deletion test/reputation-system/client-core-functionality.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,22 @@ hre.__SOLIDITY_COVERAGE_RUNNING
const url = `http://127.0.0.1:3000/0x0000/NotAValidAddress/1/all`;
const res = await request(url);
expect(res.statusCode).to.equal(400);
expect(res.statusCode).to.equal(400);
expect(JSON.parse(res.body).message).to.equal("One of the parameters was incorrect");
});

it("should correctly respond to a request for the currently known states", async () => {
await client.initialise(colonyNetwork.address, 1);
await metaColony.setReputationMiningCycleReward(100);

const url = `http://127.0.0.1:3000/rootHashes`;
const res = await request(url);
expect(res.statusCode).to.equal(200);
const nextRootHash = await client._miner.reputationTree.getRootHash();
const currentRootHash = await client._miner.previousReputationTree.getRootHash();
const response = JSON.parse(res.body);

expect(response.currentRootHash).to.equal(currentRootHash);
expect(response.nextRootHash).to.equal(nextRootHash);
});
});
});

0 comments on commit 3f8df23

Please sign in to comment.