-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
3,013 additions
and
49 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ authors = ["SkyeKiwi <[email protected]>"] | |
build = "build.rs" | ||
|
||
[dependencies] | ||
skw_ipfs = { path = "../crates/skw-ipfs" } | ||
sgx_types = { path = "../../teaclave-sgx-sdk/sgx_types" } | ||
sgx_urts = { path = "../../teaclave-sgx-sdk/sgx_urts" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "near-test-contracts" | ||
version = "0.0.0" | ||
publish = false | ||
authors = ["Near Inc <[email protected]>"] | ||
# Please update rust-toolchain.toml as well when changing version here: | ||
rust-version = "1.56.0" | ||
edition = "2021" | ||
license = "Apache-2.0" | ||
|
||
[dependencies] | ||
once_cell = "1" | ||
wat = "1.0.40" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
A collection of smart-contract used in nearcore tests. | ||
|
||
Rust contracts are built via `build.rs`, the Assembly Script contract | ||
is build manually and committed to the git repository. | ||
`res/near_evm.wasm` and `res/ZombieOwnership.bin` are taken from | ||
<https://github.com/near/near-evm/tree/a651e9be680b59cca9aad86c1f9e9e9b54ad9c06> | ||
and it's for reproduce a performance issue encountered in EVM | ||
contracts. | ||
|
||
If you want to use a contract from rust core, add | ||
|
||
```toml | ||
[dev-dependencies] | ||
near-test-contracts = { path = "../near-test-contracts" } | ||
``` | ||
|
||
to the Cargo.toml and use `near_test_contract::rs_contract()`. | ||
|
||
If you want to use a contract from an integration test, you can read | ||
the wasm file directly from the `./res` directory. To populate | ||
`./res`, you need to make sure that this crate was compiled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use std::path::Path; | ||
use std::path::PathBuf; | ||
use std::process::Command; | ||
use std::{env, fs, io, process}; | ||
|
||
fn main() { | ||
if let Err(err) = try_main() { | ||
eprintln!("{}", err); | ||
process::exit(1); | ||
} | ||
} | ||
|
||
fn try_main() -> io::Result<()> { | ||
build_contract("./test-contract-rs", &[], "test_contract_rs")?; | ||
build_contract( | ||
"./test-contract-rs", | ||
&["--features", "nightly_protocol_features"], | ||
"nightly_test_contract_rs", | ||
)?; | ||
build_contract("./contract-for-fuzzing-rs", &[], "contract_for_fuzzing_rs")?; | ||
build_contract( | ||
"./test-contract-rs", | ||
&["--features", "base_protocol"], | ||
"test_contract_rs_base_protocol", | ||
)?; | ||
Ok(()) | ||
} | ||
|
||
fn build_contract(dir: &str, args: &[&str], output: &str) -> io::Result<()> { | ||
let mut cmd = cargo_build_cmd(); | ||
cmd.args(args); | ||
cmd.current_dir(dir); | ||
check_status(cmd)?; | ||
|
||
let target_dir = shared_target_dir().unwrap_or_else(|| format!("./{}/target", dir).into()); | ||
fs::copy( | ||
target_dir.join(format!("wasm32-unknown-unknown/release/{}.wasm", dir.replace('-', "_"))), | ||
format!("./res/{}.wasm", output), | ||
)?; | ||
println!("cargo:rerun-if-changed=./{}/src/lib.rs", dir); | ||
println!("cargo:rerun-if-changed=./{}/Cargo.toml", dir); | ||
Ok(()) | ||
} | ||
|
||
fn cargo_build_cmd() -> Command { | ||
let mut res = Command::new("cargo"); | ||
res.env("RUSTFLAGS", "-C link-arg=-s"); | ||
res.env_remove("CARGO_ENCODED_RUSTFLAGS"); | ||
if let Some(target_dir) = shared_target_dir() { | ||
res.env("CARGO_TARGET_DIR", target_dir); | ||
} | ||
|
||
res.args(&["build", "--target=wasm32-unknown-unknown", "--release"]); | ||
res | ||
} | ||
|
||
fn check_status(mut cmd: Command) -> io::Result<()> { | ||
let status = cmd.status().map_err(|err| { | ||
io::Error::new(io::ErrorKind::Other, format!("command `{:?}` failed to run: {}", cmd, err)) | ||
})?; | ||
if !status.success() { | ||
return Err(io::Error::new( | ||
io::ErrorKind::Other, | ||
format!("command `{:?}` exited with non-zero status: {:?}", cmd, status), | ||
)); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn shared_target_dir() -> Option<PathBuf> { | ||
let target_dir = env::var("CARGO_TARGET_DIR").ok()?; | ||
// Avoid sharing the same target directory with the patent Cargo | ||
// invocation, to avoid deadlock on the target dir. | ||
// | ||
// That is, this logic is needed for the case like the following: | ||
// | ||
// CARGO_TARGET_DIR=/tmp cargo build -p near-test-contracts --release | ||
Some(Path::new(&target_dir).join("near-test-contracts")) | ||
} |
7 changes: 7 additions & 0 deletions
7
mock-enclave/src/near-test-contracts/contract-for-fuzzing-rs/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
mock-enclave/src/near-test-contracts/contract-for-fuzzing-rs/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "contract-for-fuzzing-rs" | ||
version = "0.1.0" | ||
authors = ["Near Inc <[email protected]>"] | ||
publish = false | ||
# Please update rust-toolchain.toml as well when changing version here: | ||
rust-version = "1.56.0" | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "z" | ||
lto = true | ||
debug = false | ||
panic = "abort" | ||
rpath = false | ||
debug-assertions = false | ||
incremental = false | ||
|
||
[workspace] | ||
members = [] |
Oops, something went wrong.