diff --git a/src/grant-fund.ts b/src/grant-fund.ts index 1cd04f7..185e158 100644 --- a/src/grant-fund.ts +++ b/src/grant-fund.ts @@ -285,9 +285,8 @@ export function handleVoteCast(event: VoteCastEvent): void { const proposalId = bigIntToBytes(event.params.proposalId) const proposal = Proposal.load(proposalId) as Proposal if (proposal != null) { - // TODO: need to be able to access the distributionId at that block height or call getDistributionIdAtBlock()? - // load distribution entity - const distributionId = bigIntToBytes(getCurrentDistributionId(event.address)) + // load distribution entity using the distributionId from the proposal + const distributionId = proposal.distribution! const distributionPeriod = DistributionPeriod.load(distributionId) as DistributionPeriod // load voter's distributionPeriodVotes diff --git a/src/utils/grants/distribution.ts b/src/utils/grants/distribution.ts index 60e7e90..8d9936c 100644 --- a/src/utils/grants/distribution.ts +++ b/src/utils/grants/distribution.ts @@ -24,6 +24,7 @@ export function getCurrentDistributionId(grantFundAddress: Address): BigInt { return distributionIdResult } +// FIXME: update this for the latest version of the contract export function getCurrentStage(currentBlockNumber: BigInt, distributionPeriod: DistributionPeriod): String { if (currentBlockNumber.lt(distributionPeriod.endBlock - FUNDING_PERIOD_LENGTH)) { return "SCREENING" diff --git a/tests/grant-fund.test.ts b/tests/grant-fund.test.ts index 5cecae9..0a9a078 100644 --- a/tests/grant-fund.test.ts +++ b/tests/grant-fund.test.ts @@ -13,6 +13,7 @@ import { handleProposalCreated, handleProposalExecuted, handleDistributionPeriodStarted, + handleVoteCast, } from "../src/grant-fund"; import { createDelegateRewardClaimedEvent, @@ -20,6 +21,7 @@ import { createProposalCreatedEvent, createProposalExecutedEvent, createDistributionPeriodStartedEvent, + createVoteCastEvent, } from "./utils/grant-fund-utils"; import { DISTRIBUTION_PERIOD_LENGTH, @@ -294,5 +296,80 @@ describe("Grant Fund assertions", () => { assert.entityCount("ProposalExecuted", 1); }); + test("ScreeningVote", () => { + /***********************/ + /*** Submit Proposal ***/ + /***********************/ + + // mock parameters + const ajnaTokenAddress = Address.fromString("0x0000000000000000000000000000000000000035"); + const grantFundAddress = Address.fromString("0x00000000000000000000006772616E7466756E64") + const proposalId = BigInt.fromI32(234); + const proposer = Address.fromString( + "0x0000000000000000000000000000000000000025" + ); + const targets = [ajnaTokenAddress, ajnaTokenAddress]; + const values = [ZERO_BI, ZERO_BI]; + const signatures = [ + "transfer(address,uint256)", + "transfer(address,uint256)", + ]; + const calldatas = [ + Bytes.fromHexString("0x000000"), + Bytes.fromHexString("0x000000"), + ]; + const distributionId = BigInt.fromI32(234); + const startBlock = ONE_BI; + const endBlock = startBlock.plus(DISTRIBUTION_PERIOD_LENGTH); + const description = "test proposal"; + + // mock GrantFund contract calls + const newDistributionPeriodStartedEvent = createDistributionPeriodStartedEvent( + distributionId, + startBlock, + endBlock + ); + newDistributionPeriodStartedEvent.address = grantFundAddress + handleDistributionPeriodStarted(newDistributionPeriodStartedEvent); + mockGetDistributionId(grantFundAddress, distributionId); + + // create mock event + const newProposalCreatedEvent = createProposalCreatedEvent( + proposalId, + proposer, + targets, + values, + signatures, + calldatas, + startBlock, + endBlock, + description + ); + newProposalCreatedEvent.address = grantFundAddress + handleProposalCreated(newProposalCreatedEvent); + + /*******************************/ + /*** Screening Vote Proposal ***/ + /*******************************/ + + // mock parameters + const voter = Address.fromString("0x0000000000000000000000000000000000000050"); + const votesCast = BigInt.fromI32(234); + const reason = "" + + const screeningVoteCastEvent = createVoteCastEvent(voter, proposalId, 1, votesCast, reason); + handleVoteCast(screeningVoteCastEvent); + + }); + + test("getFundingVotingPowerUsed", () => { + + }); + + + test("FundingVote", () => { + + }); + test("FundedSlateUpdated", () => {}); }); diff --git a/tests/utils/mock-function.ts b/tests/utils/mock-function.ts new file mode 100644 index 0000000..e69de29