Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test add program task #32

Merged
merged 5 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@
"@ethersproject/wallet": "5.7.0",
"@openzeppelin/contracts": "4.6.0",
"@rari-capital/solmate": "6.4.0",
"@types/chai-as-promised": "^7.1.5",
"@uniswap/lib": "https://github.com/Uniswap/solidity-lib",
"@uniswap/v2-periphery": "https://github.com/Uniswap/v2-periphery",
"alchemist": "https://github.com/itirabasso/alchemist",
"chai-as-promised": "^7.1.1",
"ds-auth": "https://github.com/dapphub/ds-auth",
"ds-math": "https://github.com/dapphub/ds-math",
"ds-test": "https://github.com/dapphub/ds-test",
Expand Down
46 changes: 0 additions & 46 deletions scripts/deploy.ts

This file was deleted.

143 changes: 70 additions & 73 deletions tasks/aludel.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { AbiCoder } from "@ethersproject/abi";
import { formatEther } from "ethers/lib/utils";
import { task } from "hardhat/config";
import { task, types } from "hardhat/config";
import "@nomiclabs/hardhat-ethers";
import { parseEther } from "@ethersproject/units";
import { AddressZero } from "@ethersproject/constants";

// this function is meant to avoid polluting the tests with console output, and
// log on every other scenario
// console.log actually receives several whatevers
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const log = (...args: any[]) => {
if (global.before === undefined) {
console.log(...args);
}
};

export const ETHER = (amount = 1) => parseEther(amount.toString());
export const DAYS = (days = 1) => days * 60 * 60 * 24;
Expand Down Expand Up @@ -33,10 +42,10 @@ task("launch-program")
.setAction(async (args, { ethers, network }) => {
// log config

console.log("Network");
console.log(" ", network.name);
console.log("Task Args");
console.log(args);
log("Network");
log(" ", network.name);
log("Task Args");
log(args);

// compile

Expand All @@ -45,9 +54,9 @@ task("launch-program")
// get signer

const signer = (await ethers.getSigners())[0];
console.log("Signer");
console.log(" at", signer.address);
console.log(" ETH", formatEther(await signer.getBalance()));
log("Signer");
log(" at", signer.address);
log(" ETH", formatEther(await signer.getBalance()));

// get factory instance
const factory = await ethers.getContractAt(
Expand Down Expand Up @@ -99,25 +108,25 @@ task("update-template")
.setAction(async (args, { ethers, network }) => {
// log config

console.log("Network");
console.log(" ", network.name);
console.log("Task Args");
console.log(args);
log("Network");
log(" ", network.name);
log("Task Args");
log(args);

// get signer

const signer = (await ethers.getSigners())[0];
console.log("Signer");
console.log(" at", signer.address);
console.log(" ETH", formatEther(await signer.getBalance()));
log("Signer");
log(" at", signer.address);
log(" ETH", formatEther(await signer.getBalance()));

// get factory instance
const factory = await ethers.getContractAt(
"src/contracts/AludelFactory.sol:AludelFactory",
args.aludelFactory
);

console.log(factory);
log(factory);

// deploy minimal proxy using `params` as init params
await (
Expand All @@ -133,17 +142,17 @@ task("add-template")
.setAction(async (args, { ethers, network }) => {
// log config

console.log("Network");
console.log(" ", network.name);
console.log("Task Args");
console.log(args);
log("Network");
log(" ", network.name);
log("Task Args");
log(args);

// get signer

const signer = (await ethers.getSigners())[0];
console.log("Signer");
console.log(" at", signer.address);
console.log(" ETH", formatEther(await signer.getBalance()));
log("Signer");
log(" at", signer.address);
log(" ETH", formatEther(await signer.getBalance()));

// get factory instance
const factory = await ethers.getContractAt(
Expand All @@ -166,17 +175,17 @@ task("delist-program")
.setAction(async (args, { ethers, network }) => {
// log config

console.log("Network");
console.log(" ", network.name);
console.log("Task Args");
console.log(args);
log("Network");
log(" ", network.name);
log("Task Args");
log(args);

// get signer

const signer = (await ethers.getSigners())[0];
console.log("Signer");
console.log(" at", signer.address);
console.log(" ETH", formatEther(await signer.getBalance()));
log("Signer");
log(" at", signer.address);
log(" ETH", formatEther(await signer.getBalance()));

// get factory instance
const factory = await ethers.getContractAt(
Expand All @@ -188,49 +197,37 @@ task("delist-program")
await (await factory.delistProgram(args.program)).wait();
});

task("add-program")
.addParam("aludelFactory", "address of the aludel factory")
Comment on lines -191 to -192
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use these tasks for locally deployed contracts, and it would be helpful to overwrite deployed addresses.

I think we need to leave it as an optional param

task("add-program", "add a pre-existing aludel to the network's aludel factory")
.addParam("program", "deployed address of the program")
.addParam(
"template",
"Optional. deployed address of the program's template",
AddressZero
)
.addParam("template", "address of the program's template")
.addParam("name", "the name of the program")
.addParam("stakingTokenUrl", "the URL of the staking token")
.addParam(
.addParam("stakingTokenUrl", "the URL where to buy the staking token")
.addOptionalParam(
"startTime",
"the program start time in utc timestamp format (seconds)"
"the program start time in utc timestamp format (seconds). Default is now.",
Math.floor(Date.now() / 1000), // js date is in milliseconds, not an actual unix epoch
types.int
)
.setAction(async (args, { ethers, network }) => {
// log config

console.log("Network");
console.log(" ", network.name);
console.log("Task Args");
console.log(args);

// get signer

const signer = (await ethers.getSigners())[0];
console.log("Signer");
console.log(" at", signer.address);
console.log(" ETH", formatEther(await signer.getBalance()));

// get factory instance
const factory = await ethers.getContractAt(
"src/contracts/AludelFactory.sol:AludelFactory",
args.aludelFactory
);

// deploy minimal proxy using `params` as init params
await (
await factory.addProgram(
args.program,
args.template,
args.name,
args.stakingTokenUrl,
args.startTime
)
).wait();
});
.setAction(
async (args, { getNamedAccounts, ethers, network, deployments }) => {
// get factory instance
const factoryAddress = (await deployments.get("AludelFactory")).address;
const factory = await ethers.getContractAt(
"src/contracts/AludelFactory.sol:AludelFactory",
factoryAddress
);
const { deployer } = await getNamedAccounts();
log(`Adding template ${args.template} to factory ${factoryAddress}`);
log(` on network ${network.name} by default deployer ${deployer}`);

await (
await factory.addProgram(
args.program,
args.template,
args.name,
args.stakingTokenUrl,
args.startTime
)
).wait();
}
);
69 changes: 67 additions & 2 deletions test/deployments.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { expect } from "chai";
import chai, { expect } from "chai";
import { AbiCoder } from "ethers/lib/utils";
import { deployments, ethers } from "hardhat";
import { deployments, ethers, run } from "hardhat";
import {
AludelFactory,
Aludel,
CrucibleFactory,
MockERC20,
PowerSwitchFactory,
RewardPoolFactory,
} from "../typechain-types";
import { GEYSER_V2_VANITY_ADDRESS } from "../constants";
import chaiAsPromised from "chai-as-promised";
import { DAYS } from "./utils";
chai.use(chaiAsPromised);

describe("Aludel factory deployments", function () {
describe("WHEN deploying a template set", () => {
Expand Down Expand Up @@ -48,6 +52,67 @@ describe("Aludel factory deployments", function () {
const factory = await ethers.getContractFactory("MockERC20");
return (await factory.deploy(name, "MockERC20")) as MockERC20;
}
describe("GIVEN a preexisting program", () => {
let preexistingProgram: Aludel;
beforeEach(async () => {
const ethersFactory = await ethers.getContractFactory(
"src/contracts/aludel/AludelV2.sol:AludelV2"
);
preexistingProgram = (await ethersFactory.deploy()) as Aludel;
});

describe("WHEN adding it with the add-program task, AND passing al parameters", () => {
beforeEach(async () => {
await run("add-program", {
program: preexistingProgram.address,
template: GEYSER_V2_VANITY_ADDRESS,
name: "some name",
stakingTokenUrl: "http://buy.here",
startTime: 69,
});
});
it("THEN it is listed", async () => {
const program = await factory.programs(preexistingProgram.address);
expect(program.name).to.eq("some name");
});
});

it("WHEN adding it with the add-program task, AND omitting the template THEN it fails because the template is not optional", async () => {
await expect(
run("add-program", {
program: preexistingProgram.address,
name: "some name",
stakingTokenUrl: "http://buy.here",
startTime: 69,
})
).to.be.rejectedWith(
"HH306: The 'template' parameter expects a value, but none was passed"
);
});

describe("WHEN adding it with the add-program task, AND omitting the startTime", () => {
beforeEach(async () => {
await run("add-program", {
program: preexistingProgram.address,
template: GEYSER_V2_VANITY_ADDRESS,
name: "some name",
stakingTokenUrl: "http://buy.here",
});
});
it("THEN the current timestamp is used", async () => {
const program = await factory.programs(preexistingProgram.address);
const currentTime = Date.now() / 1000;
// we have to use a difference of a stupid amount of seconds, since
// the optional param in the task is evaluated when the task is
// registered, and when running the entire test suite, there could be
// a large difference with the time at which the test is run. This
// should not be relevant for actual task runs, since the task is run
// just a few milliseconds after being registered
expect(program.startTime.toNumber()).to.be.lt(currentTime);
expect(program.startTime.toNumber()).to.be.gt(currentTime - 400);
});
});
});

describe("GIVEN a PowerSwitchFactory, a CrucibleFactory, a RewardPoolFactory, and some other stuff", () => {
let powerSwitchFactory: PowerSwitchFactory;
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@
"@types/node" "*"
"@types/responselike" "*"

"@types/chai-as-promised@^7.1.3":
"@types/chai-as-promised@^7.1.3", "@types/chai-as-promised@^7.1.5":
version "7.1.5"
resolved "https://registry.yarnpkg.com/@types/chai-as-promised/-/chai-as-promised-7.1.5.tgz#6e016811f6c7a64f2eed823191c3a6955094e255"
integrity sha512-jStwss93SITGBwt/niYrkf2C+/1KTeZCZl1LaeezTlqppAKeoQC7jxyqYuP72sxBGKCIbw7oHgbYssIRzT5FCQ==
Expand Down