mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-20 03:21:01 +00:00
Add test with standard json args
This commit is contained in:
@@ -12,6 +12,8 @@ use std::path::PathBuf;
|
|||||||
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
#[cfg(target_os = "emscripten")]
|
||||||
|
use std::fs::File;
|
||||||
|
|
||||||
use crate::solc::pipeline::Pipeline as SolcPipeline;
|
use crate::solc::pipeline::Pipeline as SolcPipeline;
|
||||||
use crate::solc::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
|
use crate::solc::standard_json::input::settings::metadata::Metadata as SolcStandardJsonInputSettingsMetadata;
|
||||||
@@ -41,7 +43,20 @@ pub struct Input {
|
|||||||
impl Input {
|
impl Input {
|
||||||
/// A shortcut constructor from stdin.
|
/// A shortcut constructor from stdin.
|
||||||
pub fn try_from_stdin(solc_pipeline: SolcPipeline) -> anyhow::Result<Self> {
|
pub fn try_from_stdin(solc_pipeline: SolcPipeline) -> anyhow::Result<Self> {
|
||||||
let mut input: Self = serde_json::from_reader(std::io::BufReader::new(std::io::stdin()))?;
|
let mut input: Self = serde_json::from_reader({
|
||||||
|
#[cfg(target_os = "emscripten")]
|
||||||
|
{
|
||||||
|
std::io::BufReader::new(
|
||||||
|
File::open("/in")
|
||||||
|
.map_err(|error| anyhow::anyhow!("File /in openning error: {}", error))?,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "emscripten"))]
|
||||||
|
{
|
||||||
|
std::io::BufReader::new(std::io::stdin())
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
input
|
input
|
||||||
.settings
|
.settings
|
||||||
.output_selection
|
.output_selection
|
||||||
|
|||||||
+58
-15
@@ -5,25 +5,68 @@ import solc from 'solc';
|
|||||||
// Import the Emscripten module
|
// Import the Emscripten module
|
||||||
import ModuleFactory from './resolc.js';
|
import ModuleFactory from './resolc.js';
|
||||||
|
|
||||||
async function runCompiler() {
|
// Solidity source code
|
||||||
const Module = await ModuleFactory();
|
const input = `
|
||||||
Module.solc = solc;
|
// SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8;
|
||||||
// Create input Solidity source code
|
contract Baseline {
|
||||||
const input = `
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
pragma solidity ^0.8;
|
|
||||||
contract Baseline {
|
|
||||||
function baseline() public payable {}
|
function baseline() public payable {}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
// Write the input Solidity code to the Emscripten file system
|
async function runCompiler() {
|
||||||
Module.FS.writeFile('./input.sol', input);
|
const Module = await ModuleFactory();
|
||||||
|
Module.solc = solc;
|
||||||
|
|
||||||
// Compile the Solidity source code
|
// Write the input Solidity code to the Emscripten file system
|
||||||
Module.callMain(['./input.sol', '-O3','--bin']);
|
Module.FS.writeFile('./input.sol', input);
|
||||||
|
|
||||||
|
// Compile the Solidity source code
|
||||||
|
Module.callMain(['./input.sol', '-O3','--bin']);
|
||||||
|
}
|
||||||
|
|
||||||
|
const compilerStandardJsonInput = {
|
||||||
|
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'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
async function runCompilerWithStandardJson() {
|
||||||
|
const Module = await ModuleFactory();
|
||||||
|
Module.solc = solc;
|
||||||
|
|
||||||
|
// Write the input Solidity code to the Emscripten file system
|
||||||
|
Module.FS.writeFile('/in', JSON.stringify(compilerStandardJsonInput));
|
||||||
|
|
||||||
|
// Compile the Solidity source code
|
||||||
|
Module.callMain(['--standard-json']);
|
||||||
}
|
}
|
||||||
|
|
||||||
runCompiler().catch(err => {
|
runCompiler().catch(err => {
|
||||||
console.error('Error:', err);
|
console.error('Error:', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
runCompilerWithStandardJson().catch(err => {
|
||||||
|
console.error('Error:', err);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ mergeInto(LibraryManager.library, {
|
|||||||
let outputFile = newModule.FS.readFile('/out', { encoding: 'utf8' });
|
let outputFile = newModule.FS.readFile('/out', { encoding: 'utf8' });
|
||||||
parentPort.postMessage({ output: outputFile });
|
parentPort.postMessage({ output: outputFile });
|
||||||
}
|
}
|
||||||
});`
|
});`;
|
||||||
|
|
||||||
function compileWithWorker(inputJson, callback) {
|
function compileWithWorker(inputJson, callback) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user