Skip to content

Commit

Permalink
fix FundedSlate bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Jul 27, 2023
1 parent ddf7abb commit 36c820c
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/grant-fund.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ export function handleFundedSlateUpdated(event: FundedSlateUpdatedEvent): void {
distributionPeriod.topSlate = event.params.fundedSlateHash

// create FundedSlate entity
const fundedSlate = new FundedSlate(distributionId) as FundedSlate
const fundedSlate = new FundedSlate(fundedSlateUpdated.fundedSlateHash_) as FundedSlate
fundedSlate.distribution = distributionId
fundedSlate.updateBlock = event.block.number

// get the list of proposals in the slate
const proposalsInSlate = getProposalsInSlate(event.address, fundedSlateUpdated.distributionId_)
const proposals = fundedSlate.proposals
const proposalsInSlate = getProposalsInSlate(event.address, fundedSlateUpdated.fundedSlateHash_)
const proposals: Bytes[] = []
let totalTokensRequested = ZERO_BD
let totalFundingVotesReceived = ZERO_BD

Expand Down
4 changes: 2 additions & 2 deletions src/utils/grants/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export function removeProposalFromList(proposalId: Bytes, proposalList: Array<By
/*** Contract Calls ***/
/**********************/

export function getProposalsInSlate(grantFundAddress: Address, distributionId: BigInt): Array<BigInt> {
export function getProposalsInSlate(grantFundAddress: Address, slateHash: Bytes): Array<BigInt> {
const grantFundContract = GrantFund.bind(grantFundAddress)
const getProposalsInSlateResult = grantFundContract.getTopTenProposals(distributionId.toI32())
const getProposalsInSlateResult = grantFundContract.getFundedProposalSlate(slateHash)

return getProposalsInSlateResult
}
118 changes: 114 additions & 4 deletions tests/grant-fund.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
handleProposalExecuted,
handleDistributionPeriodStarted,
handleVoteCast,
handleFundedSlateUpdated,
} from "../src/grant-fund";
import {
createDelegateRewardClaimedEvent,
Expand All @@ -23,6 +24,7 @@ import {
createProposalExecutedEvent,
createDistributionPeriodStartedEvent,
createVoteCastEvent,
createFundedSlateUpdatedEvent,
} from "./utils/grant-fund-utils";
import {
DISTRIBUTION_PERIOD_LENGTH,
Expand All @@ -33,7 +35,7 @@ import {
ZERO_BI,
} from "../src/utils/constants";
import { addressToBytes, bigIntToBytes, decimalToWad, wadToDecimal } from "../src/utils/convert";
import { mockGetDistributionId, mockGetTreasury, mockGetVotesFunding, mockGetVotesScreening } from "./utils/common";
import { mockGetDistributionId, mockGetFundedProposalSlate, mockGetTreasury, mockGetVotesFunding, mockGetVotesScreening } from "./utils/common";
import { getDistributionPeriodVoteId, getFundingVoteId, getScreeningVoteId } from "../src/utils/grants/voter";

// Tests structure (matchstick-as >=0.5.0)
Expand Down Expand Up @@ -481,8 +483,6 @@ describe("Grant Fund assertions", () => {
const screeningVoteCastEvent = createVoteCastEvent(voter, proposalId, 1, votesCast, reason, startBlock, BigInt.fromI32(1));
handleVoteCast(screeningVoteCastEvent);

// TODO: advance state to funding stage

/*****************************/
/*** Funding Vote Proposal ***/
/*****************************/
Expand Down Expand Up @@ -591,5 +591,115 @@ describe("Grant Fund assertions", () => {

});

test("FundedSlateUpdated", () => {});
test("FundedSlateUpdated", () => {

/***********************/
/*** Submit Proposal ***/
/***********************/

// mock parameters
const ajnaTokenAddress = Address.fromString("0x0000000000000000000000000000000000000035");
const grantFundAddress = Address.fromString("0xa16081f360e3847006db660bae1c6d1b2e17ec2a")
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 = ONE_BI;
const startBlock = ONE_BI;
const endBlock = startBlock.plus(DISTRIBUTION_PERIOD_LENGTH);
const description = "test proposal";

// start distribution period
// mock GrantFund contract calls
const newDistributionPeriodStartedEvent = createDistributionPeriodStartedEvent(
distributionId,
startBlock,
endBlock
);
newDistributionPeriodStartedEvent.address = grantFundAddress
handleDistributionPeriodStarted(newDistributionPeriodStartedEvent);
mockGetDistributionId(grantFundAddress, distributionId);

// submit proposal
// create mock event
const newProposalCreatedEvent = createProposalCreatedEvent(
proposalId,
proposer,
targets,
values,
signatures,
calldatas,
startBlock,
endBlock,
description
);
newProposalCreatedEvent.address = grantFundAddress
handleProposalCreated(newProposalCreatedEvent);

/*****************************/
/*** Funding Vote Proposal ***/
/*****************************/

// mock parameters
const voter = Address.fromString("0x0000000000000000000000000000000000000050");
let votesCast = BigInt.fromI32(-234);
const reason = ""

// TODO: need to convert back from WAD
const fundingVotingPower = votesCast.times(votesCast);

mockGetVotesFunding(grantFundAddress, distributionId, voter, fundingVotingPower);

votesCast = BigInt.fromI32(-234);
const fundingVoteCastEvent = createVoteCastEvent(voter, proposalId, 0, votesCast, reason, startBlock.plus(SCREENING_PERIOD_LENGTH).plus(BigInt.fromI32(1)), BigInt.fromI32(1));
handleVoteCast(fundingVoteCastEvent);

/********************/
/*** Update Slate ***/
/********************/

const fundedProposalSlate = [proposalId]

// TODO: need to determine how to best hash the proposalId array
const fundedSlateHash = Bytes.fromHexString("0x000010")

mockGetFundedProposalSlate(grantFundAddress, fundedSlateHash, fundedProposalSlate);

const updateSlateEvent = createFundedSlateUpdatedEvent(distributionId, fundedSlateHash)
handleFundedSlateUpdated(updateSlateEvent);

/********************/
/*** Assert State ***/
/********************/

// check GrantFund attributes
assert.entityCount("GrantFund", 1);

// check Proposal attributes
assert.entityCount("Proposal", 1);

assert.entityCount("DistributionPeriod", 1);
assert.entityCount("FundedSlate", 1);

logStore();

// // check FundedSlate attributes
// assert.fieldEquals(
// "FundedSlate",
// `${fundedSlateHash.toHexString()}`,
// "totalFundingVotesReceived",
// `${votesCast}`
// );

});
});
10 changes: 10 additions & 0 deletions tests/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,16 @@ export function mockGetTreasury(grantFund: Address, expectedTreasury: BigInt): v
])
}

export function mockGetFundedProposalSlate(grantFund: Address, slateHash: Bytes, expectedProposals: Array<BigInt>): void {
createMockedFunction(grantFund, 'getFundedProposalSlate', 'getFundedProposalSlate(bytes32):(uint256[])')
.withArgs([
ethereum.Value.fromFixedBytes(slateHash)
])
.returns([
ethereum.Value.fromUnsignedBigIntArray(expectedProposals),
])
}

/*******************************/
/*** Position Mock Functions ***/
/*******************************/
Expand Down

0 comments on commit 36c820c

Please sign in to comment.