mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-15 16:11:05 +00:00
Add the revive tests in the browsers (#158)
This commit is contained in:
committed by
GitHub
parent
7f81f37e0c
commit
939138d0cd
@@ -106,6 +106,7 @@ jobs:
|
|||||||
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
|
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||||
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
|
iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
|
||||||
scoop install bun@${{ env.BUN_VERSION }}
|
scoop install bun@${{ env.BUN_VERSION }}
|
||||||
|
scoop install wget
|
||||||
Join-Path (Resolve-Path ~).Path "scoop\shims" >> $Env:GITHUB_PATH
|
Join-Path (Resolve-Path ~).Path "scoop\shims" >> $Env:GITHUB_PATH
|
||||||
|
|
||||||
- name: Install Bun on macOS and Linux
|
- name: Install Bun on macOS and Linux
|
||||||
@@ -114,13 +115,16 @@ jobs:
|
|||||||
curl -fsSL https://bun.sh/install | bash -s bun-v${{ env.BUN_VERSION }}
|
curl -fsSL https://bun.sh/install | bash -s bun-v${{ env.BUN_VERSION }}
|
||||||
echo "$HOME/.bun/bin" >> $GITHUB_PATH
|
echo "$HOME/.bun/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
- name: Confirm Installations
|
- name: Install packages
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Run Playwright tests
|
||||||
run: |
|
run: |
|
||||||
node --version
|
cd js
|
||||||
bun --version
|
npx playwright install --with-deps
|
||||||
|
npx playwright test
|
||||||
|
|
||||||
- name: Test revive
|
- name: Test revive
|
||||||
run: |
|
run: |
|
||||||
echo "Running tests for ${{ matrix.os }}"
|
echo "Running tests for ${{ matrix.os }}"
|
||||||
npm install
|
|
||||||
npm run test:wasm
|
npm run test:wasm
|
||||||
|
|||||||
@@ -15,4 +15,7 @@ package-lock.json
|
|||||||
/*.html
|
/*.html
|
||||||
/build
|
/build
|
||||||
soljson.js
|
soljson.js
|
||||||
|
test-results
|
||||||
|
playwright-report
|
||||||
|
.cache
|
||||||
emsdk
|
emsdk
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
const { test, expect } = require('@playwright/test');
|
||||||
|
|
||||||
|
const validCompilerInput = {
|
||||||
|
language: 'Solidity',
|
||||||
|
sources: {
|
||||||
|
'MyContract.sol': {
|
||||||
|
content: `
|
||||||
|
// SPDX-License-Identifier: UNLICENSED
|
||||||
|
pragma solidity ^0.8.0;
|
||||||
|
contract MyContract {
|
||||||
|
function greet() public pure returns (string memory) {
|
||||||
|
return "Hello";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
optimizer: {
|
||||||
|
enabled: true,
|
||||||
|
runs: 200,
|
||||||
|
},
|
||||||
|
outputSelection: {
|
||||||
|
'*': {
|
||||||
|
'*': ['abi', 'evm.bytecode'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
async function runWorker(page, input) {
|
||||||
|
return await page.evaluate((input) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const worker = new Worker('worker.js'); // Path to your worker.js file
|
||||||
|
worker.postMessage(JSON.stringify(input));
|
||||||
|
|
||||||
|
worker.onmessage = (event) => {
|
||||||
|
resolve(event.data.output);
|
||||||
|
worker.terminate(); // Clean up the worker
|
||||||
|
};
|
||||||
|
|
||||||
|
worker.onerror = (error) => {
|
||||||
|
reject(error.message || error); // Provide error message for clarity
|
||||||
|
worker.terminate(); // Clean up the worker
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}, input); // Pass the input as an argument to the function
|
||||||
|
}
|
||||||
|
|
||||||
|
test('Test browser', async ({ page }) => {
|
||||||
|
await page.goto("http://127.0.0.1:8080");
|
||||||
|
await page.setContent("");
|
||||||
|
|
||||||
|
const result = await runWorker(page, validCompilerInput);
|
||||||
|
|
||||||
|
expect(typeof result).toBe('string');
|
||||||
|
let output = JSON.parse(result);
|
||||||
|
expect(output).toHaveProperty('contracts');
|
||||||
|
expect(output.contracts['MyContract.sol']).toHaveProperty('MyContract');
|
||||||
|
expect(output.contracts['MyContract.sol'].MyContract).toHaveProperty('abi');
|
||||||
|
expect(output.contracts['MyContract.sol'].MyContract).toHaveProperty('evm');
|
||||||
|
expect(output.contracts['MyContract.sol'].MyContract.evm).toHaveProperty('bytecode');
|
||||||
|
});
|
||||||
+44
-28
@@ -1,35 +1,51 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Web Worker Example</title>
|
<title>Web Worker Example</title>
|
||||||
<style>
|
<style>
|
||||||
/* Ensure the pre tag wraps long lines */
|
/* Ensure the pre tag wraps long lines */
|
||||||
pre {
|
pre {
|
||||||
white-space: pre-wrap; /* Wrap long lines */
|
white-space: pre-wrap; /* Wrap long lines */
|
||||||
word-wrap: break-word; /* Break long words */
|
word-wrap: break-word; /* Break long words */
|
||||||
max-width: 100%; /* Optional: Ensures it doesn't overflow container */
|
max-width: 100%; /* Optional: Ensures it doesn't overflow container */
|
||||||
overflow-wrap: break-word; /* Another method for wrapping */
|
overflow-wrap: break-word; /* Another method for wrapping */
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>Revive Compilation Output</h1>
|
<h1>Revive Compilation Output</h1>
|
||||||
<pre id="output"></pre>
|
<pre id="output"></pre>
|
||||||
<script>
|
<script>
|
||||||
var outputElement = document.getElementById('output');
|
var outputElement = document.getElementById('output');
|
||||||
var worker = new Worker('./worker.js');
|
var worker = new Worker('./worker.js');
|
||||||
worker.addEventListener('message', function (e) {
|
const standardJsonInput = {
|
||||||
const output = e.data.output
|
language: 'Solidity',
|
||||||
outputElement.textContent = output;
|
sources: {
|
||||||
}, false);
|
contract: {
|
||||||
|
content: 'contract MyContract { function f() public { } }',
|
||||||
|
}
|
||||||
|
},
|
||||||
|
settings: {
|
||||||
|
optimizer: {
|
||||||
|
enabled: true,
|
||||||
|
runs: 200,
|
||||||
|
},
|
||||||
|
outputSelection: {
|
||||||
|
'*': {
|
||||||
|
'*': ['abi'],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
worker.addEventListener('message', function (e) {
|
||||||
|
outputElement.textContent = e.data.output;
|
||||||
|
}, false);
|
||||||
|
|
||||||
worker.postMessage({
|
worker.postMessage(JSON.stringify(standardJsonInput));
|
||||||
contractCode: 'contract C { function f() public { } }',
|
</script>
|
||||||
})
|
</body>
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -4,32 +4,12 @@ importScripts('./resolc.js');
|
|||||||
|
|
||||||
// Handle messages from the main thread
|
// Handle messages from the main thread
|
||||||
onmessage = async function (e) {
|
onmessage = async function (e) {
|
||||||
const contractCode = e.data.contractCode
|
|
||||||
const sourceCode = {
|
|
||||||
language: 'Solidity',
|
|
||||||
sources: {
|
|
||||||
contract: {
|
|
||||||
content: contractCode,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
settings: {
|
|
||||||
optimizer: {
|
|
||||||
enabled: true,
|
|
||||||
runs: 200,
|
|
||||||
},
|
|
||||||
outputSelection: {
|
|
||||||
'*': {
|
|
||||||
'*': ['abi'],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const m = createRevive();
|
const m = createRevive();
|
||||||
|
|
||||||
m.soljson = Module;
|
m.soljson = Module;
|
||||||
|
|
||||||
// Set input data for stdin
|
// Set input data for stdin
|
||||||
m.writeToStdin(JSON.stringify(sourceCode));
|
m.writeToStdin(e.data);
|
||||||
|
|
||||||
// Compile the Solidity source code
|
// Compile the Solidity source code
|
||||||
m.callMain(['--standard-json']);
|
m.callMain(['--standard-json']);
|
||||||
|
|||||||
+3
-2
@@ -8,11 +8,12 @@
|
|||||||
"fetch:soljson": "wget https://binaries.soliditylang.org/wasm/soljson-v0.8.28+commit.7893614a.js -O ./examples/web/soljson.js",
|
"fetch:soljson": "wget https://binaries.soliditylang.org/wasm/soljson-v0.8.28+commit.7893614a.js -O ./examples/web/soljson.js",
|
||||||
"example:web": "npm run fetch:soljson && http-server ./examples/web/",
|
"example:web": "npm run fetch:soljson && http-server ./examples/web/",
|
||||||
"example:node": "node ./examples/node/run_revive.js",
|
"example:node": "node ./examples/node/run_revive.js",
|
||||||
"test:node": "mocha --timeout 10000 ./tests",
|
"test:node": "mocha --timeout 20000 ./tests",
|
||||||
"test:bun": "bun test",
|
"test:bun": "bun test --timeout 20000 node.test",
|
||||||
"test:all": "npm run test:node && npm run test:bun"
|
"test:all": "npm run test:node && npm run test:bun"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@playwright/test": "^1.49.1",
|
||||||
"chai": "^5.1.2",
|
"chai": "^5.1.2",
|
||||||
"http-server": "^14.1.1",
|
"http-server": "^14.1.1",
|
||||||
"mocha": "^11.0.1"
|
"mocha": "^11.0.1"
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
const { defineConfig, devices } = require('@playwright/test');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see https://playwright.dev/docs/test-configuration
|
||||||
|
*/
|
||||||
|
module.exports = defineConfig({
|
||||||
|
testDir: './e2e',
|
||||||
|
/* Run tests in files in parallel */
|
||||||
|
fullyParallel: true,
|
||||||
|
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||||
|
forbidOnly: !!process.env.CI,
|
||||||
|
/* Retry on CI only */
|
||||||
|
retries: process.env.CI ? 2 : 0,
|
||||||
|
/* Opt out of parallel tests on CI. */
|
||||||
|
workers: process.env.CI ? 1 : undefined,
|
||||||
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||||
|
reporter: 'list',
|
||||||
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||||
|
use: {
|
||||||
|
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||||
|
baseURL: 'http://127.0.0.1:8080',
|
||||||
|
|
||||||
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||||
|
trace: 'on-first-retry',
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Configure projects for major browsers */
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'chromium',
|
||||||
|
use: { ...devices['Desktop Chrome'] },
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'firefox',
|
||||||
|
use: { ...devices['Desktop Firefox'] },
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: 'webkit',
|
||||||
|
use: { ...devices['Desktop Safari'] },
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
/* Run your local dev server before starting the tests */
|
||||||
|
webServer: {
|
||||||
|
command: 'npm run example:web',
|
||||||
|
url: 'http://127.0.0.1:8080',
|
||||||
|
reuseExistingServer: !process.env.CI,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user