Skip to content

Commit

Permalink
Merge pull request #117 from HausDAO/feat/fixture-updates
Browse files Browse the repository at this point in the history
Fixture updates
  • Loading branch information
santteegt authored Sep 26, 2023
2 parents 63071fe + 313649f commit 649ce4c
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 88 deletions.
3 changes: 1 addition & 2 deletions contracts/interfaces/IBaalAndVaultSummoner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ interface IBaalAndVaultSummoner {
bytes32 referrer,
string memory name
) external returns (address _daoAddress, address _vaultAddress);

}
}
2 changes: 1 addition & 1 deletion deploy/004_deploy_bv_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const deployFn: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
from: deployer,
args: [],
proxy: {
proxyContract: 'OpenZeppelinTransparentProxy',
proxyContract: 'UUPS',
methodName: 'initialize',
},
log: true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daohaus/baal-contracts",
"version": "1.2.12",
"version": "1.2.13",
"description": "Lo, also it is the time of His rain.",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ export * from "./signDelegation";
export * from "./signPermit";
export * from "./signVote";
export * from "./util";
export * from "./addresses/setup";
export { deployments as DEPLOYMENT_ADDRESSES } from "./addresses/deployed";
export * from "../test/utils";
93 changes: 48 additions & 45 deletions test/BaalSafe.test.ts

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions test/Tribute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
revertMessages,
} from './utils/baal';
import { moveForwardPeriods } from './utils/evm';
import { baalSetup, Signer } from './utils/fixtures';
import { submitAndProcessTributeProposal } from './utils/tribute';
import { baalSetup, ProposalHelpers, Signer } from './utils/fixtures';
import {
Baal,
TestERC20,
Expand Down Expand Up @@ -42,6 +41,8 @@ describe("Tribute proposal type", function () {
const yes = true;
const no = false;

let proposalHelpers: ProposalHelpers;

beforeEach(async () => {
const {
Baal,
Expand All @@ -52,7 +53,8 @@ describe("Tribute proposal type", function () {
MultiSend,
TributeMinion,
WETH,
signers
signers,
helpers,
} = await baalSetup({});

baal = Baal;
Expand All @@ -65,6 +67,8 @@ describe("Tribute proposal type", function () {
// poster = Poster;
tributeMinion = TributeMinion;
users = signers;

proposalHelpers = helpers;
});

describe("Dangerous proposal tribute", () => {
Expand Down Expand Up @@ -181,7 +185,7 @@ describe("Tribute proposal type", function () {

const currentShares = await sharesToken.balanceOf(users.applicant.address);

users.applicant.tributeMinion && await submitAndProcessTributeProposal({
users.applicant.tributeMinion && await proposalHelpers.submitAndProcessTributeProposal({
tributeMinion: users.applicant.tributeMinion,
baal,
applicantAddress: users.applicant.address,
Expand Down Expand Up @@ -236,7 +240,7 @@ describe("Tribute proposal type", function () {

const currentShares = await sharesToken.balanceOf(users.applicant.address);

users.applicant.tributeMinion && await submitAndProcessTributeProposal({
users.applicant.tributeMinion && await proposalHelpers.submitAndProcessTributeProposal({
tributeMinion: users.applicant.tributeMinion,
baal,
applicantAddress: users.applicant.address,
Expand Down Expand Up @@ -269,7 +273,7 @@ describe("Tribute proposal type", function () {

// await users.summoner.weth?.approve(tributeMinion.address, tribute);

// users.summoner.tributeMinion && await submitAndProcessTributeProposal({
// users.summoner.tributeMinion && await proposalHelpers.submitAndProcessTributeProposal({
// tributeMinion: users.summoner.tributeMinion,
// baal,
// applicantAddress: users.summoner.address,
Expand Down
28 changes: 18 additions & 10 deletions test/utils/baal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export enum SHAMAN_PERMISSIONS {
ALL,
};

export const defaultDAOSettings = {
export const defaultDAOSettings: DAOSettings = {
GRACE_PERIOD_IN_SECONDS: 43200,
VOTING_PERIOD_IN_SECONDS: 432000,
PROPOSAL_OFFERING: 0,
Expand Down Expand Up @@ -301,29 +301,37 @@ export const setupBaal = async ({
return await getNewBaalAddresses(tx);
};

export type ProposalParams = {
baal: Baal;
encodedAction: string;
proposal: ProposalType;
proposalId?: BigNumberish;
daoSettings?: DAOSettings;
extraSeconds?: number;
};

export const submitAndProcessProposal = async ({
baal,
encodedAction,
proposal,
proposalId,
}: {
baal: Baal;
encodedAction: string;
proposal: ProposalType;
proposalId?: BigNumberish;
}) => {
daoSettings = defaultDAOSettings,
extraSeconds = 2,
}: ProposalParams) => {
await baal.submitProposal(encodedAction, proposal.expiration, proposal.baalGas, ethers.utils.id(proposal.details));
const id = proposalId ? proposalId : await baal.proposalCount();
await baal.submitVote(id, true);
await moveForwardPeriods(defaultDAOSettings.VOTING_PERIOD_IN_SECONDS, 2);
await moveForwardPeriods(daoSettings.VOTING_PERIOD_IN_SECONDS, extraSeconds);
return await baal.processProposal(id, encodedAction);
};

export const setShamanProposal = async (
baal: Baal,
multisend: MultiSend,
shamanAddress: string,
permission: BigNumberish
permission: BigNumberish,
daoSettings = defaultDAOSettings,
extraSeconds = 2,
) => {
const setShaman = baal.interface.encodeFunctionData('setShamans', [
[shamanAddress],
Expand All @@ -341,7 +349,7 @@ export const setShamanProposal = async (
await baal.submitProposal(setShamanAction, 0, 0, '');
const proposalId = await baal.proposalCount();
await baal.submitVote(proposalId, true);
await moveForwardPeriods(defaultDAOSettings.VOTING_PERIOD_IN_SECONDS, 2);
await moveForwardPeriods(daoSettings.VOTING_PERIOD_IN_SECONDS, extraSeconds);
await baal.processProposal(proposalId, setShamanAction);
return proposalId;
};
Expand Down
38 changes: 31 additions & 7 deletions test/utils/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { deployments } from 'hardhat';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

import { Baal, BaalLessShares, BaalSummoner, GnosisSafe, Loot, MockBaal, MultiSend, Poster, Shares, TestERC20, TributeMinion } from '../../src/types';
import { DAOSettings, NewBaalAddresses, NewBaalParams, SummonSetup, defaultDAOSettings, defaultSummonSetup, setupBaal } from './baal';
import { DAOSettings, NewBaalAddresses, NewBaalParams, ProposalParams, ProposalType, SummonSetup, defaultDAOSettings, defaultSummonSetup, setShamanProposal, setupBaal, submitAndProcessProposal } from './baal';
import { BigNumberish, ContractTransaction } from 'ethers';
import { TributeProposalParams, TributeProposalStatus, submitAndProcessTributeProposal } from './tribute';

export type Signer = {
address: string;
Expand All @@ -16,7 +18,13 @@ export type Signer = {
dai?: TestERC20;
};

type BaalSetupType = {
export type ProposalHelpers = {
submitAndProcessProposal: (params: Omit<ProposalParams, "daoSettings">) => Promise<ContractTransaction>,
submitAndProcessTributeProposal: (params: Omit<TributeProposalParams, "daoSettings">) => Promise<TributeProposalStatus>,
setShamanProposal: (baal: Baal, multisend: MultiSend, shamanAddress: string, permission: BigNumberish) => Promise<number>,
};

export type BaalSetupType = {
Loot: Loot;
Shares: Shares;
Baal: Baal;
Expand All @@ -30,6 +38,8 @@ type BaalSetupType = {
signers: {
[key: string]: Signer;
};
daoSettings: DAOSettings;
helpers: ProposalHelpers;
}

type MockBaalSetupType = {
Expand Down Expand Up @@ -189,7 +199,7 @@ export const baalSetup = deployments.createFixture<BaalSetupType, BaalSetupOpts>
) => {
const { ethers, deployments, getNamedAccounts, getUnnamedAccounts } = hre;
const { deployer } = await getNamedAccounts();
const [summoner, applicant, shaman, s1, s2, s3, s4, s5, s6] = await getUnnamedAccounts();
const [summoner, applicant, shaman] = await getUnnamedAccounts();

await deployments.fixture(['Infra', 'TributeMinion', 'BaalSummoner', ...(options?.fixtureTags || [])]); // Deployment Tags

Expand All @@ -213,14 +223,16 @@ export const baalSetup = deployments.createFixture<BaalSetupType, BaalSetupOpts>
};
const applicantDist = { shares, loot };

const daoSettings = {
...defaultDAOSettings,
...options?.daoSettings,
};

const setupParams: NewBaalParams = {
baalSummoner,
baalSingleton,
poster,
config: {
...defaultDAOSettings,
...options?.daoSettings,
},
config: daoSettings,
adminConfig: [sharesPaused, lootPaused],
shamans: [[shaman], [shamanPermissions]],
shares: [
Expand Down Expand Up @@ -260,6 +272,7 @@ export const baalSetup = deployments.createFixture<BaalSetupType, BaalSetupOpts>
: await setupUsersDefault({ addresses, baal, hre });

return {
daoSettings,
Loot: lootToken,
Shares: sharesToken,
// Baal: (await ethers.getContract('Baal', deployer)) as Baal,
Expand All @@ -272,6 +285,17 @@ export const baalSetup = deployments.createFixture<BaalSetupType, BaalSetupOpts>
WETH: weth,
DAI: dai,
signers,
helpers: {
setShamanProposal: (baal, multisend, shamanAddress, permission) => {
return setShamanProposal(baal, multisend, shamanAddress, permission, daoSettings);
},
submitAndProcessProposal: (params) => {
return submitAndProcessProposal({ ...params, daoSettings });
},
submitAndProcessTributeProposal(params) {
return submitAndProcessTributeProposal({ ...params, daoSettings });
},
}
};


Expand Down
44 changes: 28 additions & 16 deletions test/utils/tribute.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
import { defaultDAOSettings } from './baal';
import { DAOSettings, defaultDAOSettings } from './baal';
import { moveForwardPeriods } from './evm';
import { Baal, TributeMinion } from '../../src/types';
import { BigNumber } from 'ethers';

const yes = true;

export type TributeProposalParams = {
tributeMinion: TributeMinion,
baal: Baal,
applicantAddress: string,
tributeToken: string,
tribute: number,
requestedShares: number,
requestedLoot: number,
sponsor?: boolean;
proposalId?: number;
proposalOffering?: number;
proposalExpiration?: number;
proposalBaalGas?: number;
daoSettings?: DAOSettings;
extraSeconds?: number;
};

export type TributeProposalStatus = {
spentInGas: BigNumber;
state: number;
propStatus: [boolean, boolean, boolean, boolean];
};

export const submitAndProcessTributeProposal = async ({
tributeMinion,
baal,
Expand All @@ -18,20 +41,9 @@ export const submitAndProcessTributeProposal = async ({
proposalOffering = 0,
proposalExpiration = 0,
proposalBaalGas = 0,
}: {
tributeMinion: TributeMinion,
baal: Baal,
applicantAddress: string,
tributeToken: string,
tribute: number,
requestedShares: number,
requestedLoot: number,
sponsor?: boolean;
proposalId?: number;
proposalOffering?: number;
proposalExpiration?: number;
proposalBaalGas?: number;
}) => {
daoSettings = defaultDAOSettings,
extraSeconds = 2,
}: TributeProposalParams): Promise<TributeProposalStatus> => {

const tx_1 = await tributeMinion.submitTributeProposal(
baal.address,
Expand All @@ -49,7 +61,7 @@ export const submitAndProcessTributeProposal = async ({
const tx_2_r = tx_2 ? await tx_2.wait() : undefined;
const tx_3 = await baal.submitVote(proposalId, yes);
const tx_3_r = await tx_3.wait();
await moveForwardPeriods(defaultDAOSettings.VOTING_PERIOD_IN_SECONDS, 2);
await moveForwardPeriods(daoSettings.VOTING_PERIOD_IN_SECONDS, extraSeconds);

const encodedProposal = await tributeMinion.encodeTributeProposal(
baal.address,
Expand Down

0 comments on commit 649ce4c

Please sign in to comment.