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

Fix stack overflow issue #184

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ rustflags = [
"-Clink-arg=--pre-js=js/embed/pre.js",
"-Clink-arg=-sNODEJS_CATCH_EXIT=0",
"-Clink-arg=-sDISABLE_EXCEPTION_CATCHING=0",
"-Clink-arg=-sSTACK_SIZE=128kb",
"-Copt-level=3"
]
19 changes: 19 additions & 0 deletions js/e2e/web.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,22 @@ test('should return not found error for missing imports in browser', async ({pag
expect(output.errors[0]).toHaveProperty('message');
expect(output.errors[0].message).toContain('Source "nonexistent/console.sol" not found');
});

test('should successfully compile a valid Solidity contract that instantiates another contract in browser', async ({ page }) => {
await page.goto("http://127.0.0.1:8080");
await page.setContent("");
const standardInput = loadFixture('instantiate.json')
const result = await runWorker(page, standardInput);

expect(typeof result).toBe('string');
let output = JSON.parse(result);
expect(output).toHaveProperty('contracts');
expect(output.contracts['fixtures/instantiate.sol']).toHaveProperty('ChildContract');
expect(output.contracts['fixtures/instantiate.sol'].ChildContract).toHaveProperty('abi');
expect(output.contracts['fixtures/instantiate.sol'].ChildContract).toHaveProperty('evm');
expect(output.contracts['fixtures/instantiate.sol'].ChildContract.evm).toHaveProperty('bytecode');
expect(output.contracts['fixtures/instantiate.sol']).toHaveProperty('MainContract');
expect(output.contracts['fixtures/instantiate.sol'].MainContract).toHaveProperty('abi');
expect(output.contracts['fixtures/instantiate.sol'].MainContract).toHaveProperty('evm');
expect(output.contracts['fixtures/instantiate.sol'].MainContract.evm).toHaveProperty('bytecode');
});
20 changes: 20 additions & 0 deletions js/fixtures/instantiate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"language": "Solidity",
"sources": {
"fixtures/instantiate.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.8.2 <0.9.0;\ncontract ChildContract {\n constructor() {\n }\n}\ncontract MainContract {\n constructor() {\n ChildContract newContract = new ChildContract();\n }\n}"
}
},
"settings": {
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": ["abi"]
}
}
}
}

34 changes: 34 additions & 0 deletions js/tests/node.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,38 @@ describe('Compile Function Tests', function () {
expect(output.errors[0].message).to.exist;
expect(output.errors[0].message).to.include('Source "nonexistent/console.sol" not found');
});

it("should successfully compile a valid Solidity contract that instantiates another contract", async function () {
const standardInput = loadFixture("instantiate.json");

const result = await compile(standardInput);
expect(result).to.be.a("string");
const output = JSON.parse(result);
expect(output).to.have.property("contracts");
expect(output.contracts["fixtures/instantiate.sol"]).to.have.property(
"ChildContract",
);
expect(output.contracts["fixtures/instantiate.sol"].ChildContract).to.have.property(
"abi",
);
expect(output.contracts["fixtures/instantiate.sol"].ChildContract).to.have.property(
"evm",
);
expect(
output.contracts["fixtures/instantiate.sol"].ChildContract.evm,
).to.have.property("bytecode");
expect(output.contracts["fixtures/instantiate.sol"]).to.have.property(
"MainContract",
);
expect(output.contracts["fixtures/instantiate.sol"].MainContract).to.have.property(
"abi",
);
expect(output.contracts["fixtures/instantiate.sol"].MainContract).to.have.property(
"evm",
);
expect(
output.contracts["fixtures/instantiate.sol"].MainContract.evm,
).to.have.property("bytecode");
});

});
Loading