Skip to content

Commit

Permalink
Fix integration tests & Optimize binary (#432)
Browse files Browse the repository at this point in the history
> fix and add integration tests back
> add sibling crosschain tests
> optimize for lto binary
  • Loading branch information
yrong authored Dec 9, 2021
1 parent 37a59ee commit 8098403
Show file tree
Hide file tree
Showing 9 changed files with 428 additions and 53 deletions.
320 changes: 308 additions & 12 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
# "integration-tests",
"integration-tests",
"node/cli",
"node/inspect",
"node/primitives",
Expand Down Expand Up @@ -33,6 +33,10 @@ split-debuginfo = "unpacked"
[profile.release]
panic = "unwind"

[profile.production]
inherits = "release"
lto = true

# The list of dependencies below (which can be both direct and indirect dependencies) are crates
# that are suspected to be CPU-intensive, and that are unlikely to require debugging (as some of
# their debug info might be missing) or to require to be frequently recompiled. We compile these
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WORKDIR /app
COPY . /app

RUN export PATH="$PATH:$HOME/.cargo/bin" && \
make build-all-release
make production-release

# ===== SECOND STAGE ======

Expand All @@ -44,7 +44,7 @@ RUN rm -rf /usr/share && \
ln -s /spec /bifrost/.local/share/spec

USER bifrost
COPY --from=builder /app/target/release/bifrost /usr/local/bin
COPY --from=builder /app/target/production/bifrost /usr/local/bin
COPY ./node/service/res/asgard.json /spec
COPY ./node/service/res/bifrost.json /spec

Expand Down
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test-all:

.PHONY: integration-test
integration-test:
SKIP_WASM_BUILD= cargo test -p runtime-integration-tests --features=with-asgard-runtime
SKIP_WASM_BUILD= cargo test -p runtime-integration-tests --features=with-bifrost-runtime

.PHONY: clean
clean:
Expand Down Expand Up @@ -166,6 +166,11 @@ keystore:
./target/release/bifrost key insert --chain $(CHAIN) --keystore-path ./resources/keystore --suri "$(SURI)" --key-type aura
./target/release/bifrost key insert --chain $(CHAIN) --keystore-path ./resources/keystore --suri "$(SURI)" --key-type gran

.PHONY: copy-genesis-config-production
copy-genesis-config-production:
mkdir -p "target/production/res"
cp -r node/service/res/genesis_config target/production/res

.PHONY: production-release
production-release:
.maintain/publish-release.sh
cargo build -p node-cli --locked --features "with-bifrost-runtime" --profile production
7 changes: 1 addition & 6 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ bifrost-vsbond-auction = { path = "../pallets/vsbond-auction", default-features
bifrost-vtoken-mint = { path = "../pallets/vtoken-mint", default-features = false }
pallet-vesting = { package = "bifrost-vesting", path = "../pallets/vesting", default-features = false }
xcm-support = { path = "../xcm-support", default-features = false }
asgard-runtime = { path = "../runtime/asgard", default-features = false }
bifrost-runtime = { path = "../runtime/bifrost", default-features = false }

# orml
Expand All @@ -121,16 +120,13 @@ cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech/cumul
polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }
kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.12" }
xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator" }
xcm-emulator = { git = "https://github.com/bifrost-finance/xcm-simulator", rev = "18f6d9e78d1fe92c167594b88b218793ac38bc1f" }

node-service = { path = "../node/service", features = ["with-all-runtime"] }

[features]
default = ["std"]
no_std = []
with-asgard-runtime=[
"node-service/with-asgard-runtime"
]
with-bifrost-runtime=[
"node-service/with-bifrost-runtime"
]
Expand Down Expand Up @@ -209,6 +205,5 @@ std = [
"orml-xcm-support/std",
"zenlink-protocol/std",
"zenlink-protocol-runtime-api/std",
"asgard-runtime/std",
"bifrost-runtime/std"
]
40 changes: 24 additions & 16 deletions integration-tests/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,20 @@ pub use sp_runtime::{
pub const ALICE: [u8; 32] = [0u8; 32];
pub const BOB: [u8; 32] = [1u8; 32];

#[cfg(feature = "with-asgard-runtime")]
pub use asgard_imports::*;

#[cfg(feature = "with-asgard-runtime")]
mod asgard_imports {
pub use asgard_runtime::{
constants::currency::DOLLARS, create_x2_multilocation, AccountId, Balance, Balances,
BifrostCrowdloanId, BlockNumber, Call, Currencies, CurrencyId, Event, ExistentialDeposit,
ExistentialDeposits, NativeCurrencyId, Origin, OriginCaller, ParachainInfo,
ParachainSystem, Perbill, Proxy, RelayCurrencyId, RelaychainSovereignSubAccount, Runtime,
Salp, Scheduler, Session, SlotLength, System, Tokens, TreasuryPalletId, Utility, Vesting,
XTokens, XcmConfig,
#[cfg(feature = "with-bifrost-runtime")]
pub use bifrost_imports::*;
use bifrost_runtime::{ExistentialDeposit, NativeCurrencyId};

#[cfg(feature = "with-bifrost-runtime")]
mod bifrost_imports {
pub use bifrost_runtime::{
create_x2_multilocation, AccountId, Balance, Balances, BifrostCrowdloanId, BlockNumber,
Call, Currencies, CurrencyId, Event, ExistentialDeposit, ExistentialDeposits,
NativeCurrencyId, Origin, OriginCaller, ParachainInfo, ParachainSystem, Perbill, Proxy,
RelayCurrencyId, RelaychainSovereignSubAccount, Runtime, Salp, Scheduler, Session,
SlotLength, System, Tokens, TreasuryPalletId, Utility, Vesting, XTokens, XcmConfig,
};
pub use bifrost_runtime_common::dollar;
pub use frame_support::parameter_types;
pub use sp_runtime::traits::AccountIdConversion;
}
Expand Down Expand Up @@ -88,11 +89,12 @@ pub fn get_all_module_accounts() -> Vec<AccountId> {

pub struct ExtBuilder {
balances: Vec<(AccountId, CurrencyId, Balance)>,
parachain_id: u32,
}

impl Default for ExtBuilder {
fn default() -> Self {
Self { balances: vec![] }
Self { balances: vec![], parachain_id: 2001 }
}
}

Expand All @@ -102,6 +104,12 @@ impl ExtBuilder {
self
}

#[allow(dead_code)]
pub fn parachain_id(mut self, parachain_id: u32) -> Self {
self.parachain_id = parachain_id;
self
}

pub fn build(self) -> sp_io::TestExternalities {
let mut t = frame_system::GenesisConfig::default().build_storage::<Runtime>().unwrap();

Expand Down Expand Up @@ -139,7 +147,7 @@ impl ExtBuilder {
.unwrap();

<parachain_info::GenesisConfig as GenesisBuild<Runtime>>::assimilate_storage(
&parachain_info::GenesisConfig { parachain_id: 2001.into() },
&parachain_info::GenesisConfig { parachain_id: self.parachain_id.into() },
&mut t,
)
.unwrap();
Expand Down Expand Up @@ -182,8 +190,8 @@ fn parachain_subaccounts_are_unique() {
fn salp() {
ExtBuilder::default()
.balances(vec![
(AccountId::from(ALICE), RelayCurrencyId::get(), 100 * DOLLARS),
(AccountId::from(BOB), RelayCurrencyId::get(), 100 * DOLLARS),
(AccountId::from(ALICE), RelayCurrencyId::get(), 100 * dollar(RelayCurrencyId::get())),
(AccountId::from(BOB), RelayCurrencyId::get(), 100 * dollar(RelayCurrencyId::get())),
])
.build()
.execute_with(|| {
Expand Down
61 changes: 56 additions & 5 deletions integration-tests/src/kusama_cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//! Cross-chain transfer tests within Kusama network.
use frame_support::assert_ok;
use node_primitives::{CurrencyId, TokenSymbol};
use orml_traits::MultiCurrency;
use xcm::{latest::prelude::*, VersionedMultiAssets, VersionedMultiLocation};
use xcm_emulator::TestExt;
Expand All @@ -34,15 +35,15 @@ fn transfer_from_relay_chain() {
Box::new(VersionedMultiLocation::V1(
X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any }).into()
)),
Box::new(VersionedMultiAssets::V1((Here, DOLLARS).into())),
Box::new(VersionedMultiAssets::V1((Here, dollar(RelayCurrencyId::get())).into())),
0,
));
});

Bifrost::execute_with(|| {
assert_eq!(
Tokens::free_balance(RelayCurrencyId::get(), &AccountId::from(BOB)),
999_936_000_000
999_872_000_000
);
});
}
Expand All @@ -53,11 +54,11 @@ fn transfer_to_relay_chain() {
assert_ok!(XTokens::transfer(
Origin::signed(ALICE.into()),
RelayCurrencyId::get(),
DOLLARS,
Box::new(MultiLocation::new(
dollar(RelayCurrencyId::get()),
Box::new(xcm::VersionedMultiLocation::V1(MultiLocation::new(
1,
X1(Junction::AccountId32 { id: BOB, network: NetworkId::Any })
)),
))),
4_000_000_000
));
});
Expand All @@ -66,3 +67,53 @@ fn transfer_to_relay_chain() {
assert_eq!(kusama_runtime::Balances::free_balance(&AccountId::from(BOB)), 999_893_333_340);
});
}

#[test]
fn transfer_to_sibling() {
TestNet::reset();

fn bifrost_reserve_account() -> AccountId {
use sp_runtime::traits::AccountIdConversion;
polkadot_parachain::primitives::Sibling::from(2001).into_account()
}

Bifrost::execute_with(|| {
assert_ok!(Tokens::deposit(
CurrencyId::Token(TokenSymbol::KAR),
&AccountId::from(ALICE),
100_000_000_000_000
));
});

Sibling::execute_with(|| {
assert_ok!(Tokens::deposit(
CurrencyId::Token(TokenSymbol::KAR),
&bifrost_reserve_account(),
100_000_000_000_000
));
});

Bifrost::execute_with(|| {
assert_ok!(XTokens::transfer(
Origin::signed(ALICE.into()),
CurrencyId::Token(TokenSymbol::KAR),
10_000_000_000_000,
Box::new(
MultiLocation::new(
1,
X2(
Parachain(2000),
Junction::AccountId32 { network: NetworkId::Any, id: BOB.into() }
)
)
.into()
),
1_000_000_000,
));

assert_eq!(
Tokens::free_balance(CurrencyId::Token(TokenSymbol::KAR), &AccountId::from(ALICE)),
90_000_000_000_000
);
});
}
26 changes: 21 additions & 5 deletions integration-tests/src/kusama_test_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

//! Relay chain and parachains emulation.
use bifrost_runtime_common::dollar;
use cumulus_primitives_core::ParaId;
use frame_support::traits::GenesisBuild;
use node_primitives::TokenSymbol::KSM;
use polkadot_primitives::v1::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE};
use polkadot_runtime_parachains::configuration::HostConfiguration;
use sp_runtime::traits::AccountIdConversion;
Expand All @@ -39,7 +41,15 @@ decl_test_parachain! {
pub struct Bifrost {
Runtime = Runtime,
Origin = Origin,
new_ext = bifrost_ext(),
new_ext = para_ext(2001),
}
}

decl_test_parachain! {
pub struct Sibling {
Runtime = Runtime,
Origin = Origin,
new_ext = para_ext(2000),
}
}

Expand All @@ -48,6 +58,7 @@ decl_test_network! {
relay_chain = KusamaNet,
parachains = vec![
(2001, Bifrost),
(2000, Sibling),
],
}
}
Expand Down Expand Up @@ -96,8 +107,8 @@ pub fn kusama_ext() -> sp_io::TestExternalities {

pallet_balances::GenesisConfig::<Runtime> {
balances: vec![
(AccountId::from(ALICE), 2002 * DOLLARS),
(ParaId::from(2001).into_account(), 2 * DOLLARS),
(AccountId::from(ALICE), 2002 * dollar(CurrencyId::Token(KSM))),
(ParaId::from(2001).into_account(), 2 * dollar(CurrencyId::Token(KSM))),
],
}
.assimilate_storage(&mut t)
Expand All @@ -120,8 +131,13 @@ pub fn kusama_ext() -> sp_io::TestExternalities {
ext
}

pub fn bifrost_ext() -> sp_io::TestExternalities {
pub fn para_ext(parachain_id: u32) -> sp_io::TestExternalities {
ExtBuilder::default()
.balances(vec![(AccountId::from(ALICE), RelayCurrencyId::get(), 10 * DOLLARS)])
.balances(vec![(
AccountId::from(ALICE),
RelayCurrencyId::get(),
10 * dollar(RelayCurrencyId::get()),
)])
.parachain_id(parachain_id)
.build()
}
8 changes: 4 additions & 4 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#![cfg(test)]
#[cfg(feature = "with-asgard-runtime")]
#[cfg(feature = "with-bifrost-runtime")]
mod integration_tests;
#[cfg(feature = "with-asgard-runtime")]
#[cfg(feature = "with-bifrost-runtime")]
mod kusama_cross_chain_transact;
#[cfg(feature = "with-asgard-runtime")]
#[cfg(feature = "with-bifrost-runtime")]
mod kusama_cross_chain_transfer;
#[cfg(feature = "with-asgard-runtime")]
#[cfg(feature = "with-bifrost-runtime")]
mod kusama_test_net;

0 comments on commit 8098403

Please sign in to comment.