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

Merged
merged 6 commits into from
Jan 31, 2025
Merged
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"
]
42 changes: 38 additions & 4 deletions js/e2e/web.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function runWorker(page, input) {
}, input);
}

test('should successfully compile valid Solidity code in browser', async ({ page }) => {
test('should successfully compile valid Solidity code in the browser', async ({ page }) => {
await page.goto("http://127.0.0.1:8080");
await page.setContent("");
const standardInput = loadFixture('storage.json')
Expand All @@ -41,7 +41,7 @@ test('should successfully compile valid Solidity code in browser', async ({ page
expect(output.contracts['fixtures/storage.sol'].Storage.evm).toHaveProperty('bytecode');
});

test('should successfully compile large valid Solidity code in browser', async ({ page }) => {
test('should successfully compile large valid Solidity code in the browser', async ({ page }) => {
await page.goto("http://127.0.0.1:8080");
await page.setContent("");
const standardInput = loadFixture('token.json')
Expand All @@ -56,7 +56,7 @@ test('should successfully compile large valid Solidity code in browser', async (
expect(output.contracts['fixtures/token.sol'].MyToken.evm).toHaveProperty('bytecode');
});

test('should throw an error for invalid Solidity code in browser', async ({ page }) => {
test('should throw an error for invalid Solidity code in the browser', async ({ page }) => {
await page.goto("http://127.0.0.1:8080");
await page.setContent("");
const standardInput = loadFixture('invalid_contract_content.json')
Expand All @@ -71,7 +71,7 @@ test('should throw an error for invalid Solidity code in browser', async ({ page
expect(output.errors[0].type).toContain('ParserError');
});

test('should return not found error for missing imports in browser', async ({page}) => {
test('should return not found error for missing imports in the browser', async ({page}) => {
await page.goto("http://127.0.0.1:8080");
await page.setContent("");
const standardInput = loadFixture('missing_import.json')
Expand All @@ -85,3 +85,37 @@ 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 the 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');
});

test('should successfully compile a valid Solidity contract that instantiates the token contracts in the browser', async ({ page }) => {
await page.goto("http://127.0.0.1:8080");
await page.setContent("");
const standardInput = loadFixture('instantiate_tokens.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_tokens.sol']).toHaveProperty('TokensFactory');
expect(output.contracts['fixtures/instantiate_tokens.sol'].TokensFactory).toHaveProperty('abi');
expect(output.contracts['fixtures/instantiate_tokens.sol'].TokensFactory).toHaveProperty('evm');
expect(output.contracts['fixtures/instantiate_tokens.sol'].TokensFactory.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"]
}
}
}
}

Loading
Loading