Skip to content

Commit c458700

Browse files
authored
fix: Rust compilation and clippy errors (#1102)
* fix: Rust compilation and clippy errors - Remove unused import (`errors::HasherError`). - Allow `clippy::too_many_arguments`. - Remove `RemainingAccounts::new()` - we can just `#[derive(Default)]` and instantiate with `RemainingAccounts::default()`. * ci: Run examples tests when `examples/**` are modified
1 parent 08b666a commit c458700

File tree

4 files changed

+71
-11
lines changed

4 files changed

+71
-11
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
paths:
6+
- "examples/**"
7+
pull_request:
8+
branches:
9+
- "*"
10+
paths:
11+
- "examples/**"
12+
types:
13+
- opened
14+
- synchronize
15+
- reopened
16+
- ready_for_review
17+
18+
name: examples-tests
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
system-programs:
26+
name: system-programs
27+
if: github.event.pull_request.draft == false
28+
runs-on: ubuntu-latest
29+
timeout-minutes: 60
30+
strategy:
31+
matrix:
32+
include:
33+
- program: token-escrow-test
34+
sub-tests: '[
35+
"cargo test-sbf -p token-escrow -- --test-threads=1"
36+
]'
37+
- program: name-service-test
38+
sub-tests: '[
39+
"cargo test-sbf -p name-service -- --test-threads=1"
40+
]'
41+
42+
steps:
43+
- name: Checkout sources
44+
uses: actions/checkout@v4
45+
46+
- name: Setup and build
47+
uses: ./.github/actions/setup-and-build
48+
49+
- name: build-programs
50+
run: |
51+
source ./scripts/devenv.sh
52+
anchor build
53+
54+
- name: ${{ matrix.program }}
55+
run: |
56+
source ./scripts/devenv.sh
57+
58+
IFS=',' read -r -a sub_tests <<< "${{ join(fromJSON(matrix['sub-tests']), ', ') }}"
59+
for subtest in "${sub_tests[@]}"
60+
do
61+
echo "$subtest"
62+
eval "RUSTFLAGS=\"-D warnings\" $subtest"
63+
done

examples/name-service/programs/name-service/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::net::{Ipv4Addr, Ipv6Addr};
22

33
use anchor_lang::{prelude::*, solana_program::hash};
44
use borsh::{BorshDeserialize, BorshSerialize};
5-
use light_hasher::{bytes::AsByteVec, errors::HasherError, DataHasher, Discriminator, Poseidon};
5+
use light_hasher::{bytes::AsByteVec, DataHasher, Discriminator, Poseidon};
66
use light_sdk::{
77
light_accounts,
88
merkle_context::{PackedAddressMerkleContext, PackedMerkleContext, PackedMerkleOutputContext},
@@ -28,6 +28,7 @@ declare_id!("7yucc7fL3JGbyMwg4neUaenNSdySS39hbAk89Ao3t1Hz");
2828
pub mod name_service {
2929
use super::*;
3030

31+
#[allow(clippy::too_many_arguments)]
3132
pub fn create_record<'info>(
3233
ctx: Context<'_, '_, '_, 'info, NameService<'info>>,
3334
proof: CompressedProof,
@@ -71,6 +72,7 @@ pub mod name_service {
7172
Ok(())
7273
}
7374

75+
#[allow(clippy::too_many_arguments)]
7476
pub fn update_record<'info>(
7577
ctx: Context<'_, '_, '_, 'info, NameService<'info>>,
7678
proof: CompressedProof,
@@ -127,6 +129,7 @@ pub mod name_service {
127129
Ok(())
128130
}
129131

132+
#[allow(clippy::too_many_arguments)]
130133
pub fn delete_record<'info>(
131134
ctx: Context<'_, '_, '_, 'info, NameService<'info>>,
132135
proof: CompressedProof,

examples/name-service/programs/name-service/tests/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ async fn create_record<R: RpcConnection>(
137137
)
138138
.await;
139139

140-
let mut remaining_accounts = RemainingAccounts::new();
140+
let mut remaining_accounts = RemainingAccounts::default();
141141

142142
let merkle_output_context = MerkleOutputContext {
143143
merkle_tree_pubkey: env.merkle_tree_pubkey,
@@ -210,7 +210,7 @@ async fn update_record<R: RpcConnection>(
210210
)
211211
.await;
212212

213-
let mut remaining_accounts = RemainingAccounts::new();
213+
let mut remaining_accounts = RemainingAccounts::default();
214214

215215
let merkle_context =
216216
pack_merkle_context(compressed_account.merkle_context, &mut remaining_accounts);
@@ -273,7 +273,7 @@ async fn delete_record<R: RpcConnection>(
273273
)
274274
.await;
275275

276-
let mut remaining_accounts = RemainingAccounts::new();
276+
let mut remaining_accounts = RemainingAccounts::default();
277277

278278
let merkle_context =
279279
pack_merkle_context(compressed_account.merkle_context, &mut remaining_accounts);

sdk/src/merkle_context.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,13 @@ use anchor_lang::prelude::{AccountMeta, AnchorDeserialize, AnchorSerialize, Pubk
66
pub use light_system_program::sdk::compressed_account::{MerkleContext, PackedMerkleContext};
77

88
/// Collection of remaining accounts which are sent to the program.
9+
#[derive(Default)]
910
pub struct RemainingAccounts {
1011
next_index: u8,
1112
map: HashMap<Pubkey, u8>,
1213
}
1314

1415
impl RemainingAccounts {
15-
pub fn new() -> Self {
16-
Self {
17-
next_index: 0,
18-
map: HashMap::new(),
19-
}
20-
}
21-
2216
/// Returns the index of the provided `pubkey` in the collection.
2317
///
2418
/// If the provided `pubkey` is not a part of the collection, it gets

0 commit comments

Comments
 (0)