Skip to content

Commit

Permalink
Start tests for FraxSharesAllocatorVoting with withdrawal to owner
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLienid committed Aug 17, 2023
1 parent f32efe7 commit 98dfac0
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ contract FraxSharesAllocator is Initializable, OwnableUpgradeable {

/* ======== INITIALIZER ======== */
function initialize(
address _treasury,
address _fxs,
address _veFXS,
address _veFXSYieldDistributorV4
Expand Down
122 changes: 122 additions & 0 deletions test/allocators/FraxSharesAllocatorVotingV2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import chai, { expect } from "chai";
import { ethers, upgrades, config } from "hardhat";
import { BigNumber } from "ethers";
import {
ITreasury,
IveFXS,
FraxSharesAllocatorVoting,
OlympusTreasury,
ERC20,
FraxSharesAllocatorVoting__factory
} from "../../types";
import { coins } from "../utils/coins";
import { olympus } from "../utils/olympus";
import { helpers } from "../utils/helpers";
import { vefxsAbi, wlContractAbi } from "../utils/fxsAllocatorAbis";

const ZERO_ADDRESS = ethers.utils.getAddress("0x0000000000000000000000000000000000000000");
const MAX_TIME = 4 * 365 * 86400 + 1;

describe("FraxSharesAllocatorVotingV2", () => {
describe("Integration Tests", () => {
// signers
let owner: SignerWithAddress;
let other: SignerWithAddress;
let newOwner: SignerWithAddress;
let fxsWallet: SignerWithAddress;
let wlOwner: SignerWithAddress;

// contracts
let treasury: OlympusTreasury;
let factory: FraxSharesAllocatorVoting__factory;
let allocator: FraxSharesAllocatorVoting;

// tokens
let fxs: ERC20;
let veFXS: any;

// network
let url: string = config.networks.hardhat.forking!.url;

// variables
let snapshotId: number = 0;

before(async () => {
await helpers.pinBlock(17935468, url);

[owner, other, newOwner] = await ethers.getSigners();

fxsWallet = await helpers.impersonate("0xF977814e90dA44bFA03b6295A0616a897441aceC");
wlOwner = await helpers.impersonate("0xb1748c79709f4ba2dd82834b8c82d4a505003f27");

fxs = await helpers.getCoin(coins.fxs);
veFXS = await ethers.getContractAt(vefxsAbi, "0xc8418aF6358FFddA74e09Ca9CC3Fe03Ca6aDC5b0");

treasury = (await ethers.getContractAt(
"OlympusTreasury",
olympus.treasury
)) as OlympusTreasury;

factory = (await ethers.getContractFactory("FraxSharesAllocatorVoting")) as FraxSharesAllocatorVoting__factory;
factory = factory.connect(owner);
allocator = (await upgrades.deployProxy(factory, [
treasury.address,
fxs.address,
veFXS.address,
"0xc6764e58b36e26b08Fd1d2AeD4538c02171fA872"
])) as FraxSharesAllocatorVoting;
});

beforeEach(async () => {
snapshotId = await helpers.snapshot();
});

afterEach(async () => {
await helpers.revert(snapshotId);
});

describe("deposit", () => {
it("should do nothing on deposit", async () => {
const fxsTreasuryBalanceBefore = await fxs.balanceOf(treasury.address);
const fxsAllocatorBalanceBefore = await fxs.balanceOf(allocator.address);

allocator.connect(owner).deposit(1);

const fxsTreasuryBalanceAfter = await fxs.balanceOf(treasury.address);
const fxsAllocatorBalanceAfter = await fxs.balanceOf(allocator.address);

expect(fxsTreasuryBalanceAfter).to.eq(fxsTreasuryBalanceBefore);
expect(fxsAllocatorBalanceAfter).to.eq(fxsAllocatorBalanceBefore);
});
});

describe("setTreasury", () => {
it("should do nothing on setTreasury", async () => {
const treasuryBefore = await allocator.treasury();
allocator.connect(owner).setTreasury(ZERO_ADDRESS);
const treasuryAfter = await allocator.treasury();

expect(treasuryBefore).to.eq(treasuryAfter);
});
});

describe("withdrawToken", () => {
it("should send tokens to owner on withdraw", async () => {
// transfer fxs in
await fxs.connect(fxsWallet).transfer(allocator.address, 1000);

const fxsBalanceBefore = await fxs.balanceOf(owner.address);
const fxsAllocatorBalanceBefore = await fxs.balanceOf(allocator.address);

await allocator.connect(owner).withdrawToken(fxs.address, 1000);

const fxsBalanceAfter = await fxs.balanceOf(owner.address);
const fxsAllocatorBalanceAfter = await fxs.balanceOf(allocator.address);

expect(fxsBalanceAfter).to.eq(fxsBalanceBefore.add(1000));
expect(fxsAllocatorBalanceAfter).to.eq(fxsAllocatorBalanceBefore.sub(1000));
});
});
});
});

0 comments on commit 98dfac0

Please sign in to comment.