Skip to content

Commit

Permalink
test: migrate remaining test files to hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisfc68 committed Dec 23, 2024
1 parent 2d27d6a commit 37c941d
Show file tree
Hide file tree
Showing 6 changed files with 1,157 additions and 13 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/slither.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ jobs:
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

- name: Use Node.js 19.6.0
- name: Use Node.js 20.15.1
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: "19.6.0"
node-version: "20.15.1"

- name: NPM Login
run: npm config set //npm.pkg.github.com/:_authToken ${{ secrets.GITHUB_TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm config set //npm.pkg.github.com/:_authToken $GITHUB_TOKEN

- name: Install dependencies
run: npm ci
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
- repo: local
hooks:
- id: code-style
name: Check contact code style
name: Check contract code style
entry: npm run lint:sol
language: system
types: [file]
Expand Down
2 changes: 1 addition & 1 deletion scripts/deployment-utils/deploy-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface LiquidityBridgeContractLibraries {
bridge: string;
}

const BRIDGE_ADDRESS = "0x0000000000000000000000000000000001000006";
export const BRIDGE_ADDRESS = "0x0000000000000000000000000000000001000006";

async function deployProxyLibraries(
network: string
Expand Down
111 changes: 110 additions & 1 deletion test/deployment.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { expect } from "chai";
import hre from "hardhat";
import { ethers } from "hardhat";
import { deployLbcProxy } from "../scripts/deployment-utils/deploy-proxy";
import {
BRIDGE_ADDRESS,
deployLbcProxy,
} from "../scripts/deployment-utils/deploy-proxy";
import { upgradeLbcProxy } from "../scripts/deployment-utils/upgrade-proxy";
import { ZERO_ADDRESS } from "./utils/constants";

describe("LiquidityBridgeContract deployment process should", function () {
let proxyAddress: string;
Expand All @@ -28,4 +32,109 @@ describe("LiquidityBridgeContract deployment process should", function () {
const version = await lbc.version();
expect(version).to.equal("1.3.0");
});

it("validate minimiumCollateral arg in initialize", async () => {
const LiquidityBridgeContract = await ethers.getContractFactory(
"LiquidityBridgeContract",
{
libraries: {
BtcUtils: ZERO_ADDRESS,
SignatureValidator: ZERO_ADDRESS,
Quotes: ZERO_ADDRESS,
},
}
);
const lbc = await LiquidityBridgeContract.deploy();
const MINIMUM_COLLATERAL = ethers.parseEther("0.02");
const RESIGN_DELAY_BLOCKS = 15;
const initializeTx = lbc.initialize(
BRIDGE_ADDRESS,
MINIMUM_COLLATERAL,
1,
50,
RESIGN_DELAY_BLOCKS,
1,
1,
false
);
await expect(initializeTx).to.be.revertedWith("LBC072");
});

it("validate resignDelayBlocks arg in initialize", async () => {
const LiquidityBridgeContract = await ethers.getContractFactory(
"LiquidityBridgeContract",
{
libraries: {
BtcUtils: ZERO_ADDRESS,
SignatureValidator: ZERO_ADDRESS,
Quotes: ZERO_ADDRESS,
},
}
);
const lbc = await LiquidityBridgeContract.deploy();
const MINIMUM_COLLATERAL = ethers.parseEther("0.6");
const RESIGN_DELAY_BLOCKS = 14;
const initializeTx = lbc.initialize(
BRIDGE_ADDRESS,
MINIMUM_COLLATERAL,
1,
50,
RESIGN_DELAY_BLOCKS,
1,
1,
false
);
await expect(initializeTx).to.be.revertedWith("LBC073");
});

it("validate reward percentage arg in initialize", async () => {
const LiquidityBridgeContract = await ethers.getContractFactory(
"LiquidityBridgeContract",
{
libraries: {
BtcUtils: ZERO_ADDRESS,
SignatureValidator: ZERO_ADDRESS,
Quotes: ZERO_ADDRESS,
},
}
);
const MINIMUM_COLLATERAL = ethers.parseEther("0.6");
const RESIGN_DELAY_BLOCKS = 60;

const parameters = {
bridge: BRIDGE_ADDRESS,
minCollateral: MINIMUM_COLLATERAL,
minPegin: 1,
resignBlocks: RESIGN_DELAY_BLOCKS,
dustThreshold: 1,
btcBlockTime: 1,
mainnet: false,
};
const percentages = [
{ value: 0, ok: true },
{ value: 1, ok: true },
{ value: 99, ok: true },
{ value: 100, ok: true },
{ value: 101, ok: false },
];

for (const { value, ok } of percentages) {
const lbc = await LiquidityBridgeContract.deploy();
const initializeTx = lbc.initialize(
parameters.bridge,
parameters.minCollateral,
parameters.minPegin,
value,
parameters.resignBlocks,
parameters.dustThreshold,
parameters.btcBlockTime,
parameters.mainnet
);
if (ok) {
await expect(initializeTx).not.to.be.reverted;
} else {
await expect(initializeTx).to.be.revertedWith("LBC004");
}
}
});
});
Loading

0 comments on commit 37c941d

Please sign in to comment.