Skip to content

Commit

Permalink
Competition indexing (#478)
Browse files Browse the repository at this point in the history
* Fix #476

* Fix #470

* Bump version

* Fix

* Rename subbmisions -> suggestions

* Rename

* Rename
  • Loading branch information
ben-kaufman committed Feb 13, 2020
1 parent 52669fd commit e4b286d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/subgraph",
"version": "0.0.38-2",
"version": "0.0.38-3",
"author": "DAOstack (https://www.daostack.io)",
"license": "GPL-3.0",
"description": "A caching layer for daostack using The Graph",
Expand Down
7 changes: 5 additions & 2 deletions src/mappings/Competition/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ export function handleNewCompetitionProposal(event: NewCompetitionProposal): voi
competitionProposal.createdAt = event.block.timestamp;
competitionProposal.suggestions = [];
competitionProposal.winningSuggestions = [];
competitionProposal.totalSubmissions = BigInt.fromI32(0);
competitionProposal.totalSuggestions = BigInt.fromI32(0);
competitionProposal.totalVotes = BigInt.fromI32(0);
competitionProposal.numberOfWinningSuggestions = BigInt.fromI32(0);
competitionProposal.admin = event.params._admin;
competitionProposal.save();
let proposal = Proposal.load(competitionProposal.id);
if (proposal != null) {
Expand Down Expand Up @@ -81,7 +83,7 @@ export function handleNewSuggestion(event: NewSuggestion): void {
let competitionSuggestions = competitionProposal.suggestions;
competitionSuggestions.push(competitionSuggestion.id);
competitionProposal.suggestions = competitionSuggestions;
competitionProposal.totalSubmissions = competitionProposal.totalSubmissions.plus(BigInt.fromI32(1));
competitionProposal.totalSuggestions = competitionProposal.totalSuggestions.plus(BigInt.fromI32(1));
competitionProposal.save();
}
}
Expand Down Expand Up @@ -178,6 +180,7 @@ export function handleNewVote(event: NewVote): void {
}
competitionProposal.winningSuggestions = winningSuggestions;
competitionProposal.totalVotes = competitionProposal.totalVotes.plus(BigInt.fromI32(1));
competitionProposal.numberOfWinningSuggestions = BigInt.fromI32(winningSuggestions.length);
competitionProposal.save();
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/mappings/Competition/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ type CompetitionProposal @entity {
winningSuggestions: [CompetitionSuggestion!]
votes: [CompetitionVote!] @derivedFrom(field: "proposal")
createdAt: BigInt!
totalSubmissions: BigInt!
totalSuggestions: BigInt!
totalVotes: BigInt!
numberOfWinningSuggestions: BigInt!
admin: Bytes!
}

type CompetitionSuggestion @entity {
Expand Down
20 changes: 14 additions & 6 deletions test/0.0.1-rc.41/Competition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ describe('Competition', () => {
winningSuggestions {
suggestionId
}
totalSubmissions
totalSuggestions
totalVotes
numberOfWinningSuggestions
admin
}
}`);

Expand Down Expand Up @@ -203,8 +205,10 @@ describe('Competition', () => {
votes: [],
createdAt: timestampPropose.toString(),
winningSuggestions: [],
totalSubmissions: '0',
totalSuggestions: '0',
totalVotes: '0',
numberOfWinningSuggestions: '0',
admin: '0x0000000000000000000000000000000000000000',
});

// Pass the ContributionReward proposal to approve the competition
Expand Down Expand Up @@ -342,8 +346,9 @@ describe('Competition', () => {
winningSuggestions {
suggestionId
}
totalSubmissions
totalSuggestions
totalVotes
numberOfWinningSuggestions
}
}`;

Expand All @@ -353,8 +358,9 @@ describe('Competition', () => {
{ suggestionId: suggestionId2.toString() },
],
winningSuggestions: [],
totalSubmissions: '2',
totalSuggestions: '2',
totalVotes: '0',
numberOfWinningSuggestions: '0',
});

// Get rep balance
Expand Down Expand Up @@ -456,15 +462,17 @@ describe('Competition', () => {
let proposalVotesSnapshotBlockQuery = `{
competitionProposal(id: "${proposalId}") {
snapshotBlock
totalSubmissions
totalSuggestions
totalVotes
numberOfWinningSuggestions
}
}`;

expect((await sendQuery(proposalVotesSnapshotBlockQuery)).competitionProposal).toMatchObject({
snapshotBlock: blockNumberVote1.toString(),
totalSubmissions: '2',
totalSuggestions: '2',
totalVotes: '3',
numberOfWinningSuggestions: '2',
});

let proposalVotesWinningSuggestionsQuery = `{
Expand Down

0 comments on commit e4b286d

Please sign in to comment.