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

Foreign token minting tests #282

Merged
merged 5 commits into from
Dec 8, 2023
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
2 changes: 0 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ on:
- "**.md"
env:
CARGO_TERM_COLOR: always
GCP_ZONE: europe-west3-a

jobs:
check_branch:
Expand All @@ -41,7 +40,6 @@ jobs:
image_family: ubuntu-2004-lts
machine_type: e2-highcpu-32
disk_size: 100
machine_zone: ${{ env.GCP_ZONE }}
ephemeral: true

test-features:
Expand Down
4 changes: 2 additions & 2 deletions libs/common-types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ pub mod currency_decimals {

// A way to generate different currencies from a number.
// Can be used in tests/benchmarks to generate different currencies.
impl From<u32> for CurrencyId {
fn from(value: u32) -> Self {
impl From<ForeignAssetId> for CurrencyId {
fn from(value: ForeignAssetId) -> Self {
CurrencyId::ForeignAsset(value)
}
}
Expand Down
48 changes: 48 additions & 0 deletions pallets/proposals/src/tests/foreign_asset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::{mock::*, *};
use frame_support::{assert_noop, assert_ok, error::BadOrigin};
use test_utils::*;

#[test]
fn set_foreign_asset_signer_check_permission_for_edit() {
build_test_externality().execute_with(|| {
assert_ok!(Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE));
assert_eq!(ForeignCurrencySigner::<Test>::get().unwrap(), ALICE, "Alice should have been set as signer.");
assert_ok!(Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), BOB));
assert_eq!(ForeignCurrencySigner::<Test>::get().unwrap(), BOB, "Bob should be set as signer.");
assert_noop!(Proposals::set_foreign_asset_signer(RuntimeOrigin::signed(BOB), ALICE), BadOrigin);
})
}

#[test]
fn foreign_asset_signer_can_mint() {
build_test_externality().execute_with(|| {
let currency_id = CurrencyId::ForeignAsset(10);
let beneficiary = BOB;
let amount = 92839572;
let _ = Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE);
let asset_signer = ForeignCurrencySigner::<Test>::get().unwrap();
assert_eq!(
Tokens::free_balance(currency_id, &BOB),
0
);
assert_ok!(Proposals::mint_offchain_assets(RuntimeOrigin::signed(asset_signer), beneficiary, currency_id, amount));
assert_eq!(
Tokens::free_balance(currency_id, &BOB),
amount
);
})
}

#[test]
fn non_foreign_asset_signer_cannot_mint() {
build_test_externality().execute_with(|| {
let currency_id = CurrencyId::ForeignAsset(10);
let beneficiary = BOB;
let amount = 92839572;
let _ = Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE);
let asset_signer = ForeignCurrencySigner::<Test>::get().unwrap();

assert_noop!(Proposals::mint_offchain_assets(RuntimeOrigin::signed(BOB), beneficiary, currency_id, amount), Error::<Test>::RequireForeignAssetSigner);
assert_noop!(Proposals::mint_offchain_assets(RuntimeOrigin::signed(CHARLIE), beneficiary, currency_id, amount), Error::<Test>::RequireForeignAssetSigner);
})
}
1 change: 1 addition & 0 deletions pallets/proposals/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pub mod disputes;
pub mod immutable_votes;
pub mod pallet;
pub mod refunds;
pub mod foreign_asset;
Loading