Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[428] Improve CI/CD #506

Merged
merged 15 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Build-CI
on:
pull_request:
branches: [Develop, main]
branches: [Develop, main-net-runtime]
push:
branches: [Develop, main]
branches: [Develop, main-net-runtime]
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -12,31 +12,52 @@ jobs:
- name: Cache Rust Dependecies
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Install toolchain
run: ./scripts/init.sh
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Add wasm toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
target: wasm32-unknown-unknown
override: true
- name: Add fmt
# v1.5.0 includes fixes of closures formatting
run: |
cd ..
git clone --depth 1 https://github.com/rust-lang/rustfmt
cd rustfmt
git fetch --tags
git checkout v1.5.0
export CFG_RELEASE=nightly
export CFG_RELEASE_CHANNEL=nightly
cargo clean -p rustfmt-nightly
cargo install --path . --force
cd ../Polkadex
- name: Build Project
run: |
cargo clean
# cargo build --release --features runtime-benchmarks
cargo build
cargo clean
# cargo build --release --features runtime-benchmarks
RUSTFLAGS="-D warnings" cargo build
- name: Check Formatting
run: cargo fmt --check
- name: Check Clippy
run: |
rustup component add clippy --toolchain=nightly
cargo +nightly clippy -- -D warnings
- name: Test Project
run: cargo test
- name: Run Cargo Trampulin
if: github.event_name == 'push'
uses: actions-rs/tarpaulin@v0.1
with:
version: '0.15.0'
args: '--exclude polkadex-node node-polkadex-runtime polkadex-primitives --workspace'
- name: Upload to codecov.io
if: github.event_name == 'push'
uses: codecov/codecov-action@v1.0.2
uses: codecov/codecov-action@v3
with:
token: ${{secrets.CODECOV_TOKEN}}
fail_ci_if_error: true
- name: Archive code coverage results
if: github.event_name == 'push'
uses: actions/upload-artifact@v1
Expand Down
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ members = [
"pallets/test-token-provider"
]


[patch."https://github.com/open-web3-stack/open-runtime-module-library.git"]
orml-vesting = { git = "https://github.com/Polkadex-Substrate/open-runtime-module-library.git", branch="polkadot-v0.9.28"}

2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2021"
[dependencies]
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" }
node-polkadex-runtime = { path = "../runtime", version = "3.0.0" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28" }
2 changes: 0 additions & 2 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ sp-trie = { git = "https://github.com/paritytech/substrate", branch = "polkadot-
frame-try-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", optional = true }
try-runtime-cli = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.28", optional = true }



[dev-dependencies]
futures = "0.3.9"
tempfile = "3.1.0"
Expand Down
5 changes: 1 addition & 4 deletions node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
let extrinsic: OpaqueExtrinsic = create_extrinsic(
self.client.as_ref(),
acc,
BalancesCall::transfer_keep_alive {
dest: self.dest.clone().into(),
value: self.value.into(),
},
BalancesCall::transfer_keep_alive { dest: self.dest.clone().into(), value: self.value },
Some(nonce),
)
.into();
Expand Down
36 changes: 18 additions & 18 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,24 @@ fn udon_testnet_config_genesis() -> GenesisConfig {
)> = vec![];
for idx in 1..4 {
let babe = sp_core::sr25519::Pair::from_string(
&*(seed.to_owned() + idx.to_string().as_str() + "//babe"),
&(seed.to_owned() + idx.to_string().as_str() + "//babe"),
None,
)
.unwrap();
let imon = sp_core::sr25519::Pair::from_string(
&*(seed.to_owned() + idx.to_string().as_str() + "//imon"),
&(seed.to_owned() + idx.to_string().as_str() + "//imon"),
None,
)
.unwrap();
let audi = sp_core::sr25519::Pair::from_string(
&*(seed.to_owned() + idx.to_string().as_str() + "//audi"),
&(seed.to_owned() + idx.to_string().as_str() + "//audi"),
None,
)
.unwrap();

// Granpda uses ed25519 cryptography
let gran = sp_core::ed25519::Pair::from_string(
&*(seed.to_owned() + idx.to_string().as_str() + "//grandpa"),
&(seed.to_owned() + idx.to_string().as_str() + "//grandpa"),
None,
)
.unwrap();
Expand All @@ -107,16 +107,16 @@ fn udon_testnet_config_genesis() -> GenesisConfig {
]
.into();

let enclave_developement_account: AccountId = hex![
"90ea3ff124ecd5732b9e95a85f6bf17258e735be5dd950351f4269956de0b976"
]
.into();
let orderbook_test_main_account: AccountId = hex! [
"6e9fb6f4db2e7efcb189ae75b98705976bf10a419edbce4b9a6a7a065826b82c"
].into();
testnet_genesis(initial_authorities, vec![],
Some(vec![enclave_developement_account, orderbook_test_main_account]),
root_key)
let enclave_developement_account: AccountId =
hex!["90ea3ff124ecd5732b9e95a85f6bf17258e735be5dd950351f4269956de0b976"].into();
let orderbook_test_main_account: AccountId =
hex!["6e9fb6f4db2e7efcb189ae75b98705976bf10a419edbce4b9a6a7a065826b82c"].into();
testnet_genesis(
initial_authorities,
vec![],
Some(vec![enclave_developement_account, orderbook_test_main_account]),
root_key,
)
}

/// Staging testnet config.
Expand Down Expand Up @@ -325,7 +325,7 @@ pub fn testnet_genesis(
const ERC20_PDEX_SUPPLY: u128 = 3_172_895 * PDEX;
// Total funds in treasury also includes 2_000_000 PDEX for parachain auctions
let mut treasury_funds: u128 = 10_200_000 * PDEX;
treasury_funds = treasury_funds -
treasury_funds -=
adjust_treasury_balance_for_initial_validators(initial_authorities.len(), ENDOWMENT);

// Treasury Account Id
Expand All @@ -352,7 +352,7 @@ pub fn testnet_genesis(

let mut total_claims: u128 = 0;
for (_, balance) in &claims {
total_claims = total_claims + balance;
total_claims += balance;
}

assert_eq!(total_claims, 6_627_105 * PDEX, "Total claims is configured correctly");
Expand All @@ -363,7 +363,7 @@ pub fn testnet_genesis(

let mut total_supply: u128 = 0;
for (_, balance) in &endowed_accounts {
total_supply = total_supply + balance.clone()
total_supply += *balance
}

if development_accounts.is_none() {
Expand Down Expand Up @@ -416,7 +416,7 @@ pub fn testnet_genesis(
phantom: Default::default(),
},
democracy: Default::default(),
sudo: SudoConfig { key: Some(root_key.clone()) },
sudo: SudoConfig { key: Some(root_key) },
babe: BabeConfig {
authorities: Default::default(),
epoch_config: Some(node_polkadex_runtime::BABE_GENESIS_EPOCH_CONFIG),
Expand Down
3 changes: 1 addition & 2 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ where
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashFor<Block>>,
// C::Api: polkadex_ido_rpc::PolkadexIdoRuntimeApi<Block, AccountId, Hash>,
{
use pallet_ocex_rpc::{PolkadexOcexRpc, PolkadexOcexRpcApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
use sc_finality_grandpa_rpc::{Grandpa, GrandpaApiServer};
Expand Down Expand Up @@ -167,7 +166,7 @@ where
)?;

// io.merge(StateMigration::new(client.clone(), backend, deny_unsafe).into_rpc())?;
io.merge(Dev::new(client.clone(), deny_unsafe).into_rpc())?;
io.merge(Dev::new(client, deny_unsafe).into_rpc())?;
// TODO: Upgrade IDO RPC to match latest commit
// io.merge(polkadex_ido_rpc::PolkadexIdoRpcApi::to_delegate(
// polkadex_ido_rpc::PolkadexIdoRpc::new(client),
Expand Down
7 changes: 4 additions & 3 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ pub fn create_extrinsic(
let signature = raw_payload.using_encoded(|e| sender.sign(e));

node_polkadex_runtime::UncheckedExtrinsic::new_signed(
function.clone(),
function,
sp_runtime::AccountId32::from(sender.public()).into(),
node_polkadex_runtime::Signature::Sr25519(signature.clone()),
extra.clone(),
node_polkadex_runtime::Signature::Sr25519(signature),
extra,
)
}
use sc_network_common::service::NetworkEventStream;

#[allow(clippy::type_complexity)]
pub fn new_partial(
config: &Configuration,
) -> Result<
Expand Down
9 changes: 6 additions & 3 deletions pallets/asset-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub mod pallet {
pub recipient: H160,
}

#[derive(Clone, Copy, PartialEq, Encode, Decode)]
#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode)]
pub struct WithdrawalLimit;
impl Get<u32> for WithdrawalLimit {
fn get() -> u32 {
Expand Down Expand Up @@ -176,12 +176,14 @@ pub mod pallet {
if !withdrawal_execution_block.is_zero() {
let pending_withdrawals = <PendingWithdrawals<T>>::get(withdrawal_execution_block);
for withdrawal in pending_withdrawals {
if let Err(_) = chainbridge::Pallet::<T>::transfer_fungible(
if chainbridge::Pallet::<T>::transfer_fungible(
withdrawal.chain_id,
withdrawal.rid,
withdrawal.recipient.0.to_vec(),
Self::convert_balance_to_eth_type(withdrawal.amount),
) {
)
.is_err()
{
Self::deposit_event(Event::<T>::FungibleTransferFailed);
}
}
Expand Down Expand Up @@ -229,6 +231,7 @@ pub mod pallet {
/// * `destination_add`: Recipient's Account
/// * `amount`: Amount to be minted in Recipient's Account
/// * `rid`: Resource ID
#[allow(clippy::unnecessary_lazy_evaluations)]
#[pallet::weight((195_000_000).saturating_add(T::DbWeight::get().writes(2 as Weight)))]
pub fn mint_asset(
origin: OriginFor<T>,
Expand Down
2 changes: 1 addition & 1 deletion pallets/chainbridge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ pub mod pallet {
ensure!(id != T::BridgeChainId::get(), Error::<T>::InvalidChainId);
// Cannot whitelist with an existing entry
ensure!(!Self::chain_whitelisted(id), Error::<T>::ChainAlreadyWhitelisted);
ChainNonces::<T>::insert(&id, 0);
ChainNonces::<T>::insert(id, 0);
Self::deposit_event(Event::ChainWhitelisted(id));
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/ocex/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ std = [
"sp-runtime/std",
"sp-std/std",
"serde",
]
]
3 changes: 1 addition & 2 deletions pallets/ocex/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use polkadex_primitives::assets::AssetId;
pub use polkadex_primitives::{AccountId, Balance, BlockNumber, Hash};
#[cfg(feature = "std")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use sp_std::vec::Vec;

#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
Expand All @@ -31,7 +30,7 @@ impl From<AssetId> for StringAssetId {
fn from(asset: AssetId) -> Self {
match asset {
AssetId::polkadex => StringAssetId::POLKADEX,
AssetId::asset(num) => StringAssetId::Asset(num.into()),
AssetId::asset(num) => StringAssetId::Asset(num),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pallets/ocex/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ sp-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.28", default-features = false }
pallet-ocex-primitives = {path = "../common", default-features = false}
pallet-ocex-runtime-api = {path = "runtime-api" }
polkadex-primitives = { default-features = false, branch = "polkadot-v0.9.28", git = "https://github.com/Polkadex-Substrate/polkadex-primitives.git" }
polkadex-primitives = { default-features = false, branch = "polkadot-v0.9.28", git = "https://github.com/Polkadex-Substrate/polkadex-primitives.git" }
2 changes: 1 addition & 1 deletion pallets/ocex/rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ std = [
"sp-std/std",
"sp-runtime/std",
"pallet-ocex-primitives/std"
]
]
4 changes: 1 addition & 3 deletions pallets/ocex/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![cfg_attr(not(feature = "std"), no_std)]
use codec::{Codec, Decode};
use codec::Codec;
use pallet_ocex_primitives::WithdrawalWithPrimitives;
use polkadex_primitives::{assets::AssetId, withdrawal::Withdrawal, Balance};
use sp_runtime::traits::Zero;
use sp_std::vec::Vec;
sp_api::decl_runtime_apis! {
pub trait PolkadexOcexRuntimeApi<AccountId,Hash> where AccountId: Codec, Hash : Codec{
Expand Down
10 changes: 3 additions & 7 deletions pallets/ocex/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ use codec::Codec;
use jsonrpsee::{
core::{async_trait, Error as JsonRpseeError, RpcResult},
proc_macros::rpc,
types::error::{CallError, ErrorCode, ErrorObject},
types::error::{CallError, ErrorObject},
};
use pallet_ocex_primitives::WithdrawalWithPrimitives;
pub use pallet_ocex_runtime_api::PolkadexOcexRuntimeApi;
use sp_api::ProvideRuntimeApi;
use sp_blockchain::HeaderBackend;
use sp_rpc::number::NumberOrHex;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
};
use sp_runtime::{generic::BlockId, traits::Block as BlockT};

const RUNTIME_ERROR: i32 = 1;

Expand All @@ -32,7 +28,7 @@ pub trait PolkadexOcexRpcApi<BlockHash, AccountId, Hash> {

pub struct PolkadexOcexRpc<Client, Block> {
client: Arc<Client>,
_marker: std::marker::PhantomData<Block>,
_marker: PhantomData<Block>,
}

impl<Client, Block> PolkadexOcexRpc<Client, Block> {
Expand Down
Loading