Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
saeed-zil committed Mar 6, 2024
1 parent 074ae12 commit 2a7b845
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/deployer/ScillaContractDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ export async function deployFromFile(
}

export function compressContract(code: string): string {
code = code.replace(/\(\*.*?\*\)/gms, "");
return code.replace(/(^[ \t]*\n)/gm, "");
// Remove comments
code = code.replace(/(\(\*.*?\*\))/gms, "");

// Remove empty lines
code = code.replace(/(^[ \t]*\n)/gm, "");

// Remove extra whitespace at the end of the lines
return code.replace(/[ \t]+$/gm, "");
}
43 changes: 43 additions & 0 deletions test/contract-compression.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { expect } from "chai";

import { compressContract } from "../src/deployer/ScillaContractDeployer";

describe("Contract Compression", function () {
it("#1", async function () {
const code = `(***************************************************)
(* The contract definition *)
(***************************************************)
contract HelloWorld
(owner: ByStr20)`
const compressed = compressContract(code);
expect(compressed).to.be.eq(`contract HelloWorld
(owner: ByStr20)`)
});

it("#2", async function () {
const code = `(*something*)contract HelloWorld
(owner: ByStr20)`
const compressed = compressContract(code);
expect(compressed).to.be.eq(`contract HelloWorld
(owner: ByStr20)`)
});

it("#3", async function () {
const code = `contract HelloWorld (* a dummy comment*)
(owner: ByStr20)`
const compressed = compressContract(code);
expect(compressed).to.be.eq(`contract HelloWorld
(owner: ByStr20)`)
});

it("#4", async function () {
const code = `contract WithComment (*contract name*)
()
(*fields*)
field welcome_msg : String = "" (*welcome*) (*another comment*) `
const compressed = compressContract(code);
expect(compressed).to.be.eq(`contract WithComment
()
field welcome_msg : String = ""`)
});
});

0 comments on commit 2a7b845

Please sign in to comment.