Skip to content

Commit

Permalink
Foreign token minting tests (#282)
Browse files Browse the repository at this point in the history
* test

* forign signer can mint

* negative minting test

* remove it (#285)
  • Loading branch information
f-gate authored Dec 8, 2023
1 parent 210ccc3 commit 5c64d8b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
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;

0 comments on commit 5c64d8b

Please sign in to comment.