Skip to content

test: Added tests for Base_SpokePool.sol #818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ module.exports = {
node: true,
},
plugins: ["@typescript-eslint"],
extends: ["standard", "plugin:prettier/recommended", "plugin:node/recommended"],
extends: ["standard", "plugin:prettier/recommended", "plugin:node/recommended", "plugin:mocha/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaVersion: 12,
},
rules: {
"node/no-unsupported-features/es-syntax": ["error", { ignores: ["modules"] }],
"node/no-missing-import": [
"error",
{
tryExtensions: [".js", ".ts"],
resolvePaths: ["."],
},
],
"mocha/no-exclusive-tests": "error",
"@typescript-eslint/no-var-requires": 0,
},
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ The latest contract deployments on Production will always be under the `deployed

## Requirements

This repository assumes you have [Node](https://nodejs.org/en/download/package-manager) installed, with a minimum version of 16.18.0. Depending on what you want to do with the repo you might also need [foundry](https://book.getfoundry.sh/getting-started/installation) and [anchor](https://www.anchor-lang.com/docs/installation) to also be installed. If you have build issues please insure these are both installed first.
This repository assumes you have [Node](https://nodejs.org/en/download/package-manager) installed, with a minimum version of 16.18.0. Depending on what you want to do with the repo you might also need [foundry](https://book.getfoundry.sh/getting-started/installation) and [anchor](https://www.anchor-lang.com/docs/installation) to also be installed. If you have build issues please ensure these are both installed first.

Note if you get build issues on the initial `yarn` command try downgrading to node 20.17 (`nvm use 20.17`). If you've never used anchor before you might need to run `avm use latest` as well.
**Note**
If you get build issues on the initial `yarn` command try downgrading to node 20.17 (`nvm use 20.17`). If you've never used anchor before you might need to run `avm use latest` as well.

## Build

Expand Down
5 changes: 2 additions & 3 deletions scripts/svm/bridgeLiabilityToHubPool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
/**
* Script: Bridge USDC Liability to Hub Pool
*
Expand Down Expand Up @@ -27,10 +28,8 @@ import * as anchor from "@coral-xyz/anchor";
import { AnchorProvider, BN, Program } from "@coral-xyz/anchor";
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { PublicKey, SystemProgram } from "@solana/web3.js";
// eslint-disable-next-line camelcase
import { MessageTransmitter } from "../../target/types/message_transmitter";
import { SvmSpoke } from "../../target/types/svm_spoke";
// eslint-disable-next-line camelcase
import {
CIRCLE_IRIS_API_URL_DEVNET,
CIRCLE_IRIS_API_URL_MAINNET,
Expand Down Expand Up @@ -124,7 +123,7 @@ async function bridgeLiabilityToHubPool(): Promise<void> {
// Resolve Solana USDC addresses.
const svmUsdc = isDevnet ? SOLANA_USDC_DEVNET : SOLANA_USDC_MAINNET;

const [statePda, _] = PublicKey.findProgramAddressSync(
const [statePda] = PublicKey.findProgramAddressSync(
[Buffer.from("state"), seed.toArrayLike(Buffer, "le", 8)],
svmSpokeProgram.programId
);
Expand Down
61 changes: 61 additions & 0 deletions test/evm/hardhat/chain-specific-spokepools/Base_SpokePool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { ethers, expect, Contract, FakeContract, SignerWithAddress, getContractFactory } from "../../../../utils/utils";
import { hre } from "../../../../utils/utils.hre";
import { hubPoolFixture } from "../fixtures/HubPool.Fixture";
import { smock } from "@defi-wonderland/smock";

let hubPool: Contract, spokePool: Contract, weth: Contract, usdc: Contract;
let owner: SignerWithAddress;
let cctpTokenMessenger: FakeContract;

const tokenMessengerAbi = [
{
inputs: [],
name: "localToken",
outputs: [{ internalType: "address", name: "", type: "address" }],
stateMutability: "view",
type: "function",
},
];

describe("Base Spoke Pool", function () {
beforeEach(async function () {
[owner] = await ethers.getSigners();
({ weth, usdc, hubPool } = await hubPoolFixture());

cctpTokenMessenger = await smock.fake(tokenMessengerAbi);

spokePool = await hre.upgrades.deployProxy(
await getContractFactory("Base_SpokePool", owner),
[0, owner.address, hubPool.address],
{
kind: "uups",
unsafeAllow: ["delegatecall"],
constructorArgs: [weth.address, 60 * 60, 9 * 60 * 60, usdc.address, cctpTokenMessenger.address],
}
);
});

describe("Initialization", function () {
it("Should initialize with correct constructor parameters", async function () {
expect(await spokePool.wrappedNativeToken()).to.equal(weth.address);
expect(await spokePool.usdcToken()).to.equal(usdc.address);
expect(await spokePool.cctpTokenMessenger()).to.equal(cctpTokenMessenger.address);
});

it("Should initialize with correct proxy parameters", async function () {
expect(await spokePool.numberOfDeposits()).to.equal(0);
expect(await spokePool.crossDomainAdmin()).to.equal(owner.address);
expect(await spokePool.withdrawalRecipient()).to.equal(hubPool.address);
});

it("Should initialize with correct OVM_ETH", async function () {
expect(await spokePool.l2Eth()).to.equal("0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000");
});
});

describe("Error cases", function () {
it("Should revert on reinitialization", async function () {
await expect(spokePool.connect(owner).initialize(0, owner.address, hubPool.address)).to.be.reverted;
});
});
});