Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
saeed-zil committed Mar 6, 2024
1 parent 2f1f1f8 commit 074ae12
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/deployer/Deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class ContractDeployer {
this.contractParams.push(this.txParams);
}

const contract = deploy(
const contract = await deploy(
this.hre,
this.contractName,
this.compress,
Expand Down
19 changes: 15 additions & 4 deletions src/deployer/ScillaContractDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export type OptionalUserDefinedLibraryList = UserDefinedLibrary[] | null;
export async function deploy(
hre: HardhatRuntimeEnvironment,
contractName: string,
compressContract: boolean,
compress: boolean,
userDefinedLibraries: OptionalUserDefinedLibraryList,
...args: any[]
): Promise<ScillaContract> {
Expand Down Expand Up @@ -157,6 +157,7 @@ export async function deploy(
const [tx, sc] = await deployFromFile(
contractInfo.path,
init,
compress,
txParamsForContractDeployment
);
sc.deployed_by = tx;
Expand All @@ -168,7 +169,8 @@ export async function deploy(

export const deployLibrary = async (
hre: HardhatRuntimeEnvironment,
libraryName: string
libraryName: string,
compress: boolean
): Promise<ScillaContract> => {
const contractInfo: ContractInfo = hre.scillaContracts[libraryName];
if (contractInfo === undefined) {
Expand All @@ -177,7 +179,7 @@ export const deployLibrary = async (

const init: Init = fillLibraryInit();

const [tx, sc] = await deployFromFile(contractInfo.path, init, {}); // FIXME: In #45
const [tx, sc] = await deployFromFile(contractInfo.path, init, compress, {}); // FIXME: In #45
sc.deployed_by = tx;

return sc;
Expand Down Expand Up @@ -262,6 +264,7 @@ const fillInit = (
export async function deployFromFile(
path: string,
init: Init,
compress: boolean,
txParamsForContractDeployment: any
): Promise<[Transaction, ScillaContract]> {
if (setup === null) {
Expand All @@ -272,7 +275,10 @@ export async function deployFromFile(
}

const deployer = setup.zilliqa.wallet.defaultAccount ?? setup.accounts[0];
const code = read(path);
let code = read(path);
if (compress) {
code = compressContract(code);
}
const contract = setup.zilliqa.contracts.new(code, init);
const [tx, sc] = await contract.deploy(
{ ...setup, pubKey: deployer.publicKey, ...txParamsForContractDeployment },
Expand All @@ -288,3 +294,8 @@ export async function deployFromFile(

return [tx, sc];
}

export function compressContract(code: string): string {
code = code.replace(/\(\*.*?\*\)/gms, "");
return code.replace(/(^[ \t]*\n)/gm, "");
}
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,22 @@ extendEnvironment((hre) => {

hre.deployScillaLibrary = lazyFunction(
() =>
async (libraryName: string): Promise<ScillaContract> => {
return deployLibrary(hre, libraryName);
async (
libraryName: string,
compress: boolean
): Promise<ScillaContract> => {
return deployLibrary(hre, libraryName, compress);
}
);

hre.deployScillaFile = lazyFunction(
() =>
async (
contractPath: string,
init: Init
init: Init,
compress: boolean
): Promise<[Transaction, ScillaContract]> => {
return deployFromFile(contractPath, init, {});
return deployFromFile(contractPath, init, compress, {});
}
);

Expand Down
8 changes: 6 additions & 2 deletions src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@ declare module "hardhat/types/runtime" {
userDefinedLibraries: UserDefinedLibrary[],
...args: any[]
) => Promise<ScillaContract>;
deployScillaLibrary: (contractName: string) => Promise<ScillaContract>;
deployScillaLibrary: (
contractName: string,
compress: boolean
) => Promise<ScillaContract>;
deployScillaFile: (
contractName: string,
init: Init
init: Init,
compress: boolean
) => Promise<[Transaction, ScillaContract]>;
getZilliqaChainId: () => number;
getNetworkUrl: () => string;
Expand Down
17 changes: 17 additions & 0 deletions test/deploy.live.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,24 @@ describe("", function () {
.withContractParams("Hello world!")
.deploy();

console.log(contract.isDeployed());
expect(contract.address).not.null;
});

it("Should be able to deploy a contract with compression", async function () {
const contract = await this.hre.contractDeployer
.withName("HelloWorld")
.withContractParams("sss")
.withContractCompression()
.deploy();

console.log(contract.error);

const tx = await contract.getHello();
await expect(tx).to.have.eventLogWithParams("getHello()", {
value: "",
vname: "msg",
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

(***************************************************)
(* The contract definition *)
(***************************************************)
scilla_version 0 (*version*)

contract WithComment (*contract name*)
()
(*fields*)
field welcome_msg : String = "" (*welcome*)

(*first transition*)
transition setHello (msg : String)
is_owner = builtin eq owner _sender;
match is_owner with
| False =>
e = {_eventname : "setHello()"; code : not_owner_code};
event e
| True =>
welcome_msg := msg;
e = {_eventname : "setHello()"; code : set_hello_code};
event e
end
end

(*second transition*)
transition getHello ()
r <- welcome_msg; (*dummy comment*)
e = {_eventname: "getHello()"; msg: r};
event e
end

0 comments on commit 074ae12

Please sign in to comment.