Skip to content
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

test: Added tests for Base_SpokePool.sol #818

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 4 additions & 3 deletions scripts/svm/bridgeLiabilityToHubPool.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable node/no-missing-require */
/* eslint-disable node/no-missing-import */
/* eslint-disable camelcase */
/**
* Script: Bridge USDC Liability to Hub Pool
*
Expand Down Expand Up @@ -27,10 +30,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 +125,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
2 changes: 2 additions & 0 deletions scripts/svm/closeRelayerPdas.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable node/no-missing-require */
Dhruv-Varshney-developer marked this conversation as resolved.
Show resolved Hide resolved
/* eslint-disable node/no-missing-import */
// This script closes all Relayer PDAs associated with tracking fill Status. Relayers should do this periodically to
// reclaim the lamports within these tracking accounts. Fill Status PDAs can be closed on the deposit has expired.
import * as anchor from "@coral-xyz/anchor";
Expand Down
1 change: 1 addition & 0 deletions scripts/svm/generateExternalTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-process-exit */
import * as anchor from "@coral-xyz/anchor";
import { exec } from "child_process";
import * as fs from "fs";
Expand Down
62 changes: 62 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,62 @@
/* eslint-disable node/no-missing-import */
Dhruv-Varshney-developer marked this conversation as resolved.
Show resolved Hide resolved
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;
});
});
});
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable node/no-missing-import */
import { mockTreeRoot, amountToReturn, amountHeldByPool } from "../constants";
import { ethers, expect, Contract, SignerWithAddress, getContractFactory, seedContract } from "../../../../utils/utils";
import { hre } from "../../../../utils/utils.hre";
Expand Down
Loading