diff --git a/README.md b/README.md index 31404c0..66c5291 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,4 @@ yarn test:chain The command for running only the Eth Broker tests is: ``` yarn test:chain ./packages/chain/test/broker.test.js -``` +``` \ No newline at end of file diff --git a/packages/chain/contracts/Eth_broker.sol b/packages/chain/contracts/Eth_broker.sol index 533b85b..0cae0a5 100644 --- a/packages/chain/contracts/Eth_broker.sol +++ b/packages/chain/contracts/Eth_broker.sol @@ -22,7 +22,6 @@ contract Eth_broker { // ------------------------------------------------------------------------- // Events // ------------------------------------------------------------------------- - // Emitted when tokens are minted event mintTokensWithEth( address indexed buyer, // The address of the buyer @@ -217,7 +216,7 @@ contract Eth_broker { mutex() returns (bool) { - (uint256 daiNeeded, uint256 ethReceived) = _commonMint( + (uint256 daiNeeded, uint256 ethReceived, uint256 ethSpent) = _commonMint( _tokenAmount, _maxDaiSpendAmount, _deadline, @@ -228,7 +227,7 @@ contract Eth_broker { msg.sender, _tokenAmount, daiNeeded, - ethReceived, + ethSpent, _maxDaiSpendAmount ); // Returning that the mint executed successfully @@ -263,7 +262,7 @@ contract Eth_broker { mutex() returns (bool) { - (uint256 daiNeeded, uint256 ethReceived) = _commonMint( + (uint256 daiNeeded, uint256 ethReceived, uint256 ethSpent) = _commonMint( _tokenAmount, _maxDaiSpendAmount, _deadline, @@ -275,7 +274,7 @@ contract Eth_broker { _to, _tokenAmount, daiNeeded, - ethReceived, + ethSpent, _maxDaiSpendAmount ); // Returning that the mint executed successfully @@ -339,7 +338,7 @@ contract Eth_broker { "Curve burn failed" ); // Getting expected ETH for DAI - uint256 ethMin = sellRewardDai(_minDaiSellValue); + uint256 ethMin = sellRewardDai(dai_.balanceOf(address(this))); // Approving the router as a spender require( dai_.approve( @@ -349,6 +348,7 @@ contract Eth_broker { "DAI approve failed" ); // Selling DAI received for ETH + uint[] memory swapOutputs = new uint[](2); router_.swapExactTokensForETH( daiReward, ethMin, @@ -361,7 +361,7 @@ contract Eth_broker { msg.sender, _tokenAmount, daiReward, - ethMin, + swapOutputs[1], _minDaiSellValue ); // Returning that the burn executed successfully @@ -406,7 +406,8 @@ contract Eth_broker { internal returns( uint256 daiNeeded, - uint256 ethReceived + uint256 ethReceived, + uint256 ethSpent ) { // Getting the exact needed amount of DAI for desired token amount @@ -417,7 +418,9 @@ contract Eth_broker { "DAI required for trade above max" ); // Swapping sent ETH for exact amount of DAI needed - router_.swapETHForExactTokens.value(msg.value)( + uint256[] memory swapOutputs = new uint[](2); + + swapOutputs = router_.swapETHForExactTokens.value(msg.value)( daiNeeded, getPath(true), address(this), @@ -425,6 +428,7 @@ contract Eth_broker { ); // Getting the amount of ETH received ethReceived = address(this).balance; + ethSpent = swapOutputs[0]; // Approving the curve as a spender require( dai_.approve(address(curve_), daiNeeded), diff --git a/packages/chain/test/broker.test.js b/packages/chain/test/broker.test.ts similarity index 93% rename from packages/chain/test/broker.test.js rename to packages/chain/test/broker.test.ts index 64a24dd..6c1fc5c 100644 --- a/packages/chain/test/broker.test.js +++ b/packages/chain/test/broker.test.ts @@ -1,37 +1,33 @@ -require("@nomiclabs/hardhat-waffle"); -const hre = require("hardhat"); -const { expect, assert } = require("chai"); -const { - ethers, - curve_abi, - token_abi, - mock_dai_abi, - eth_broker_abi, - mock_router_abi, +import { formatUnits } from "@ethersproject/units"; +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { expect, assert } from "chai"; +import { Contract } from "ethers"; +import { ethers, waffle } from "hardhat"; +import { pre_mint_sequence, tokenSettings, test_settings, -} = require("./settings.test.js"); -const { network } = require("hardhat"); +} from "./settings.test"; + describe("🤝 Broker tests", () => { - let investor; - let owner; - let user; - let user_two; + let investor: SignerWithAddress; + let owner: SignerWithAddress; + let user: SignerWithAddress; + let user_two: SignerWithAddress; - let deployer; - let tokenInstance; - let curveInstance; - let collateralInstance; - let brokerInstance; - let mockRouterInstance; - let mockWethInstance; + let tokenInstance: Contract; + let curveInstance: Contract; + let collateralInstance: Contract; + let brokerInstance: Contract; + let mockRouterInstance: Contract; + let mockWethInstance: Contract; - const provider = new ethers.providers.JsonRpcProvider(); + const provider = waffle.provider; beforeEach(async () => { - const accounts = await ethers.getSigners(); + await provider.ready + const accounts = await ethers.getSigners(); owner = accounts[0]; investor = accounts[1]; user = accounts[2]; @@ -51,7 +47,6 @@ describe("🤝 Broker tests", () => { tokenSettings.dai.symbol, tokenSettings.dai.decimals ); - const curveArtifacts = await ethers.getContractFactory("Curve"); curveInstance = await curveArtifacts.deploy( tokenInstance.address, @@ -99,12 +94,7 @@ describe("🤝 Broker tests", () => { mockRouterInstance = await mockRouterArtifacts.deploy( mockWethInstance.address, ); - // priv key for account 0 of Hardhat - const ownerWallet = new ethers.Wallet( - "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", - provider - ); - await ownerWallet.sendTransaction({ + await owner.sendTransaction({ to: mockRouterInstance.address, value: test_settings.eth_broker.eth.seed_eth_amount }); @@ -248,25 +238,21 @@ describe("🤝 Broker tests", () => { ); // Testing expected behaviour - // expect(mockRouterEthBalance.toString()).to.equal(test_settings.eth_broker.eth.seed_eth_amount.toString()); assert.equal( mockRouterEthBalance.toString(), test_settings.eth_broker.eth.seed_eth_amount.toString(), "Eth balance of broker is incorrect" ); - // expect(mockRouterEthBalanceAfter.toString()).to.equal(test_settings.eth_broker.eth.mock_router_eth_balance_after_swap.toString()); assert.equal( mockRouterEthBalanceAfter.toString(), test_settings.eth_broker.eth.mock_router_eth_balance_after_swap.toString(), "Eth balance of broker is incorrect after swap" ); - // expect(balanceOfUserDAI.toString()).to.equal(test_settings.eth_broker.dai.almost_one_eth); assert.equal( balanceOfUserDAI.toString(), test_settings.eth_broker.dai.almost_one_eth, "User started with incorrect DAI balance" ); - // expect(balanceOfUserDaiAfter.toString()).to.equal("0"); assert.equal( balanceOfUserDaiAfter.toString(), 0, @@ -283,7 +269,6 @@ describe("🤝 Broker tests", () => { it("buy price expected", async () => { let buyPrice = await brokerInstance.buyPrice(test_settings.bzz.buyAmount); - // expect(buyPrice.toString()).to.equal(test_settings.eth_broker.eth.buy_price); assert.equal( buyPrice.toString(), test_settings.eth_broker.eth.buy_price, @@ -300,7 +285,6 @@ describe("🤝 Broker tests", () => { ); // Testing expected behaviour - // expect(sellRewardAmount.toString()).to.equal(test_settings.eth_broker.eth.sell_reward); assert.equal( sellRewardAmount.toString(), test_settings.eth_broker.eth.sell_reward, @@ -317,7 +301,6 @@ describe("🤝 Broker tests", () => { ); // Testing expected behaviour - // expect(sellRewardAmount.toString()).to.equal(test_settings.eth_broker.eth.almost_one_eth); assert.equal( sellRewardAmount.toString(), test_settings.eth_broker.eth.almost_one_eth, @@ -334,25 +317,21 @@ describe("🤝 Broker tests", () => { let hardCodedWethAddress = "0xacDdD0dBa07959Be810f6cd29E41b127b29E4A8a"; // Testing expected behaviour - // expect(buyPath[0]).to.equal(hardCodedWethAddress); assert.equal( buyPath[0], hardCodedWethAddress, "WETH address in trade route incorrect" ); - // expect(sellPath[1]).to.equal(hardCodedWethAddress); assert.equal( sellPath[1], hardCodedWethAddress, "WETH address in trade route incorrect" ); - // expect(buyPath[1]).to.equal(collateralInstance.address); assert.equal( buyPath[1], collateralInstance.address, "DAI address in trade route incorrect" ); - // expect(sellPath[0]).to.equal(collateralInstance.address); assert.equal( sellPath[0], collateralInstance.address, @@ -365,7 +344,6 @@ describe("🤝 Broker tests", () => { it("get time works as expected", async () => { let time = await brokerInstance.getTime(); - // expect(time.toString()).to.not.equal("0"); assert.notEqual(time.toString(), 0, "Time has not be correctly relayed"); }); }); @@ -467,57 +445,47 @@ describe("🤝 Broker tests", () => { // Testing expected behaviour assert.equal( mockRouterEthBalance.toString(), - test_settings.eth_broker.eth.seed_eth_amount, + test_settings.eth_broker.eth.seed_eth_amount.toString(), "Mock router ETH balance incorrect" ); - assert.equal( mockRouterEthBalanceAfter.toString(), test_settings.eth_broker.eth.mock_router_eth_balance_after_mint, "Mock router ETH balance incorrect after mint" ); - assert.notEqual( userEthBalance.toString(), userEthBalanceAfter.toString(), "User ETH balance does not change with mint" ); - assert.equal( daiCost.toString(), test_settings.dai.buyCost, "DAI cost for token amount unexpected" ); - assert.equal( ethCost.toString(), test_settings.eth_broker.eth.buy_price, "ETH cost for token amount unexpected" ); - assert.equal( buyPrice.toString(), test_settings.eth_broker.eth.buy_price, "ETH (raw) cost for token amount unexpected" ); // user balances changes as expected with mint - assert.equal(userDaiBalance.toString(), 0, "User starts without DAI"); - assert.equal(userBzzBalance.toString(), 0, "User starts without BZZ"); - assert.notEqual( userEthBalance.toString(), userEthBalanceAfter.toString(), "User ETH balance did not change with mint" ); - assert.equal( userDaiBalanceAfter.toString(), 0, "User DAI balance incorrectly changed with eth mint" ); - assert.equal( userBzzBalanceAfter.toString(), test_settings.bzz.buyAmount, @@ -525,31 +493,26 @@ describe("🤝 Broker tests", () => { ); // broker balance remains 0 on all assets assert.equal(0, brokerDaiBalance.toString(), "broker dai balance non 0"); - assert.equal( brokerBzzBalance.toString(), brokerDaiBalance.toString(), "broker bzz balance non 0" ); - assert.equal( brokerEthBalance.toString(), brokerDaiBalance.toString(), "broker eth balance non 0" ); - assert.equal( brokerDaiBalanceAfter.toString(), brokerDaiBalance.toString(), "broker dai balance after non 0" ); - assert.equal( brokerBzzBalanceAfter.toString(), brokerDaiBalance.toString(), "broker bzz balance after non 0" ); - assert.equal( brokerEthBalanceAfter.toString(), brokerDaiBalance.toString(), @@ -561,7 +524,6 @@ describe("🤝 Broker tests", () => { pre_mint_sequence.dai.cost, "Curve DAI is not as expected before mint" ); - assert.equal( curveDaiBalanceAfter.toString(), test_settings.dai.curve_collateral_after_buy, @@ -573,7 +535,6 @@ describe("🤝 Broker tests", () => { test_settings.eth_broker.bzz.initial_supply, "initial supply of bzz token unexpected" ); - assert.equal( tokenSupplyAfter.toString(), test_settings.eth_broker.bzz.after_buy, @@ -585,13 +546,11 @@ describe("🤝 Broker tests", () => { mockRouterBzzBalanceAfter.toString(), "Mock router BZZ balance incorrect (non 0)" ); - assert.equal( mockRouterDaiBalance.toString(), test_settings.eth_broker.eth.seed_eth_amount, "mock router starts with incorrect dai balance" ); - assert.equal( mockRouterDaiBalanceAfter.toString(), test_settings.eth_broker.dai.mock_router_dai_balance_after_mint, @@ -691,22 +650,19 @@ describe("🤝 Broker tests", () => { // Testing expected behaviour assert.equal( mockRouterEthBalance.toString(), - test_settings.eth_broker.eth.seed_eth_amount, + test_settings.eth_broker.eth.seed_eth_amount.toString(), "Mock router ETH balance incorrect" ); - assert.equal( mockRouterEthBalanceAfter.toString(), test_settings.eth_broker.eth.mock_router_eth_balance_after_mint, "Mock router ETH balance incorrect after mint" ); - assert.notEqual( userEthBalance.toString(), userEthBalanceAfter.toString(), "User ETH balance does not change with mint" ); - assert.equal( daiCost.toString(), test_settings.dai.buyCost, @@ -718,7 +674,6 @@ describe("🤝 Broker tests", () => { test_settings.eth_broker.eth.buy_price, "ETH cost for token amount unexpected" ); - assert.equal( buyPrice.toString(), test_settings.eth_broker.eth.buy_price, @@ -726,21 +681,17 @@ describe("🤝 Broker tests", () => { ); // user balances changes as expected with mint assert.equal(userDaiBalance.toString(), 0, "User starts without DAI"); - assert.equal(userBzzBalance.toString(), 0, "User starts without BZZ"); - assert.notEqual( userEthBalance.toString(), userEthBalanceAfter.toString(), "User ETH balance did not change with mint" ); - assert.equal( userDaiBalanceAfter.toString(), 0, "User DAI balance incorrectly changed with eth mint" ); - assert.equal( userBzzBalanceAfter.toString(), 0, @@ -748,21 +699,17 @@ describe("🤝 Broker tests", () => { ); // user receiver balances changes as expected with mint assert.equal(userReceiverDaiBalance.toString(), 0, "User starts without DAI"); - assert.equal(userReceiverBzzBalance.toString(), 0, "User starts without BZZ"); - assert.notEqual( userReceiverEthBalance.toString(), userEthBalanceAfter.toString(), "User ETH balance did not change with mint" ); - assert.equal( userReceiverDaiBalanceAfter.toString(), 0, "User DAI balance incorrectly changed with eth mint" ); - assert.equal( userReceiverBzzBalanceAfter.toString(), test_settings.bzz.buyAmount.toString(), @@ -770,31 +717,26 @@ describe("🤝 Broker tests", () => { ); // broker balance remains 0 on all assets assert.equal(0, brokerDaiBalance.toString(), "broker dai balance non 0"); - assert.equal( brokerBzzBalance.toString(), brokerDaiBalance.toString(), "broker bzz balance non 0" ); - assert.equal( brokerEthBalance.toString(), brokerDaiBalance.toString(), "broker eth balance non 0" ); - assert.equal( brokerDaiBalanceAfter.toString(), brokerDaiBalance.toString(), "broker dai balance after non 0" ); - assert.equal( brokerBzzBalanceAfter.toString(), brokerDaiBalance.toString(), "broker bzz balance after non 0" ); - assert.equal( brokerEthBalanceAfter.toString(), brokerDaiBalance.toString(), @@ -806,7 +748,6 @@ describe("🤝 Broker tests", () => { pre_mint_sequence.dai.cost, "Curve DAI is not as expected before mint" ); - assert.equal( curveDaiBalanceAfter.toString(), test_settings.dai.curve_collateral_after_buy, @@ -818,7 +759,6 @@ describe("🤝 Broker tests", () => { test_settings.eth_broker.bzz.initial_supply, "initial supply of bzz token unexpected" ); - assert.equal( tokenSupplyAfter.toString(), test_settings.eth_broker.bzz.after_buy, @@ -830,13 +770,11 @@ describe("🤝 Broker tests", () => { mockRouterBzzBalanceAfter.toString(), "Mock router BZZ balance incorrect (non 0)" ); - assert.equal( mockRouterDaiBalance.toString(), test_settings.eth_broker.eth.seed_eth_amount, "mock router starts with incorrect dai balance" ); - assert.equal( mockRouterDaiBalanceAfter.toString(), test_settings.eth_broker.dai.mock_router_dai_balance_after_mint, @@ -958,16 +896,14 @@ describe("🤝 Broker tests", () => { ); // User balance in various currencies expected assert.equal(userDaiBalance.toString(), 0, "User DAI balance incorrect"); - assert.equal( userBzzBalance.toString(), test_settings.bzz.buyAmount.toString(), "User BZZ balance incorrect" ); - assert.notEqual( userEthBalance.toString(), - 0, + "0", "User ETH balance incorrect" ); // broker balances are as expected @@ -976,16 +912,14 @@ describe("🤝 Broker tests", () => { 0, "broker incorrectly has a balance in DAI" ); - assert.equal( brokerBzzBalance.toString(), 0, "broker incorrectly has a balance in BZZ" ); - assert.equal( brokerEthBalance.toString(), - 0, + "0", "broker incorrectly has a balance in ETH" ); // Curve has correct balance @@ -1000,13 +934,11 @@ describe("🤝 Broker tests", () => { test_settings.eth_broker.eth.seed_eth_amount.toString(), "Mock router has incorrect DAI balance" ); - assert.equal( mockRouterBzzBalance.toString(), 0, "Mock router has incorrect BZZ balance" ); - assert.equal( mockRouterEthBalance.toString(), test_settings.eth_broker.eth.seed_eth_amount.toString(), @@ -1018,19 +950,16 @@ describe("🤝 Broker tests", () => { test_settings.eth_broker.bzz.initial_supply, "BZZ current supply incorrect" ); - assert.equal( daiCost.toString(), test_settings.eth_broker.dai.buy_cost, "DAI cost for token amount unexpected" ); - assert.equal( ethCost.toString(), test_settings.eth_broker.eth.sell_reward, "ETH cost for token amount unexpected" ); - assert.equal( buyPrice.toString(), test_settings.eth_broker.eth.sell_reward, @@ -1042,13 +971,11 @@ describe("🤝 Broker tests", () => { 0, "User incorrectly has left over DAI after burn" ); - assert.equal( userBzzBalanceAfter.toString(), 0, "User incorrectly has left over BZZ after burn" ); - assert.notEqual( userEthBalanceAfter.toString(), userEthBalance.toString(), @@ -1060,16 +987,14 @@ describe("🤝 Broker tests", () => { 0, "broker incorrectly has a balance in DAI" ); - assert.equal( brokerBzzBalanceAfter.toString(), 0, "broker incorrectly has a balance in BZZ" ); - assert.equal( brokerEthBalanceAfter.toString(), - 0, + "0", "broker incorrectly has a balance in ETH after burn" ); // Curve has correct balance @@ -1084,13 +1009,11 @@ describe("🤝 Broker tests", () => { test_settings.eth_broker.dai.mock_router_dai_balance_after_burn.toString(), "Mock router has incorrect DAI balance" ); - assert.equal( mockRouterBzzBalanceAfter.toString(), 0, "Mock router has incorrect BZZ balance" ); - assert.equal( mockRouterEthBalanceAfter.toString(), test_settings.eth_broker.eth.mock_router_eth_balance_after_burn.toString(), diff --git a/packages/chain/test/curve.test.js b/packages/chain/test/curve.test.ts similarity index 98% rename from packages/chain/test/curve.test.js rename to packages/chain/test/curve.test.ts index 9f81964..95c8555 100644 --- a/packages/chain/test/curve.test.js +++ b/packages/chain/test/curve.test.ts @@ -1,26 +1,22 @@ -require("@nomiclabs/hardhat-waffle"); -const hre = require("hardhat"); -const { expect, assert } = require("chai"); -const { - ethers, - curve_abi, - token_abi, - mock_dai_abi, +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { expect, assert } from "chai"; +import { Contract } from "ethers"; +import { ethers } from "hardhat"; +import { pre_mint_sequence, tokenSettings, test_settings - } = require("./settings.test.js"); + } from "./settings.test"; describe('📈 Curve tests', () => { - let investor; - let owner; - let user; - let user_two; + let investor: SignerWithAddress; + let owner: SignerWithAddress; + let user: SignerWithAddress; + let user_two: SignerWithAddress; - let deployer; - let tokenInstance; - let curveInstance; - let collateralInstance; + let tokenInstance: Contract; + let curveInstance: Contract; + let collateralInstance: Contract; beforeEach(async () => { const accounts = await ethers.getSigners(); @@ -970,6 +966,7 @@ const { await expect(tokenInstance.connect(user).burn( test_settings.bzz.sellAmount )).to.be.revertedWith(test_settings.errors.minter_is_minter); + // Approve a spender await tokenInstance.connect(user).approve( user_two.address, @@ -980,6 +977,7 @@ const { user_two.address, test_settings.bzz.sellAmount )).to.be.revertedWith(test_settings.errors.minter_is_minter); + }); /** * Tests that if a user with a minter role can burn and burnFrom. diff --git a/packages/chain/test/curve_calc.test.js b/packages/chain/test/curve_calc.test.ts similarity index 94% rename from packages/chain/test/curve_calc.test.js rename to packages/chain/test/curve_calc.test.ts index a2891d8..7ade589 100644 --- a/packages/chain/test/curve_calc.test.js +++ b/packages/chain/test/curve_calc.test.ts @@ -1,33 +1,27 @@ -require("@nomiclabs/hardhat-waffle"); -const hre = require("hardhat"); -const { expect } = require("chai"); -const { - ethers, - curve_test_abi, - token_abi, - mock_dai_abi, +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { expect } from "chai"; +import { Contract } from "ethers"; +import { ethers } from "hardhat"; +import { pre_mint_sequence, tokenSettings, test_settings -} = require("./settings.test.js"); +} from "./settings.test"; describe("🧮 Curve Calculations Tests", () => { - let investor; - let owner; - let user; - let user_two; + let investor: SignerWithAddress; + let owner: SignerWithAddress; + let user: SignerWithAddress; - let deployer; - let tokenInstance; - let collateralInstance; - let curveTestInstance; + let tokenInstance: Contract; + let collateralInstance: Contract; + let curveTestInstance: Contract; beforeEach(async () => { const accounts = await ethers.getSigners(); owner = accounts[0]; investor = accounts[1]; user = accounts[2]; - user_two = accounts[3]; const accountSlice = accounts.slice(4,19); const lossaEther = ethers.utils.parseEther("9999.99"); @@ -86,6 +80,7 @@ describe("🧮 Curve Calculations Tests", () => { expect(initialCost.toString()).to.equal(pre_mint_sequence.dai.cost); expect(primFuncAtZero.toString()).to.equal("0"); + }); /** * Testing that the price per token is never 0, even before the curve has @@ -98,6 +93,7 @@ describe("🧮 Curve Calculations Tests", () => { expect(spotPriceAtStart.toString()).to.not.equal("0"); expect(spotPriceAtStart.toString()).to.equal("1"); + }); }); @@ -143,6 +139,7 @@ describe("🧮 Curve Calculations Tests", () => { let helper = await curveTestInstance.helper(pre_mint_sequence.whole); // Testing expected behaviour expect(helper.toString()).to.equal(test_settings.helper_value); + }); /** * Testing that after the curve has pre-minted that the price for each @@ -172,6 +169,7 @@ describe("🧮 Curve Calculations Tests", () => { expect(primFuncAtPreMint.toString()).to.equal(test_settings.dai.curve_coll_at_prem); expect(spotPricePostMint.toString()).to.equal(test_settings.dai.one_cost); + }); /** * Testing that after the curves pre-mint the sell price for each token @@ -200,6 +198,7 @@ describe("🧮 Curve Calculations Tests", () => { ); // Testing expected behaviour expect(sellRewardWithdraw[0].toString()).to.equal(test_settings.dai.buyCost); + }); }); }); \ No newline at end of file diff --git a/packages/chain/test/curve_pre_mint.test.js b/packages/chain/test/curve_pre_mint.test.ts similarity index 98% rename from packages/chain/test/curve_pre_mint.test.js rename to packages/chain/test/curve_pre_mint.test.ts index 42eaaed..f20c990 100644 --- a/packages/chain/test/curve_pre_mint.test.js +++ b/packages/chain/test/curve_pre_mint.test.ts @@ -1,33 +1,27 @@ -require("@nomiclabs/hardhat-waffle"); -const hre = require("hardhat"); -const { expect, assert } = require("chai"); -const { - ethers, - curve_abi, - token_abi, - mock_dai_abi, +import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers"; +import { expect, assert } from "chai"; +import { Contract } from "ethers"; +import { ethers } from "hardhat"; +import { pre_mint_sequence, tokenSettings, test_settings - } = require("./settings.test.js"); + } from "./settings.test"; describe('🍃 Curve pre-mint tests', () => { - let investor; - let owner; - let user; - let user_two; + let investor: SignerWithAddress; + let owner: SignerWithAddress; + let user: SignerWithAddress; - let deployer; - let tokenInstance; - let curveInstance; - let collateralInstance; + let tokenInstance: Contract; + let curveInstance: Contract; + let collateralInstance: Contract; beforeEach(async () => { const accounts = await ethers.getSigners(); owner = accounts[0]; investor = accounts[1]; user = accounts[2]; - user_two = accounts[3]; const tokenArtifacts = await ethers.getContractFactory("Token"); tokenInstance = await tokenArtifacts.deploy( diff --git a/packages/chain/test/settings.test.js b/packages/chain/test/settings.test.ts similarity index 84% rename from packages/chain/test/settings.test.js rename to packages/chain/test/settings.test.ts index 37f42ee..576b3cd 100644 --- a/packages/chain/test/settings.test.js +++ b/packages/chain/test/settings.test.ts @@ -1,14 +1,6 @@ -const { ethers } = require("hardhat"); -let curve_abi = require("../artifacts/contracts/Curve.sol/Curve.json"); -let curve_test_abi = require("../artifacts/contracts/Curve_test.sol/curve_test.json"); -let token_abi = require("../artifacts/contracts/Token.sol/Token.json"); -let i_token_abi = require("../artifacts/contracts/I_Token.sol/I_Token.json"); -let i_curve_abi = require("../artifacts/contracts/I_Curve.sol/I_Curve.json"); -let mock_dai_abi = require("../artifacts/contracts/Mock_dai.sol/Mock_dai.json"); -let eth_broker_abi = require("../artifacts/contracts/Eth_broker.sol/Eth_broker.json"); -let mock_router_abi = require("../artifacts/contracts/Mock_router.sol/Mock_router.json"); +import { ethers } from "hardhat"; -const pre_mint_sequence = { +export const pre_mint_sequence = { // These amounts are each half of the open market supply first_half: ethers.utils.parseUnits("31250000", 16), second_half: ethers.utils.parseUnits("31250000", 16), @@ -29,7 +21,7 @@ const pre_mint_sequence = { }, }; -const tokenSettings = { +export const tokenSettings = { dai: { name: "DAI", symbol: "DAI", @@ -48,7 +40,7 @@ const tokenSettings = { }, }; -const test_settings = { +export const test_settings = { bzz: { one: ethers.utils.parseUnits("1", tokenSettings.bzz.decimals), buyAmount: ethers.utils.parseUnits("1000", tokenSettings.bzz.decimals), @@ -132,7 +124,7 @@ const test_settings = { }, }; -var erc20 = { +export var erc20 = { events: { transfer: "Transfer", approval: "Approval", @@ -164,20 +156,3 @@ var erc20 = { zero_address: "0x0000000000000000000000000000000000000000", }, }; - -module.exports = { - ethers, - curve_abi, - curve_test_abi, - token_abi, - i_token_abi, - i_curve_abi, - mock_dai_abi, - eth_broker_abi, - mock_router_abi, - pre_mint_sequence, - tokenSettings, - test_settings, - erc20, -}; - diff --git a/packages/chain/test/token.test.js b/packages/chain/test/token.test.ts similarity index 89% rename from packages/chain/test/token.test.js rename to packages/chain/test/token.test.ts index 934be29..ce4894e 100644 --- a/packages/chain/test/token.test.js +++ b/packages/chain/test/token.test.ts @@ -1,12 +1,9 @@ -require("@nomiclabs/hardhat-waffle"); -const hre = require("hardhat"); -const { expect, assert } = require("chai"); -const { - ethers, - token_abi, +import { expect, assert } from "chai"; +import { ethers } from "hardhat"; +import { erc20, tokenSettings -} = require("./settings.test.js"); +} from "./settings.test"; describe("🤑 Token Tests", () => { // Contract instance