OUT_DIR > artifacts

This commit is contained in:
Luke Parker 2024-09-15 00:57:43 -04:00
parent a38d135059
commit 0813351f1f
7 changed files with 27 additions and 13 deletions

2
Cargo.lock generated
View file

@ -1320,7 +1320,7 @@ dependencies = [
[[package]]
name = "build-solidity-contracts"
version = "0.1.0"
version = "0.1.1"
[[package]]
name = "bumpalo"

View file

@ -1,6 +1,6 @@
[package]
name = "build-solidity-contracts"
version = "0.1.0"
version = "0.1.1"
description = "A helper function to build Solidity contracts"
license = "MIT"
repository = "https://github.com/serai-dex/serai/tree/develop/networks/ethereum/build-contracts"

View file

@ -4,7 +4,7 @@
use std::{path::PathBuf, fs, process::Command};
/// Build contracts placed in `contracts/`, outputting to `artifacts/`.
/// Build contracts from the specified path, outputting the artifacts to the specified path.
///
/// Requires solc 0.8.25.
pub fn build(contracts_path: &str, artifacts_path: &str) -> Result<(), String> {
@ -33,7 +33,7 @@ pub fn build(contracts_path: &str, artifacts_path: &str) -> Result<(), String> {
#[rustfmt::skip]
let args = [
"--base-path", ".",
"-o", "./artifacts", "--overwrite",
"-o", artifacts_path, "--overwrite",
"--bin", "--bin-runtime", "--abi",
"--via-ir", "--optimize",
"--no-color",

View file

@ -6,7 +6,7 @@ license = "AGPL-3.0-only"
repository = "https://github.com/serai-dex/serai/tree/develop/networks/ethereum/schnorr"
authors = ["Luke Parker <lukeparker5132@gmail.com>", "Elizabeth Binks <elizabethjbinks@gmail.com>"]
edition = "2021"
rust-version = "1.79"
rust-version = "1.81"
[package.metadata.docs.rs]
all-features = true

View file

@ -1,3 +1,9 @@
use std::{env, fs};
fn main() {
build_solidity_contracts::build("contracts", "artifacts").unwrap();
let artifacts_path = env::var("OUT_DIR").unwrap().to_string() + "/ethereum-schnorr-contract";
if !fs::exists(&artifacts_path).unwrap() {
fs::create_dir(&artifacts_path).unwrap();
}
build_solidity_contracts::build("contracts", &artifacts_path).unwrap();
}

View file

@ -4,7 +4,8 @@
#![allow(non_snake_case)]
/// The initialization bytecode of the Schnorr library.
pub const INIT_BYTECODE: &str = include_str!("../artifacts/Schnorr.bin");
pub const INIT_BYTECODE: &str =
include_str!(concat!(env!("OUT_DIR"), "/ethereum-schnorr-contract/Schnorr.bin"));
mod public_key;
pub use public_key::PublicKey;

View file

@ -17,11 +17,11 @@ use alloy_node_bindings::{Anvil, AnvilInstance};
use crate::{PublicKey, Signature};
#[allow(warnings)]
#[allow(needless_pass_by_value)]
#[allow(clippy::all)]
#[allow(clippy::ignored_unit_patterns)]
#[allow(clippy::redundant_closure_for_method_calls)]
#[expect(warnings)]
#[expect(needless_pass_by_value)]
#[expect(clippy::all)]
#[expect(clippy::ignored_unit_patterns)]
#[expect(clippy::redundant_closure_for_method_calls)]
mod abi {
alloy_sol_types::sol!("contracts/tests/Schnorr.sol");
pub(crate) use TestSchnorr::*;
@ -40,7 +40,14 @@ async fn setup_test() -> (AnvilInstance, Arc<RootProvider<SimpleRequest>>, Addre
let _: () = provider
.raw_request(
"anvil_setCode".into(),
[address.to_string(), include_str!("../artifacts/TestSchnorr.bin-runtime").to_string()],
[
address.to_string(),
include_str!(concat!(
env!("OUT_DIR"),
"/ethereum-schnorr-contract/TestSchnorr.bin-runtime"
))
.to_string(),
],
)
.await
.unwrap();