mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 17:18:01 +00:00
Add test fixtures for the revive WASM version (#160)
This commit is contained in:
committed by
GitHub
parent
8ffe072fee
commit
b78b2b2af9
+63
-39
@@ -1,63 +1,87 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
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'],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
function loadFixture(fixture) {
|
||||
const fixturePath = path.resolve(__dirname, `../fixtures/${fixture}`);
|
||||
return JSON.parse(fs.readFileSync(fixturePath, 'utf-8'));
|
||||
}
|
||||
|
||||
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
|
||||
const worker = new Worker('worker.js');
|
||||
worker.postMessage(JSON.stringify(input));
|
||||
|
||||
worker.onmessage = (event) => {
|
||||
resolve(event.data.output);
|
||||
worker.terminate(); // Clean up the worker
|
||||
worker.terminate();
|
||||
};
|
||||
|
||||
worker.onerror = (error) => {
|
||||
reject(error.message || error); // Provide error message for clarity
|
||||
worker.terminate(); // Clean up the worker
|
||||
reject(error.message || error);
|
||||
worker.terminate();
|
||||
};
|
||||
});
|
||||
}, input); // Pass the input as an argument to the function
|
||||
}, input);
|
||||
}
|
||||
|
||||
test('Test browser', async ({ page }) => {
|
||||
test('should successfully compile valid Solidity code in browser', async ({ page }) => {
|
||||
await page.goto("http://127.0.0.1:8080");
|
||||
await page.setContent("");
|
||||
|
||||
const result = await runWorker(page, validCompilerInput);
|
||||
const standardInput = loadFixture('storage.json')
|
||||
const result = await runWorker(page, standardInput);
|
||||
|
||||
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');
|
||||
expect(output.contracts['fixtures/storage.sol']).toHaveProperty('Storage');
|
||||
expect(output.contracts['fixtures/storage.sol'].Storage).toHaveProperty('abi');
|
||||
expect(output.contracts['fixtures/storage.sol'].Storage).toHaveProperty('evm');
|
||||
expect(output.contracts['fixtures/storage.sol'].Storage.evm).toHaveProperty('bytecode');
|
||||
});
|
||||
|
||||
test('should successfully compile large valid Solidity code in browser', async ({ page }) => {
|
||||
await page.goto("http://127.0.0.1:8080");
|
||||
await page.setContent("");
|
||||
const standardInput = loadFixture('token.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/token.sol']).toHaveProperty('MyToken');
|
||||
expect(output.contracts['fixtures/token.sol'].MyToken).toHaveProperty('abi');
|
||||
expect(output.contracts['fixtures/token.sol'].MyToken).toHaveProperty('evm');
|
||||
expect(output.contracts['fixtures/token.sol'].MyToken.evm).toHaveProperty('bytecode');
|
||||
});
|
||||
|
||||
test('should throw an error for invalid Solidity code in browser', async ({ page }) => {
|
||||
await page.goto("http://127.0.0.1:8080");
|
||||
await page.setContent("");
|
||||
const standardInput = loadFixture('invalid_contract_content.json')
|
||||
const result = await runWorker(page, standardInput);
|
||||
|
||||
expect(typeof result).toBe('string');
|
||||
let output = JSON.parse(result);
|
||||
expect(output).toHaveProperty('errors');
|
||||
expect(Array.isArray(output.errors)).toBeTruthy(); // Check if it's an array
|
||||
expect(output.errors.length).toBeGreaterThan(0);
|
||||
expect(output.errors[0]).toHaveProperty('type');
|
||||
expect(output.errors[0].type).toContain('ParserError');
|
||||
});
|
||||
|
||||
test('should return not found error for missing imports in browser', async ({page}) => {
|
||||
await page.goto("http://127.0.0.1:8080");
|
||||
await page.setContent("");
|
||||
const standardInput = loadFixture('missing_import.json')
|
||||
const result = await runWorker(page, standardInput);
|
||||
|
||||
expect(typeof result).toBe('string');
|
||||
let output = JSON.parse(result);
|
||||
expect(output).toHaveProperty('errors');
|
||||
expect(Array.isArray(output.errors)).toBeTruthy(); // Check if it's an array
|
||||
expect(output.errors.length).toBeGreaterThan(0);
|
||||
expect(output.errors[0]).toHaveProperty('message');
|
||||
expect(output.errors[0].message).toContain('Source "nonexistent/console.sol" not found');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user