Skip to content

Commit

Permalink
Lint and pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgall committed Nov 1, 2024
1 parent 2837bb2 commit 22b9dba
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 222 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { deployNonUpgradeable } from "../helpers/deployNonUpgradeable";
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { deployNonUpgradeable } from '../helpers/deployNonUpgradeable';

const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
await deployNonUpgradeable(hre, "LinearERC20VotingWithHatsProposalCreation");
await deployNonUpgradeable(hre, 'LinearERC20VotingWithHatsProposalCreation');
};

export default func;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { deployNonUpgradeable } from "../helpers/deployNonUpgradeable";
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { deployNonUpgradeable } from '../helpers/deployNonUpgradeable';

const func: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
await deployNonUpgradeable(hre, "LinearERC721VotingWithHatsProposalCreation");
await deployNonUpgradeable(hre, 'LinearERC721VotingWithHatsProposalCreation');
};

export default func;
180 changes: 70 additions & 110 deletions test/Azorius-LinearERC20VotingWithHatsProposalCreation.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { SignerWithAddress } from "@nomicfoundation/hardhat-ethers/signers";
import { expect } from "chai";
import hre from "hardhat";
import { ethers } from "ethers";
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers';
import { expect } from 'chai';
// eslint-disable-next-line import/no-extraneous-dependencies
import { ethers } from 'ethers';
import hre from 'hardhat';

import {
GnosisSafe,
Expand All @@ -14,23 +15,22 @@ import {
VotesERC20__factory,
ModuleProxyFactory,
GnosisSafeL2__factory,
} from "../typechain-types";
} from '../typechain-types';

import {
getGnosisSafeL2Singleton,
getGnosisSafeProxyFactory,
getModuleProxyFactory,
} from './GlobalSafeDeployments.test';
import {
calculateProxyAddress,
predictGnosisSafeAddress,
buildSafeTransaction,
safeSignTypedData,
buildSignatureBytes,
} from "./helpers";

import {
getGnosisSafeL2Singleton,
getGnosisSafeProxyFactory,
getModuleProxyFactory,
} from "./GlobalSafeDeployments.test";
} from './helpers';

describe("LinearERC20VotingWithHatsProposalCreation", () => {
describe('LinearERC20VotingWithHatsProposalCreation', () => {
// Deployed contracts
let gnosisSafe: GnosisSafe;
let azorius: Azorius;
Expand All @@ -49,9 +49,7 @@ describe("LinearERC20VotingWithHatsProposalCreation", () => {
// Gnosis
let createGnosisSetupCalldata: string;

const saltNum = BigInt(
"0x856d90216588f9ffc124d1480a440e1c012c7a816952bc968d737bae5d4e139c"
);
const saltNum = BigInt('0x856d90216588f9ffc124d1480a440e1c012c7a816952bc968d737bae5d4e139c');

beforeEach(async () => {
gnosisSafeProxyFactory = getGnosisSafeProxyFactory();
Expand All @@ -64,7 +62,7 @@ describe("LinearERC20VotingWithHatsProposalCreation", () => {

createGnosisSetupCalldata =
// eslint-disable-next-line camelcase
GnosisSafeL2__factory.createInterface().encodeFunctionData("setup", [
GnosisSafeL2__factory.createInterface().encodeFunctionData('setup', [
[gnosisSafeOwner.address],
1,
ethers.ZeroAddress,
Expand All @@ -79,110 +77,95 @@ describe("LinearERC20VotingWithHatsProposalCreation", () => {
createGnosisSetupCalldata,
saltNum,
await gnosisSafeL2Singleton.getAddress(),
gnosisSafeProxyFactory
gnosisSafeProxyFactory,
);

// Deploy Gnosis Safe
await gnosisSafeProxyFactory.createProxyWithNonce(
await gnosisSafeL2Singleton.getAddress(),
createGnosisSetupCalldata,
saltNum
saltNum,
);

gnosisSafe = await hre.ethers.getContractAt(
"GnosisSafe",
predictedGnosisSafeAddress
);
gnosisSafe = await hre.ethers.getContractAt('GnosisSafe', predictedGnosisSafeAddress);

// Deploy Votes ERC-20 mastercopy contract
votesERC20Mastercopy = await new VotesERC20__factory(deployer).deploy();

const votesERC20SetupCalldata =
// eslint-disable-next-line camelcase
VotesERC20__factory.createInterface().encodeFunctionData("setUp", [
abiCoder.encode(
["string", "string", "address[]", "uint256[]"],
["DCNT", "DCNT", [], []]
),
VotesERC20__factory.createInterface().encodeFunctionData('setUp', [
abiCoder.encode(['string', 'string', 'address[]', 'uint256[]'], ['DCNT', 'DCNT', [], []]),
]);

await moduleProxyFactory.deployModule(
await votesERC20Mastercopy.getAddress(),
votesERC20SetupCalldata,
"10031021"
'10031021',
);

const predictedVotesERC20Address = await calculateProxyAddress(
moduleProxyFactory,
await votesERC20Mastercopy.getAddress(),
votesERC20SetupCalldata,
"10031021"
'10031021',
);

votesERC20 = await hre.ethers.getContractAt(
"VotesERC20",
predictedVotesERC20Address
);
votesERC20 = await hre.ethers.getContractAt('VotesERC20', predictedVotesERC20Address);
// Deploy Azorius module
azoriusMastercopy = await new Azorius__factory(deployer).deploy();

const azoriusSetupCalldata =
// eslint-disable-next-line camelcase
Azorius__factory.createInterface().encodeFunctionData("setUp", [
Azorius__factory.createInterface().encodeFunctionData('setUp', [
abiCoder.encode(
["address", "address", "address", "address[]", "uint32", "uint32"],
['address', 'address', 'address', 'address[]', 'uint32', 'uint32'],
[
gnosisSafeOwner.address,
await gnosisSafe.getAddress(),
await gnosisSafe.getAddress(),
[],
60, // timelock period in blocks
60, // execution period in blocks
]
],
),
]);

await moduleProxyFactory.deployModule(
await azoriusMastercopy.getAddress(),
azoriusSetupCalldata,
"10031021"
'10031021',
);

const predictedAzoriusAddress = await calculateProxyAddress(
moduleProxyFactory,
await azoriusMastercopy.getAddress(),
azoriusSetupCalldata,
"10031021"
'10031021',
);

azorius = await hre.ethers.getContractAt(
"Azorius",
predictedAzoriusAddress
);
azorius = await hre.ethers.getContractAt('Azorius', predictedAzoriusAddress);

// Deploy LinearERC20VotingWithHatsProposalCreation
linearERC20VotingWithHatsMastercopy =
await new LinearERC20VotingWithHatsProposalCreation__factory(
deployer
).deploy();
await new LinearERC20VotingWithHatsProposalCreation__factory(deployer).deploy();

const mockHatsContractAddress =
"0x1234567890123456789012345678901234567890";
const mockHatsContractAddress = '0x1234567890123456789012345678901234567890';

const linearERC20VotingWithHatsSetupCalldata =
LinearERC20VotingWithHatsProposalCreation__factory.createInterface().encodeFunctionData(
"setUp",
'setUp',
[
abiCoder.encode(
[
"address",
"address",
"address",
"uint32",
"uint256",
"uint256",
"address",
"uint256[]",
'address',
'address',
'address',
'uint32',
'uint256',
'uint256',
'address',
'uint256[]',
],
[
gnosisSafeOwner.address,
Expand All @@ -193,28 +176,27 @@ describe("LinearERC20VotingWithHatsProposalCreation", () => {
500000,
mockHatsContractAddress,
[1n], // Use a mock hat ID
]
],
),
]
],
);

await moduleProxyFactory.deployModule(
await linearERC20VotingWithHatsMastercopy.getAddress(),
linearERC20VotingWithHatsSetupCalldata,
"10031021"
'10031021',
);

const predictedLinearERC20VotingWithHatsAddress =
await calculateProxyAddress(
moduleProxyFactory,
await linearERC20VotingWithHatsMastercopy.getAddress(),
linearERC20VotingWithHatsSetupCalldata,
"10031021"
);
const predictedLinearERC20VotingWithHatsAddress = await calculateProxyAddress(
moduleProxyFactory,
await linearERC20VotingWithHatsMastercopy.getAddress(),
linearERC20VotingWithHatsSetupCalldata,
'10031021',
);

linearERC20VotingWithHats = await hre.ethers.getContractAt(
"LinearERC20VotingWithHatsProposalCreation",
predictedLinearERC20VotingWithHatsAddress
'LinearERC20VotingWithHatsProposalCreation',
predictedLinearERC20VotingWithHatsAddress,
);

// Enable the strategy on Azorius
Expand All @@ -223,10 +205,9 @@ describe("LinearERC20VotingWithHatsProposalCreation", () => {
.enableStrategy(await linearERC20VotingWithHats.getAddress());

// Create transaction on Gnosis Safe to setup Azorius module
const enableAzoriusModuleData = gnosisSafe.interface.encodeFunctionData(
"enableModule",
[await azorius.getAddress()]
);
const enableAzoriusModuleData = gnosisSafe.interface.encodeFunctionData('enableModule', [
await azorius.getAddress(),
]);

const enableAzoriusModuleTx = buildSafeTransaction({
to: await gnosisSafe.getAddress(),
Expand All @@ -235,13 +216,7 @@ describe("LinearERC20VotingWithHatsProposalCreation", () => {
nonce: await gnosisSafe.nonce(),
});

const sigs = [
await safeSignTypedData(
gnosisSafeOwner,
gnosisSafe,
enableAzoriusModuleTx
),
];
const sigs = [await safeSignTypedData(gnosisSafeOwner, gnosisSafe, enableAzoriusModuleTx)];

const signatureBytes = buildSignatureBytes(sigs);

Expand All @@ -257,52 +232,37 @@ describe("LinearERC20VotingWithHatsProposalCreation", () => {
enableAzoriusModuleTx.gasPrice,
enableAzoriusModuleTx.gasToken,
enableAzoriusModuleTx.refundReceiver,
signatureBytes
)
).to.emit(gnosisSafe, "ExecutionSuccess");
signatureBytes,
),
).to.emit(gnosisSafe, 'ExecutionSuccess');
});

it("Gets correctly initialized", async () => {
expect(await linearERC20VotingWithHats.owner()).to.eq(
gnosisSafeOwner.address
);
expect(await linearERC20VotingWithHats.governanceToken()).to.eq(
await votesERC20.getAddress()
);
expect(await linearERC20VotingWithHats.azoriusModule()).to.eq(
await azorius.getAddress()
);
it('Gets correctly initialized', async () => {
expect(await linearERC20VotingWithHats.owner()).to.eq(gnosisSafeOwner.address);
expect(await linearERC20VotingWithHats.governanceToken()).to.eq(await votesERC20.getAddress());
expect(await linearERC20VotingWithHats.azoriusModule()).to.eq(await azorius.getAddress());
expect(await linearERC20VotingWithHats.hatsContract()).to.eq(
"0x1234567890123456789012345678901234567890"
'0x1234567890123456789012345678901234567890',
);
});

it("Cannot call setUp function again", async () => {
it('Cannot call setUp function again', async () => {
const setupParams = ethers.AbiCoder.defaultAbiCoder().encode(
[
"address",
"address",
"address",
"uint32",
"uint256",
"uint256",
"address",
"uint256[]",
],
['address', 'address', 'address', 'uint32', 'uint256', 'uint256', 'address', 'uint256[]'],
[
gnosisSafeOwner.address,
await votesERC20.getAddress(),
await azorius.getAddress(),
60, // voting period
500000, // quorum numerator
500000, // basis numerator
"0x1234567890123456789012345678901234567890",
'0x1234567890123456789012345678901234567890',
[1n],
]
],
);

await expect(
linearERC20VotingWithHats.setUp(setupParams)
).to.be.revertedWith("Initializable: contract is already initialized");
await expect(linearERC20VotingWithHats.setUp(setupParams)).to.be.revertedWith(
'Initializable: contract is already initialized',
);
});
});
Loading

0 comments on commit 22b9dba

Please sign in to comment.