Skip to content

Commit c93b885

Browse files
Merge pull request #1 from trustwallet/master
Adds Safety and Codecov CI (trustwallet#4408)
2 parents 3b6d7e8 + 9693d83 commit c93b885

File tree

49 files changed

+1190
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1190
-138
lines changed

.github/workflows/flutter-ci.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Flutter CI
2+
3+
on:
4+
push:
5+
branches: [ dev, master ]
6+
pull_request:
7+
branches: [ dev, master ]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-24.04
16+
if: github.event.pull_request.draft == false
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Install system dependencies
20+
run: |
21+
tools/install-sys-dependencies-linux
22+
tools/install-rust-dependencies
23+
- name: Cache internal dependencies
24+
id: internal_cache
25+
uses: actions/cache@v3
26+
with:
27+
path: build/local
28+
key: ${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('tools/install-sys-dependencies-linux') }}-internal-${{ hashFiles('tools/install-dependencies') }}-${{ hashFiles('tools/dependencies-version') }}
29+
- name: Install internal dependencies
30+
run: |
31+
tools/install-dependencies
32+
env:
33+
CC: /usr/bin/clang
34+
CXX: /usr/bin/clang++
35+
if: steps.internal_cache.outputs.cache-hit != 'true'
36+
37+
- name: Cache Rust
38+
uses: Swatinem/rust-cache@v2
39+
with:
40+
workspaces: |
41+
rust
42+
43+
- name: Code generation
44+
run: |
45+
tools/generate-files native
46+
env:
47+
CC: /usr/bin/clang
48+
CXX: /usr/bin/clang++
49+
50+
- name: Setup Dart
51+
uses: dart-lang/setup-dart@v1
52+
with:
53+
sdk: '3.8.1'
54+
cache: true
55+
cache-key: dart-3.8.1
56+
cache-path: ${{ github.workspace }}/.pub-cache
57+
58+
- name: Install Dart dependencies
59+
run: |
60+
cd flutter
61+
dart pub get
62+
dart pub upgrade
63+
64+
- name: Flutter build
65+
run: |
66+
tools/flutter-build
67+
env:
68+
CC: /usr/bin/clang
69+
CXX: /usr/bin/clang++
70+
Lines changed: 112 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Linux CI Rust
1+
name: Rust CI
22

33
on:
44
push:
@@ -16,7 +16,7 @@ concurrency:
1616

1717
jobs:
1818
# Check formatting, clippy warnings, run tests and check code coverage.
19-
build-and-test:
19+
rust-lints:
2020
permissions:
2121
contents: read
2222
checks: write
@@ -51,18 +51,6 @@ jobs:
5151
cargo clippy -- -D warnings
5252
working-directory: rust
5353

54-
- name: Run tests
55-
run: |
56-
tools/rust-coverage
57-
58-
- name: Gather and check Rust code coverage
59-
run: |
60-
tools/check-coverage rust/coverage.stats rust/coverage.info
61-
62-
- name: Run Doc tests
63-
run: |
64-
tools/rust-test doc
65-
6654
# Run Rust tests in WASM.
6755
test-wasm:
6856
runs-on: ubuntu-24.04
@@ -163,3 +151,113 @@ jobs:
163151
comment-author: 'github-actions[bot]'
164152
edit-mode: replace
165153
body-path: 'report-diff.md'
154+
155+
memory-profiler:
156+
runs-on: ubuntu-24.04
157+
if: github.event.pull_request.draft == false
158+
steps:
159+
- uses: actions/checkout@v4
160+
with:
161+
submodules: true
162+
163+
- name: Run sccache-cache
164+
uses: mozilla-actions/sccache-action@v0.0.8
165+
166+
- name: Cache Rust
167+
uses: Swatinem/rust-cache@v2
168+
with:
169+
workspaces: |
170+
rust
171+
172+
- name: Install llvm
173+
run: |
174+
# to get the symbolizer for debug symbol resolution
175+
sudo apt install llvm
176+
177+
- name: Install nightly
178+
uses: dtolnay/rust-toolchain@nightly
179+
180+
- name: Enable debug symbols
181+
run: |
182+
cd rust
183+
# to fix buggy leak analyzer:
184+
# https://github.com/japaric/rust-san#unrealiable-leaksanitizer
185+
# ensure there's a profile.dev section
186+
if ! grep -qE '^[ \t]*[profile.dev]' Cargo.toml; then
187+
echo >> Cargo.toml
188+
echo '[profile.dev]' >> Cargo.toml
189+
fi
190+
# remove pre-existing opt-levels in profile.dev
191+
sed -i '/^\s*\[profile.dev\]/,/^\s*\[/ {/^\s*opt-level/d}' Cargo.toml
192+
# now set opt-level to 1
193+
sed -i '/^\s*\[profile.dev\]/a opt-level = 1' Cargo.toml
194+
cat Cargo.toml
195+
196+
- name: cargo test -Zsanitizer=address
197+
# only --lib --tests b/c of https://github.com/rust-lang/rust/issues/53945
198+
run: |
199+
cd rust
200+
cargo test --lib --tests --all-features --target x86_64-unknown-linux-gnu
201+
env:
202+
ASAN_OPTIONS: "detect_odr_violation=0:detect_leaks=0"
203+
RUSTFLAGS: "-Z sanitizer=address"
204+
205+
- name: cargo test -Zsanitizer=leak
206+
if: always()
207+
run: |
208+
cd rust
209+
cargo test --all-features --target x86_64-unknown-linux-gnu
210+
env:
211+
RUSTFLAGS: "-Z sanitizer=leak"
212+
213+
coverage:
214+
runs-on: ubuntu-24.04
215+
if: github.event.pull_request.draft == false
216+
217+
steps:
218+
- uses: actions/checkout@v3
219+
- name: Install system dependencies
220+
run: |
221+
tools/install-sys-dependencies-linux
222+
223+
- name: Run sccache-cache
224+
uses: mozilla-actions/sccache-action@v0.0.8
225+
226+
- name: Cache Rust
227+
uses: Swatinem/rust-cache@v2
228+
with:
229+
workspaces: |
230+
rust
231+
232+
- name: Install Rust dependencies
233+
run: |
234+
tools/install-rust-dependencies dev
235+
236+
- name: cargo generate-lockfile
237+
if: hashFiles('Cargo.lock') == ''
238+
run: |
239+
cd rust
240+
cargo generate-lockfile
241+
242+
- name: Run tests
243+
run: |
244+
tools/rust-coverage
245+
246+
- name: Run Doc tests
247+
run: |
248+
tools/rust-test doc
249+
250+
- name: Record Rust version
251+
run: echo "RUST=$(rustc --version)" >> "$GITHUB_ENV"
252+
253+
# TODO: Uncomment this when we have a codecov token
254+
# - name: Upload to codecov.io
255+
# uses: codecov/codecov-action@v5
256+
# with:
257+
# fail_ci_if_error: true
258+
# token: ${{ secrets.CODECOV_TOKEN }}
259+
# env_vars: OS,RUST
260+
261+
- name: Gather and check Rust code coverage
262+
run: |
263+
tools/check-coverage rust/coverage.stats rust/lcov.info

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ emsdk/
5757
wasm-build/
5858

5959
# Code coverage files
60+
lcov.info
6061
coverage.info
6162
coverage/
6263
swift/test_output/

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ elseif (${TW_COMPILE_JAVA})
9191
find_package(JNI REQUIRED)
9292
target_include_directories(TrustWalletCore PRIVATE ${JNI_INCLUDE_DIRS})
9393
target_link_libraries(TrustWalletCore PUBLIC ${WALLET_CORE_BINDGEN} ${PROJECT_NAME}_INTERFACE PRIVATE TrezorCrypto protobuf Boost::boost)
94+
elseif (${FLUTTER})
95+
message("Configuring for Flutter")
96+
file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h)
97+
add_library(TrustWalletCore SHARED ${sources} ${PROTO_SRCS} ${PROTO_HDRS})
98+
target_link_libraries(TrustWalletCore PUBLIC ${WALLET_CORE_BINDGEN} ${PROJECT_NAME}_INTERFACE PRIVATE TrezorCrypto protobuf Boost::boost)
9499
else ()
95100
message("Configuring standalone")
96101
file(GLOB_RECURSE sources src/*.c src/*.cc src/*.cpp src/*.h)

android/app/src/androidTest/java/com/trustwallet/core/app/blockchains/theopennetwork/TestTheOpenNetworkSigner.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TestTheOpenNetworkSigner {
2626

2727
val transfer = TheOpenNetwork.Transfer.newBuilder()
2828
.setDest("EQBm--PFwDv1yCeS-QTJ-L8oiUpqo9IT1BwgVptlSq3ts90Q")
29-
.setAmount(10)
29+
.setAmount(ByteString.copyFrom("0A".toHexByteArray())) // 10
3030
.setMode(TheOpenNetwork.SendMode.PAY_FEES_SEPARATELY_VALUE or TheOpenNetwork.SendMode.IGNORE_ACTION_PHASE_ERRORS_VALUE)
3131
.setBounceable(true)
3232
.build()
@@ -52,15 +52,15 @@ class TestTheOpenNetworkSigner {
5252
val privateKey = PrivateKey("c054900a527538c1b4325688a421c0469b171c29f23a62da216e90b0df2412ee".toHexByteArray())
5353

5454
val jettonTransfer = TheOpenNetwork.JettonTransfer.newBuilder()
55-
.setJettonAmount(500 * 1000 * 1000)
55+
.setJettonAmount(ByteString.copyFrom("1DCD6500".toHexByteArray())) // 500 * 1000 * 1000
5656
.setToOwner("EQAFwMs5ha8OgZ9M4hQr80z9NkE7rGxUpE1hCFndiY6JnDx8")
5757
.setResponseAddress("EQBaKIMq5Am2p_rfR1IFTwsNWHxBkOpLTmwUain5Fj4llTXk")
58-
.setForwardAmount(1)
58+
.setForwardAmount(ByteString.copyFrom("01".toHexByteArray())) // 1
5959
.build()
6060

6161
val transfer = TheOpenNetwork.Transfer.newBuilder()
6262
.setDest("EQBiaD8PO1NwfbxSkwbcNT9rXDjqhiIvXWymNO-edV0H5lja")
63-
.setAmount(100 * 1000 * 1000)
63+
.setAmount(ByteString.copyFrom("05F5E100".toHexByteArray())) // 100 * 1000 * 1000
6464
.setMode(TheOpenNetwork.SendMode.PAY_FEES_SEPARATELY_VALUE or TheOpenNetwork.SendMode.IGNORE_ACTION_PHASE_ERRORS_VALUE)
6565
.setComment("test comment")
6666
.setBounceable(true)
@@ -100,7 +100,7 @@ class TestTheOpenNetworkSigner {
100100
val transfer = TheOpenNetwork.Transfer.newBuilder()
101101
.setDest(dogeChatbotDeployingAddress)
102102
// 0.069 TON
103-
.setAmount(69_000_000)
103+
.setAmount(ByteString.copyFrom("041CDB40".toHexByteArray())) // 69_000_000
104104
.setMode(TheOpenNetwork.SendMode.PAY_FEES_SEPARATELY_VALUE or TheOpenNetwork.SendMode.IGNORE_ACTION_PHASE_ERRORS_VALUE)
105105
.setBounceable(false)
106106
.setStateInit(dogeChatbotStateInit)

android/gradlew

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if isHelp; then
1515
fi
1616

1717
echo "#### Installing system dependencies ... ####"
18-
if [[ $(uname) == "Darwin" ]]; then
18+
if [[ $(uname -s) == "Darwin" ]]; then
1919
tools/install-sys-dependencies-mac
2020
else
2121
tools/install-sys-dependencies-linux

cmake/StandardSettings.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#
22
# Default settings
33
#
4-
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
4+
if (NOT FLUTTER)
5+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
6+
endif ()
57
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
68
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
79
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version" FORCE)
@@ -66,7 +68,7 @@ endif ()
6668
option(TW_UNIT_TESTS "Enable the unit tests of the project" ON)
6769
option(TW_BUILD_EXAMPLES "Enable the examples builds of the project" ON)
6870

69-
if (ANDROID OR IOS_PLATFORM OR TW_COMPILE_WASM OR TW_COMPILE_JAVA)
71+
if (ANDROID OR IOS_PLATFORM OR TW_COMPILE_WASM OR TW_COMPILE_JAVA OR FLUTTER)
7072
set(TW_UNIT_TESTS OFF)
7173
set(TW_BUILD_EXAMPLES OFF)
7274
endif()

flutter/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/
4+
*.dylib
5+
wallet_core_bindings.dart

flutter/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.0
2+
3+
- Initial version.

0 commit comments

Comments
 (0)