Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rbajollari committed Jan 27, 2024
1 parent 491b479 commit eae6e5c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 25 deletions.
2 changes: 1 addition & 1 deletion contracts/MockOjo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract MockOjo {
uint256 amount;
}

Balance[] public balances ;
Balance[] public balances;

constructor(address ojo_) {
ojo = IOjo(ojo_);
Expand Down
19 changes: 16 additions & 3 deletions test/MockOjo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,23 @@ describe("Deploy", function () {
const [deployer, axelarGateway, axelarGasReceiver] = await ethers.getSigners();

const Ojo = await ethers.getContractFactory("Ojo");
const ojo = await Ojo.deploy(axelarGateway.address, axelarGasReceiver.address);
const ojoImplementation = await Ojo.deploy(axelarGateway.address, axelarGasReceiver.address);

const ojoChain = "ojoChain";
const ojoAddress = "ojoAddress";
const resolveWindow = 100;
const initParams = ethers.AbiCoder.defaultAbiCoder().encode(["string", "string", "uint256"],[ojoChain, ojoAddress, resolveWindow]);

const OjoProxy = await ethers.getContractFactory("OjoProxy");
const ojoProxy = await OjoProxy.deploy();

ojoProxy.init(await ojoImplementation.getAddress(), await deployer.getAddress(), initParams);

const ojoContract = ojoImplementation.attach(await ojoProxy.getAddress());
const ojo = await ethers.getContractAt("Ojo", await ojoContract.getAddress())

const MockOjo = await ethers.getContractFactory("MockOjo");
const mockOjo = await MockOjo.deploy(ojo.address);
const mockOjo = await MockOjo.deploy(await ojo.getAddress());

return {deployer, mockOjo, ojo}
}
Expand All @@ -20,6 +33,6 @@ describe("Deploy", function () {
it("sets address of ojo contract correctly", async function(){
const { mockOjo, ojo} = await loadFixture(deployMockOjoContract);

expect(await mockOjo.ojo()).eq(ojo.address);
expect(await mockOjo.ojo()).eq(await ojo.getAddress());
})
})
32 changes: 18 additions & 14 deletions test/Ojo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { expect } from "chai";
import { ethers } from "hardhat";
import { } from "../scripts/utils";

describe("Deploy OjoContract", function () {
describe("Deploy OjoContract", function() {
async function deployOjoContract() {
// Contracts are deployed using the first signer/account by default
const [deployer, otherAccount, axelarGateway, axelarGasReceiver] = await ethers.getSigners();
Expand All @@ -13,40 +14,43 @@ describe("Deploy OjoContract", function () {
const ojoChain = "ojoChain";
const ojoAddress = "ojoAddress";
const resolveWindow = 100;
const initParams = ethers.utils.defaultAbiCoder.encode(["string", "string", "uint256"],[ojoChain, ojoAddress, resolveWindow]);
const initParams = ethers.AbiCoder.defaultAbiCoder().encode(["string", "string", "uint256"],[ojoChain, ojoAddress, resolveWindow]);

const OjoProxy = await ethers.getContractFactory("OjoProxy");
const ojoProxy = await OjoProxy.deploy();
ojoProxy.init(ojoImplementation.address, deployer.address, initParams);

return {deployer, otherAccount, ojoProxy, ojoImplementation}
ojoProxy.init(await ojoImplementation.getAddress(), await deployer.getAddress(), initParams);

const ojoContract = ojoImplementation.attach(await ojoProxy.getAddress());
const ojo = await ethers.getContractAt("Ojo", await ojoContract.getAddress())

return {deployer, otherAccount, ojo}
}

it("restricts access on onlyOwnwer methods", async function(){
const {deployer, otherAccount, ojoProxy, ojoImplementation} = await loadFixture(deployOjoContract);
const ojo = ojoProxy.attach(ojoImplementation.address);
it("restricts access on onlyOwnwer methods", async function() {
const {deployer, otherAccount, ojo} = await loadFixture(deployOjoContract);

// check owner
expect(await ojo.owner()).eq(deployer.address);
expect(await ojo.owner()).eq(await deployer.getAddress());

// owner can update ojoChain, ojoAddress, and resolveWindow
await ojo.connect(deployer.address).updateOjoChain("ojoChain2");
await ojo.connect(deployer).updateOjoChain("ojoChain2");
expect(await ojo.ojoChain()).eq("ojoChain2");

await ojo.connect(deployer.address).updateOjoAddress("ojoAddress2");
await ojo.connect(deployer).updateOjoAddress("ojoAddress2");
expect(await ojo.ojoAddress()).eq("ojoAddress2");

await ojo.connect(deployer.address).updateResolveWindow(150);
await ojo.connect(deployer).updateResolveWindow(150);
expect(await ojo.resolveWindow()).eq(150);

// other account cannot update ojoChain, ojoAddress, and resolveWindow
expect(ojo.connect(otherAccount.address).updateOjoChain("ojoChain3")).to.be.revertedWithCustomError;
expect(ojo.connect(otherAccount).updateOjoChain("ojoChain3")).to.be.revertedWithCustomError;
expect(await ojo.ojoChain()).eq("ojoChain2");

expect(ojo.connect(deployer.address).updateOjoAddress("ojoAddress2")).to.be.revertedWithCustomError;
expect(ojo.connect(otherAccount).updateOjoAddress("ojoAddress3")).to.be.revertedWithCustomError;
expect(await ojo.ojoAddress()).eq("ojoAddress2");

expect(ojo.connect(deployer.address).updateResolveWindow(150)).to.be.revertedWithCustomError;
expect(ojo.connect(otherAccount).updateResolveWindow(200)).to.be.revertedWithCustomError;
expect(await ojo.resolveWindow()).eq(150);
})
})
15 changes: 8 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,9 @@
integrity sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==

"@types/node@*", "@types/node@>=16.0.0":
version "20.11.7"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.7.tgz#cb49aedd758c978c30806d0c38b520ed2a3df6e0"
integrity sha512-GPmeN1C3XAyV5uybAf4cMLWT9fDWcmQhZVtMFu7OR32WjrqGG+Wnk2V1d0bmtUyE/Zy1QJ9BxyiTih9z8Oks8A==
version "20.11.8"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.8.tgz#bdb6de1048613c3c6ab6c341c37e8fd1a7860308"
integrity sha512-i7omyekpPTNdv4Jb/Rgqg0RU8YqLcNsI12quKSDkRXNfx7Wxdm6HhK1awT3xTgEkgxPn3bvnSpiEAc7a7Lpyow==
dependencies:
undici-types "~5.26.4"

Expand Down Expand Up @@ -1098,7 +1098,7 @@ [email protected]:
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.0.9.tgz#91b4792588a7738c25f35dd6f63752a2f8776135"
integrity sha512-LEyx4aLEC3x6T0UguF6YILf+ntvmOaWsVfENmIW0E9H09vKlLDGelMjjSm0jkDHALj8A8quZ/HapKNigzwge+Q==

abstract-level@^1.0.0, abstract-level@^1.0.2, abstract-level@^1.0.3:
abstract-level@^1.0.0, abstract-level@^1.0.2, abstract-level@^1.0.3, abstract-level@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/abstract-level/-/abstract-level-1.0.4.tgz#3ad8d684c51cc9cbc9cf9612a7100b716c414b57"
integrity sha512-eUP/6pbXBkMbXFdx4IH2fVgvB7M0JvR7/lIL33zcs0IBcwjdzSSl31TOJsaCzmKSSDF9h8QYSOJux4Nd4YJqFg==
Expand Down Expand Up @@ -2974,10 +2974,11 @@ level-transcoder@^1.0.1:
module-error "^1.0.1"

level@^8.0.0:
version "8.0.0"
resolved "https://registry.yarnpkg.com/level/-/level-8.0.0.tgz#41b4c515dabe28212a3e881b61c161ffead14394"
integrity sha512-ypf0jjAk2BWI33yzEaaotpq7fkOPALKAgDBxggO6Q9HGX2MRXn0wbP1Jn/tJv1gtL867+YOjOB49WaUF3UoJNQ==
version "8.0.1"
resolved "https://registry.yarnpkg.com/level/-/level-8.0.1.tgz#737161db1bc317193aca4e7b6f436e7e1df64379"
integrity sha512-oPBGkheysuw7DmzFQYyFe8NAia5jFLAgEnkgWnK3OXAuJr8qFT+xBQIwokAZPME2bhPFzS8hlYcL16m8UZrtwQ==
dependencies:
abstract-level "^1.0.4"
browser-level "^1.0.1"
classic-level "^1.2.0"

Expand Down

0 comments on commit eae6e5c

Please sign in to comment.