Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit 768e538

Browse files
c410-f3rjleni
andauthored
Fix CI (#111)
* Fix CI * Take test config from environment Co-authored-by: Juan Leni <juan.leni@zondax.ch>
1 parent 8eeba18 commit 768e538

File tree

9 files changed

+55
-45
lines changed

9 files changed

+55
-45
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ jobs:
6464
name: Initial configuration
6565
command: |
6666
sudo apt-get install -y default-jdk g++ gcc valgrind snapd
67-
wget -O sdk.install.sh "https://get.sdkman.io"
68-
sudo bash sdk.install.sh
69-
sudo source "/root/.sdkman/bin/sdkman-init.sh"
70-
sudo sdk install kotlin
7167
rustup install nightly
7268
cargo +nightly install cbindgen
7369
- run: OUT_DIR=/tmp/c ./.circleci/test_c.sh
@@ -195,6 +191,8 @@ workflows:
195191
<<: *no-tags
196192
- tests_rust:
197193
<<: *no-tags
194+
- tests_ffi:
195+
<<: *no-tags
198196
- tests_wasm:
199197
<<: *no-tags
200198
- tests_service:
@@ -206,6 +204,8 @@ workflows:
206204
<<: *only-release-tags
207205
- tests_rust:
208206
<<: *only-release-tags
207+
- tests_ffi:
208+
<<: *only-release-tags
209209
- tests_wasm:
210210
<<: *only-release-tags
211211
- tests_service:

.circleci/test_c.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ mkdir $OUT_DIR
33
cp -r ../examples/ffi/c/* $OUT_DIR
44
rustup default nightly
55
cbindgen --config cbindgen.toml --crate filecoin-signer-ffi --lang c --output $OUT_DIR/filecoin_signer_ffi.h
6-
rustup default stable
76
cargo build
87
cp ../target/debug/libfilecoin_signer_ffi.so $OUT_DIR
98
( cd $OUT_DIR; gcc main.c -L. -lfilecoin_signer_ffi -o main )

.circleci/test_cpp.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ mkdir $OUT_DIR
33
cp -r ../examples/ffi/c++/* $OUT_DIR
44
rustup default nightly
55
cbindgen --config cbindgen.toml --crate filecoin-signer-ffi --lang c++ --output $OUT_DIR/filecoin_signer_ffi.h
6-
rustup default stable
76
cargo build
87
cp ../target/debug/libfilecoin_signer_ffi.so $OUT_DIR
98
( cd $OUT_DIR; g++ main.cpp -L. -lfilecoin_signer_ffi -o main )

.circleci/test_kotlin.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
wget -O sdk.install.sh "https://get.sdkman.io"
2+
bash sdk.install.sh
3+
. ~/.sdkman/bin/sdkman-init.sh
4+
sdk install kotlin
5+
16
cd signer-ffi
27
mkdir $OUT_DIR
38
cp -r ../examples/ffi/kotlin/* $OUT_DIR

service/src/service/client.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,12 @@ pub async fn get_status(url: &str, jwt: &str, cid_message: Value) -> Result<Valu
122122
#[cfg(test)]
123123
mod tests {
124124
use crate::service::client::{get_nonce, get_status};
125+
use crate::service::test_helper::tests;
125126

126127
use jsonrpc_core::types::error::{Error, ErrorCode};
127128
use jsonrpc_core::Response;
128129
use serde_json::json;
129130

130-
const TEST_URL: &str = "http://86.192.13.13:1234/rpc/v0";
131-
const JWT: &str = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.xK1G26jlYnAEnGLJzN1RLywghc4p4cHI6ax_6YOv0aI";
132-
133131
#[tokio::test]
134132
async fn decode_error() {
135133
let data = b"{\"jsonrpc\":\"2.0\",\"id\":1,\"error\":{\"code\":1,\"message\":\"cbor input had wrong number of fields\"}}\n";
@@ -141,7 +139,8 @@ mod tests {
141139
async fn example_something_else_and_retrieve_nonce() {
142140
let addr = "t02";
143141

144-
let nonce = get_nonce(&TEST_URL, &JWT, &addr).await;
142+
let credentials = tests::get_remote_credentials();
143+
let nonce = get_nonce(&credentials.url, &credentials.jwt, &addr).await;
145144

146145
println!("{:?}", nonce);
147146

@@ -164,7 +163,10 @@ mod tests {
164163
"Params":""
165164
});
166165

167-
let status = get_status(&TEST_URL, &JWT, params).await.unwrap();
166+
let credentials = tests::get_remote_credentials();
167+
let status = get_status(&credentials.url, &credentials.jwt, params)
168+
.await
169+
.unwrap();
168170

169171
println!("{:?}", status);
170172

@@ -176,7 +178,8 @@ mod tests {
176178
let params =
177179
json!({ "/": "bafy2bzaceaxm23epjsmh75yvzcecsrbavlmkcxnva66bkdebdcnyw3bjrc74u" });
178180

179-
let status = get_status(&TEST_URL, &JWT, params).await;
181+
let credentials = tests::get_remote_credentials();
182+
let status = get_status(&credentials.url, &credentials.jwt, params).await;
180183

181184
println!("{:?}", status);
182185
let _err_jsonrpc = Error {
@@ -194,7 +197,8 @@ mod tests {
194197
let params =
195198
json!({ "/": "bafy2bzacedbo3svni7n2jb57exuqh4v5zvjjethf3p74zgv7yfdtczce2yu4u" });
196199

197-
let status = get_status(&TEST_URL, &JWT, params).await;
200+
let credentials = tests::get_remote_credentials();
201+
let status = get_status(&credentials.url, &credentials.jwt, params).await;
198202

199203
println!("{:?}", status);
200204
assert!(status.is_err());

service/src/service/handlers.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ impl warp::reject::Reject for ServiceError {}
7979
mod tests {
8080
use crate::config::RemoteNodeSection;
8181
use crate::service::handlers::v0_post;
82+
use crate::service::test_helper::tests;
83+
84+
use crate::service::test_helper::tests::get_remote_credentials;
8285
use futures_await_test::async_test;
8386
use jsonrpc_core::{Call, Id, MethodCall, Params, Version};
8487
use warp::Reply;
8588

86-
const TEST_URL: &str = "http://86.192.13.13:1234/rpc/v0";
87-
const JWT: &str = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.xK1G26jlYnAEnGLJzN1RLywghc4p4cHI6ax_6YOv0aI";
88-
8989
#[async_test]
9090
async fn returns_jsonrpc_error_not_found() {
9191
let bad_call = Call::from(MethodCall {
@@ -95,11 +95,7 @@ mod tests {
9595
id: Id::Num(1),
9696
});
9797

98-
let config = RemoteNodeSection {
99-
url: TEST_URL.to_string(),
100-
jwt: JWT.to_string(),
101-
};
102-
98+
let config = get_remote_credentials();
10399
let response = v0_post(bad_call, config).await;
104100

105101
assert!(response.is_err());
@@ -116,11 +112,7 @@ mod tests {
116112
id: Id::Num(1),
117113
});
118114

119-
let config = RemoteNodeSection {
120-
url: TEST_URL.to_string(),
121-
jwt: JWT.to_string(),
122-
};
123-
115+
let config = get_remote_credentials();
124116
let reply = v0_post(bad_call, config).await.unwrap();
125117

126118
let response = reply.into_response();

service/src/service/methods.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,11 @@ pub async fn send_signed_tx(
260260
mod tests {
261261
use crate::config::RemoteNodeSection;
262262
use crate::service::methods::get_status;
263+
use crate::service::test_helper::tests;
264+
use crate::service::test_helper::tests::get_remote_credentials;
263265
use jsonrpc_core::{Id, MethodCall, Params, Success, Version};
264266
use serde_json::json;
265267

266-
//const TEST_URL: &str = "http://86.192.13.13:1234/rpc/v0";
267-
const TEST_URL: &str = "https://proxy.openworklabs.com/rpc/v0";
268-
const JWT: &str = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.xK1G26jlYnAEnGLJzN1RLywghc4p4cHI6ax_6YOv0aI";
269-
270268
#[tokio::test]
271269
async fn example_get_status_transaction() {
272270
let params_str = json!({ "cid_message": "bafy2bzacea2ob4bctlucgp2okbczqvk5ctx4jqjapslz57mbcmnnzyftgeqgu" });
@@ -295,11 +293,7 @@ mod tests {
295293
id: Id::Num(123),
296294
};
297295

298-
let config = RemoteNodeSection {
299-
url: TEST_URL.to_string(),
300-
jwt: JWT.to_string(),
301-
};
302-
296+
let config = get_remote_credentials();
303297
let status = get_status(mc, config).await.unwrap();
304298

305299
println!("{:?}", status);
@@ -332,11 +326,7 @@ mod tests {
332326
id: Id::Num(0),
333327
};
334328

335-
let config = RemoteNodeSection {
336-
url: TEST_URL.to_string(),
337-
jwt: JWT.to_string(),
338-
};
339-
329+
let config = get_remote_credentials();
340330
let status = get_status(mc, config).await;
341331

342332
println!("{:?}", status);
@@ -367,11 +357,7 @@ mod tests {
367357
id: Id::Num(0),
368358
};
369359

370-
let config = RemoteNodeSection {
371-
url: TEST_URL.to_string(),
372-
jwt: JWT.to_string(),
373-
};
374-
360+
let config = get_remote_credentials();
375361
let status = get_status(mc, config).await;
376362

377363
println!("{:?}", status);

service/src/service/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ mod error;
1313
mod handlers;
1414
mod methods;
1515

16+
#[cfg(test)]
17+
mod test_helper;
18+
1619
fn jsonrpc_body() -> impl Filter<Extract = (Call,), Error = warp::Rejection> + Clone {
1720
// When accepting a body, we want a JSON body and to reject huge payloads)...
1821
const MAX_SIZE: u64 = 1024 * 16;

service/src/service/test_helper.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#[cfg(test)]
2+
pub mod tests {
3+
use crate::config::RemoteNodeSection;
4+
use std::env;
5+
6+
pub fn get_remote_credentials() -> RemoteNodeSection {
7+
const DEFAULT_TEST_URL: &str = "http://127.0.0.1:1234/rpc/v0";
8+
const DEFAULT_JWT: &str = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJBbGxvdyI6WyJyZWFkIiwid3JpdGUiLCJzaWduIiwiYWRtaW4iXX0.xK1G26jlYnAEnGLJzN1RLywghc4p4cHI6ax_6YOv0aI";
9+
10+
let url = match env::var_os("LOTUS_SECRET_URL") {
11+
Some(val) => String::from(val.to_string_lossy()),
12+
None => DEFAULT_TEST_URL.to_string(),
13+
};
14+
15+
let jwt = match env::var_os("LOTUS_SECRET_JWT") {
16+
Some(val) => String::from(val.to_string_lossy()),
17+
None => DEFAULT_JWT.to_string(),
18+
};
19+
20+
RemoteNodeSection { url, jwt }
21+
}
22+
}

0 commit comments

Comments
 (0)