Skip to content

Commit

Permalink
chore: rename split to swap
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Apr 9, 2024
1 parent 14dc1e5 commit 6f39374
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion moksha-mint/src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ mod tests {
}

#[tokio::test]
async fn test_split_zero() -> anyhow::Result<()> {
async fn test_swap_zero() -> anyhow::Result<()> {
let docker = Cli::default();
let image = create_postgres_image();
let node = docker.run(image);
Expand Down
2 changes: 0 additions & 2 deletions moksha-mint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,6 @@ mod tests {
Ok(())
}

// ### v1 api tests

#[tokio::test]
async fn test_get_v1_keys() -> anyhow::Result<()> {
let docker = Cli::default();
Expand Down
32 changes: 16 additions & 16 deletions moksha-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ where
let selected_tokens = (wallet_keyset.mint_url.to_owned(), selected_proofs.clone()).into();

let (remaining_tokens, result) = self
.split_tokens(wallet_keyset, &selected_tokens, amount.into())
.swap_tokens(wallet_keyset, &selected_tokens, amount.into())
.await?;

let mut tx = self.localstore.begin_tx().await?;
Expand All @@ -303,7 +303,7 @@ where
) -> Result<(), MokshaWalletError> {
let total_amount = tokens.total_amount();
let (_, redeemed_tokens) = self
.split_tokens(wallet_keyset, tokens, total_amount.into())
.swap_tokens(wallet_keyset, tokens, total_amount.into())
.await?;
let mut tx = self.localstore.begin_tx().await?;
self.localstore
Expand Down Expand Up @@ -355,20 +355,20 @@ where
let total_proofs = {
let selected_tokens =
(wallet_keyset.mint_url.to_owned(), selected_proofs.clone()).into();
let split_result = self
.split_tokens(wallet_keyset, &selected_tokens, ln_amount.into())
let swap_result = self
.swap_tokens(wallet_keyset, &selected_tokens, ln_amount.into())
.await?;

let mut tx = self.localstore.begin_tx().await?;
self.localstore
.delete_proofs(&mut tx, &selected_proofs)
.await?;
self.localstore
.add_proofs(&mut tx, &split_result.0.proofs())
.add_proofs(&mut tx, &swap_result.0.proofs())
.await?;
tx.commit().await?;

split_result.1.proofs()
swap_result.1.proofs()
};

let fee_blind = self
Expand Down Expand Up @@ -455,17 +455,17 @@ where
let total_proofs = {
let selected_tokens =
(wallet_keyset.mint_url.to_owned(), selected_proofs.clone()).into();
let split_result = self
.split_tokens(wallet_keyset, &selected_tokens, ln_amount.into())
let swap_result = self
.swap_tokens(wallet_keyset, &selected_tokens, ln_amount.into())
.await?;
self.localstore
.delete_proofs(&mut tx, &selected_proofs)
.await?;
self.localstore
.add_proofs(&mut tx, &split_result.0.proofs())
.add_proofs(&mut tx, &swap_result.0.proofs())
.await?;

split_result.1.proofs()
swap_result.1.proofs()
};

let melt_response = self
Expand Down Expand Up @@ -514,7 +514,7 @@ where
Ok(secret_range)
}

pub async fn split_tokens(
pub async fn swap_tokens(
&self,
wallet_keyset: &WalletKeyset,
tokens: &TokenV3,
Expand Down Expand Up @@ -990,8 +990,8 @@ mod tests {
}

#[tokio::test]
async fn test_split() -> anyhow::Result<()> {
let split_response = read_fixture_as::<PostSwapResponse>("post_split_response_24_40.json")?;
async fn test_swap() -> anyhow::Result<()> {
let split_response = read_fixture_as::<PostSwapResponse>("post_swap_response_24_40.json")?;
let mut client = create_mock();
client
.expect_post_swap()
Expand All @@ -1009,7 +1009,7 @@ mod tests {
.await?;

let tokens = read_fixture("token_64.cashu")?.try_into()?;
let result = wallet.split_tokens(&keyset, &tokens, 20.into()).await?;
let result = wallet.swap_tokens(&keyset, &tokens, 20.into()).await?;

let first = result.0;

Expand Down Expand Up @@ -1069,7 +1069,7 @@ mod tests {
.expect_post_melt_quote_bolt11()
.returning(move |_, _, _| Ok(quote_response.clone()));

let swap_response = read_fixture_as::<PostSwapResponse>("post_split_response_24_40.json")?;
let swap_response = read_fixture_as::<PostSwapResponse>("post_swap_response_24_40.json")?;
mock_client
.expect_post_swap()
.returning(move |_, _, _| Ok(swap_response.clone()));
Expand Down Expand Up @@ -1123,7 +1123,7 @@ mod tests {
mock_client
.expect_post_melt_quote_bolt11()
.returning(move |_, _, _| Ok(quote_response.clone()));
let swap_response = read_fixture_as::<PostSwapResponse>("post_split_response_24_40.json")?;
let swap_response = read_fixture_as::<PostSwapResponse>("post_swap_response_24_40.json")?;
mock_client
.expect_post_swap()
.returning(move |_, _, _| Ok(swap_response.clone()));
Expand Down

0 comments on commit 6f39374

Please sign in to comment.