Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BeroBurny committed Feb 8, 2024
1 parent 2f2f0ee commit 322624a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
21 changes: 5 additions & 16 deletions packages/plugin/src/MultichainHardhatRuntimeEnvironmentField.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class MultichainHardhatRuntimeEnvironmentField {
this.web3 = new Web3(provider);
}

public ADAPTER_ADDRESS = vars.get(
private ADAPTER_ADDRESS = vars.get(
"ADAPTER_ADDRESS",
"0x85d62ad850b322152bf4ad9147bfbf097da42217"
);
Expand Down Expand Up @@ -105,34 +105,23 @@ export class MultichainHardhatRuntimeEnvironmentField {
const RESOURCE_ID =
"0x000000000000000000000000000000000000000000000000000000000000cafe";

const gasMultiplier = this.hre.network.name.includes("arbi") ? 10 : 1;
const txOptionsAdapter = { gasLimit: 1900000 * gasMultiplier };
const txOptionsCreateX = { gasLimit: 2700000 * gasMultiplier };

const createX = new this.web3.eth.Contract(CreateXABI);
const createXResponse = await createX
.deploy({
data: CreateXBytecode,
})
.send({ from: deployer, ...txOptionsCreateX });
.send({ from: deployer });
const createXAddress = createXResponse.options.address || ZERO_ADDRESS;
console.log(`CreateX locally deployed: ${createXAddress}`);

const adapter = new this.web3.eth.Contract(AdapterABI);
const adapterEncodedAbi = adapter
const adapterResponse = await adapter
.deploy({
data: AdapterBytecode,
arguments: [createXAddress, bridgeAddress, RESOURCE_ID],
})
.encodeABI();

const salt = `${deployer}000000000000000000000000`;
const receipt = await createX.methods
.deployCreate3(salt, adapterEncodedAbi)
.send({ from: deployer, ...txOptionsAdapter });

const adapterAddress = receipt.events!.ContractCreation.returnValues
.newContract as string;
.send({ from: deployer });
const adapterAddress = adapterResponse.options.address || ZERO_ADDRESS;

console.log(
`Adapter locally deployed: ${adapterAddress}` +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// We load the plugin here.
import { HardhatUserConfig } from "hardhat/types";
import { Environment } from "@buildwithsygma/sygma-sdk-core";

import "../../../src/index";

const config: HardhatUserConfig = {
solidity: "0.7.3",
defaultNetwork: "hardhat",
multichain: {
environment: Environment.TESTNET,
},
};

export default config;
7 changes: 7 additions & 0 deletions packages/plugin/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from "path";
import { resetHardhatContext } from "hardhat/plugins-testing";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { TASK_NODE } from "hardhat/builtin-tasks/task-names";

declare module "mocha" {
interface Context {
Expand All @@ -19,3 +20,9 @@ export function useEnvironment(fixtureProjectName: string) {
resetHardhatContext();
});
}

export function useHardhatNode() {
beforeEach("Loading hardhat node", function () {
this.hre.run(TASK_NODE);
});
}
18 changes: 17 additions & 1 deletion packages/plugin/test/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import chaiAsPromised from "chai-as-promised";
import { Environment } from "@buildwithsygma/sygma-sdk-core";
import { MultichainHardhatRuntimeEnvironmentField } from "../src/MultichainHardhatRuntimeEnvironmentField";

import { useEnvironment } from "./helpers";
import { useEnvironment, useHardhatNode } from "./helpers";

use(chaiAsPromised);

Expand Down Expand Up @@ -35,4 +35,20 @@ describe("Integration tests examples", function () {
describe("Hardhat Runtime Environment extension", function () {
useEnvironment("hardhat-project");
});

describe("Hardhat Runtime Environment extension - initLocalEnvironment", function () {
useEnvironment("hardhat-localhost");
useHardhatNode();

it("Should deploy all required contracts on testnet", async function () {
const addresses = await this.hre.multichain.initLocalEnvironment();

assert.deepEqual(addresses, {
adapterAddress: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
createXAddress: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
bridgeAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
feeHandlerAddress: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
});
});
});
});

0 comments on commit 322624a

Please sign in to comment.