Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
Add first test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNeshi committed Jul 19, 2023
1 parent b291dcf commit 1352e2c
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 10 deletions.
106 changes: 96 additions & 10 deletions test/core/accounts/AccountsDeployContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,131 @@ import hre from "hardhat";
import {
AccountsDeployContract,
AccountsDeployContract__factory,
Registrar,
Registrar__factory,
SubDao,
SubDaoEmitter,
SubDaoEmitter__factory,
SubDaoLib,
SubDaoLib__factory,
SubDao__factory,
TestFacetProxyContract,
} from "typechain-types";
import {getSigners} from "utils";
import {genWallet, getSigners} from "utils";
import {deployFacetAsProxy} from "./utils/deployTestFacet";
import {FakeContract, smock} from "@defi-wonderland/smock";
import {expect, use} from "chai";
import {DEFAULT_REGISTRAR_CONFIG, EndowmentType, TokenType, VeTypeEnum} from "test/utils";
import {RegistrarStorage} from "typechain-types/contracts/core/registrar/Registrar";

use(smock.matchers);

describe("AccountsDeployContract", function () {
const {ethers} = hre;

let owner: SignerWithAddress;
const endowId = 1;

let accOwner: SignerWithAddress;
let proxyAdmin: SignerWithAddress;
let user: SignerWithAddress;
let endowOwner: SignerWithAddress;

let facet: AccountsDeployContract;
let state: TestFacetProxyContract;

let registrarFake: FakeContract<Registrar>;
let subdaoFake: FakeContract<SubDao>;
let subdaoEmitterFake: FakeContract<SubDaoEmitter>;

before(async function () {
const signers = await getSigners(hre);
owner = signers.apTeam1;
accOwner = signers.apTeam1;
proxyAdmin = signers.proxyAdmin;
user = signers.deployer;
endowOwner = signers.deployer;

const subdaoLibFake: FakeContract<SubDaoLib> = await smock.fake<SubDaoLib>(
new SubDaoLib__factory()
);
console.log("deployed lib", subdaoLibFake.address);
subdaoFake = await smock.fake<SubDao>(
new SubDao__factory({
"contracts/normalized_endowment/subdao/SubDaoLib.sol:SubDaoLib": subdaoLibFake.address,
})
);
console.log("deployed subdao", subdaoFake.address);
subdaoEmitterFake = await smock.fake<SubDaoEmitter>(new SubDaoEmitter__factory());
registrarFake = await smock.fake<Registrar>(new Registrar__factory());

const config: RegistrarStorage.ConfigStruct = {
...DEFAULT_REGISTRAR_CONFIG,
subdaoGovContract: subdaoFake.address,
proxyAdmin: proxyAdmin.address,
subdaoEmitter: subdaoEmitterFake.address,
};
registrarFake.queryConfig.returns(config);
});

beforeEach(async function () {
const Facet = new AccountsDeployContract__factory(owner);
const Facet = new AccountsDeployContract__factory(accOwner);
const facetImpl = await Facet.deploy();
state = await deployFacetAsProxy(hre, owner, proxyAdmin, facetImpl.address);
state = await deployFacetAsProxy(hre, accOwner, proxyAdmin, facetImpl.address);

await state.setConfig({
owner: owner.address,
owner: accOwner.address,
version: "1",
networkName: "Polygon",
registrarContract: ethers.constants.AddressZero,
registrarContract: registrarFake.address,
nextAccountId: 1,
maxGeneralCategoryId: 1,
subDao: ethers.constants.AddressZero,
earlyLockedWithdrawFee: {bps: 1000, payoutAddress: ethers.constants.AddressZero},
reentrancyGuardLocked: false,
});

facet = AccountsDeployContract__factory.connect(state.address, owner);
facet = AccountsDeployContract__factory.connect(state.address, accOwner);
});

describe("upon createDaoContract", () => {
it("reverts if caller is not Accounts Diamond itself", async () => {
await expect(
facet.connect(endowOwner).createDaoContract({
endowOwner: endowOwner.address,
endowType: EndowmentType.Charity,
expirationPeriod: 0,
id: endowId,
owner: endowOwner.address,
proposalDeposit: 1,
quorum: 1,
registrarContract: registrarFake.address,
snapshotPeriod: 0,
threshold: 0,
timelockPeriod: 0,
token: {
token: TokenType.New,
data: {
existingData: "",
newInitialSupply: 0,
newName: "",
newSymbol: "",
veBondingDecimals: 18,
veBondingName: "",
veBondingPeriod: 0,
veBondingReserveDecimals: 18,
veBondingReserveDenom: "",
veBondingSymbol: "",
veBondingType: {
ve_type: VeTypeEnum.Constant,
data: {
power: 0,
scale: 0,
slope: 0,
value: 0,
},
},
},
},
votingPeriod: 0,
})
).to.be.revertedWith("Unauthorized");
});
});
});
17 changes: 17 additions & 0 deletions test/utils/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,20 @@ export enum FeeTypes {
EarlyLockedWithdrawCharity,
EarlyLockedWithdrawNormal,
}

export enum EndowmentType {
Charity,
Normal,
}

export enum VeTypeEnum {
Constant,
Linear,
SquarRoot,
}

export enum TokenType {
Existing,
New,
VeBonding,
}

0 comments on commit 1352e2c

Please sign in to comment.