Add integration tests for vault client functionality - #22
Conversation
- Implement tests for deposit, task creation, payment release, and withdrawal. - Include checks for available balance adjustments and task state validation. - Utilize Vitest for concurrent test execution and setup. - Ensure proper handling of edge cases, such as double release on completed tasks and insufficient balance for task creation.
📝 WalkthroughWalkthroughAdds a Vitest integration test suite ( ChangesVault Client Integration Tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/orchestrator/src/__tests__/vault-client.integration.test.ts`:
- Around line 109-133: The sendUsdcFromFundedOrchestrator function shares a
single source account across concurrent tests, causing sequence number race
conditions on Stellar. Replace all instances of it.concurrent with it to
serialize the tests that call this function. This includes the test definitions
around the sendUsdcFromFundedOrchestrator function itself and any other test
blocks that invoke USDC funding operations (affecting the areas mentioned at
lines 169-177 and 255-350), ensuring tests execute sequentially rather than in
parallel.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8b8282e4-df41-4d69-b0f7-0b77914679f6
📒 Files selected for processing (5)
package.jsonpackages/orchestrator/package.jsonpackages/orchestrator/public/assets/index-90giOIxm.jspackages/orchestrator/public/index.htmlpackages/orchestrator/src/__tests__/vault-client.integration.test.ts
| async function sendUsdcFromFundedOrchestrator(destination: string, amount: string): Promise<void> { | ||
| if (!ORCHESTRATOR_SECRET_KEY) { | ||
| throw new Error('Missing ORCHESTRATOR_SECRET_KEY for USDC funding'); | ||
| } | ||
|
|
||
| const source = Keypair.fromSecret(ORCHESTRATOR_SECRET_KEY); | ||
| const server = horizonServer(); | ||
| const account = await server.loadAccount(source.publicKey()); | ||
| const tx = new TransactionBuilder(account, { | ||
| fee: '100', | ||
| networkPassphrase: NETWORK_PASSPHRASE, | ||
| }) | ||
| .addOperation( | ||
| Operation.payment({ | ||
| destination, | ||
| asset: USDC, | ||
| amount, | ||
| }), | ||
| ) | ||
| .setTimeout(30) | ||
| .build(); | ||
|
|
||
| tx.sign(source); | ||
| await server.submitTransaction(tx); | ||
| } |
There was a problem hiding this comment.
Shared funding account + it.concurrent can cause intermittent tx_bad_seq failures.
sendUsdcFromFundedOrchestrator signs from one source account (ORCHESTRATOR_SECRET_KEY) while all scenarios run concurrently. On Stellar, that creates sequence-number races and flaky integration runs.
Suggested low-effort fix (serialize the live-network tests)
- it.concurrent('`@integration` Deposit increases available by 1 USDC', { tags: ['integration'] }, async () => {
+ it('`@integration` Deposit increases available by 1 USDC', { tags: ['integration'] }, async () => {
@@
- it.concurrent('`@integration` Create task decreases available and get_task returns the task', { tags: ['integration'] }, async () => {
+ it('`@integration` Create task decreases available and get_task returns the task', { tags: ['integration'] }, async () => {
@@
- it.concurrent('`@integration` Release payment increases orchestrator USDC balance', { tags: ['integration'] }, async () => {
+ it('`@integration` Release payment increases orchestrator USDC balance', { tags: ['integration'] }, async () => {
@@
- it.concurrent('`@integration` Withdraw remaining balance leaves available at 0', { tags: ['integration'] }, async () => {
+ it('`@integration` Withdraw remaining balance leaves available at 0', { tags: ['integration'] }, async () => {
@@
- it.concurrent('`@integration` Double release on completed task fails', { tags: ['integration'] }, async () => {
+ it('`@integration` Double release on completed task fails', { tags: ['integration'] }, async () => {
@@
- it.concurrent('`@integration` Creating a task with insufficient available balance fails', { tags: ['integration'] }, async () => {
+ it('`@integration` Creating a task with insufficient available balance fails', { tags: ['integration'] }, async () => {Also applies to: 169-177, 255-350
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/orchestrator/src/__tests__/vault-client.integration.test.ts` around
lines 109 - 133, The sendUsdcFromFundedOrchestrator function shares a single
source account across concurrent tests, causing sequence number race conditions
on Stellar. Replace all instances of it.concurrent with it to serialize the
tests that call this function. This includes the test definitions around the
sendUsdcFromFundedOrchestrator function itself and any other test blocks that
invoke USDC funding operations (affecting the areas mentioned at lines 169-177
and 255-350), ensuring tests execute sequentially rather than in parallel.
|
LGTM! Just fix the CI fail @BigJohn-dev |
|
You've been unresponsive so far regarding the PR after reaching out privately. The CI fail is a small fix or are you experiencing some difficulties? If no response from you i'll have to assign the task to someone else |
Closes #6
Orchestrator Vault Client and Integration Testing
This document describes the CleverVault integration point used by the orchestrator and the new live integration tests covering the full vault lifecycle on Stellar testnet.
Overview
The orchestrator interacts with the CleverVault Soroban contract via
packages/orchestrator/src/agent-vault-client.ts.That client provides two modes of operation:
User-signed XDR builders for Freighter-style flows:
buildRegisterOrchestratorXdr— register a user/orchestrator mappingbuildDepositXdr— deposit USDC into the vaultbuildWithdrawXdr— withdraw available USDC from the vaultbuildCancelTaskXdr— cancel an active task and refund unused budgetServer-side orchestrator operations signed by the orchestrator keypair:
createTask— lock a task budget from user available balancereleasePayment— release payment from the vault to the orchestratorcompleteTask/forceCompleteTask— complete the task and unlock remaining balanceThe client also exposes read-only views:
getAvailable— available (unlocked) vault balancegetBalance— total vault balancegetAccount— full vault account summary for the userConfiguration
The client uses these environment variables:
AGENT_VAULT_CONTRACT_ID— address of the deployed CleverVault contractSTELLAR_RPC_URL— Soroban RPC endpoint (defaults tohttps://soroban-testnet.stellar.org)ORCHESTRATOR_SECRET_KEY— orchestrator wallet secret used in test setup and funding helpersIf
AGENT_VAULT_CONTRACT_IDis missing or invalid, the client disables live vault features and returns safe defaults for read-only calls.Live Vault Lifecycle
The orchestrator vault lifecycle tested in
packages/orchestrator/src/__tests__/vault-client.integration.test.tscovers:Integration Tests
The new integration suite lives in:
packages/orchestrator/src/__tests__/vault-client.integration.test.tsEach test is tagged with
@integrationand usesit.concurrent(..., { tags: ['integration'] }, ...)so Vitest can filter them separately.Running integration tests
From the repository root:
From the orchestrator package:
Excluding integration tests from default CI runs
The root
package.jsonis configured sonpm testexcludes integration-tagged tests:npm testThis runs only unit tests and leaves live Soroban testnet coverage to the dedicated integration command.
Notes
AGENT_VAULT_CONTRACT_ID.test:integrationscript for convenience.Summary by CodeRabbit