diff --git a/gear-programs/bridging-payment/src/wasm/tests/utils.rs b/gear-programs/bridging-payment/src/wasm/tests/utils.rs index 14dc48e3..8ca11046 100644 --- a/gear-programs/bridging-payment/src/wasm/tests/utils.rs +++ b/gear-programs/bridging-payment/src/wasm/tests/utils.rs @@ -252,11 +252,13 @@ impl VftGateway for Program<'_> { let init_config = vft_gateway_app::services::InitConfig::new( [1; 20].into(), BRIDGE_BUILTIN_ID.into(), + 1010.into(), vft_gateway_app::services::Config::new( 15_000_000_000, 15_000_000_000, 15_000_000_000, 15_000_000_000, + 15_000_000_000, 1000, 20_000_000_000, ), diff --git a/gear-programs/vft-gateway/src/services/error.rs b/gear-programs/vft-gateway/src/services/error.rs index 1c9c17d9..d6e65e9b 100644 --- a/gear-programs/vft-gateway/src/services/error.rs +++ b/gear-programs/vft-gateway/src/services/error.rs @@ -21,4 +21,6 @@ pub enum Error { BurnTokensFailed, BridgeBuiltinMessageFailed, TokensRefunded, + NotEthClient, + NotEnoughGas, } diff --git a/gear-programs/vft-gateway/src/services/mod.rs b/gear-programs/vft-gateway/src/services/mod.rs index 1680f09b..4bd3a423 100644 --- a/gear-programs/vft-gateway/src/services/mod.rs +++ b/gear-programs/vft-gateway/src/services/mod.rs @@ -119,6 +119,7 @@ where self.data_mut().vara_to_eth_token_id.remove(&vara_token_id); } + #[allow(clippy::too_many_arguments)] pub fn update_config( &mut self, gas_to_burn_tokens: Option, @@ -170,7 +171,9 @@ where let data = self.data(); let sender = self.exec_context.actor_id(); - assert_eq!(sender, data.eth_client, "Only eth client can mint tokens"); + if sender != data.eth_client { + return Err(Error::NotEthClient); + } let config = self.config(); if gstd::exec::gas_available() @@ -178,7 +181,7 @@ where + config.gas_to_process_mint_request + config.gas_for_reply_deposit { - panic!("Please attach more gas"); + return Err(Error::NotEnoughGas); } let msg_id = gstd::msg::id(); @@ -254,15 +257,13 @@ where .get_message_info(&msg_id) .expect("Unexpected: msg status does not exist"); - let (sender, amount, receiver, vara_token_id) = if let TxDetails::TransferVaraToEth { + let TxDetails::TransferVaraToEth { vara_token_id, sender, amount, receiver, } = msg_info.details - { - (sender, amount, receiver, vara_token_id) - } else { + else { panic!("Wrong message type") }; diff --git a/gear-programs/vft-gateway/src/wasm/tests/utils.rs b/gear-programs/vft-gateway/src/wasm/tests/utils.rs index 4eb6f202..59f900c8 100644 --- a/gear-programs/vft-gateway/src/wasm/tests/utils.rs +++ b/gear-programs/vft-gateway/src/wasm/tests/utils.rs @@ -135,7 +135,7 @@ pub trait VftGateway { from: u64, msg_id: MessageId, ) -> Result<(U256, H160), Error>; - fn mint_tokens(&self, from: u64, vara_token_id: ActorId, amount: U256, receiver: ActorId); + fn mint_tokens(&self, from: u64, vara_token_id: ActorId, amount: U256, receiver: ActorId, error: bool); fn get_msg_tracker_state(&self) -> Vec<(MessageId, MessageInfo)>; } @@ -235,7 +235,7 @@ impl VftGateway for Program<'_> { reply.2 } - fn mint_tokens(&self, from: u64, vara_token_id: ActorId, amount: U256, receiver: ActorId) { + fn mint_tokens(&self, from: u64, vara_token_id: ActorId, amount: U256, receiver: ActorId, error: bool) { let payload = [ "VftGateway".encode(), "MintTokens".encode(), @@ -251,8 +251,11 @@ impl VftGateway for Program<'_> { let reply = <(String, String, Result<(), Error>)>::decode(&mut log_entry.payload()) .expect("Unable to decode reply"); - println!("{:?}", reply.2); - assert!(reply.2.is_ok()); + if error { + assert!(reply.2.is_err()); + } else { + assert!(reply.2.is_ok()); + } } fn get_msg_tracker_state(&self) -> Vec<(MessageId, MessageInfo)> { diff --git a/gear-programs/vft-gateway/src/wasm/tests/vft_gateway.rs b/gear-programs/vft-gateway/src/wasm/tests/vft_gateway.rs index b126d69c..014accd6 100644 --- a/gear-programs/vft-gateway/src/wasm/tests/vft_gateway.rs +++ b/gear-programs/vft-gateway/src/wasm/tests/vft_gateway.rs @@ -237,12 +237,36 @@ fn test_mint_tokens_from_eth_client() { vft.grant_minter_role(ADMIN_ID, vft_gateway.id()); - vft_gateway.mint_tokens(ETH_CLIENT_ID, vft.id().into(), amount, receiver.into()); + vft_gateway.mint_tokens(ETH_CLIENT_ID, vft.id().into(), amount, receiver.into(), false); let balance = vft.balance_of(receiver.into()); assert_eq!(balance, amount); } +#[test] +fn test_mint_tokens_from_arbitrary_address() { + let system = System::new(); + system.init_logger(); + + let vft = Program::token(&system, TOKEN_ID); + let gear_bridge_builtin = + Program::mock_with_id(&system, BRIDGE_BUILTIN_ID, GearBridgeBuiltinMock); + assert!(!gear_bridge_builtin + .send_bytes(ADMIN_ID, b"INIT") + .main_failed()); + + let vft_gateway = Program::vft_gateway(&system); + + let receiver: u64 = 10000; + let amount = U256::from(10_000_000_000_u64); + + vft.grant_minter_role(ADMIN_ID, vft_gateway.id()); + + let wrond_address = 1010; + + vft_gateway.mint_tokens(wrond_address, vft.id().into(), amount, receiver.into(), true); +} + #[test] fn calculate_bridge_builtint() { let bytes = hash((b"built/in", 3).encode().as_slice()); diff --git a/gear-programs/vft-gateway/src/wasm/vft-gateway.idl b/gear-programs/vft-gateway/src/wasm/vft-gateway.idl index f39d1797..b4f6a426 100644 --- a/gear-programs/vft-gateway/src/wasm/vft-gateway.idl +++ b/gear-programs/vft-gateway/src/wasm/vft-gateway.idl @@ -35,6 +35,8 @@ type Error = enum { BurnTokensFailed, BridgeBuiltinMessageFailed, TokensRefunded, + NotEthClient, + NotEnoughGas, }; type MessageInfo = struct {