Skip to content

Commit b669370

Browse files
committedFeb 4, 2025··
chore: override user inputs when swapping
1 parent 3ecba4e commit b669370

File tree

6 files changed

+13
-37
lines changed

6 files changed

+13
-37
lines changed
 

‎contracts/soroban/contracts/intent/src/error.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,5 @@ pub enum ContractError {
1313
OrderNotFound = 7,
1414
OrderAlreadyFilled = 8,
1515
OrderMismatched = 9,
16-
InvalidEmitterAddress = 10,
17-
InvalidNetwork = 11,
18-
NetworkIdMisconfigured = 12,
16+
InvalidNetwork = 10,
1917
}

‎contracts/soroban/contracts/intent/src/swap.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,13 @@ pub fn swap_order(env: &Env, order: SwapOrder) -> Result<(), ContractError> {
99

1010
sender.require_auth();
1111

12-
if order.src_nid() != storage::nid(&env)? {
13-
return Err(ContractError::NetworkIdMisconfigured);
14-
}
15-
if order.emitter() != contract_address.to_string() {
16-
return Err(ContractError::InvalidEmitterAddress);
17-
}
18-
1912
let token = Address::from_string(&order.token());
2013
helpers::transfer_token(&env, &token, &sender, &contract_address, order.amount());
2114

2215
let deposit_id = storage::increment_deposit_id(&env);
2316
order.set_id(deposit_id);
17+
order.set_src_nid(storage::nid(&env)?);
18+
order.set_emitter(contract_address.to_string());
2419

2520
storage::store_order(&env, deposit_id, &order);
2621
event::swap_intent(

‎contracts/soroban/contracts/intent/src/test/cancel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn test_resolve_cancel_in_same_source_and_destination_chain() {
132132
}
133133

134134
#[test]
135-
#[should_panic(expected = "HostError: Error(Contract, #11)")]
135+
#[should_panic(expected = "HostError: Error(Contract, #10)")]
136136
fn test_resolve_cancel_with_invalid_network_id() {
137137
let ctx = TestContext::default();
138138
let client = IntentClient::new(&ctx.env, &ctx.contract);

‎contracts/soroban/contracts/intent/src/test/fill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ fn test_resolve_fill() {
188188
}
189189

190190
#[test]
191-
#[should_panic(expected = "HostError: Error(Contract, #11)")]
191+
#[should_panic(expected = "HostError: Error(Contract, #10)")]
192192
fn test_resolve_fill_with_invalid_network_id() {
193193
let ctx = TestContext::default();
194194
let client = IntentClient::new(&ctx.env, &ctx.contract);

‎contracts/soroban/contracts/intent/src/test/swap.rs

-25
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,6 @@ extern crate std;
88
use super::setup::TestContext;
99
use crate::{contract::IntentClient, event::SwapIntent, types::SwapOrder};
1010

11-
#[test]
12-
#[should_panic(expected = "HostError: Error(Contract, #12)")]
13-
fn test_swap_with_misconfigured_network_id() {
14-
let ctx = TestContext::default();
15-
let client = IntentClient::new(&ctx.env, &ctx.contract);
16-
ctx.init_context(&client);
17-
18-
let src_nid = String::from_str(&ctx.env, "icon");
19-
let order = SwapOrder::new(
20-
1,
21-
ctx.contract.to_string(),
22-
src_nid,
23-
String::from_str(&ctx.env, "solana"),
24-
ctx.admin.to_string(),
25-
ctx.admin.to_string(),
26-
ctx.native_token.to_string(),
27-
100,
28-
ctx.native_token.to_string(),
29-
100,
30-
bytes!(&ctx.env, 0x00),
31-
);
32-
33-
client.swap(&order);
34-
}
35-
3611
#[test]
3712
#[should_panic(expected = "HostError: Error(Contract, #10)")]
3813
fn test_swap_with_invalid_emitter_address() {

‎contracts/soroban/contracts/intent/src/types/swap_order.rs

+8
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ impl SwapOrder {
6565
self.id = id
6666
}
6767

68+
pub fn set_src_nid(&mut self, nid: String) {
69+
self.src_nid = nid
70+
}
71+
72+
pub fn set_emitter(&mut self, emitter: String) {
73+
self.emitter = emitter
74+
}
75+
6876
pub fn emitter(&self) -> String {
6977
self.emitter.clone()
7078
}

0 commit comments

Comments
 (0)
Please sign in to comment.