Skip to content

Commit becc216

Browse files
authored
Abehjati/repo-improvement (#395)
* Use a new rustfmt file * Run cosmwasm action only when needed * Remove pre-commit from remote-executor action * Fix formatting * Run precommit for all files As previous PR was merged without pre-commit
1 parent c3fefc7 commit becc216

Some content is hidden

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

46 files changed

+1177
-1191
lines changed

.github/workflows/ethereum-contract.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
on:
22
pull_request:
3-
paths:
4-
- ethereum/**
5-
- third_party/pyth/xc-governance-sdk-js/**
3+
paths:
4+
- ethereum/**
5+
- third_party/pyth/xc-governance-sdk-js/**
66
push:
77
branches:
88
- main
9-
paths:
10-
- ethereum/**
11-
- third_party/pyth/xc-governance-sdk-js/**
9+
paths:
10+
- ethereum/**
11+
- third_party/pyth/xc-governance-sdk-js/**
1212

1313
name: Ethereum Contract
1414

@@ -33,7 +33,7 @@ jobs:
3333
uses: foundry-rs/foundry-toolchain@v1
3434
with:
3535
version: nightly
36-
36+
3737
- name: Install Forge dependencies
3838
run: npm run install-forge-deps
3939

.github/workflows/pyth-cosmwasm-contract.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ name: Pyth CosmWasm Contract
22

33
on:
44
pull_request:
5+
paths:
6+
- cosmwasm/**
7+
- third_party/pyth/p2w-sdk/rust/**
58
push:
69
branches:
710
- main
11+
paths:
12+
- cosmwasm/**
13+
- third_party/pyth/p2w-sdk/rust/**
814

915
env:
1016
CARGO_TERM_COLOR: always

.github/workflows/remote-executor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
profile: minimal
1818
toolchain: nightly
1919
components: rustfmt, clippy
20-
- uses: pre-commit/[email protected]
2120
- name: Install Solana
2221
run: |
2322
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"

.pre-commit-config.yaml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ repos:
1717
- repo: local
1818
hooks:
1919
# Hooks for the remote executor
20-
- id: cargo-fmt-executor
21-
name: Cargo format executor
20+
- id: cargo-fmt-executor-remote-executor
21+
name: Cargo format executor for remote executor
2222
language: "rust"
23-
entry: cargo +nightly fmt --manifest-path ./pythnet/remote-executor/Cargo.toml --all
23+
entry: cargo +nightly fmt --manifest-path ./pythnet/remote-executor/Cargo.toml --all -- --config-path rustfmt.toml
2424
pass_filenames: false
2525
files: pythnet/remote-executor/
2626
- id: cargo-clippy-executor
@@ -30,9 +30,16 @@ repos:
3030
pass_filenames: false
3131
files: pythnet/remote-executor/
3232
# Hooks for the attester
33-
- id: cargo-fmt-executor
34-
name: Cargo format executor
33+
- id: cargo-fmt-executor-attester
34+
name: Cargo format executor for attester
3535
language: "rust"
36-
entry: cargo +nightly fmt --manifest-path ./solana/pyth2wormhole/Cargo.toml --all
36+
entry: cargo +nightly fmt --manifest-path ./solana/pyth2wormhole/Cargo.toml --all -- --config-path rustfmt.toml
3737
pass_filenames: false
3838
files: solana/pyth2wormhole/
39+
# Hooks for cosmwasm contract
40+
- id: cargo-fmt-executor-cosmwasm
41+
name: Cargo format executor form cosmwasm contract
42+
language: "rust"
43+
entry: cargo +nightly fmt --manifest-path ./cosmwasm/Cargo.toml --all -- --config-path rustfmt.toml
44+
pass_filenames: false
45+
files: cosmwasm/

cosmwasm/contracts/pyth/src/contract.rs

Lines changed: 62 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
1-
use std::collections::HashSet;
2-
3-
use cosmwasm_std::{
4-
entry_point,
5-
to_binary,
6-
Binary,
7-
Deps,
8-
DepsMut,
9-
Env,
10-
MessageInfo,
11-
QueryRequest,
12-
Response,
13-
StdResult,
14-
Timestamp,
15-
WasmQuery,
16-
};
17-
18-
use pyth_sdk_cw::{
19-
PriceFeed,
20-
PriceIdentifier,
21-
PriceStatus,
22-
ProductIdentifier,
23-
};
24-
25-
use crate::msg::{
26-
ExecuteMsg,
27-
InstantiateMsg,
28-
MigrateMsg,
29-
PriceFeedResponse,
30-
QueryMsg,
31-
};
32-
use crate::state::{
33-
config,
34-
config_read,
35-
price_info,
36-
price_info_read,
37-
ConfigInfo,
38-
PriceInfo,
39-
PythDataSource,
40-
VALID_TIME_PERIOD,
1+
use {
2+
crate::{
3+
error::PythContractError,
4+
msg::{
5+
ExecuteMsg,
6+
InstantiateMsg,
7+
MigrateMsg,
8+
PriceFeedResponse,
9+
QueryMsg,
10+
},
11+
state::{
12+
config,
13+
config_read,
14+
price_info,
15+
price_info_read,
16+
ConfigInfo,
17+
PriceInfo,
18+
PythDataSource,
19+
VALID_TIME_PERIOD,
20+
},
21+
},
22+
cosmwasm_std::{
23+
entry_point,
24+
to_binary,
25+
Binary,
26+
Deps,
27+
DepsMut,
28+
Env,
29+
MessageInfo,
30+
QueryRequest,
31+
Response,
32+
StdResult,
33+
Timestamp,
34+
WasmQuery,
35+
},
36+
p2w_sdk::BatchPriceAttestation,
37+
pyth_sdk_cw::{
38+
PriceFeed,
39+
PriceIdentifier,
40+
PriceStatus,
41+
ProductIdentifier,
42+
},
43+
std::collections::HashSet,
44+
wormhole::{
45+
msg::QueryMsg as WormholeQueryMsg,
46+
state::ParsedVAA,
47+
},
4148
};
4249

43-
use crate::error::PythContractError;
44-
45-
use p2w_sdk::BatchPriceAttestation;
46-
47-
use wormhole::msg::QueryMsg as WormholeQueryMsg;
48-
use wormhole::state::ParsedVAA;
49-
5050
#[cfg_attr(not(feature = "library"), entry_point)]
5151
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
5252
Ok(Response::new())
@@ -303,27 +303,28 @@ pub fn query_price_feed(deps: Deps, env: Env, address: &[u8]) -> StdResult<Price
303303
price_feed: price_info.price_feed,
304304
})
305305
}
306-
Err(_) => Err(PythContractError::PriceFeedNotFound)?
306+
Err(_) => Err(PythContractError::PriceFeedNotFound)?,
307307
}
308308
}
309309

310310
#[cfg(test)]
311311
mod test {
312-
use cosmwasm_std::testing::{
313-
mock_dependencies,
314-
mock_env,
315-
mock_info,
316-
MockApi,
317-
MockQuerier,
318-
MockStorage,
319-
};
320-
use cosmwasm_std::{
321-
Addr,
322-
OwnedDeps,
312+
use {
313+
super::*,
314+
cosmwasm_std::{
315+
testing::{
316+
mock_dependencies,
317+
mock_env,
318+
mock_info,
319+
MockApi,
320+
MockQuerier,
321+
MockStorage,
322+
},
323+
Addr,
324+
OwnedDeps,
325+
},
323326
};
324327

325-
use super::*;
326-
327328
fn setup_test() -> (OwnedDeps<MockStorage, MockApi, MockQuerier>, Env) {
328329
(mock_dependencies(), mock_env())
329330
}

cosmwasm/contracts/pyth/src/error.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use cosmwasm_std::StdError;
2-
use thiserror::Error;
1+
use {
2+
cosmwasm_std::StdError,
3+
thiserror::Error,
4+
};
35

46
#[derive(Error, Debug)]
57
pub enum PythContractError {

cosmwasm/contracts/pyth/src/msg.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
use cosmwasm_std::Binary;
2-
use schemars::JsonSchema;
3-
use serde::{
4-
Deserialize,
5-
Serialize,
1+
use {
2+
crate::state::PythDataSource,
3+
cosmwasm_std::Binary,
4+
schemars::JsonSchema,
5+
serde::{
6+
Deserialize,
7+
Serialize,
8+
},
69
};
710

8-
use crate::state::PythDataSource;
9-
1011
type HumanAddr = String;
1112

1213
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]

cosmwasm/contracts/pyth/src/state.rs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
use std::collections::HashSet;
2-
use std::time::Duration;
3-
4-
use pyth_sdk_cw::PriceFeed;
5-
use schemars::JsonSchema;
6-
use serde::{
7-
Deserialize,
8-
Serialize,
9-
};
10-
11-
use cosmwasm_std::{
12-
Addr,
13-
Binary,
14-
Storage,
15-
Timestamp,
16-
};
17-
18-
use cosmwasm_storage::{
19-
bucket,
20-
bucket_read,
21-
singleton,
22-
singleton_read,
23-
Bucket,
24-
ReadonlyBucket,
25-
ReadonlySingleton,
26-
Singleton,
1+
use {
2+
cosmwasm_std::{
3+
Addr,
4+
Binary,
5+
Storage,
6+
Timestamp,
7+
},
8+
cosmwasm_storage::{
9+
bucket,
10+
bucket_read,
11+
singleton,
12+
singleton_read,
13+
Bucket,
14+
ReadonlyBucket,
15+
ReadonlySingleton,
16+
Singleton,
17+
},
18+
pyth_sdk_cw::PriceFeed,
19+
schemars::JsonSchema,
20+
serde::{
21+
Deserialize,
22+
Serialize,
23+
},
24+
std::{
25+
collections::HashSet,
26+
time::Duration,
27+
},
2728
};
2829

2930
pub static CONFIG_KEY: &[u8] = b"config";

cosmwasm/rustfmt.toml

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)