tests: update test sdk version; update ci; fix warnings (#38)

This commit is contained in:
Aleksey Proshutisnkiy 2022-06-30 15:54:43 +04:00 committed by GitHub
parent 6f00f8282d
commit e0a8abc1ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 695 additions and 324 deletions

View File

@ -1,39 +0,0 @@
version: 2.1
orbs:
docker: circleci/docker@1.5.0
jobs:
Build:
docker:
- image: circleci/rust:latest
resource_class: xlarge
environment:
RUST_BACKTRACE: 1
steps:
- checkout
- run: |
sudo bash .github/download_marine.sh
- restore_cache:
keys:
- aqua-ipfs00-{{ checksum "./service/pure/Cargo.lock" }}-{{ checksum "./service/effector/Cargo.lock" }}
- run: |
rustup toolchain install nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup default nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup override set nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup target add wasm32-wasi --toolchain nightly-2022-01-16-x86_64-unknown-linux-gnu
cd ./service
./build.sh
cargo test --no-fail-fast --release --all-features --
- save_cache:
paths:
- ~/.cargo
- ~/.rustup
key: aqua-ipfs00-{{ checksum "./service/pure/Cargo.lock" }}-{{ checksum "./service/effector/Cargo.lock" }}
workflows:
version: 2
CircleCI:
jobs:
- Build

View File

@ -3,7 +3,7 @@ set -o pipefail -o errexit -o nounset
set -x
MARINE_RELEASE="https://api.github.com/repos/fluencelabs/marine/releases/latest"
OUT_DIR=/usr/local/bin
OUT_DIR=~/.bin
# get metadata about release
curl -s -H "Accept: application/vnd.github.v3+json" $MARINE_RELEASE |

View File

@ -8,7 +8,7 @@ on:
jobs:
release:
name: "Publish"
runs-on: ubuntu-latest
runs-on: builder
container: rust
defaults:
run:

89
.github/workflows/rust_ci.yml vendored Normal file
View File

@ -0,0 +1,89 @@
name: Rust CI
on:
push:
workflow_dispatch:
concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true
jobs:
check:
name: cargo nextest
runs-on: builder
container: rust
defaults:
run:
working-directory: service
shell: bash
steps:
- name: Checkout sources
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: mkdir -p ~/.bin
- run: echo "~/.bin" >> $GITHUB_PATH
- name: Install Rust
working-directory: ./service
run: |
rustup toolchain install nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup default nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup override set nightly-2022-01-16-x86_64-unknown-linux-gnu
rustup target add wasm32-wasi --toolchain nightly-2022-01-16-x86_64-unknown-linux-gnu
- name: Download jq
run: |
curl -L https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 -o ~/.bin/jq
chmod +x ~/.bin/jq
- name: Download marine
run: bash $GITHUB_WORKSPACE/.github/download_marine.sh
- name: Build
run: ./build.sh
- run: cargo install --locked cargo-nextest --version 0.9.22
- run: cargo nextest run --release --all-features --no-fail-fast --retries 10 --test-threads 10
lints:
name: Lints
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
override: true
components: rustfmt, clippy
- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --manifest-path service/Cargo.toml -- --check
- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: -Z unstable-options --all --manifest-path service/Cargo.toml
continue-on-error: true # do not fail for now

View File

@ -30,4 +30,4 @@ service Ipfs("aqua-ipfs"):
set_external_api_multiaddr(multiaddr: string) -> IpfsResult
set_external_swarm_multiaddr(multiaddr: string) -> IpfsResult
set_local_api_multiaddr(multiaddr: string) -> IpfsResult
set_timeout(timeout_sec: u64)
set_timeout(timeout_sec: u64)

430
service/Cargo.lock generated
View File

@ -4,9 +4,9 @@ version = 3
[[package]]
name = "anyhow"
version = "1.0.56"
version = "1.0.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704"
[[package]]
name = "arrayref"
@ -74,6 +74,15 @@ version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytesize"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70"
dependencies = [
"serde",
]
[[package]]
name = "cargo_toml"
version = "0.8.1"
@ -199,9 +208,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.5.4"
version = "0.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53"
checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c"
dependencies = [
"cfg-if 1.0.0",
"crossbeam-utils",
@ -220,26 +229,26 @@ dependencies = [
[[package]]
name = "crossbeam-epoch"
version = "0.9.8"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c"
checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d"
dependencies = [
"autocfg",
"cfg-if 1.0.0",
"crossbeam-utils",
"lazy_static",
"memoffset",
"once_cell",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.8"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
checksum = "7d82ee10ce34d7bc12c2122495e7593a9c41347ecdd64185af4ecf72cb1a7f83"
dependencies = [
"cfg-if 1.0.0",
"lazy_static",
"once_cell",
]
[[package]]
@ -268,8 +277,18 @@ version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f2c43f534ea4b0b049015d00269734195e6d3f0f6635cb692251aca6f9f8b3c"
dependencies = [
"darling_core",
"darling_macro",
"darling_core 0.12.4",
"darling_macro 0.12.4",
]
[[package]]
name = "darling"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
dependencies = [
"darling_core 0.13.4",
"darling_macro 0.13.4",
]
[[package]]
@ -286,13 +305,38 @@ dependencies = [
"syn",
]
[[package]]
name = "darling_core"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a"
dependencies = [
"darling_core",
"darling_core 0.12.4",
"quote",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [
"darling_core 0.13.4",
"quote",
"syn",
]
@ -329,9 +373,9 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "erased-serde"
version = "0.3.20"
version = "0.3.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad132dd8d0d0b546348d7d86cb3191aad14b34e5f979781fc005c80d4ac67ffd"
checksum = "81d013529d5574a60caeda29e179e695125448e5de52e3874f7b4c1d7360e18e"
dependencies = [
"serde",
]
@ -359,9 +403,9 @@ dependencies = [
[[package]]
name = "eyre"
version = "0.6.7"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9289ed2c0440a6536e65119725cf91fc2c6b5e513bfd2e36e1134d7cca6ca12f"
checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb"
dependencies = [
"indenter",
"once_cell",
@ -369,43 +413,18 @@ dependencies = [
[[package]]
name = "fluence-app-service"
version = "0.10.2"
version = "0.17.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01c66660de99826038c5ec4ad0f5dccf10b1c8a15924aeaa5315ab49d718bfc9"
checksum = "ace6450ba26f7f1c185c0cb465b4c14b0da59419527a91ec3707842e3821b4f5"
dependencies = [
"fluence-faas",
"log",
"maplit",
"serde",
"serde_derive",
"serde_json",
"toml",
"wasmer-wasi-fl",
]
[[package]]
name = "fluence-faas"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2abf1682505636b8c3436a2787df7bbae426d4f5277f5ae4ad193032b318b7f1"
dependencies = [
"cmd_lib",
"itertools 0.9.0",
"log",
"marine-module-interface",
"marine-rs-sdk",
"marine-rs-sdk-main",
"marine-min-it-version",
"marine-runtime",
"marine-utils",
"safe-transmute",
"serde",
"serde_derive",
"serde_json",
"thiserror",
"toml",
"wasmer-interface-types-fl",
"wasmer-runtime-core-fl",
"wasmer-runtime-fl",
"wasmer-wasi-fl",
]
@ -498,20 +517,20 @@ dependencies = [
[[package]]
name = "getrandom"
version = "0.2.6"
version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad"
checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6"
dependencies = [
"cfg-if 1.0.0",
"libc",
"wasi 0.10.0+wasi-snapshot-preview1",
"wasi 0.11.0+wasi-snapshot-preview1",
]
[[package]]
name = "ghost"
version = "0.1.2"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a5bcf1bbeab73aa4cf2fde60a846858dc036163c7c33bec309f8d17de785479"
checksum = "b93490550b1782c589a350f2211fff2e34682e25fed17ef53fc4fa8fe184975e"
dependencies = [
"proc-macro2",
"quote",
@ -530,9 +549,9 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.11.2"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3"
[[package]]
name = "heck"
@ -589,9 +608,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]]
name = "indexmap"
version = "1.8.1"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee"
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
dependencies = [
"autocfg",
"hashbrown",
@ -600,9 +619,9 @@ dependencies = [
[[package]]
name = "inventory"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce6b5d8c669bfbad811d95ddd7a1c6cf9cfdbf2777e59928b6f3fa8ff54f72a0"
checksum = "84344c6e0b90a9e2b6f3f9abe5cc74402684e348df7b32adca28747e0cef091a"
dependencies = [
"ctor",
"ghost",
@ -637,17 +656,41 @@ dependencies = [
]
[[package]]
name = "it-lilo"
version = "0.1.0"
name = "it-json-serde"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99ccf40e1e08f6f47ffbafe3cfb2e3adb721ddde80b178240f038d07dc9652fb"
checksum = "9e3b7efb8eeb6892a947928c10ac963e5d5101c173924453466314bf004306b4"
dependencies = [
"serde",
"serde_derive",
"serde_json",
"serde_with",
"thiserror",
"wasmer-interface-types-fl",
]
[[package]]
name = "it-lilo"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a39dffcc610873b4c39b0fe04acac5ea77cf2eda9ed3d8a3b970b536d4e24c8"
dependencies = [
"fluence-it-types",
"it-memory-traits",
"log",
"paste",
"thiserror",
]
[[package]]
name = "it-memory-traits"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca1799ed89e51a192e80a14ab14589044de9e58f0be86087ae8699cbe59f5c40"
dependencies = [
"thiserror",
]
[[package]]
name = "it-to-bytes"
version = "0.1.0"
@ -674,9 +717,9 @@ dependencies = [
[[package]]
name = "itoa"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d"
[[package]]
name = "lazy_static"
@ -705,9 +748,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.121"
version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]]
name = "lock_api"
@ -720,9 +763,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.16"
version = "0.4.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6389c490849ff5bc16be905ae24bc913a9c8892e19b2341dbc175e14c341c2b8"
checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
dependencies = [
"cfg-if 1.0.0",
]
@ -735,18 +778,51 @@ checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "marine-build-rs-generator"
version = "0.4.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0108407ef0528984cd5b226e6d69552b1658b205f60c83305ca33179d6e9eee1"
checksum = "e276ffa953f282a83bf9396080bdfa869d5b9606a27c5475f5ef3a3e297af4d8"
dependencies = [
"marine-test-macro-impl",
]
[[package]]
name = "marine-it-generator"
version = "0.5.6"
name = "marine-core"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "890b228b9151e9dff213501986f564445a2f9ca5a706088b5d900f5ecf67f7e7"
checksum = "1bda166e903be5e13db562eab1293e35fe871aa8d9093857922f228e2158e7ea"
dependencies = [
"anyhow",
"boolinator",
"bytesize",
"it-lilo",
"it-memory-traits",
"log",
"marine-it-generator",
"marine-it-interfaces",
"marine-it-parser",
"marine-min-it-version",
"marine-module-info-parser",
"marine-module-interface",
"marine-utils",
"multimap",
"once_cell",
"parity-wasm",
"paste",
"pwasm-utils",
"semver 0.11.0",
"serde",
"thiserror",
"wasmer-interface-types-fl",
"wasmer-runtime-core-fl",
"wasmer-runtime-fl",
"wasmer-wasi-fl",
]
[[package]]
name = "marine-it-generator"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25eea53765b0886afd41197861c9a2a6a2d09dbd5f723833df35f38a71affa2a"
dependencies = [
"cargo_toml",
"it-lilo",
@ -762,9 +838,9 @@ dependencies = [
[[package]]
name = "marine-it-interfaces"
version = "0.4.1"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42e229143e72ba20e754de4766ff0d02e0cf176001f7471593f82b16c72dc26d"
checksum = "b3236d1068eaa0f1a07ab74b098b777c150c0c354a16d8869cd69ae3ff847014"
dependencies = [
"multimap",
"wasmer-interface-types-fl",
@ -772,9 +848,9 @@ dependencies = [
[[package]]
name = "marine-it-parser"
version = "0.6.8"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edd97bd85072fc540763769be153a7c8ee83391e668b37ef96d6c48decec2cd5"
checksum = "edea8966aa56f373e3b2db95432b023e20137c7d58798f74a67ee5749370d289"
dependencies = [
"anyhow",
"itertools 0.10.3",
@ -813,6 +889,16 @@ dependencies = [
"uuid",
]
[[package]]
name = "marine-min-it-version"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "890269754a531810b8c16cf00e6161e01c1183ef7ff4ff20117656316e9fdbd1"
dependencies = [
"once_cell",
"semver 0.11.0",
]
[[package]]
name = "marine-module-info-parser"
version = "0.2.2"
@ -831,9 +917,9 @@ dependencies = [
[[package]]
name = "marine-module-interface"
version = "0.1.6"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06bc36ef268bf7436916f1fa9b0c84104692a717ea5eef3c90b9f25c3407f6b7"
checksum = "eb284ad998636d64bfad9fef2849d8a02127ce9c094b4a3e53b2eb62c14e5e5f"
dependencies = [
"anyhow",
"itertools 0.10.3",
@ -844,7 +930,6 @@ dependencies = [
"thiserror",
"walrus",
"wasmer-interface-types-fl",
"wasmer-runtime-core-fl",
]
[[package]]
@ -872,9 +957,9 @@ dependencies = [
[[package]]
name = "marine-rs-sdk-test"
version = "0.4.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03e286a347527936cf97456b928bd6271e0d39fc1c6b78e99461f00e6d74f018"
checksum = "27107c7b934196f8641a73c321192587d4fccc46ec46a8969eea1dfc18b4c803"
dependencies = [
"fluence-app-service",
"marine-build-rs-generator",
@ -886,28 +971,27 @@ dependencies = [
[[package]]
name = "marine-runtime"
version = "0.7.2"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "983262d394c59d4321b141e303eb55015bc412f319d54bbad7f253e4583253b2"
checksum = "b04e7ebe49ba214363d8ce7e81cf9fd237adb10d3b9519a20677cc4ab0690009"
dependencies = [
"anyhow",
"boolinator",
"it-lilo",
"bytesize",
"cmd_lib",
"it-json-serde",
"itertools 0.9.0",
"log",
"marine-it-generator",
"marine-it-interfaces",
"marine-it-parser",
"marine-module-info-parser",
"marine-core",
"marine-module-interface",
"marine-rs-sdk",
"marine-rs-sdk-main",
"marine-utils",
"multimap",
"once_cell",
"parity-wasm",
"paste",
"pwasm-utils",
"semver 0.11.0",
"safe-transmute",
"serde",
"serde_derive",
"serde_json",
"serde_with",
"thiserror",
"toml",
"wasmer-interface-types-fl",
"wasmer-runtime-core-fl",
"wasmer-runtime-fl",
@ -916,9 +1000,9 @@ dependencies = [
[[package]]
name = "marine-test-macro"
version = "0.4.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf4d0463358f6c2459089ef8f130983dc911fd0c2aa4cb7c6b59de206f4a816e"
checksum = "15d2fcd41ef96cb32b24b3e9077fb669e072c02a1d20de869f96a4210246a32e"
dependencies = [
"marine-test-macro-impl",
"proc-macro-error",
@ -929,11 +1013,11 @@ dependencies = [
[[package]]
name = "marine-test-macro-impl"
version = "0.4.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8f4f1ae0ba20e9241e8882e6eb1b2302daa479d67eee5badb54b1520e17c0cb"
checksum = "fbd3b8c6cf4c17dca0da0051e59002ba653a9090df9b09c4a2c2a88533b760bb"
dependencies = [
"darling",
"darling 0.12.4",
"fluence-app-service",
"itertools 0.10.3",
"marine-it-parser",
@ -957,9 +1041,9 @@ dependencies = [
[[package]]
name = "marine-utils"
version = "0.2.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc5838acba84ce4d802d672afd0814fae0ae7098021ae5b06d975e70d09f812"
checksum = "1cff7a23a7f3925a712c34dfb9cd87994012d7743f016fd1533e12ab5a8335ca"
[[package]]
name = "matches"
@ -969,9 +1053,9 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]]
name = "memchr"
version = "2.4.1"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
[[package]]
name = "memmap"
@ -1052,9 +1136,9 @@ dependencies = [
[[package]]
name = "num-integer"
version = "0.1.44"
version = "0.1.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db"
checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
dependencies = [
"autocfg",
"num-traits",
@ -1062,9 +1146,9 @@ dependencies = [
[[package]]
name = "num-traits"
version = "0.2.14"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
@ -1081,9 +1165,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.10.0"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
[[package]]
name = "page_size"
@ -1097,9 +1181,9 @@ dependencies = [
[[package]]
name = "parity-wasm"
version = "0.41.0"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865"
checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92"
[[package]]
name = "parking_lot"
@ -1193,18 +1277,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.36"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
dependencies = [
"unicode-xid",
"unicode-ident",
]
[[package]]
name = "pwasm-utils"
version = "0.12.0"
version = "0.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192"
checksum = "880b3384fb00b8f6ecccd5d358b93bd2201900ae3daad213791d1864f6441f5c"
dependencies = [
"byteorder",
"log",
@ -1213,9 +1297,9 @@ dependencies = [
[[package]]
name = "quote"
version = "1.0.17"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "632d02bff7f874a36f33ea8bb416cd484b90cc66c1194b1a1110d067a7013f58"
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
dependencies = [
"proc-macro2",
]
@ -1233,9 +1317,9 @@ dependencies = [
[[package]]
name = "rayon"
version = "1.5.1"
version = "1.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90"
checksum = "bd99e5772ead8baa5215278c9b15bf92087709e9c1b2d1f97cdb5a183c933a7d"
dependencies = [
"autocfg",
"crossbeam-deque",
@ -1245,14 +1329,13 @@ dependencies = [
[[package]]
name = "rayon-core"
version = "1.9.1"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
checksum = "258bcdb5ac6dad48491bb2992db6b7cf74878b0384908af124823d118c99683f"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"lazy_static",
"num_cpus",
]
@ -1273,9 +1356,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.9"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f"
checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
[[package]]
name = "safe-transmute"
@ -1324,9 +1407,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.136"
version = "1.0.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce31e24b01e1e524df96f1c2fdd054405f8d7376249a5110886fb4b658484789"
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
dependencies = [
"serde_derive",
]
@ -1343,18 +1426,18 @@ dependencies = [
[[package]]
name = "serde_bytes"
version = "0.11.5"
version = "0.11.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16ae07dd2f88a366f15bd0632ba725227018c69a1c8550a927324f8eb8368bb9"
checksum = "212e73464ebcde48d723aa02eb270ba62eff38a9b732df31f33f1b4e145f3a54"
dependencies = [
"serde",
]
[[package]]
name = "serde_derive"
version = "1.0.136"
version = "1.0.137"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08597e7152fcd306f41838ed3e37be9eaeed2b61c42e2117266a554fab4662f9"
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
dependencies = [
"proc-macro2",
"quote",
@ -1363,9 +1446,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.79"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e8d9fa5c3b304765ce1fd9c4c8a3de2c8db365a5b91be52f186efc675681d95"
checksum = "9b7ce2b32a1aed03c558dc61a5cd328f15aff2dbc17daad8fb8af04d2100e15c"
dependencies = [
"itoa",
"ryu",
@ -1373,10 +1456,32 @@ dependencies = [
]
[[package]]
name = "smallvec"
version = "1.8.0"
name = "serde_with"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
checksum = "678b5a069e50bf00ecd22d0cd8ddf7c236f68581b03db652061ed5eb13a312ff"
dependencies = [
"serde",
"serde_with_macros",
]
[[package]]
name = "serde_with_macros"
version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082"
dependencies = [
"darling 0.13.4",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "smallvec"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc88c725d61fc6c3132893370cac4a0200e3fedf5da8331c570664b1987f5ca2"
[[package]]
name = "static_assertions"
@ -1398,13 +1503,13 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.90"
version = "1.0.98"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "704df27628939572cd88d33f171cd6f896f4eaca85252c6e0a72d8d8287ee86f"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
"unicode-ident",
]
[[package]]
@ -1427,18 +1532,18 @@ checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d"
[[package]]
name = "thiserror"
version = "1.0.30"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417"
checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.30"
version = "1.0.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b"
checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a"
dependencies = [
"proc-macro2",
"quote",
@ -1458,9 +1563,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.5.1"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2"
checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
dependencies = [
"tinyvec_macros",
]
@ -1473,9 +1578,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "toml"
version = "0.5.8"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa"
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
dependencies = [
"serde",
]
@ -1526,15 +1631,21 @@ checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
[[package]]
name = "unicode-bidi"
version = "0.3.7"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a01404663e3db436ed2746d9fefef640d868edae3cceb81c3b8d5732fda678f"
checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992"
[[package]]
name = "unicode-ident"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
[[package]]
name = "unicode-normalization"
version = "0.1.19"
version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9"
checksum = "81dee68f85cab8cf68dec42158baf3a79a1cdc065a8b103025965d6ccb7f6cbd"
dependencies = [
"tinyvec",
]
@ -1547,9 +1658,9 @@ checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]]
name = "unicode-xid"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
[[package]]
name = "unsigned-varint"
@ -1581,7 +1692,7 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
dependencies = [
"getrandom 0.2.6",
"getrandom 0.2.7",
]
[[package]]
@ -1644,6 +1755,12 @@ version = "0.10.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wasmer-clif-backend-fl"
version = "0.17.0"
@ -1698,12 +1815,13 @@ dependencies = [
[[package]]
name = "wasmer-interface-types-fl"
version = "0.20.2"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14ba3b5a07989987994b96bf5cc7ac2947005f9ff6123d71b7064232f07d28fa"
checksum = "cb2da50f3cdfee8539f69c34427cef5d66dba0c0c2596db9dbefb5aceaa7f798"
dependencies = [
"fluence-it-types",
"it-lilo",
"it-memory-traits",
"it-to-bytes",
"itertools 0.10.3",
"log",

View File

@ -19,4 +19,7 @@ serde_json = "1.0.64"
types = { path = "../types" }
[dev-dependencies]
marine-rs-sdk-test = "0.4.1"
marine-rs-sdk-test = "0.6.0"
[build-dependencies]
marine-rs-sdk-test = "0.6.0"

43
service/effector/build.rs Normal file
View File

@ -0,0 +1,43 @@
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use marine_rs_sdk_test::generate_marine_test_env;
use marine_rs_sdk_test::ServiceDescription;
fn main() {
let services = vec![
(
"ipfs_put".to_string(),
ServiceDescription {
config_path: "tests/Config_put.toml".to_string(),
modules_dir: Some("../artifacts".to_string()),
},
),
(
"ipfs_error".to_string(),
ServiceDescription {
config_path: "tests/Config_error.toml".to_string(),
modules_dir: Some("../artifacts".to_string()),
},
),
];
let target = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if target != "wasm32" {
generate_marine_test_env(services, "marine_test_env.rs", file!());
}
println!("cargo:rerun-if-changed=tests.rs");
}

View File

@ -16,7 +16,7 @@
#![allow(improper_ctypes)]
use types::{IpfsResult, IpfsPutResult, IpfsGetPeerIdResult};
use types::{IpfsGetPeerIdResult, IpfsPutResult, IpfsResult};
use marine_rs_sdk::marine;
use marine_rs_sdk::module_manifest;
@ -37,30 +37,35 @@ pub fn main() {
}
fn unwrap_mounted_binary_result(result: MountedBinaryResult) -> Result<String> {
result.into_std().ok_or(eyre::eyre!("stdout or stderr contains non valid UTF8 string"))?.map_err(|e| eyre::eyre!("ipfs cli call failed: {}", e))
result
.into_std()
.ok_or(eyre::eyre!(
"stdout or stderr contains non valid UTF8 string"
))?
.map_err(|e| eyre::eyre!("ipfs cli call failed: {}", e))
}
#[inline]
fn get_timeout_string(timeout: u64) -> String { format!("{}s", timeout) }
fn get_timeout_string(timeout: u64) -> String {
format!("{}s", timeout)
}
fn make_cmd_args(args: Vec<String>, api_multiaddr: String, timeout_sec: u64) -> Vec<String> {
args.into_iter().chain(
vec![
args.into_iter()
.chain(vec![
String::from("--timeout"),
get_timeout_string(timeout_sec),
String::from("--api"),
api_multiaddr
]).collect()
api_multiaddr,
])
.collect()
}
#[marine]
pub fn connect(multiaddr: String, api_multiaddr: String, timeout_sec: u64) -> IpfsResult {
log::info!("connect called with multiaddr {}", multiaddr);
let args = vec![
String::from("swarm"),
String::from("connect"),
multiaddr];
let args = vec![String::from("swarm"), String::from("connect"), multiaddr];
let cmd = make_cmd_args(args, api_multiaddr, timeout_sec);
unwrap_mounted_binary_result(ipfs(cmd)).map(|_| ()).into()
@ -72,19 +77,25 @@ pub fn put(file_path: String, api_multiaddr: String, timeout_sec: u64) -> IpfsPu
log::info!("put called with file path {}", file_path);
if !std::path::Path::new(&file_path).exists() {
return IpfsPutResult { success: false, error: format!("path {} doesn't exist", file_path), hash: "".to_string() };
return IpfsPutResult {
success: false,
error: format!("path {} doesn't exist", file_path),
hash: "".to_string(),
};
}
let args = vec![
String::from("add"),
String::from("-Q"),
inject_vault_host_path(file_path)
inject_vault_host_path(file_path),
];
let cmd = make_cmd_args(args, api_multiaddr, timeout_sec);
log::info!("ipfs put args {:?}", cmd);
unwrap_mounted_binary_result(ipfs(cmd)).map(|res| res.trim().to_string()).into()
unwrap_mounted_binary_result(ipfs(cmd))
.map(|res| res.trim().to_string())
.into()
}
/// Get file by provided hash from IPFS, saves it to a temporary file and returns a path to it.
@ -102,9 +113,11 @@ pub fn get(hash: String, file_path: String, api_multiaddr: String, timeout_sec:
log::info!("ipfs get args {:?}", cmd);
unwrap_mounted_binary_result(ipfs(cmd)).map(|output| {
log::info!("ipfs get output: {}", output);
}).into()
unwrap_mounted_binary_result(ipfs(cmd))
.map(|output| {
log::info!("ipfs get output: {}", output);
})
.into()
}
#[marine]
@ -113,17 +126,30 @@ pub fn get_peer_id(api_multiaddr: String, timeout_sec: u64) -> IpfsGetPeerIdResu
let cmd = make_cmd_args(vec![String::from("id")], api_multiaddr, timeout_sec);
let result = unwrap_mounted_binary_result(ipfs(cmd))?;
let result: serde_json::Value = serde_json::from_str(&result).wrap_err("ipfs response parsing failed")?;
result.get("ID").ok_or(eyre::eyre!("ID field not found in response"))?.as_str().ok_or(eyre::eyre!("ID value is not string"))?.to_string()
let result: serde_json::Value =
serde_json::from_str(&result).wrap_err("ipfs response parsing failed")?;
result
.get("ID")
.ok_or(eyre::eyre!("ID field not found in response"))?
.as_str()
.ok_or(eyre::eyre!("ID value is not string"))?
.to_string()
};
result.map_err(|e| eyre::eyre!("get_peer_id: {:?}", e)).into()
result
.map_err(|e| eyre::eyre!("get_peer_id: {:?}", e))
.into()
}
#[marine]
pub fn set_external_swarm_multiaddr(swarm_multiaddr: String, api_multiaddr: String, timeout_sec: u64) -> IpfsResult {
pub fn set_external_swarm_multiaddr(
swarm_multiaddr: String,
api_multiaddr: String,
timeout_sec: u64,
) -> IpfsResult {
let result: Result<()> = try {
let multiaddr = Multiaddr::from_str(&swarm_multiaddr).wrap_err(format!("invalid multiaddr {}", swarm_multiaddr))?;
let multiaddr = Multiaddr::from_str(&swarm_multiaddr)
.wrap_err(format!("invalid multiaddr {}", swarm_multiaddr))?;
let args = vec![
String::from("config"),
String::from("Addresses.Announce"),

View File

@ -20,15 +20,15 @@
mod effector;
/*
_initialize function that calls __wasm_call_ctors is required to mitigade memory leak
that is described in https://github.com/WebAssembly/wasi-libc/issues/298
_initialize function that calls __wasm_call_ctors is required to mitigade memory leak
that is described in https://github.com/WebAssembly/wasi-libc/issues/298
In short, without this code rust wraps every export function
with __wasm_call_ctors/__wasm_call_dtors calls. This causes memory leaks. When compiler sees
an explicit call to __wasm_call_ctors in _initialize function, it disables export wrapping.
In short, without this code rust wraps every export function
with __wasm_call_ctors/__wasm_call_dtors calls. This causes memory leaks. When compiler sees
an explicit call to __wasm_call_ctors in _initialize function, it disables export wrapping.
TODO: remove when updating to marine-rs-sdk with fix
*/
TODO: remove when updating to marine-rs-sdk with fix
*/
#[cfg(target_arch = "wasm32")]
extern "C" {
pub fn __wasm_call_ctors();
@ -42,7 +42,6 @@ fn _initialize() {
}
}
#[cfg(target_arch = "wasm32")]
pub fn main() {
_initialize(); // As __wasm_call_ctors still does necessary work, we call it at the start of the module

View File

@ -16,28 +16,22 @@
#[cfg(test)]
mod tests {
use marine_rs_sdk_test::marine_test;
marine_rs_sdk_test::include_test_env!("/marine_test_env.rs");
#[marine_test(
ipfs_effector(
config_path = "Config_error.toml",
modules_dir = "../../artifacts"
)
)]
#[test]
fn connect_failed() {
let mut effector = marine_test_env::ipfs_effector::ServiceInterface::new();
let result = effector.connect("/ip4/127.0.0.1/tcp/5001".to_string(), "/ip4/127.0.0.1/tcp/5001".to_string(), 5u64);
let mut effector = marine_test_env::ipfs_error::ServiceInterface::new();
let result = effector.connect(
"/ip4/127.0.0.1/tcp/5001".to_string(),
"/ip4/127.0.0.1/tcp/5001".to_string(),
5u64,
);
assert!(!result.success);
}
#[marine_test(
ipfs_effector(
config_path = "Config_put.toml",
modules_dir = "../../artifacts"
)
)]
#[test]
fn put_result() {
let mut effector = marine_test_env::ipfs_effector::ServiceInterface::new();
let mut effector = marine_test_env::ipfs_put::ServiceInterface::new();
let result = effector.put("tmp".to_string(), "api_multiaddr".to_string(), 1);
assert_eq!("hash", result.hash);
}

View File

@ -21,4 +21,7 @@ bs58 = "0.4.0"
types = { path = "../types" }
[dev-dependencies]
marine-rs-sdk-test = "0.4.1"
marine-rs-sdk-test = "0.6.0"
[build-dependencies]
marine-rs-sdk-test = "0.6.0"

34
service/pure/build.rs Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright 2021 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
use marine_rs_sdk_test::generate_marine_test_env;
use marine_rs_sdk_test::ServiceDescription;
fn main() {
let services = vec![(
"ipfs".to_string(),
ServiceDescription {
config_path: "tests/Config.toml".to_string(),
modules_dir: Some("../artifacts".to_string()),
},
)];
let target = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
if target != "wasm32" {
generate_marine_test_env(services, "marine_test_env.rs", file!());
}
println!("cargo:rerun-if-changed=tests.rs");
}

View File

@ -17,15 +17,15 @@
#![feature(try_blocks)]
/*
_initialize function that calls __wasm_call_ctors is required to mitigade memory leak
that is described in https://github.com/WebAssembly/wasi-libc/issues/298
_initialize function that calls __wasm_call_ctors is required to mitigade memory leak
that is described in https://github.com/WebAssembly/wasi-libc/issues/298
In short, without this code rust wraps every export function
with __wasm_call_ctors/__wasm_call_dtors calls. This causes memory leaks. When compiler sees
an explicit call to __wasm_call_ctors in _initialize function, it disables export wrapping.
In short, without this code rust wraps every export function
with __wasm_call_ctors/__wasm_call_dtors calls. This causes memory leaks. When compiler sees
an explicit call to __wasm_call_ctors in _initialize function, it disables export wrapping.
TODO: remove when updating to marine-rs-sdk with fix
*/
TODO: remove when updating to marine-rs-sdk with fix
*/
#[cfg(target_arch = "wasm32")]
extern "C" {
pub fn __wasm_call_ctors();
@ -42,7 +42,6 @@ fn _initialize() {
#[cfg(target_arch = "wasm32")]
mod pure;
#[cfg(target_arch = "wasm32")]
pub fn main() {
_initialize(); // As __wasm_call_ctors still does necessary work, we call it at the start of the module

View File

@ -16,17 +16,17 @@
#![allow(improper_ctypes)]
use types::{IpfsResult, IpfsGetResult, IpfsPutResult, IpfsGetPeerIdResult, IpfsMultiaddrResult};
use types::{IpfsGetPeerIdResult, IpfsGetResult, IpfsMultiaddrResult, IpfsPutResult, IpfsResult};
use marine_rs_sdk::marine;
use marine_rs_sdk::module_manifest;
use marine_rs_sdk::WasmLoggerBuilder;
use std::fs;
use serde::{Deserialize, Serialize};
use multiaddr::{Multiaddr, Protocol, multihash::Multihash};
use std::str::FromStr;
use eyre::WrapErr;
use multiaddr::{multihash::Multihash, Multiaddr, Protocol};
use serde::{Deserialize, Serialize};
use std::fs;
use std::str::FromStr;
const CONFIG_FILE_PATH: &str = "/tmp/multiaddr_config";
const DEFAULT_TIMEOUT_SEC: u64 = 1u64;
@ -55,7 +55,9 @@ fn save_external_api_multiaddr(multiaddr: Multiaddr) {
}
fn load_external_api_multiaddr() -> eyre::Result<Multiaddr> {
load_config().external_api_multiaddr.ok_or(eyre::eyre!("external api multiaddr is not set"))
load_config()
.external_api_multiaddr
.ok_or(eyre::eyre!("external api multiaddr is not set"))
}
fn save_local_api_multiaddr(multiaddr: Multiaddr) {
@ -65,7 +67,9 @@ fn save_local_api_multiaddr(multiaddr: Multiaddr) {
}
fn load_local_api_multiaddr() -> eyre::Result<Multiaddr> {
load_config().local_api_multiaddr.ok_or(eyre::eyre!("local api multiaddr is not set"))
load_config()
.local_api_multiaddr
.ok_or(eyre::eyre!("local api multiaddr is not set"))
}
pub fn write_config(config: Config) {
@ -93,7 +97,14 @@ pub fn get_peer_id(api_multiaddr: String, timeout: u64) -> eyre::Result<Protocol
Err(eyre::eyre!(peer_id_result.error.clone()))?;
}
Ok(Protocol::P2p(Multihash::from_bytes(&bs58::decode(peer_id_result.peer_id.clone()).into_vec()?).wrap_err(format!("error parsing peer_id from 'ipfs id': {}", peer_id_result.peer_id))?))
Ok(Protocol::P2p(
Multihash::from_bytes(&bs58::decode(peer_id_result.peer_id.clone()).into_vec()?).wrap_err(
format!(
"error parsing peer_id from 'ipfs id': {}",
peer_id_result.peer_id
),
)?,
))
}
#[marine]
@ -164,19 +175,24 @@ pub fn get_external_api_multiaddr() -> IpfsMultiaddrResult {
#[marine]
pub fn set_external_api_multiaddr(multiaddr: String) -> IpfsResult {
if load_external_api_multiaddr().is_ok() {
return eyre::Result::<()>::Err(eyre::eyre!("external api multiaddr can only be set once")).into();
return eyre::Result::<()>::Err(eyre::eyre!("external api multiaddr can only be set once"))
.into();
}
let call_parameters = marine_rs_sdk::get_call_parameters();
if call_parameters.init_peer_id != call_parameters.service_creator_peer_id {
return eyre::Result::<()>::Err(eyre::eyre!("only service creator can set external api multiaddr")).into();
return eyre::Result::<()>::Err(eyre::eyre!(
"only service creator can set external api multiaddr"
))
.into();
}
let config = load_config();
let timeout = config.timeout;
let result: eyre::Result<()> = try {
let mut multiaddr = Multiaddr::from_str(&multiaddr).wrap_err(format!("invalid multiaddr: {}", multiaddr))?;
let mut multiaddr = Multiaddr::from_str(&multiaddr)
.wrap_err(format!("invalid multiaddr: {}", multiaddr))?;
let local_maddr = load_local_api_multiaddr()?.to_string();
let mut passed_peer_id = None;
match multiaddr.iter().count() {
@ -184,12 +200,19 @@ pub fn set_external_api_multiaddr(multiaddr: String) -> IpfsResult {
passed_peer_id = multiaddr.pop();
}
2 => {}
n => Err(eyre::eyre!("multiaddr should contain 2 or 3 components, {} given", n))?,
n => Err(eyre::eyre!(
"multiaddr should contain 2 or 3 components, {} given",
n
))?,
}
let peer_id = get_peer_id(local_maddr, timeout)?;
if passed_peer_id.is_some() && passed_peer_id != Some(peer_id.clone()) {
Err(eyre::eyre!("given peer id is different from node peer_id: given {}, actual {}", passed_peer_id.unwrap().to_string(), peer_id.to_string()))?;
Err(eyre::eyre!(
"given peer id is different from node peer_id: given {}, actual {}",
passed_peer_id.unwrap().to_string(),
peer_id.to_string()
))?;
}
multiaddr.push(peer_id);
@ -208,16 +231,23 @@ pub fn get_local_api_multiaddr() -> IpfsMultiaddrResult {
#[marine]
pub fn set_local_api_multiaddr(multiaddr: String) -> IpfsResult {
if load_local_api_multiaddr().is_ok() {
return eyre::Result::<()>::Err(eyre::eyre!("local api multiaddr can only be set once")).into();
return eyre::Result::<()>::Err(eyre::eyre!("local api multiaddr can only be set once"))
.into();
}
let call_parameters = marine_rs_sdk::get_call_parameters();
if call_parameters.init_peer_id != call_parameters.service_creator_peer_id {
return eyre::Result::<()>::Err(eyre::eyre!("only service creator can set local api multiaddr")).into();
return eyre::Result::<()>::Err(eyre::eyre!(
"only service creator can set local api multiaddr"
))
.into();
}
let result: eyre::Result<()> = try {
save_local_api_multiaddr(Multiaddr::from_str(&multiaddr).wrap_err(format!("invalid multiaddr: {}", multiaddr))?)
save_local_api_multiaddr(
Multiaddr::from_str(&multiaddr)
.wrap_err(format!("invalid multiaddr: {}", multiaddr))?,
)
};
result.into()
@ -225,24 +255,35 @@ pub fn set_local_api_multiaddr(multiaddr: String) -> IpfsResult {
#[marine]
pub fn get_external_swarm_multiaddr() -> IpfsMultiaddrResult {
load_config().external_swarm_multiaddr.ok_or(eyre::eyre!("multiaddr is not set")).map(|m| m.to_string()).into()
load_config()
.external_swarm_multiaddr
.ok_or(eyre::eyre!("multiaddr is not set"))
.map(|m| m.to_string())
.into()
}
#[marine]
pub fn set_external_swarm_multiaddr(multiaddr: String) -> IpfsResult {
if load_config().external_swarm_multiaddr.is_some() {
return eyre::Result::<()>::Err(eyre::eyre!("external swarm multiaddr can only be set once")).into();
return eyre::Result::<()>::Err(eyre::eyre!(
"external swarm multiaddr can only be set once"
))
.into();
}
let call_parameters = marine_rs_sdk::get_call_parameters();
if call_parameters.init_peer_id != call_parameters.service_creator_peer_id {
return eyre::Result::<()>::Err(eyre::eyre!("only service creator can set external swarm multiaddr")).into();
return eyre::Result::<()>::Err(eyre::eyre!(
"only service creator can set external swarm multiaddr"
))
.into();
}
let result: eyre::Result<()> = try {
let mut config = load_config();
let mut multiaddr = Multiaddr::from_str(&multiaddr).wrap_err(format!("invalid multiaddr: {}", multiaddr))?;
let mut multiaddr = Multiaddr::from_str(&multiaddr)
.wrap_err(format!("invalid multiaddr: {}", multiaddr))?;
let local_maddr = load_local_api_multiaddr()?.to_string();
let mut passed_peer_id = None;
@ -251,17 +292,25 @@ pub fn set_external_swarm_multiaddr(multiaddr: String) -> IpfsResult {
passed_peer_id = multiaddr.pop();
}
2 => {}
n => Err(eyre::eyre!("multiaddr should contain 2 or 3 components, {} given", n))?,
n => Err(eyre::eyre!(
"multiaddr should contain 2 or 3 components, {} given",
n
))?,
}
let peer_id = get_peer_id(local_maddr.clone(), config.timeout)?;
if passed_peer_id.is_some() && passed_peer_id != Some(peer_id.clone()) {
Err(eyre::eyre!("given peer id is different from node peer_id: given {}, actual {}", passed_peer_id.unwrap().to_string(), peer_id.to_string()))?;
Err(eyre::eyre!(
"given peer id is different from node peer_id: given {}, actual {}",
passed_peer_id.unwrap().to_string(),
peer_id.to_string()
))?;
}
multiaddr.push(peer_id);
let set_result = ipfs_set_external_swarm_multiaddr(multiaddr.to_string(), local_maddr, config.timeout);
let set_result =
ipfs_set_external_swarm_multiaddr(multiaddr.to_string(), local_maddr, config.timeout);
if !set_result.success {
return set_result;
}
@ -280,12 +329,15 @@ pub fn set_timeout(timeout_sec: u64) {
write_config(config);
}
#[marine]
#[link(wasm_import_module = "ipfs_effector")]
extern "C" {
#[link_name = "connect"]
pub fn ipfs_connect(external_multiaddr: String, api_multiaddr: String, timeout_sec: u64) -> IpfsResult;
pub fn ipfs_connect(
external_multiaddr: String,
api_multiaddr: String,
timeout_sec: u64,
) -> IpfsResult;
/// Put provided file to ipfs, return ipfs hash of the file.
#[link_name = "put"]
@ -293,11 +345,20 @@ extern "C" {
/// Get file from ipfs by hash.
#[link_name = "get"]
pub fn ipfs_get(hash: String, file_path: String, api_multiaddr: String, timeout_sec: u64) -> IpfsResult;
pub fn ipfs_get(
hash: String,
file_path: String,
api_multiaddr: String,
timeout_sec: u64,
) -> IpfsResult;
#[link_name = "get_peer_id"]
pub fn ipfs_get_peer_id(local_multiaddr: String, timeout_sec: u64) -> IpfsGetPeerIdResult;
#[link_name = "set_external_swarm_multiaddr"]
pub fn ipfs_set_external_swarm_multiaddr(swarm_multiaddr: String, api_multiaddr: String, timeout_sec: u64) -> IpfsResult;
pub fn ipfs_set_external_swarm_multiaddr(
swarm_multiaddr: String,
api_multiaddr: String,
timeout_sec: u64,
) -> IpfsResult;
}

View File

@ -16,59 +16,60 @@
#[cfg(test)]
mod tests {
use marine_rs_sdk_test::marine_test;
marine_rs_sdk_test::include_test_env!("/marine_test_env.rs");
use marine_test_env::ipfs::ServiceInterface;
macro_rules! set_default_local_api_multiaddr {
($ipfs_pure:expr) => {
let mut ipfs_pure = marine_test_env::ipfs_pure::ServiceInterface::new();
let result = ipfs_pure.set_local_api_multiaddr("/ip4/127.0.0.1/tcp/9992".to_string());
assert!(result.success);
}
fn set_default_local_api_multiaddr(ipfs: &mut ServiceInterface) {
let result = ipfs.set_local_api_multiaddr("/ip4/127.0.0.1/tcp/9992".to_string());
assert!(result.success);
}
#[marine_test(ipfs_pure(config_path = "Config.toml", modules_dir = "../../artifacts"))]
#[test]
fn invalid_multiaddr() {
let mut ipfs = ServiceInterface::new();
let invalid_multiaddr = "invalid_multiaddr".to_string();
let mut ipfs_pure = marine_test_env::ipfs_pure::ServiceInterface::new();
let result = ipfs_pure.set_local_api_multiaddr(invalid_multiaddr.clone());
let result = ipfs.set_local_api_multiaddr(invalid_multiaddr.clone());
assert!(!result.success);
assert_eq!(format!("invalid multiaddr: {}", invalid_multiaddr), result.error);
assert_eq!(
format!("invalid multiaddr: {}", invalid_multiaddr),
result.error
);
}
#[marine_test(
ipfs_pure(config_path = "Config.toml", modules_dir = "../../artifacts"),
ipfs_effector(config_path = "Config.toml", modules_dir = "../../artifacts")
)]
#[test]
fn set_get_external_api_multiaddr() {
set_default_local_api_multiaddr!(ipfs_pure);
let mut ipfs = ServiceInterface::new();
set_default_local_api_multiaddr(&mut ipfs);
let multiaddr = "/ip4/127.0.0.1/tcp/9992";
let mut ipfs_pure = marine_test_env::ipfs_pure::ServiceInterface::new();
let result = ipfs_pure.set_external_api_multiaddr(multiaddr.to_string());
let result = ipfs.set_external_api_multiaddr(multiaddr.to_string());
assert!(result.success);
let mut ipfs_effector = marine_test_env::ipfs_effector::ServiceInterface::new();
let peer_id = ipfs_effector.get_peer_id("/ip4/127.0.0.1/tcp/5001".to_string(), 0).peer_id;
let peer_id = ipfs
.modules
.ipfs_effector
.get_peer_id("/ip4/127.0.0.1/tcp/5001".to_string(), 0)
.peer_id;
let result = ipfs_pure.get_external_api_multiaddr();
let result = ipfs.get_external_api_multiaddr();
assert!(result.success);
assert_eq!(format!("{}/p2p/{}", multiaddr, peer_id), result.multiaddr);
}
#[marine_test(
ipfs_pure(config_path = "Config.toml", modules_dir = "../../artifacts"),
ipfs_effector(config_path = "Config.toml", modules_dir = "../../artifacts")
)]
#[test]
fn set_get_external_swarm_multiaddr() {
set_default_local_api_multiaddr!(ipfs_pure);
let mut ipfs = ServiceInterface::new();
set_default_local_api_multiaddr(&mut ipfs);
let multiaddr = "/ip4/127.0.0.1/tcp/9992";
let mut ipfs_pure = marine_test_env::ipfs_pure::ServiceInterface::new();
let result = ipfs_pure.set_external_swarm_multiaddr(multiaddr.to_string());
let result = ipfs.set_external_swarm_multiaddr(multiaddr.to_string());
assert!(result.success);
let mut ipfs_effector = marine_test_env::ipfs_effector::ServiceInterface::new();
let peer_id = ipfs_effector.get_peer_id("/ip4/127.0.0.1/tcp/5001".to_string(), 0).peer_id;
let peer_id = ipfs
.modules
.ipfs_effector
.get_peer_id("/ip4/127.0.0.1/tcp/5001".to_string(), 0)
.peer_id;
let result = ipfs_pure.get_external_swarm_multiaddr();
let result = ipfs.get_external_swarm_multiaddr();
assert!(result.success);
assert_eq!(format!("{}/p2p/{}", multiaddr, peer_id), result.multiaddr);
}

View File

@ -1,3 +1,5 @@
mod results;
pub use results::{IpfsGetResult, IpfsResult, IpfsPutResult, IpfsGetPeerIdResult, IpfsMultiaddrResult};
pub use results::{
IpfsGetPeerIdResult, IpfsGetResult, IpfsMultiaddrResult, IpfsPutResult, IpfsResult,
};

View File

@ -14,8 +14,8 @@
* limitations under the License.
*/
use marine_rs_sdk::marine;
use eyre::Result;
use marine_rs_sdk::marine;
#[marine]
pub struct IpfsResult {
@ -26,8 +26,14 @@ pub struct IpfsResult {
impl From<Result<()>> for IpfsResult {
fn from(result: Result<()>) -> Self {
match result {
Ok(_) => Self { success: true, error: "".to_string() },
Err(err) => Self { success: false, error: err.to_string() }
Ok(_) => Self {
success: true,
error: "".to_string(),
},
Err(err) => Self {
success: false,
error: err.to_string(),
},
}
}
}
@ -42,8 +48,16 @@ pub struct IpfsGetResult {
impl From<Result<String>> for IpfsGetResult {
fn from(result: Result<String>) -> Self {
match result {
Ok(path) => Self { success: true, error: "".to_string(), path },
Err(err) => Self { success: false, error: err.to_string(), path: "".to_string() }
Ok(path) => Self {
success: true,
error: "".to_string(),
path,
},
Err(err) => Self {
success: false,
error: err.to_string(),
path: "".to_string(),
},
}
}
}
@ -58,8 +72,16 @@ pub struct IpfsPutResult {
impl From<Result<String>> for IpfsPutResult {
fn from(result: Result<String>) -> Self {
match result {
Ok(hash) => Self { success: true, error: "".to_string(), hash },
Err(err) => Self { success: false, error: err.to_string(), hash: "".to_string() }
Ok(hash) => Self {
success: true,
error: "".to_string(),
hash,
},
Err(err) => Self {
success: false,
error: err.to_string(),
hash: "".to_string(),
},
}
}
}
@ -74,8 +96,16 @@ pub struct IpfsGetPeerIdResult {
impl From<Result<String>> for IpfsGetPeerIdResult {
fn from(result: Result<String>) -> Self {
match result {
Ok(peer_id) => Self { success: true, error: "".to_string(), peer_id },
Err(err) => Self { success: false, error: err.to_string(), peer_id: "".to_string() }
Ok(peer_id) => Self {
success: true,
error: "".to_string(),
peer_id,
},
Err(err) => Self {
success: false,
error: err.to_string(),
peer_id: "".to_string(),
},
}
}
}
@ -90,8 +120,16 @@ pub struct IpfsMultiaddrResult {
impl From<Result<String>> for IpfsMultiaddrResult {
fn from(result: Result<String>) -> Self {
match result {
Ok(multiaddr) => Self { success: true, error: "".to_string(), multiaddr },
Err(err) => Self { success: false, error: err.to_string(), multiaddr: "".to_string() }
Ok(multiaddr) => Self {
success: true,
error: "".to_string(),
multiaddr,
},
Err(err) => Self {
success: false,
error: err.to_string(),
multiaddr: "".to_string(),
},
}
}
}