Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Competition indexing #478

Merged
merged 8 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions src/mappings/Competition/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function handleNewCompetitionProposal(event: NewCompetitionProposal): voi
competitionProposal.winningSuggestions = [];
competitionProposal.totalSubmissions = BigInt.fromI32(0);
ben-kaufman marked this conversation as resolved.
Show resolved Hide resolved
competitionProposal.totalVotes = BigInt.fromI32(0);
competitionProposal.numWinningSuggestions = BigInt.fromI32(0);
competitionProposal.admin = event.params._admin;
competitionProposal.save();
let proposal = Proposal.load(competitionProposal.id);
if (proposal != null) {
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.numWinningSuggestions = BigInt.fromI32(winningSuggestions.length);
competitionProposal.save();
ben-kaufman marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/mappings/Competition/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type CompetitionProposal @entity {
createdAt: BigInt!
totalSubmissions: BigInt!
totalVotes: BigInt!
numWinningSuggestions: BigInt!
ben-kaufman marked this conversation as resolved.
Show resolved Hide resolved
admin: Bytes!
}

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

Expand Down Expand Up @@ -205,6 +207,8 @@ describe('Competition', () => {
winningSuggestions: [],
totalSubmissions: '0',
totalVotes: '0',
numWinningSuggestions: '0',
admin: '0x0000000000000000000000000000000000000000',
});

// Pass the ContributionReward proposal to approve the competition
Expand Down Expand Up @@ -344,6 +348,7 @@ describe('Competition', () => {
}
totalSubmissions
totalVotes
numWinningSuggestions
}
}`;

Expand All @@ -355,6 +360,7 @@ describe('Competition', () => {
winningSuggestions: [],
totalSubmissions: '2',
totalVotes: '0',
numWinningSuggestions: '0',
});

// Get rep balance
Expand Down Expand Up @@ -458,13 +464,15 @@ describe('Competition', () => {
snapshotBlock
totalSubmissions
totalVotes
numWinningSuggestions
}
}`;

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

let proposalVotesWinningSuggestionsQuery = `{
Expand Down