Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Add a crate to test the in-browser light client. #4887

Merged
merged 56 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
69f00df
Use noise and timeouts on wasm
expenses Feb 10, 2020
8293bf8
It work but it's messy
expenses Feb 10, 2020
d9ba7bd
Bit of documentation
expenses Feb 11, 2020
1761e3b
Merge remote-tracking branch 'parity/master' into ashley-wasm-networking
expenses Feb 13, 2020
f650f60
Don't use wasm-opt when compiling to wasm
expenses Feb 13, 2020
47426a6
Forgot lockfile
expenses Feb 13, 2020
4dda60f
Merge branch 'ashley-wasm-networking' into ashley-browser-testing
expenses Feb 13, 2020
0e7392a
Make timeouts better
expenses Feb 13, 2020
b4a4118
wasm-pack is installed
TriplEight Feb 14, 2020
ecb71e1
job will run always; but after check-web-wasm succeds
TriplEight Feb 14, 2020
e00f237
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Feb 17, 2020
7f87dac
Forgot lockfile
expenses Feb 17, 2020
1638949
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Feb 18, 2020
3dc6918
Update dependencies
expenses Feb 18, 2020
552b402
Add 'text' to a '```' block
expenses Feb 19, 2020
69f67f8
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Feb 19, 2020
2dea5f5
Apply suggestions from code review
expenses Feb 19, 2020
d18f732
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Feb 20, 2020
486e3e6
Merge branch 'ashley-browser-testing' of github.com:paritytech/substr…
expenses Feb 20, 2020
b4e3989
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Feb 24, 2020
a98b611
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Feb 26, 2020
a83f4ee
Update lockfile
expenses Feb 26, 2020
d72223e
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 2, 2020
4d3c962
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 10, 2020
8dbdf77
Change documentation and gitlab ci config
expenses Mar 10, 2020
139aaf3
Fix mistake in gitlab config
expenses Mar 10, 2020
565236a
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 13, 2020
391c53d
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 16, 2020
82ee125
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 16, 2020
3adc4f1
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 17, 2020
bf01816
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 24, 2020
57059a3
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 26, 2020
f52c34a
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 26, 2020
bf5bef8
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 27, 2020
6e62d8d
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 30, 2020
8c2fa65
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Mar 31, 2020
6e97c8a
Fix CI test command
expenses Mar 31, 2020
16c55b9
Use chromedriver instead
expenses Apr 1, 2020
e0088d3
Try revert "Use chromedriver instead"
expenses Apr 1, 2020
70967cc
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Apr 1, 2020
ca50a22
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Apr 2, 2020
69a2340
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Apr 6, 2020
c0cf3b0
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Apr 12, 2020
ff4956d
Fix browser node
expenses Apr 12, 2020
950f45a
Fix readme
expenses Apr 12, 2020
857c402
Merge branch 'ashley-fix-browser-node' into ashley-browser-testing
expenses Apr 12, 2020
25c20dc
Bump dependencies, fix warnings
expenses Apr 12, 2020
3ddaf96
Revert the dependency bump
expenses Apr 12, 2020
59ffbe1
Revert "Revert the dependency bump"
expenses Apr 12, 2020
3a098ea
Add webdriver.json 🙏
expenses Apr 12, 2020
fda6b8c
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Apr 17, 2020
ca56eb0
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Apr 17, 2020
c839c36
Add CHROMEDRIVER_ARGS to .gitlab-ci.yml
expenses Apr 20, 2020
95f6d93
Merge remote-tracking branch 'parity/master' into ashley-browser-testing
expenses Apr 20, 2020
54eee6d
Try with 127.0.0.1 whitelisted
expenses Apr 20, 2020
02a1a44
Up the timeout to 120 seconds
expenses Apr 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ variables:
# FIXME set to release
CARGO_UNLEASH_INSTALL_PARAMS: "--version 1.0.0-alpha.10"
CARGO_UNLEASH_PKG_DEF: "--skip node node-* pallet-template pallet-example pallet-example-* subkey chain-spec-builder sp-arithmetic-fuzzer"
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER: "wasm-bindgen-test-runner"
WASM_BINDGEN_TEST_TIMEOUT: 120
CHROMEDRIVER_ARGS: "--log-level=INFO --whitelisted-ips=127.0.0.1"


.collect-artifacts: &collect-artifacts
Expand Down Expand Up @@ -312,7 +315,6 @@ test-linux-stable-int:
paths:
- ${CI_COMMIT_SHORT_SHA}_int_failure.log


check-web-wasm:
stage: test
<<: *docker-env
Expand Down Expand Up @@ -354,6 +356,15 @@ test-full-crypto-feature:

#### stage: build

test-browser-node:
stage: build
<<: *docker-env
needs:
- job: check-web-wasm
artifacts: false
script:
- cargo +nightly test --target wasm32-unknown-unknown -p node-browser-testing -Z features=itarget

build-linux-substrate: &build-binary
stage: build
<<: *collect-artifacts
Expand Down
43 changes: 43 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"bin/node-template/runtime",
"bin/node-template/pallets/template",
"bin/node/bench",
"bin/node/browser-testing",
"bin/node/cli",
"bin/node/executor",
"bin/node/primitives",
Expand Down
21 changes: 21 additions & 0 deletions bin/node/browser-testing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "node-browser-testing"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Tests for the in-browser light client."
edition = "2018"
license = "GPL-3.0"

[dependencies]
futures-timer = "3.0.2"
libp2p = { version = "0.18.0", default-features = false }
jsonrpc-core = "14.0.5"
serde = "1.0.106"
serde_json = "1.0.48"
wasm-bindgen = { version = "0.2.60", features = ["serde-serialize"] }
wasm-bindgen-futures = "0.4.10"
wasm-bindgen-test = "0.3.10"
futures = "0.3.4"

node-cli = { path = "../cli", default-features = false, features = ["browser"] }
sc-rpc-api = { path = "../../../client/rpc-api" }
84 changes: 84 additions & 0 deletions bin/node/browser-testing/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright 2020 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! # Running
//! Running this test can be done with
//! ```text
//! wasm-pack test --firefox --release --headless bin/node/browser-testing
//! ```
//! or (without `wasm-pack`)
//! ```text
//! CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_RUNNER=wasm-bindgen-test-runner WASM_BINDGEN_TEST_TIMEOUT=60 cargo test --target wasm32-unknown-unknown
//! ```
//! For debug infomation, such as the informant, run without the `--headless`
//! flag and open a browser to the url that `wasm-pack test` outputs.
//! For more infomation see https://rustwasm.github.io/docs/wasm-pack/.

use wasm_bindgen_test::{wasm_bindgen_test, wasm_bindgen_test_configure};
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen::JsValue;
use jsonrpc_core::types::{MethodCall, Success, Version, Params, Id};
use serde::de::DeserializeOwned;
use futures_timer::Delay;
use std::time::Duration;
use futures::FutureExt;

wasm_bindgen_test_configure!(run_in_browser);

const CHAIN_SPEC: &str = include_str!("../../cli/res/flaming-fir.json");

fn rpc_call(method: &str) -> String {
serde_json::to_string(&MethodCall {
jsonrpc: Some(Version::V2),
method: method.into(),
params: Params::None,
id: Id::Num(1)
}).unwrap()
}

fn deserialize_rpc_result<T: DeserializeOwned>(js_value: JsValue) -> T {
let string = js_value.as_string().unwrap();
let value = serde_json::from_str::<Success>(&string).unwrap().result;
// We need to convert a `Value::Object` into a proper type.
let value_string = serde_json::to_string(&value).unwrap();
serde_json::from_str(&value_string).unwrap()
}

#[wasm_bindgen_test]
async fn runs() {
let mut client = node_cli::start_client(CHAIN_SPEC.into(), "info".into())
.await
.unwrap();

let mut test_timeout = Delay::new(Duration::from_secs(45));
loop {
// Check that timeout hasn't expired.
assert!((&mut test_timeout).now_or_never().is_none(), "Test timed out.");

// Let the node do a bit of work.
Delay::new(Duration::from_secs(5)).await;

let state: sc_rpc_api::system::Health = deserialize_rpc_result(
JsFuture::from(client.rpc_send(&rpc_call("system_health")))
.await
.unwrap()
);

if state.should_have_peers && state.peers > 0 && state.is_syncing {
break;
}
}
}
7 changes: 7 additions & 0 deletions bin/node/browser-testing/webdriver.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"goog:chromeOptions": {
"args": [
"--whitelisted-ips=127.0.0.1"
]
}
}
1 change: 0 additions & 1 deletion bin/node/cli/src/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use crate::chain_spec::ChainSpec;
use log::info;
use wasm_bindgen::prelude::*;
use sc_service::Configuration;
use browser_utils::{
Client,
browser_configuration, set_console_error_panic_hook, init_console_log,
Expand Down