Skip to content

Commit

Permalink
fixed according review
Browse files Browse the repository at this point in the history
  • Loading branch information
LouiseMedova committed Sep 9, 2024
1 parent 38c027b commit 89c1f3d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
2 changes: 2 additions & 0 deletions gear-programs/bridging-payment/src/wasm/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
2 changes: 2 additions & 0 deletions gear-programs/vft-gateway/src/services/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ pub enum Error {
BurnTokensFailed,
BridgeBuiltinMessageFailed,
TokensRefunded,
NotEthClient,
NotEnoughGas,
}
13 changes: 7 additions & 6 deletions gear-programs/vft-gateway/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>,
Expand Down Expand Up @@ -170,15 +171,17 @@ 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()
< config.gas_to_mint_tokens
+ 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();
Expand Down Expand Up @@ -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")
};

Expand Down
11 changes: 7 additions & 4 deletions gear-programs/vft-gateway/src/wasm/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>;
}

Expand Down Expand Up @@ -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(),
Expand All @@ -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)> {
Expand Down
26 changes: 25 additions & 1 deletion gear-programs/vft-gateway/src/wasm/tests/vft_gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions gear-programs/vft-gateway/src/wasm/vft-gateway.idl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type Error = enum {
BurnTokensFailed,
BridgeBuiltinMessageFailed,
TokensRefunded,
NotEthClient,
NotEnoughGas,
};

type MessageInfo = struct {
Expand Down

0 comments on commit 89c1f3d

Please sign in to comment.