From f302dcdff2f6303c7ad62cb59ba9e974e01012cb Mon Sep 17 00:00:00 2001 From: Vova Lando Date: Tue, 12 Nov 2024 23:27:21 +0200 Subject: [PATCH 01/14] docs: how to run tests locally --- CONTRIBUTING.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 10ddf6a..0066569 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,13 +1,30 @@ ## Preparing development environment It's possible to mimic to spawn chopsticks instances in parallel for development purposes. -Chopsticks Dockerfile exposes 4 ports (8000, 8500, 9000, 9500), so you can spawn 4 instances of chopsticks and each one of them will look at different RPC. +Chopsticks Dockerfile exposes 4 ports (8000, 8500, 9000, 9500), so you can spawn up to 4 instances of chopsticks and each one of them will look at different RPC (note that those will be different chains). Note that the RPCs are not real, so the changes made on one chopsticks instance will not affect the others. 1. `cd chopsticks` 2. `docker compose up`, in case you want to just 2 instances edit the docker-compose.yml file 3. start the app with `KALATORI_CONFIG` environment variable pointing to `configs/chopsticks.toml` +## Running tests locally + +While having the kalatori app running. You can run the tests locally by running the following command: + +```bash +cd tests/kalatori-api-test-suite +yarn +yarn test +``` + +You can run specific test similarly to the following command: + +```bash +cd tests/kalatori-api-test-suite +yarn test -t "should create, repay, and automatically withdraw an order in USDC" +``` + ## Version Bumping and Release Process When you make changes that require a new version of the project, follow these steps to bump the version: From 5d290128e5d24befc1282181f375c525fe8cd3df Mon Sep 17 00:00:00 2001 From: Slesarew <33295157+Slesarew@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:02:02 +0200 Subject: [PATCH 02/14] feat: autofill tip with asset --- src/chain/utils.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/chain/utils.rs b/src/chain/utils.rs index 461e178..5af4c53 100644 --- a/src/chain/utils.rs +++ b/src/chain/utils.rs @@ -214,6 +214,7 @@ pub fn construct_batch_transaction( block: BlockHash, block_number: u32, nonce: u32, + asset: Option, ) -> Result { let mut transaction_to_fill = TransactionToFill::init(&mut (), metadata, genesis_hash.0)?; @@ -296,6 +297,13 @@ pub fn construct_batch_transaction( transaction_to_fill.populate_block_info(Some(block.0), Some(block_number.into())); transaction_to_fill.populate_nonce(nonce); + if let Some(asset) = asset { + transaction_to_fill.try_default_tip_assets_in_given_asset>( + &mut (), + &metadata, + asset, + ); + } for ext in transaction_to_fill.extensions.iter_mut() { if ext.finalize().is_none() { From 24c40c8f8d9ce42f5616e2f17be3aea370569b19 Mon Sep 17 00:00:00 2001 From: Slesarew <33295157+Slesarew@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:03:27 +0200 Subject: [PATCH 03/14] feat: pass asset id into transaction constructor to properly select fee currency --- src/chain/payout.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/chain/payout.rs b/src/chain/payout.rs index d008bf2..141d22d 100644 --- a/src/chain/payout.rs +++ b/src/chain/payout.rs @@ -118,6 +118,7 @@ pub async fn payout( block, block_number, 0, + currency.asset_id, )?; let sign_this = batch_transaction From 2e79929cb04a78e24d53de8de9c229e78823271d Mon Sep 17 00:00:00 2001 From: Slesarew <33295157+Slesarew@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:09:07 +0200 Subject: [PATCH 04/14] fix: syntax --- src/chain/utils.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chain/utils.rs b/src/chain/utils.rs index 5af4c53..d874f2f 100644 --- a/src/chain/utils.rs +++ b/src/chain/utils.rs @@ -298,7 +298,7 @@ pub fn construct_batch_transaction( transaction_to_fill.populate_block_info(Some(block.0), Some(block_number.into())); transaction_to_fill.populate_nonce(nonce); if let Some(asset) = asset { - transaction_to_fill.try_default_tip_assets_in_given_asset>( + transaction_to_fill.try_default_tip_assets_in_given_asset( &mut (), &metadata, asset, From 49f49144118f071ec9957451b91c480bad8fb328 Mon Sep 17 00:00:00 2001 From: Slesarew Date: Thu, 14 Nov 2024 11:43:34 +0200 Subject: [PATCH 05/14] chore: bump deps --- Cargo.lock | 53 ++++++++++++++++++++++++++++++++++++++++++----------- Cargo.toml | 2 +- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ffe6a8..f42a3e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -902,9 +902,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "16.0.0" +version = "17.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cf1549fba25a6fcac22785b61698317d958e96cac72a59102ea45b9ae64692" +checksum = "701bac17e9b55e0f95067c428ebcb46496587f08e8cf4ccc0fe5903bea10dbb8" dependencies = [ "cfg-if", "parity-scale-codec", @@ -1282,6 +1282,15 @@ dependencies = [ "parity-scale-codec", ] +[[package]] +name = "impl-codec" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67aa010c1e3da95bf151bd8b4c059b2ed7e75387cdb969b4f8f2723a43f9941" +dependencies = [ + "parity-scale-codec", +] + [[package]] name = "impl-trait-for-tuples" version = "0.2.2" @@ -1487,7 +1496,7 @@ dependencies = [ "mnemonic-external", "names", "parity-scale-codec", - "primitive-types", + "primitive-types 0.12.2", "reqwest", "scale-info", "serde", @@ -1980,8 +1989,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", - "impl-codec", - "uint", + "impl-codec 0.6.0", + "uint 0.9.5", +] + +[[package]] +name = "primitive-types" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15600a7d856470b7d278b3fe0e311fe28c2526348549f8ef2ff7db3299c87f5" +dependencies = [ + "fixed-hash", + "impl-codec 0.7.0", + "uint 0.10.0", ] [[package]] @@ -2716,7 +2736,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "substrate-constructor" version = "0.1.0" -source = "git+https://github.com/Alzymologist/substrate-constructor#540559207e640bfa158358cdbf736eb488c57100" +source = "git+https://github.com/Alzymologist/substrate-constructor#d6791fedc53f31bc42eef250decbd9054a738875" dependencies = [ "bitvec", "external-memory-tools", @@ -2724,19 +2744,18 @@ dependencies = [ "hex", "num-bigint", "parity-scale-codec", - "primitive-types", + "primitive-types 0.13.1", "scale-info", "sp-arithmetic", "sp-crypto-hashing", "substrate-crypto-light", "substrate_parser", - "thiserror", ] [[package]] name = "substrate-crypto-light" version = "0.1.0" -source = "git+https://github.com/Alzymologist/substrate-crypto-light#8b5d43144a622f4fdbd8f4147a302e6ff4af894c" +source = "git+https://github.com/Alzymologist/substrate-crypto-light#e1c07e19ccb19862accc2771d3b7ec0f86c80a36" dependencies = [ "base58", "blake2b_simd", @@ -2756,7 +2775,7 @@ dependencies = [ [[package]] name = "substrate_parser" version = "0.6.1" -source = "git+https://github.com/Alzymologist/substrate-parser#09f98462f5179bf3c5b6c323c53f7438caf03f06" +source = "git+https://github.com/Alzymologist/substrate-parser#ed388d969b803b4713622378bb716b2032b2c7fe" dependencies = [ "bitvec", "external-memory-tools", @@ -2765,7 +2784,7 @@ dependencies = [ "num-bigint", "parity-scale-codec", "plot_icon", - "primitive-types", + "primitive-types 0.13.1", "scale-info", "sp-arithmetic", "sp-crypto-hashing", @@ -3197,6 +3216,18 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "uint" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "909988d098b2f738727b161a106cfc7cab00c539c2687a8836f8e565976fb53e" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + [[package]] name = "unarray" version = "0.1.4" diff --git a/Cargo.toml b/Cargo.toml index d2eac2b..a98f379 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ axum-macros = "0.4" primitive-types = { version = "0.12", features = ["codec"] } jsonrpsee = { version = "0.24", features = ["ws-client"] } thiserror = "1" -frame-metadata = "16" +frame-metadata = "17" const-hex = "1" codec = { package = "parity-scale-codec", version = "3", features = [ "chain-error", From a1c639455c0f8350ca96293869b81ec5658b065e Mon Sep 17 00:00:00 2001 From: Slesarew Date: Thu, 14 Nov 2024 11:44:59 +0200 Subject: [PATCH 06/14] chore: bump primitive types --- Cargo.lock | 42 +++++------------------------------------- Cargo.toml | 2 +- src/chain/utils.rs | 2 +- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f42a3e1..47cb381 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1273,15 +1273,6 @@ dependencies = [ "png", ] -[[package]] -name = "impl-codec" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" -dependencies = [ - "parity-scale-codec", -] - [[package]] name = "impl-codec" version = "0.7.0" @@ -1496,7 +1487,7 @@ dependencies = [ "mnemonic-external", "names", "parity-scale-codec", - "primitive-types 0.12.2", + "primitive-types", "reqwest", "scale-info", "serde", @@ -1982,17 +1973,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "primitive-types" -version = "0.12.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" -dependencies = [ - "fixed-hash", - "impl-codec 0.6.0", - "uint 0.9.5", -] - [[package]] name = "primitive-types" version = "0.13.1" @@ -2000,8 +1980,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d15600a7d856470b7d278b3fe0e311fe28c2526348549f8ef2ff7db3299c87f5" dependencies = [ "fixed-hash", - "impl-codec 0.7.0", - "uint 0.10.0", + "impl-codec", + "uint", ] [[package]] @@ -2744,7 +2724,7 @@ dependencies = [ "hex", "num-bigint", "parity-scale-codec", - "primitive-types 0.13.1", + "primitive-types", "scale-info", "sp-arithmetic", "sp-crypto-hashing", @@ -2784,7 +2764,7 @@ dependencies = [ "num-bigint", "parity-scale-codec", "plot_icon", - "primitive-types 0.13.1", + "primitive-types", "scale-info", "sp-arithmetic", "sp-crypto-hashing", @@ -3204,18 +3184,6 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" -[[package]] -name = "uint" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" -dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", -] - [[package]] name = "uint" version = "0.10.0" diff --git a/Cargo.toml b/Cargo.toml index a98f379..589784b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ serde = { version = "1", features = ["derive", "rc"] } tracing = "0.1" scale-info = "2" axum-macros = "0.4" -primitive-types = { version = "0.12", features = ["codec"] } +primitive-types = { version = "0.13", features = ["codec"] } jsonrpsee = { version = "0.24", features = ["ws-client"] } thiserror = "1" frame-metadata = "17" diff --git a/src/chain/utils.rs b/src/chain/utils.rs index d874f2f..ecc3b75 100644 --- a/src/chain/utils.rs +++ b/src/chain/utils.rs @@ -300,7 +300,7 @@ pub fn construct_batch_transaction( if let Some(asset) = asset { transaction_to_fill.try_default_tip_assets_in_given_asset( &mut (), - &metadata, + metadata, asset, ); } From 45a6792b1b4e495aea0de1e4ecb5c6e306ec5b9d Mon Sep 17 00:00:00 2001 From: Slesarew Date: Thu, 14 Nov 2024 11:45:39 +0200 Subject: [PATCH 07/14] chore: fmt --- src/chain/utils.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/chain/utils.rs b/src/chain/utils.rs index ecc3b75..f2d59ff 100644 --- a/src/chain/utils.rs +++ b/src/chain/utils.rs @@ -298,11 +298,7 @@ pub fn construct_batch_transaction( transaction_to_fill.populate_block_info(Some(block.0), Some(block_number.into())); transaction_to_fill.populate_nonce(nonce); if let Some(asset) = asset { - transaction_to_fill.try_default_tip_assets_in_given_asset( - &mut (), - metadata, - asset, - ); + transaction_to_fill.try_default_tip_assets_in_given_asset(&mut (), metadata, asset); } for ext in transaction_to_fill.extensions.iter_mut() { From 4159defc910bfc095e38e6cf4bf0a506d370c4db Mon Sep 17 00:00:00 2001 From: Slesarew Date: Thu, 14 Nov 2024 22:40:35 +0200 Subject: [PATCH 08/14] fix: asset select from upstream --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 47cb381..2352c66 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2716,7 +2716,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "substrate-constructor" version = "0.1.0" -source = "git+https://github.com/Alzymologist/substrate-constructor#d6791fedc53f31bc42eef250decbd9054a738875" +source = "git+https://github.com/Alzymologist/substrate-constructor#901469814d0d903db8150c90a2b3d124cde8785e" dependencies = [ "bitvec", "external-memory-tools", @@ -3403,7 +3403,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.52.0", ] [[package]] From 29919084dfe58b48f8dd6f15bbb2e20948a83c3d Mon Sep 17 00:00:00 2001 From: Slesarew Date: Fri, 15 Nov 2024 10:30:37 +0200 Subject: [PATCH 09/14] fix: asset select from upstream --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2352c66..b5ce31b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2716,7 +2716,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "substrate-constructor" version = "0.1.0" -source = "git+https://github.com/Alzymologist/substrate-constructor#901469814d0d903db8150c90a2b3d124cde8785e" +source = "git+https://github.com/Alzymologist/substrate-constructor#4faed1fa180359b6fe41ec90c4f1ec37a982da92" dependencies = [ "bitvec", "external-memory-tools", @@ -3403,7 +3403,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] From 9b42f19ec9ef1a1918d3c4879ba504aa2bd552d9 Mon Sep 17 00:00:00 2001 From: Slesarew Date: Fri, 15 Nov 2024 23:14:37 +0200 Subject: [PATCH 10/14] fix: remove event-based balance check optimization --- src/chain/tracker.rs | 69 ++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/src/chain/tracker.rs b/src/chain/tracker.rs index ff27c09..821a3f9 100644 --- a/src/chain/tracker.rs +++ b/src/chain/tracker.rs @@ -116,52 +116,39 @@ pub fn start_chain_watch( break; } - match transfer_events( - &client, - &block, - &watcher.metadata, - ) - .await { - Ok(events) => { - let mut id_remove_list = Vec::new(); - let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis() as u64; - - for (id, invoice) in &watched_accounts { - if events.iter().any(|event| was_balance_received_at_account(&invoice.address, &event.0.fields)) { - match invoice.check(&client, &watcher, &block).await { - Ok(true) => { - state.order_paid(id.clone()).await; - id_remove_list.push(id.to_owned()); - } - Ok(false) => (), - Err(e) => { - tracing::warn!("account fetch error: {0:?}", e); - } - } - } else if invoice.death.0 >= now { - match invoice.check(&client, &watcher, &block).await { - Ok(paid) => { - if paid { - state.order_paid(id.clone()).await; - } + let mut id_remove_list = Vec::new(); + let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_millis() as u64; + // Important! There used to be a significant oprimisation that + // watched events and checked only accounts that have tranfers into + // them in given block; this was found to be unreliable: there are + // ways to transfer funds without emitting a transfer event (one + // notable example is through asset exchange procedure directed + // straight into invoice account), and probably even without any + // reliably expected event (through XCM). Thus we just scan all + // accounts, every time. Please submit a PR or an issue if you + // figure out a reliable optimization for this. + for (id, invoice) in &watched_accounts { + match invoice.check(&client, &watcher, &block).await { + Ok(true) => { + state.order_paid(id.clone()).await; + id_remove_list.push(id.to_owned()); + } + Ok(false) => ( + if invoice.death.0 >= now { id_remove_list.push(id.to_owned()); - } - Err(e) => { - tracing::warn!("account fetch error: {0:?}", e); - } - } } + ), + Err(e) => { + tracing::warn!("account fetch error: {0:?}", e); } - for id in id_remove_list { - watched_accounts.remove(&id); - } - }, - Err(e) => { - tracing::warn!("Events fetch error {e} at {}", chain.name); - break; - }, } + } + + for id in id_remove_list { + watched_accounts.remove(&id); + }; + tracing::debug!("Block {} from {} processed successfully", block.to_string(), chain.name); } ChainTrackerRequest::WatchAccount(request) => { From a60b123368c7ccfaab84638bbfaf37a88c644c56 Mon Sep 17 00:00:00 2001 From: Vova Lando Date: Sun, 17 Nov 2024 23:25:44 +0200 Subject: [PATCH 11/14] tests: added test cases to cover partial withdrawal --- src/chain/tracker.rs | 2 +- .../tests/order.test.ts | 74 +++++++++++++++++-- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/src/chain/tracker.rs b/src/chain/tracker.rs index 821a3f9..3b5366b 100644 --- a/src/chain/tracker.rs +++ b/src/chain/tracker.rs @@ -135,7 +135,7 @@ pub fn start_chain_watch( id_remove_list.push(id.to_owned()); } Ok(false) => ( - if invoice.death.0 >= now { + if invoice.death.0 <= now { id_remove_list.push(id.to_owned()); } ), diff --git a/tests/kalatori-api-test-suite/tests/order.test.ts b/tests/kalatori-api-test-suite/tests/order.test.ts index 2644e8f..68a222e 100644 --- a/tests/kalatori-api-test-suite/tests/order.test.ts +++ b/tests/kalatori-api-test-suite/tests/order.test.ts @@ -233,7 +233,7 @@ describe('Order Endpoint Blackbox Tests', () => { expect(repaidOrderDetails.withdrawal_status).toBe('completed'); }, 100000); - it.skip('should create, repay, and automatically withdraw an order in USDC', async () => { + it('should create, repay, and automatically withdraw an order in USDC', async () => { const orderId = generateRandomOrderId(); await createOrder(orderId, usdcOrderData); const orderDetails = await getOrderDetails(orderId); @@ -255,7 +255,46 @@ describe('Order Endpoint Blackbox Tests', () => { expect(repaidOrderDetails.withdrawal_status).toBe('completed'); }, 50000); - it.skip('should not automatically withdraw an order until fully repaid', async () => { + it('should not automatically withdraw DOT order until fully repaid', async () => { + const orderId = generateRandomOrderId(); + await createOrder(orderId, dotOrderData); + const orderDetails = await getOrderDetails(orderId); + const paymentAccount = orderDetails.payment_account; + expect(paymentAccount).toBeDefined(); + + const halfAmount = orderDetails.amount/2; + + // Partial repayment + await transferFunds( + orderDetails.currency.rpc_url, + paymentAccount, + halfAmount, + orderDetails.currency.asset_id + ); + // lets wait for the changes to get propagated on chain and app to catch them + await new Promise(resolve => setTimeout(resolve, 15000)); + + let repaidOrderDetails = await getOrderDetails(orderId); + expect(repaidOrderDetails.payment_status).toBe('pending'); + expect(repaidOrderDetails.withdrawal_status).toBe('waiting'); + + // Full repayment + await transferFunds( + orderDetails.currency.rpc_url, + paymentAccount, + halfAmount+5, + orderDetails.currency.asset_id + ); + + // lets wait for the changes to get propagated on chain and app to catch them + await new Promise(resolve => setTimeout(resolve, 15000)); + + repaidOrderDetails = await getOrderDetails(orderId); + expect(repaidOrderDetails.payment_status).toBe('paid'); + expect(repaidOrderDetails.withdrawal_status).toBe('completed'); + }, 100000); + + it('should not automatically withdraw USDC order until fully repaid', async () => { const orderId = generateRandomOrderId(); await createOrder(orderId, usdcOrderData); const orderDetails = await getOrderDetails(orderId); @@ -292,9 +331,9 @@ describe('Order Endpoint Blackbox Tests', () => { repaidOrderDetails = await getOrderDetails(orderId); expect(repaidOrderDetails.payment_status).toBe('paid'); expect(repaidOrderDetails.withdrawal_status).toBe('completed'); - }, 50000); + }, 100000); - it.skip('should not update order if received payment in wrong currency', async () => { + it('should not update order if received payment in wrong currency', async () => { const orderId = generateRandomOrderId(); await createOrder(orderId, usdcOrderData); const orderDetails = await getOrderDetails(orderId); @@ -317,7 +356,7 @@ describe('Order Endpoint Blackbox Tests', () => { expect(repaidOrderDetails.withdrawal_status).toBe('waiting'); }, 50000); - it('should be able to force withdraw partially repayed order', async () => { + it('should be able to force withdraw partially repayed DOT order', async () => { const orderId = generateRandomOrderId(); await createOrder(orderId, dotOrderData); const orderDetails = await getOrderDetails(orderId); @@ -342,6 +381,31 @@ describe('Order Endpoint Blackbox Tests', () => { expect(forcedOrderDetails.withdrawal_status).toBe('forced'); }, 100000); + it('should be able to force withdraw partially repayed USDC order', async () => { + const orderId = generateRandomOrderId(); + await createOrder(orderId, usdcOrderData); + const orderDetails = await getOrderDetails(orderId); + const paymentAccount = orderDetails.payment_account; + expect(paymentAccount).toBeDefined(); + + await transferFunds(orderDetails.currency.rpc_url, paymentAccount, usdcOrderData.amount/2); + + // lets wait for the changes to get propagated on chain and app to catch them + await new Promise(resolve => setTimeout(resolve, 15000)); + + const partiallyRepaidOrderDetails = await getOrderDetails(orderId); + expect(partiallyRepaidOrderDetails.payment_status).toBe('pending'); + expect(partiallyRepaidOrderDetails.withdrawal_status).toBe('waiting'); + + const response = await request(baseUrl) + .post(`/v2/order/${orderId}/forceWithdrawal`); + expect(response.status).toBe(201); + + let forcedOrderDetails = await getOrderDetails(orderId); + expect(forcedOrderDetails.payment_status).toBe('pending'); + expect(forcedOrderDetails.withdrawal_status).toBe('forced'); + }, 100000); + it('should return 404 for non-existing order on force withdrawal', async () => { const nonExistingOrderId = 'nonExistingOrder123'; const response = await request(baseUrl) From ad3e210dd8eab8746176bc7c082dfc0db57c7bf4 Mon Sep 17 00:00:00 2001 From: Vova Lando Date: Mon, 18 Nov 2024 11:48:22 +0200 Subject: [PATCH 12/14] chore: minor style, version bump --- CHANGELOG.md | 12 ++++++++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/chain/tracker.rs | 8 ++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be68587..e5feb8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. +## [0.2.7] - 2024-11-18 + +### ๐Ÿš€ Features + +- Asset Hub transactions with fee currency + - Autofill tip with asset + - Pass asset id into transaction constructor to properly select fee currency + +### ๐Ÿงช Testing + +- Test cases to cover partial withdrawal and Asset Gub transfers + ## [0.2.6] - 2024-11-01 ### ๐Ÿš€ Features diff --git a/Cargo.lock b/Cargo.lock index b5ce31b..1821db8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1473,7 +1473,7 @@ dependencies = [ [[package]] name = "kalatori" -version = "0.2.6" +version = "0.2.7" dependencies = [ "ahash", "async-lock", diff --git a/Cargo.toml b/Cargo.toml index 589784b..7b67f27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "kalatori" authors = ["Alzymologist Oy "] -version = "0.2.6" +version = "0.2.7" edition = "2021" description = "A gateway daemon for Kalatori." license = "GPL-3.0-or-later" diff --git a/src/chain/tracker.rs b/src/chain/tracker.rs index 3b5366b..47eb8bc 100644 --- a/src/chain/tracker.rs +++ b/src/chain/tracker.rs @@ -133,12 +133,12 @@ pub fn start_chain_watch( Ok(true) => { state.order_paid(id.clone()).await; id_remove_list.push(id.to_owned()); - } - Ok(false) => ( + }, + Ok(false) => { if invoice.death.0 <= now { - id_remove_list.push(id.to_owned()); + id_remove_list.push(id.to_owned()); } - ), + }, Err(e) => { tracing::warn!("account fetch error: {0:?}", e); } From bef60c7b550d4721e2c578634a8815125c5c18ed Mon Sep 17 00:00:00 2001 From: Vova Lando Date: Mon, 18 Nov 2024 13:33:18 +0200 Subject: [PATCH 13/14] chore: another fmt --- src/chain/tracker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chain/tracker.rs b/src/chain/tracker.rs index 47eb8bc..b1607e4 100644 --- a/src/chain/tracker.rs +++ b/src/chain/tracker.rs @@ -144,7 +144,7 @@ pub fn start_chain_watch( } } } - + for id in id_remove_list { watched_accounts.remove(&id); }; From 0f2bb693b37003e71989835bd077219e9230ea20 Mon Sep 17 00:00:00 2001 From: Vova Lando Date: Mon, 18 Nov 2024 22:02:52 +0200 Subject: [PATCH 14/14] chore: bump substrate-constructor --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1821db8..a1f0bf9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2716,7 +2716,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "substrate-constructor" version = "0.1.0" -source = "git+https://github.com/Alzymologist/substrate-constructor#4faed1fa180359b6fe41ec90c4f1ec37a982da92" +source = "git+https://github.com/Alzymologist/substrate-constructor#09c877f9ef228508e9d1fbeb3f66bcb782b70bb6" dependencies = [ "bitvec", "external-memory-tools",