Factory.test.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const { expect } = require("chai")
  2. const { ethers } = require("hardhat")
  3. const { getAddr, deployNew, callAsContract } = require("./util/helpers")
  4. const { ZERO_ADDRESS } = require("./util/constants")
  5. describe("Factory:", function () {
  6. let owner, alice, poolId, chainId, sharedDecimals, localDecimals, router, factory, mockToken, fakeContract
  7. before(async function () {
  8. ;({ owner, alice, fakeContract } = await getAddr(ethers))
  9. poolId = 1
  10. chainId = 1
  11. sharedDecimals = 18
  12. localDecimals = sharedDecimals
  13. })
  14. beforeEach(async function () {
  15. router = await deployNew("Router")
  16. factory = await deployNew("Factory", [router.address])
  17. mockToken = await deployNew("MockToken", ["Token", "TKN", 18])
  18. })
  19. it("constructor() - reverts when router is 0x0", async function () {
  20. await expect(deployNew("Factory", [ZERO_ADDRESS])).to.revertedWith("Stargate: _router cant be 0x0")
  21. })
  22. it("setDefaultFeelLibrary() - reverts when router is 0x0", async function () {
  23. await expect(factory.setDefaultFeeLibrary(ZERO_ADDRESS)).to.revertedWith("Stargate: fee library cant be 0x0")
  24. })
  25. it("allPoolsLength()", async function () {
  26. expect(await factory.allPoolsLength()).to.equal(0)
  27. })
  28. it("createPool() - reverts if creatPair() is called for existing _poolId", async function () {
  29. await callAsContract(factory, router.address, "createPool(uint256,address,uint8,uint8,string,string)", [
  30. poolId,
  31. mockToken.address,
  32. sharedDecimals,
  33. localDecimals,
  34. "USDC Pool",
  35. "S*USDC",
  36. ])
  37. await expect(
  38. callAsContract(factory, router.address, "createPool(uint256,address,uint8,uint8,string,string)", [
  39. poolId,
  40. mockToken.address,
  41. sharedDecimals,
  42. localDecimals,
  43. "USDC Pool",
  44. "S*USDC",
  45. ])
  46. ).to.be.revertedWith("Stargate: Pool already created")
  47. })
  48. it("createPool() - increments allPoolsLength()", async function () {
  49. for (let _poolId = 1; _poolId < 10; ++_poolId) {
  50. await callAsContract(factory, router.address, "createPool(uint256,address,uint8,uint8,string,string)", [
  51. _poolId,
  52. mockToken.address,
  53. sharedDecimals,
  54. localDecimals,
  55. "USDC Pool",
  56. "S*USDC",
  57. ])
  58. expect(await factory.allPoolsLength()).to.equal(_poolId)
  59. }
  60. })
  61. it("createPool() - reverts when called by non router", async function () {
  62. await expect(factory.createPool(poolId, mockToken.address, sharedDecimals, localDecimals, "USDC Pool", "S*USDC")).to.be.revertedWith(
  63. "Stargate: caller must be Router."
  64. )
  65. })
  66. it("renounceOwnership() doesnt affect ownership", async function () {
  67. expect(await factory.owner()).to.equal(owner.address)
  68. await factory.renounceOwnership()
  69. expect(await factory.owner()).to.equal(owner.address)
  70. })
  71. })