Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vrde committed Dec 1, 2023
1 parent 83cbc4c commit a9b905f
Show file tree
Hide file tree
Showing 17 changed files with 310 additions and 153 deletions.
37 changes: 37 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @type{import('./lib/internal/types').DAOConfig}
*/
const config = {
multisigAddress: "",
tokenName: "Teledisko DAO",
tokenSymbol: "TD",
governanceTokenName: "Teledisko DAO Governance",
governanceTokenSymbol: "TDGOV",
shareTokenName: "Teledisko DAO Share",
shareTokenSymbol: "TDSHARE",
reserveAddress: "0x...",
usdcAddress: "0x15c3eb3b621d1bff62cba1c9536b7c1ae9149b57",
diaOracleAddress: "0x3141274e597116f0bfcf07aeafa81b6b39c94325",
contributors: [
{
name: "Alice",
address: "0x...",
status: "board",
tokens: "",
},
{
name: "Bob",
address: "0x...",
status: "contributor",
tokens: "",
},
{
name: "Carol",
address: "0x...",
status: "contributor",
tokens: "",
},
],
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

pragma solidity ^0.8.16;

contract DIAOracleV2Mock {
contract DIAOracleV2 {
mapping(string => uint256) public values;
address oracleUpdater;

Expand Down
8 changes: 8 additions & 0 deletions contracts/mocks/IERC20Mintable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import "@openzeppelin/contracts/interfaces/IERC20.sol";

interface IERC20Mintable is IERC20 {
function mint(address account, uint256 amount) external;
}
4 changes: 2 additions & 2 deletions contracts/mocks/TokenMock.sol → contracts/mocks/USDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity 0.8.16;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract TokenMock is ERC20 {
constructor() ERC20("TokenMock", "TM") {}
contract USDC is ERC20 {
constructor(string memory name, string memory symbol) ERC20(name, symbol) {}

function mint(address to, uint256 amount) public {
_mint(to, amount);
Expand Down
9 changes: 4 additions & 5 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { readFile } from "fs/promises";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import {
DIAOracleV2Mock__factory,
DIAOracleV2__factory,
GovernanceToken__factory,
ProxyAdmin__factory,
ResolutionManager__factory,
ShareholderRegistry__factory,
TokenMock__factory,
USDC__factory,
Voting__factory,
} from "../typechain";

Expand Down Expand Up @@ -53,9 +53,9 @@ type ContractFactory =
| typeof ResolutionManager__factory
| typeof GovernanceToken__factory
| typeof Voting__factory
| typeof TokenMock__factory
| typeof USDC__factory
| typeof ProxyAdmin__factory
| typeof DIAOracleV2Mock__factory;
| typeof DIAOracleV2__factory;

export async function loadContract<T extends ContractFactory>(
hre: HardhatRuntimeEnvironment,
Expand All @@ -70,7 +70,6 @@ export async function loadContract<T extends ContractFactory>(
const [deployer] = await hre.ethers.getSigners();
const { chainId, name: networkName } = await hre.ethers.provider.getNetwork();
const addresses = networks[chainId];
console.log(networks);

if (!addresses || !addresses[name]) {
console.error(`Cannot find address for ${name} in network ${networkName}.`);
Expand Down
2 changes: 0 additions & 2 deletions lib/environment/hardhat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class NeokingdomDAOHardhat extends NeokingdomDAO {
config: Partial<Config> = {}
) {
const deployer = config.deployer ? config.deployer : await getWallet(hre);
const reserve = config.reserve ? config.reserve : deployer.address;
const chainId = config.chainId
? config.chainId
: (await hre.ethers.provider.getNetwork()).chainId;
Expand All @@ -31,7 +30,6 @@ export class NeokingdomDAOHardhat extends NeokingdomDAO {
...config,
chainId,
deployer,
reserve,
});

return new NeokingdomDAOHardhat(hre, newConfig);
Expand Down
26 changes: 13 additions & 13 deletions lib/environment/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { ethers, upgrades } from "hardhat";

import {
DAORoles,
DIAOracleV2Mock,
GovernanceToken,
IDIAOracleV2,
InternalMarket,
NeokingdomToken,
ProxyAdmin,
RedemptionController,
ResolutionManager,
ShareholderRegistry,
TokenMock,
USDC,
Voting,
} from "../../typechain";
import { Config, NeokingdomDAO } from "../internal/core";
import { ContractNames, NeokingdomContracts } from "../internal/types";

export class NeokingdomDAOMemory extends NeokingdomDAO {
contracts: Partial<NeokingdomContracts>;
nextStep = 0;
nextStep: { [key: string]: number } = {};

constructor(config: Config) {
super(config);
Expand All @@ -38,12 +38,12 @@ export class NeokingdomDAOMemory extends NeokingdomDAO {
return this.contracts;
}

public async setNextStep(n: number) {
this.nextStep = n;
public async setNextStep(n: number, sequenceName: string) {
this.nextStep[sequenceName] = n;
}

public async getNextStep() {
return this.nextStep;
public async getNextStep(sequenceName: string) {
return this.nextStep[sequenceName] || 0;
}

async deploy(contractName: ContractNames, args: any[] = []) {
Expand Down Expand Up @@ -88,17 +88,17 @@ export class NeokingdomDAOMemory extends NeokingdomDAO {
case "ShareholderRegistry":
this.contracts.shareholderRegistry = contract as ShareholderRegistry;
break;
case "TokenMock":
this.contracts.tokenMock = contract as TokenMock;
case "USDC":
this.contracts.usdc = contract as USDC;
break;
case "Voting":
this.contracts.voting = contract as Voting;
break;
case "ProxyAdmin":
this.contracts.proxyAdmin = contract as ProxyAdmin;
case "DIAOracleV2":
this.contracts.diaOracle = contract as IDIAOracleV2;
break;
case "DIAOracleV2Mock":
this.contracts.diaOracleV2Mock = contract as DIAOracleV2Mock;
default:
throw new Error(`Unknown contract ${contractName}`);
}
}
}
1 change: 0 additions & 1 deletion lib/internal/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {

export type Config = {
deployer: Wallet | SignerWithAddress;
reserve: string;
chainId: number;
verifyContracts: boolean;
saveNetworkConfig: boolean;
Expand Down
47 changes: 32 additions & 15 deletions lib/internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,29 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import {
DAORoles,
DAORoles__factory,
DIAOracleV2Mock,
DIAOracleV2Mock__factory,
ERC20Mintable__factory,
GovernanceToken,
GovernanceToken__factory,
IDIAOracleV2,
IDIAOracleV2__factory,
IERC20Mintable,
IERC20__factory,
InternalMarket,
InternalMarket__factory,
NeokingdomToken,
NeokingdomToken__factory,
ProxyAdmin,
ProxyAdmin__factory,
RedemptionController,
RedemptionController__factory,
ResolutionManager,
ResolutionManager__factory,
ShareholderRegistry,
ShareholderRegistry__factory,
TokenMock,
TokenMock__factory,
USDC__factory,
Voting,
Voting__factory,
} from "../../typechain";
import { DeployConfig } from "../sequence/deploy";
import { NeokingdomDAO } from "./core";

export const FACTORIES = {
Expand All @@ -37,10 +39,9 @@ export const FACTORIES = {
RedemptionController: RedemptionController__factory,
ResolutionManager: ResolutionManager__factory,
ShareholderRegistry: ShareholderRegistry__factory,
TokenMock: TokenMock__factory,
USDC: USDC__factory,
Voting: Voting__factory,
ProxyAdmin: ProxyAdmin__factory,
DIAOracleV2Mock: DIAOracleV2Mock__factory,
DIAOracleV2: DIAOracleV2Mock__factory,
} as const;

export type ContractNames = keyof typeof FACTORIES;
Expand All @@ -52,8 +53,25 @@ export type Contributor = {
tokens: string;
};

export type Address = `0x${string}`;

export type DAOConfig = {
testnet: boolean;
multisigAddress: Address;
tokenName: string;
tokenSymbol: string;
governanceTokenName: string;
governanceTokenSymbol: string;
shareTokenName: string;
shareTokenSymbol: string;
reserveAddress: Address;
usdcAddress: Address;
diaOracleAddress: Address;
contributors: Contributor[];
};

export type ContextGenerator<T extends Context> = (
n: NeokingdomDAO
neokingdomDao: NeokingdomDAO
) => Promise<T>;

export type NeokingdomContracts = {
Expand All @@ -64,10 +82,9 @@ export type NeokingdomContracts = {
redemptionController: RedemptionController;
resolutionManager: ResolutionManager;
shareholderRegistry: ShareholderRegistry;
tokenMock: TokenMock;
usdc: IERC20Mintable;
voting: Voting;
proxyAdmin: ProxyAdmin;
diaOracleV2Mock: DIAOracleV2Mock;
diaOracle: IDIAOracleV2;
};

export type Context = {};
Expand Down Expand Up @@ -97,17 +114,17 @@ export const CONTRACT_NAMES = [
"redemptionController",
"resolutionManager",
"shareholderRegistry",
"tokenMock",
"usdc",
"voting",
"proxyAdmin",
"diaOracleV2Mock",
"diaOracle",
];

export function isNeokingdomContracts(
n: Partial<NeokingdomContracts>
): n is NeokingdomContracts {
for (let name of CONTRACT_NAMES) {
if (!(name in n)) {
console.log("missing", name);
return false;
}
}
Expand Down
Loading

0 comments on commit a9b905f

Please sign in to comment.