mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-04-22 12:38:03 +00:00
Add tests for the Revive WASM version (#147)
This commit is contained in:
committed by
GitHub
parent
f49d145e9a
commit
d7d60da6f1
@@ -0,0 +1,32 @@
|
||||
const soljson = require('solc/soljson');
|
||||
const createRevive = require('./resolc.js');
|
||||
|
||||
async function compile(standardJsonInput) {
|
||||
if (!standardJsonInput) {
|
||||
throw new Error('Input JSON for the Solidity compiler is required.');
|
||||
}
|
||||
|
||||
// Initialize the compiler
|
||||
const compiler = createRevive();
|
||||
compiler.soljson = soljson;
|
||||
|
||||
// Provide input to the compiler
|
||||
compiler.writeToStdin(JSON.stringify(standardJsonInput));
|
||||
|
||||
// Run the compiler
|
||||
compiler.callMain(['--standard-json']);
|
||||
|
||||
// Collect output
|
||||
const stdout = compiler.readFromStdout();
|
||||
const stderr = compiler.readFromStderr();
|
||||
|
||||
// Check for errors and throw if stderr exists
|
||||
if (stderr) {
|
||||
throw new Error(`Compilation failed: ${stderr}`);
|
||||
}
|
||||
|
||||
// Return the output if no errors
|
||||
return stdout;
|
||||
}
|
||||
|
||||
module.exports = { compile };
|
||||
@@ -1,5 +1,4 @@
|
||||
const soljson = require('solc/soljson');
|
||||
const createRevive = require('./resolc.js');
|
||||
const { compile } = require('./revive.js');
|
||||
|
||||
const compilerStandardJsonInput = {
|
||||
language: 'Solidity',
|
||||
@@ -30,16 +29,8 @@ const compilerStandardJsonInput = {
|
||||
};
|
||||
|
||||
async function runCompiler() {
|
||||
const m = createRevive();
|
||||
m.soljson = soljson;
|
||||
|
||||
// Set input data for stdin
|
||||
m.writeToStdin(JSON.stringify(compilerStandardJsonInput));
|
||||
|
||||
// Compile the Solidity source code
|
||||
let x = m.callMain(['--standard-json']);
|
||||
console.log("Stdout: " + m.readFromStdout());
|
||||
console.error("Stderr: " + m.readFromStderr());
|
||||
let output = await compile(compilerStandardJsonInput)
|
||||
console.log("Output: " + output);
|
||||
}
|
||||
|
||||
runCompiler().catch(err => {
|
||||
|
||||
Reference in New Issue
Block a user