Skip to content

Commit cabf713

Browse files
authored
Merge pull request #396 from Gogo-Eng/ci/issue-310-add-clippy-step
ci: add cargo clippy checks to contract workflows (#310)
2 parents 55ec1f5 + c83d91c commit cabf713

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

.github/workflows/contract-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ jobs:
1717
- name: Install Rust stable toolchain
1818
uses: dtolnay/rust-toolchain@stable
1919
with:
20+
components: clippy
2021
targets: wasm32-unknown-unknown
2122

2223
- name: Cache Cargo dependencies
2324
uses: Swatinem/rust-cache@v2
2425
with:
2526
workspaces: stellar-contracts -> target
2627

28+
- name: Run clippy (deny warnings)
29+
run: cd stellar-contracts && cargo clippy --all-targets --all-features -- -D warnings
30+
2731
- name: Run contract tests
2832
run: cd stellar-contracts && cargo test

.github/workflows/contracts.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
uses: dtolnay/rust-toolchain@stable
3232
with:
3333
toolchain: stable
34+
components: clippy
3435
targets: wasm32-unknown-unknown
3536

3637
- name: Cache Cargo registry
@@ -49,3 +50,6 @@ jobs:
4950

5051
- name: Build WASM release
5152
run: cargo build --target wasm32-unknown-unknown --release
53+
54+
- name: Run clippy (deny warnings)
55+
run: cargo clippy --all-targets --all-features -- -D warnings

stellar-contracts/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![no_std]
2+
#![allow(deprecated)]
3+
#![allow(clippy::too_many_arguments)]
24
use soroban_sdk::{
35
contract, contracterror, contractimpl, contracttype, token, xdr::ToXdr, Address, Bytes, BytesN,
46
Env, Symbol, Vec,
@@ -409,7 +411,7 @@ impl FiatBridge {
409411

410412
// Transfer
411413
let token_client = token::Client::new(&env, &token);
412-
token_client.transfer(&from, &env.current_contract_address(), &amount);
414+
token_client.transfer(&from, env.current_contract_address(), &amount);
413415

414416
// State update
415417
let receipt_counter: u64 = env
@@ -2099,7 +2101,7 @@ impl FiatBridge {
20992101
.ok_or(Error::NotInitialized)?;
21002102
admin.require_auth();
21012103

2102-
let total_ops = operations.len() as u32;
2104+
let total_ops = operations.len();
21032105
let mut success_count: u32 = 0;
21042106
let mut failure_count: u32 = 0;
21052107
let mut first_failed_index: Option<u32> = None;
@@ -2128,6 +2130,7 @@ impl FiatBridge {
21282130
};
21292131

21302132
env.events().publish(
2133+
(Symbol::new(&env, "batch_ok"), Symbol::new(&env, "v1")),
21312134
(EVENT_VERSION, Symbol::new(&env, "batch_ok")),
21322135
(success_count, failure_count, total_ops),
21332136
);
@@ -2182,8 +2185,8 @@ impl FiatBridge {
21822185
return Err(Error::InternalError);
21832186
}
21842187
let mut arr = [0u8; 4];
2185-
for i in 0..4 {
2186-
arr[i] = bytes.get(i as u32).ok_or(Error::InternalError)?;
2188+
for (i, slot) in arr.iter_mut().enumerate() {
2189+
*slot = bytes.get(i as u32).ok_or(Error::InternalError)?;
21872190
}
21882191
Ok(u32::from_be_bytes(arr))
21892192
}
@@ -2193,8 +2196,8 @@ impl FiatBridge {
21932196
return Err(Error::InternalError);
21942197
}
21952198
let mut arr = [0u8; 16];
2196-
for i in 0..16 {
2197-
arr[i] = bytes.get(i as u32).ok_or(Error::InternalError)?;
2199+
for (i, slot) in arr.iter_mut().enumerate() {
2200+
*slot = bytes.get(i as u32).ok_or(Error::InternalError)?;
21982201
}
21992202
Ok(i128::from_be_bytes(arr))
22002203
}

stellar-contracts/src/test.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ fn test_get_config_snapshot() {
475475
assert_eq!(config.lock_period, bridge.get_lock_period());
476476
assert_eq!(config.cooldown_ledgers, bridge.get_cooldown());
477477
assert_eq!(config.inactivity_threshold, DEFAULT_INACTIVITY_THRESHOLD);
478-
assert_eq!(config.allowlist_enabled, false);
478+
assert!(!config.allowlist_enabled);
479479
assert_eq!(config.emergency_recovery, None);
480480
assert_eq!(config.anti_sandwich_delay, bridge.get_anti_sandwich_delay());
481481
}
@@ -2608,6 +2608,10 @@ mod proptest_deposit {
26082608
use proptest::prelude::*;
26092609

26102610
// Deposit invariants that must hold for every positive amount <= limit:
2611+
// 1. deposit() succeeds
2612+
// 2. contract balance increases by exactly amount
2613+
// 3. user balance decreases by exactly amount
2614+
// 4. get_user_deposited() returns amount
26112615
// 1. deposit() succeeds
26122616
// 2. contract balance increases by exactly `amount`
26132617
// 3. user balance decreases by exactly `amount`

0 commit comments

Comments
 (0)