Skip to content

Commit

Permalink
move test code into integration module
Browse files Browse the repository at this point in the history
Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele committed Jul 4, 2022
1 parent 348b5ea commit 0c84612
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 179 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ jobs:
- uses: actions-rs/toolchain@v1
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/cargo@v1
with:
command: test
args: --lib
- run: make test

sdk-test:
runs-on: ubuntu-latest
Expand Down
61 changes: 30 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ App_C_Flags := $(SGX_COMMON_CFLAGS) -fPIC -Wno-attributes $(App_Include_Paths)

App_Rust_Path := ./target/$(OUTPUT_PATH)
App_Enclave_u_Object :=lib/libEnclave_u.a
App_Name := sgxrars
App_Name := lcp
App_Dir := bin/$(App_Name)

######## Enclave Settings ########
Expand Down Expand Up @@ -172,7 +172,11 @@ fmt:

.PHONY: test
test:
@cargo test --lib
cargo test --lib --workspace --exclude integration-test

.PHONY: integration-test
integration-test:
SGX_MODE=HW cargo test --package integration-test

.PHONY: proto
proto:
Expand Down
20 changes: 1 addition & 19 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,30 +1,12 @@
[package]
name = "sgxrars"
name = "lcp"
version = "0.0.1"
edition = "2021"
build = "build.rs"

[dependencies]
sgx_types = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
sgx_urts = { git = "https://github.com/apache/teaclave-sgx-sdk.git" }
ibc = {git = "https://github.com/bluele/ibc-rs", branch = "sgx", default-features = false }
ibc-relayer = {git = "https://github.com/bluele/ibc-rs", branch = "sgx", default-features = false }
ibc-proto = { git = "https://github.com/bluele/ibc-rs", branch = "sgx", default-features = false }
tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs", rev = "235480171081fed74de7b3d3c19911304df29831", features = ["http-client", "websocket-client"] }

anyhow = { version = "1.0.56" }
thiserror = { version = "1.0.30" }
tokio = { version = "1.0" }
log = "0.4.8"
env_logger = "0.9.0"

host = { path = "../modules/host" }
enclave-api = { path = "../modules/enclave-api" }
enclave-commands = { path = "../modules/enclave-commands" }
attestation-report = { path = "../modules/attestation-report" }
settings = { path = "../modules/settings" }
relay-tendermint = { path = "../modules/relay/tendermint" }
lcp-ibc-client = { path = "../modules/ibc-client" }

[features]
default = []
123 changes: 1 addition & 122 deletions app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,124 +1,3 @@
use attestation_report::EndorsedAttestationReport;
use enclave_api::{Enclave, EnclaveAPI};
use enclave_commands::{CommandResult, CommitmentProofPair, LightClientResult, UpdateClientResult};
use ibc::core::{
ics23_commitment::commitment::CommitmentProofBytes,
ics24_host::identifier::{ChannelId, PortId},
};
use ibc_proto::ibc::core::commitment::v1::MerkleProof;
use log::*;
use settings::ENDORSED_ATTESTATION_PATH;
use std::{str::FromStr, sync::Arc};
use tokio::runtime::Runtime as TokioRuntime;

mod relayer;

static ENCLAVE_FILE: &'static str = "enclave.signed.so";

fn main() -> Result<(), anyhow::Error> {
fn main() {
env_logger::init();
let rt = Arc::new(TokioRuntime::new()?);

let spid = std::env::var("SPID")?;
let ias_key = std::env::var("IAS_KEY")?;

let enclave = match host::enclave::init_enclave(ENCLAVE_FILE) {
Ok(r) => {
info!("[+] Init Enclave Successful {}!", r.geteid());
r
}
Err(x) => {
panic!("[-] Init Enclave Failed {}!", x.as_str());
}
};

let enclave = Enclave::new(enclave);

if let Err(e) = enclave.init_enclave_key(spid.as_bytes(), ias_key.as_bytes()) {
panic!("[-] ECALL Enclave Failed {:?}!", e);
} else {
info!("[+] remote attestation success...");
}

let report = EndorsedAttestationReport::read_from_file(&ENDORSED_ATTESTATION_PATH).unwrap();
let quote = attestation_report::parse_quote_from_report(&report.report).unwrap();
info!("report={:?}", quote.raw.report_body.report_data.d);

// register the key into onchain

let mut rly = relayer::create_relayer(rt, "ibc0")?;

// XXX use non-latest height here
let initial_height = rly
.query_latest_height()?
.decrement()?
.decrement()?
.decrement()?;

let (client_state, consensus_state) = rly.fetch_state_as_any(initial_height)?;
info!(
"initial_height: {:?} client_state: {:?}, consensus_state: {:?}",
initial_height, client_state, consensus_state
);

let proof = if let CommandResult::LightClient(LightClientResult::InitClient(res)) = enclave
.init_client("07-tendermint", client_state, consensus_state)
.unwrap()
{
res.0
} else {
panic!("unexpected result type")
};
let commitment = proof.commitment();
let client_id = commitment.client_id;

info!("generated client id is {}", client_id.as_str().to_string());

let target_header =
rly.create_header(commitment.new_height, commitment.new_height.increment())?;
let res = enclave.update_client(client_id.clone(), target_header.into())?;

info!("update_client's result is {:?}", res);

let height = match res {
CommandResult::LightClient(LightClientResult::UpdateClient(UpdateClientResult(res))) => {
res.commitment().new_height
}
_ => unreachable!(),
};

info!("current height is {}", height);

let (port_id, channel_id) = (
PortId::from_str("cross")?,
ChannelId::from_str("channel-0")?,
);
let res = rly.proven_channel(&port_id, &channel_id, Some(height))?;

info!("expected channel is {:?}", res.0);

let res = enclave.verify_channel(
client_id.clone(),
res.0,
"ibc".into(),
port_id,
channel_id,
CommitmentProofPair(res.2, merkle_proof_to_bytes(res.1)?),
)?;

let cs = lcp_ibc_client::client_state::ClientState::default();
let client = lcp_ibc_client::client_def::LCPClient {};

// client.initialise(&client_state, &consensus_state)?;

// TODO implement the verification testing

enclave.destroy();

Ok(())
}

fn merkle_proof_to_bytes(proof: MerkleProof) -> Result<Vec<u8>, anyhow::Error> {
let proof = CommitmentProofBytes::try_from(proof)?;
Ok(proof.into())
}
22 changes: 21 additions & 1 deletion tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
[package]
name = "tests-integration"
name = "integration-test"
version = "0.1.0"
edition = "2021"
build = "build.rs"

[dependencies]
ibc = {git = "https://github.com/bluele/ibc-rs", branch = "sgx", default-features = false }
ibc-relayer = {git = "https://github.com/bluele/ibc-rs", branch = "sgx", default-features = false }
ibc-proto = { git = "https://github.com/bluele/ibc-rs", branch = "sgx", default-features = false }
tendermint-rpc = { git = "https://github.com/informalsystems/tendermint-rs", rev = "235480171081fed74de7b3d3c19911304df29831", features = ["http-client", "websocket-client"] }

anyhow = { version = "1.0.56" }
thiserror = { version = "1.0.30" }
tokio = { version = "1.0" }
log = "0.4.8"
env_logger = "0.9.0"

host = { path = "../../modules/host" }
enclave-api = { path = "../../modules/enclave-api" }
enclave-commands = { path = "../../modules/enclave-commands" }
attestation-report = { path = "../../modules/attestation-report" }
settings = { path = "../../modules/settings" }
relay-tendermint = { path = "../../modules/relay/tendermint" }
lcp-ibc-client = { path = "../../modules/ibc-client" }

[features]
default = []
Loading

0 comments on commit 0c84612

Please sign in to comment.