Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saeed-zil committed Mar 5, 2024
1 parent ea27e08 commit bbb44be
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 89 deletions.
76 changes: 0 additions & 76 deletions src/deployer/Builder.ts

This file was deleted.

88 changes: 88 additions & 0 deletions src/deployer/Deployer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { TxParams } from "@zilliqa-js/account";
import { HardhatPluginError } from "hardhat/plugins";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import {
OptionalUserDefinedLibraryList,
ScillaContract,
UserDefinedLibrary,
} from "./ScillaContractDeployer";

export class ContractDeployer {
private contractName: string;
private compress: boolean;
private userDefinedLibraries: OptionalUserDefinedLibraryList;
private txParams: TxParams | null;
private contractParams: any[];

constructor(private hre: HardhatRuntimeEnvironment) {
this.contractName = "";
this.compress = false;
this.userDefinedLibraries = null;
this.txParams = null;
this.contractParams = [];
}

reset(): ContractDeployer {
this.contractName = "";
this.compress = false;
this.userDefinedLibraries = null;
this.txParams = null;
this.contractParams = [];
return this;
}

withName(contractName: string): ContractDeployer {
this.contractName = contractName;
return this;
}

withContractParams(params: any[]): ContractDeployer {
this.contractParams = params;
return this;
}

withTxParams(params: TxParams): ContractDeployer {
this.txParams = params;
return this;
}

withContractCompression(): ContractDeployer {
this.compress = true;
return this;
}

withUserDefinedLibraries(libraries: UserDefinedLibrary[]) {
this.userDefinedLibraries = libraries;
return this;
}

async deploy(): Promise<ScillaContract> {
if (!!this.contractName.trim()) {
throw new HardhatPluginError(
"hardhat-scilla-plugin",
"You must specify the contract name in order to deploy it."
);
}
if (this.txParams) {
this.contractParams.push(this.txParams);
}

let contract;
if (this.userDefinedLibraries) {
contract = await this.hre.deployScillaContractWithLib(
this.contractName,
this.userDefinedLibraries,
...this.contractParams
);
} else {
contract = await this.hre.deployScillaContract(
this.contractName,
...this.contractParams
);
}

this.reset();
return contract;
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Init } from "@zilliqa-js/contract";
import { extendEnvironment } from "hardhat/config";
import { lazyFunction, lazyObject } from "hardhat/plugins";

import { ContractDeployer } from "./deployer/Deployer";
import {
deploy,
deployFromFile,
Expand Down Expand Up @@ -36,6 +37,7 @@ extendEnvironment((hre) => {
// We use lazyObject to avoid initializing things until they are actually
// needed.
hre.scillaContracts = lazyObject(() => loadScillaContractsInfo());
hre.contractDeployer = lazyObject(() => new ContractDeployer(hre));
hre.setScillaDefaults = lazyFunction(() => (params) => {
return updateSetup(params);
});
Expand Down
7 changes: 5 additions & 2 deletions src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Init } from "@zilliqa-js/contract";
import "hardhat/types/config";
import "hardhat/types/runtime";

import { ContractDeployer } from "./deployer/Deployer";
import {
ScillaContract,
UserDefinedLibrary,
Expand All @@ -16,9 +17,12 @@ import { ZilliqaHardhatObject } from "./ZilliqaHardhatObject";

declare module "hardhat/types/runtime" {
export interface HardhatRuntimeEnvironment {
zilliqa: ZilliqaHardhatObject;
scillaContracts: ScillaContracts;
contractDeployer: ContractDeployer;

interactWithScillaContract: (
contractAdress: string
contractAddress: string
) => Promise<ScillaContract | undefined>;
deployScillaContract: (
contractName: string,
Expand All @@ -34,7 +38,6 @@ declare module "hardhat/types/runtime" {
contractName: string,
init: Init
) => Promise<[Transaction, ScillaContract]>;
zilliqa: ZilliqaHardhatObject;
getZilliqaChainId: () => number;
getNetworkUrl: () => string;
getPrivateKeys: () => string[];
Expand Down
5 changes: 3 additions & 2 deletions test/defaults.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { BN, Long } from "@zilliqa-js/util";
import chai, { expect } from "chai";

import { scillaChaiEventMatcher } from "./chai-matcher/ScillaChaiMatchers";
import { setup } from "./deployer/ScillaContractDeployer";
import { scillaChaiEventMatcher } from "../src/chai-matcher/ScillaChaiMatchers";
import { setup } from "../src/deployer/ScillaContractDeployer";

import { useEnvironment } from "./helpers";

chai.use(scillaChaiEventMatcher);
Expand Down
5 changes: 2 additions & 3 deletions test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import { resetHardhatContext } from "hardhat/plugins-testing";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import path from "path";

import { initZilliqa } from "../src/deployer/ScillaContractDeployer";
import { updateContractsInfo } from "../src/parser/ScillaContractsInfoUpdater";
import * as ZilliqaHardhatObject from "../src/ZilliqaHardhatObject";

import { initZilliqa } from "./deployer/ScillaContractDeployer";
import { updateContractsInfo } from "./parser/ScillaContractsInfoUpdater";

declare module "mocha" {
interface Context {
hre: HardhatRuntimeEnvironment;
Expand Down
2 changes: 1 addition & 1 deletion test/logs-simplifier.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BigNumber } from "@ethersproject/bignumber";
import { expect } from "chai";

import { simplifyLogs } from "./chai-matcher/LogsSimplifier";
import { simplifyLogs } from "../src/chai-matcher/LogsSimplifier";

describe("", function () {
describe("Logs simplifier", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/scilla-checker.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chai from "chai";
import chaiSubset from "chai-subset";

import { runScillaChecker } from "./hardhat-tasks/ScillaChecker";
import { runScillaChecker } from "../src/hardhat-tasks/ScillaChecker";
chai.use(chaiSubset);

describe("", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/scilla-contracts-updater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ContractInfo,
loadScillaContractsInfo,
updateContractsInfo,
} from "./parser/ScillaContractsInfoUpdater";
} from "../src/parser/ScillaContractsInfoUpdater";
chai.use(chaiSubset);

describe("", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/scilla-generate-adt-type.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chai, { expect } from "chai";
import chaiSubset from "chai-subset";

import { ParsedContract, parseScilla } from "./parser/ScillaParser";
import { ParsedContract, parseScilla } from "../src/parser/ScillaParser";
chai.use(chaiSubset);

describe("Scilla Parser should parse contracts successfully", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/scilla-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ParsedContract,
parseScilla,
parseScillaLibrary,
} from "./parser/ScillaParser";
} from "../src/parser/ScillaParser";
chai.use(chaiSubset);

describe("", function () {
Expand Down
2 changes: 1 addition & 1 deletion test/zilliqa.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { expect } from "chai";

import { initZilliqa } from "../src/deployer/ScillaContractDeployer";
import * as ZilliqaHardhatObject from "../src/ZilliqaHardhatObject";

import { initZilliqa } from "./deployer/ScillaContractDeployer";

describe("", function () {
let zobj: ZilliqaHardhatObject.ZilliqaHardhatObject;
Expand Down

0 comments on commit bbb44be

Please sign in to comment.