From 2c2bb3c2ec71a12cfbd210abe701082c1acdd169 Mon Sep 17 00:00:00 2001 From: f-gate Date: Tue, 5 Dec 2023 10:52:33 +0000 Subject: [PATCH 1/4] test --- pallets/proposals/src/tests/foreign_asset.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 pallets/proposals/src/tests/foreign_asset.rs diff --git a/pallets/proposals/src/tests/foreign_asset.rs b/pallets/proposals/src/tests/foreign_asset.rs new file mode 100644 index 00000000..adccad46 --- /dev/null +++ b/pallets/proposals/src/tests/foreign_asset.rs @@ -0,0 +1,19 @@ +#[test] +fn set_foreign_asset_signer_check_permission_for_edit() { + build_test_externality().execute_with(|| { + Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE); + assert!(ForeignCurrencySigner::::get().unwrap(), ALICE); + Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), BOB); + assert!(ForeignCurrencySigner::::get().unwrap(), BOB); + + assert_noop!(Proposals::set_foreign_asset_signer(RuntimeOrigin::signed(BOB), ALICE), BadOrigin); + }) +} + + +#[test] +fn foreign_asset_signer_can_mint() { + build_test_externality().execute_with(|| { + + }) +} \ No newline at end of file From f37edb85c4f73eca940c191b9386b77424a56117 Mon Sep 17 00:00:00 2001 From: f-gate Date: Tue, 5 Dec 2023 11:07:36 +0000 Subject: [PATCH 2/4] forign signer can mint --- libs/common-types/src/tokens.rs | 4 ++-- pallets/proposals/src/tests/foreign_asset.rs | 25 ++++++++++++++++---- pallets/proposals/src/tests/mod.rs | 1 + 3 files changed, 23 insertions(+), 7 deletions(-) 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 index adccad46..0d6f80b8 100644 --- a/pallets/proposals/src/tests/foreign_asset.rs +++ b/pallets/proposals/src/tests/foreign_asset.rs @@ -1,19 +1,34 @@ +use crate::{mock::*, *}; +use frame_support::{assert_noop, assert_ok}; +use test_utils::*; + #[test] fn set_foreign_asset_signer_check_permission_for_edit() { build_test_externality().execute_with(|| { - Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE); + assert_ok!(Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE)); assert!(ForeignCurrencySigner::::get().unwrap(), ALICE); - Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), BOB); + assert_ok!(Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), BOB)); assert!(ForeignCurrencySigner::::get().unwrap(), BOB); - 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 = ForeignAsset(10); + let beneficiary = BOB; + let amount 92839572; + 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 + ); }) } \ 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; From 86a2dd964fb5c6130029e990b7a7dc342a289b27 Mon Sep 17 00:00:00 2001 From: f-gate Date: Tue, 5 Dec 2023 13:08:14 +0000 Subject: [PATCH 3/4] negative minting test --- pallets/proposals/src/tests/foreign_asset.rs | 28 +++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/pallets/proposals/src/tests/foreign_asset.rs b/pallets/proposals/src/tests/foreign_asset.rs index 0d6f80b8..172ab741 100644 --- a/pallets/proposals/src/tests/foreign_asset.rs +++ b/pallets/proposals/src/tests/foreign_asset.rs @@ -1,14 +1,14 @@ use crate::{mock::*, *}; -use frame_support::{assert_noop, assert_ok}; +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!(ForeignCurrencySigner::::get().unwrap(), 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!(ForeignCurrencySigner::::get().unwrap(), 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); }) } @@ -16,19 +16,33 @@ fn set_foreign_asset_signer_check_permission_for_edit() { #[test] fn foreign_asset_signer_can_mint() { build_test_externality().execute_with(|| { - let currency_id = ForeignAsset(10); + let currency_id = CurrencyId::ForeignAsset(10); let beneficiary = BOB; - let amount 92839572; - Proposals::set_foreign_asset_signer(RuntimeOrigin::root(), ALICE); + 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_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 From 42953521bac82b2690152855d5fbcfd2c613d203 Mon Sep 17 00:00:00 2001 From: gatsey <42411328+f-gate@users.noreply.github.com> Date: Tue, 5 Dec 2023 13:58:14 +0000 Subject: [PATCH 4/4] remove it (#285) --- .github/workflows/build.yml | 2 -- 1 file changed, 2 deletions(-) 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: