mirror of
https://github.com/pezkuwichain/revive-differential-tests.git
synced 2026-04-25 22:07:59 +00:00
da31e66fb4
Before this commit, the types that were used for the compiler input and output were the resolc compiler types which was a leaky abstraction as we have traits to abstract the compilers away but we expose their internal types out to other crates. This commit did the following: 1. Made the compiler IO types fully generic so that all of the logic for constructing the map of compiled contracts is all done by the compiler implementation and not by the consuming code. 2. Changed the input types used for Solc to be the forge standard JSON types for Solc instead of resolc.
82 lines
2.4 KiB
Rust
82 lines
2.4 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use revive_dt_compiler::{Compiler, SolidityCompiler, revive_resolc::Resolc, solc::Solc};
|
|
use revive_dt_config::Arguments;
|
|
use semver::Version;
|
|
|
|
#[test]
|
|
fn contracts_can_be_compiled_with_solc() {
|
|
// Arrange
|
|
let args = Arguments::default();
|
|
let compiler_path = Solc::get_compiler_executable(&args, Version::new(0, 8, 30)).unwrap();
|
|
|
|
// Act
|
|
let output = Compiler::<Solc>::new()
|
|
.with_source("./tests/assets/array_one_element/callable.sol")
|
|
.unwrap()
|
|
.with_source("./tests/assets/array_one_element/main.sol")
|
|
.unwrap()
|
|
.try_build(compiler_path);
|
|
|
|
// Assert
|
|
let output = output.expect("Failed to compile");
|
|
assert_eq!(output.contracts.len(), 2);
|
|
|
|
let main_file_contracts = output
|
|
.contracts
|
|
.get(
|
|
&PathBuf::from("./tests/assets/array_one_element/main.sol")
|
|
.canonicalize()
|
|
.unwrap(),
|
|
)
|
|
.unwrap();
|
|
let callable_file_contracts = output
|
|
.contracts
|
|
.get(
|
|
&PathBuf::from("./tests/assets/array_one_element/callable.sol")
|
|
.canonicalize()
|
|
.unwrap(),
|
|
)
|
|
.unwrap();
|
|
assert!(main_file_contracts.contains_key("Main"));
|
|
assert!(callable_file_contracts.contains_key("Callable"));
|
|
}
|
|
|
|
#[test]
|
|
fn contracts_can_be_compiled_with_resolc() {
|
|
// Arrange
|
|
let args = Arguments::default();
|
|
let compiler_path = Resolc::get_compiler_executable(&args, Version::new(0, 8, 30)).unwrap();
|
|
|
|
// Act
|
|
let output = Compiler::<Resolc>::new()
|
|
.with_source("./tests/assets/array_one_element/callable.sol")
|
|
.unwrap()
|
|
.with_source("./tests/assets/array_one_element/main.sol")
|
|
.unwrap()
|
|
.try_build(compiler_path);
|
|
|
|
// Assert
|
|
let output = output.expect("Failed to compile");
|
|
assert_eq!(output.contracts.len(), 2);
|
|
|
|
let main_file_contracts = output
|
|
.contracts
|
|
.get(
|
|
&PathBuf::from("./tests/assets/array_one_element/main.sol")
|
|
.canonicalize()
|
|
.unwrap(),
|
|
)
|
|
.unwrap();
|
|
let callable_file_contracts = output
|
|
.contracts
|
|
.get(
|
|
&PathBuf::from("./tests/assets/array_one_element/callable.sol")
|
|
.canonicalize()
|
|
.unwrap(),
|
|
)
|
|
.unwrap();
|
|
assert!(main_file_contracts.contains_key("Main"));
|
|
assert!(callable_file_contracts.contains_key("Callable"));
|
|
}
|