diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 58b35af0..bc29d304 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,6 @@ on: - "**.md" env: CARGO_TERM_COLOR: always - GCP_ZONE: europe-west3-a jobs: check_branch: @@ -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: diff --git a/libs/common-types/src/tokens.rs b/libs/common-types/src/tokens.rs index 060318b8..179387ac 100644 --- a/libs/common-types/src/tokens.rs +++ b/libs/common-types/src/tokens.rs @@ -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 for CurrencyId { - fn from(value: u32) -> Self { +impl From for CurrencyId { + fn from(value: ForeignAssetId) -> Self { CurrencyId::ForeignAsset(value) } } diff --git a/pallets/proposals/src/tests/foreign_asset.rs b/pallets/proposals/src/tests/foreign_asset.rs new file mode 100644 index 00000000..172ab741 --- /dev/null +++ b/pallets/proposals/src/tests/foreign_asset.rs @@ -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::::get().unwrap(), ALICE, "Alice should have been set as signer."); + assert_ok!(Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), BOB)); + assert_eq!(ForeignCurrencySigner::::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::::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::::get().unwrap(); + + assert_noop!(Proposals::mint_offchain_assets(RuntimeOrigin::signed(BOB), beneficiary, currency_id, amount), Error::::RequireForeignAssetSigner); + assert_noop!(Proposals::mint_offchain_assets(RuntimeOrigin::signed(CHARLIE), beneficiary, currency_id, amount), Error::::RequireForeignAssetSigner); + }) +} \ No newline at end of file diff --git a/pallets/proposals/src/tests/mod.rs b/pallets/proposals/src/tests/mod.rs index 0eeec162..7af5ca3a 100644 --- a/pallets/proposals/src/tests/mod.rs +++ b/pallets/proposals/src/tests/mod.rs @@ -2,3 +2,4 @@ pub mod disputes; pub mod immutable_votes; pub mod pallet; pub mod refunds; +pub mod foreign_asset;