Skip to content

Add Blend v2 integration test suite - #664

Open
aditya1702 wants to merge 14 commits into
blend/pr5-graphqlfrom
blend/pr6-integration-tests
Open

Add Blend v2 integration test suite#664
aditya1702 wants to merge 14 commits into
blend/pr5-graphqlfrom
blend/pr6-integration-tests

Conversation

@aditya1702

@aditya1702 aditya1702 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Deploys the full Blend v2 protocol stack (Comet BLND:USDC LP, mock SEP-40 oracle, emitter, pool factory, backstop, one pool with USDC/XLM reserves) on the standalone integration-test network — replicating blend-utils' mock-example.ts deployment order (pinned commit b05242df, wasm provenance + sha256s in infrastructure/testdata/blend/README.md) — then executes real Blend operations and asserts DB state and GraphQL responses through both ingestion paths.

Coverage

  • Operations (11/15 Blend event shapes end-to-end), asserted per (category, reason): supply (BLEND_SUPPLY, CREDIT), withdraw (BLEND_SUPPLY, DEBIT), supply/withdraw collateral (BLEND_COLLATERAL, CREDIT/DEBIT), borrow and repay (BLEND_DEBT, BORROW/REPAY), pool and backstop emissions claims (BLEND_EMISSIONS / BLEND_BACKSTOP_EMISSIONS, CLAIM), liquidation (oracle-forced undercollateralization → new_auction → 50% fill; both (BLEND_AUCTION, FILL) counterparty rows with auctionType/counterparty/lot/bid asserted + auction position folds), backstop deposit (BLEND_BACKSTOP, CREDIT), and queue/dequeue withdrawal (BLEND_BACKSTOP_QUEUE, ADD/REMOVE).
  • Read side: reserve rates/APYs vs mock-oracle prices, Comet LP valuation (backstop USD), oracle price snapshots (SEP-40 leg + Comet BLND/LP legs), emissions accrual and claims (claimedBlnd, backstopClaimedLp, token_id = -1 backstop streams), exact net_supplied/net_borrowed cost-basis folds, Q4W JSONB with the ~17-day expiration observed live over GraphQL while queued, and lifetime claimed totals (blend_pool_claimed / blend_backstop_claimed fold positive after the phase-2 claims, with a phase-1 both-empty guard).
  • Ingestion paths: BlendMigrationTestSuite runs protocol-setupprotocol-migrate current-stateprotocol-migrate history (datastore backend, MinIO-fed by the ledger exporter) with cursor-handoff pre/post assertions — the history mode's first automated coverage. BlendLiveIngestionTestSuite restarts ingest with BLEND_PRICE_INTERVAL / BLEND_BACKSTOP_LP_CONTRACT_ID — and the API container with the same LP pin (new RestartAPIContainer helper; the resolvers price backstop USD through it, and the restarted container's fresh host port re-points WBClient) — then asserts the full Freighter-facing GraphQL surface (blendPools, blendPool, account.blendPositions incl. activeAuctions for the partially-filled liquidation, Blend state changes incl. fillPercent). Ingest catch-up waits poll the RPC tip vs the ingest cursor (WaitForIngestCatchup) instead of fixed sleeps. The API container pins GRAPHQL_COMPLEXITY_LIMIT=30000: the SDK's full-selection catalog query costs ~26k under the server's complexity accounting (deliberate — the suite selects every field).

Not covered end-to-end (unit tests only)

  • Backstop withdraw (BLEND_BACKSTOP, DEBIT) — the Q4W lockup is 17 days of wall-clock time; ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING only accelerates ledger cadence, not close time, so the lockup cannot elapse on standalone.
  • Flash loan (BLEND_DEBT, FLASH_LOAN) — needs a custom receiver contract.
  • Bad/defaulted debt (BLEND_DEBT, BAD_DEBT/BURN) — require draining the backstop below threshold plus a full liquidation leaving residual debt.

Production changes

  • blndTokenAddress (internal/services/blend/validator.go) gains a standalone-network case: the suite issues BLND from the network master account (keypair.Root of the passphrase), so its SAC address is a fixed constant, letting pool emissions-claim rows carry the real BLND token_id on standalone. Pinned by a unit test and asserted at deploy time in the test setup.
  • canonicalBackstopAddress (same file) gains the matching standalone-network case: the processor folds backstop-shaped entries/events only from the canonical backstop, and on an unpinned network that pin resolves to empty and drops all backstop state (which is what failed this suite — the whale's blend_backstop_positions row never materialized). The suite deploys the backstop from the master account with a fixed salt, so its address is deterministic and pinned the same way: unit test + deploy-time assertion.
  • pkg/wbclient gains Blend query methods (GetBlendPools, GetBlendPool, GetAccountBlendPositions) and client-side DTOs + inline fragments for the eight concrete Blend state-change types, registered through the generic unmarshal dispatch and validated against the real schema by schema_validation_test.go, with unit tests. The DTOs mirror the schema completely: BlendPool.admin/inRewardZone and BlendAccountPositions.activeAuctions (new BlendAuction DTO), enforced by the struct↔fragment parity test.
  • The test-infra i128 encoder validates the signed range [-2^127, 2^127-1] — magnitudes that fit 16 bytes but flip the sign bit are rejected, with boundary tests.

Test infrastructure added

  • Per-actor Soroban executor (executeSorobanOperationAs): arbitrary tx source, RPC-fresh sequences, simulation-provided auth nonces (the existing helper hardcodes nonce 0, safe only for the master account's first use).
  • Salted contract deploys + address precompute, used to break the emitter↔backstop circular dependency by precomputing the backstop's address before deployment.
  • Typed wrappers for every pool/backstop/emitter/oracle/Comet call, ScVal builders with symbol-sorted UDT maps (unit-tested), and named fixture constants so assertions reference the same values the operations used.

Blend phase adds ~100s to make integration-test (total run ~4.5 min, well under the 30m timeout). Verified green twice, including a FORCE_REBUILD=true from-scratch run.

🤖 Generated with Claude Code

@aditya1702
aditya1702 force-pushed the blend/pr6-integration-tests branch from 6f67e5f to 39422d7 Compare July 15, 2026 20:52
@aditya1702
aditya1702 force-pushed the blend/pr6-integration-tests branch from 39422d7 to a98eef2 Compare July 16, 2026 16:56
@aditya1702
aditya1702 force-pushed the blend/pr6-integration-tests branch 2 times, most recently from 8cc6a07 to 7cf40f1 Compare July 21, 2026 18:45
@aditya1702
aditya1702 force-pushed the blend/pr6-integration-tests branch from d67184b to e29e695 Compare July 22, 2026 19:26
@aditya1702
aditya1702 force-pushed the blend/pr6-integration-tests branch from e29e695 to 930f6ad Compare July 22, 2026 19:36
@aditya1702
aditya1702 force-pushed the blend/pr6-integration-tests branch from 930f6ad to 64ce80f Compare July 22, 2026 20:02
@aditya1702
aditya1702 force-pushed the blend/pr6-integration-tests branch from 64ce80f to 81c3229 Compare July 22, 2026 22:45
@aditya1702
aditya1702 requested a review from Copilot July 27, 2026 17:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds comprehensive Blend v2 standalone-network integration coverage across migration and live-ingestion paths, alongside supporting GraphQL, SDK, pricing, and rate-calculation changes.

Changes:

  • Deploys and exercises a complete Blend v2 test stack.
  • Adds Blend SDK models, queries, state-change decoding, and GraphQL resolvers.
  • Refines emission/rate projection, oracle scoping, and complexity accounting.

Reviewed changes

Copilot reviewed 42 out of 50 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
cmd/serve.go Wires the Blend LP contract setting.
internal/data/blend/oracle_prices.go Scopes backstop prices to the configured Comet contract.
internal/data/blend/oracle_prices_test.go Tests scoped price retrieval.
internal/data/blend/readers.go Removes the unused all-reserves reader.
internal/data/blend/readers_test.go Removes its reader test.
internal/integrationtests/main_test.go Adds Blend integration phases.
internal/integrationtests/blend_test.go Implements migration and live-ingestion assertions.
internal/integrationtests/infrastructure/main_setup.go Exposes ingestion catch-up waiting.
internal/integrationtests/infrastructure/contract_deployment.go Adds deterministic salted deployment support.
internal/integrationtests/infrastructure/contract_deployment_test.go Tests contract-address precomputation.
internal/integrationtests/infrastructure/blend_setup.go Deploys and configures the Blend stack.
internal/integrationtests/infrastructure/blend_operations.go Adds Soroban value builders and actor execution.
internal/integrationtests/infrastructure/blend_operations_test.go Tests Blend operation infrastructure.
internal/integrationtests/infrastructure/blend_fixtures.go Defines two-phase Blend operations.
internal/integrationtests/infrastructure/blend_contracts.go Adds typed contract wrappers.
internal/integrationtests/infrastructure/testdata/blend/README.md Documents WASM provenance and hashes.
internal/integrationtests/infrastructure/testdata/blend/comet.wasm Provides the pinned Comet contract.
internal/integrationtests/infrastructure/testdata/blend/comet_factory.wasm Provides the Comet factory.
internal/integrationtests/infrastructure/testdata/blend/emitter.wasm Provides the emissions contract.
internal/integrationtests/infrastructure/testdata/blend/oracle.wasm Provides the mock oracle.
internal/integrationtests/infrastructure/testdata/blend/pool_factory.wasm Provides the pool factory.
internal/services/blend/validator.go Pins standalone BLND and backstop addresses.
internal/services/blend/validator_test.go Tests standalone address pins.
internal/services/blend/rates.go Refines rate and emissions projection.
internal/services/blend/rates_test.go Tests projection behavior.
internal/serve/serve.go Wires pricing configuration and complexity rules.
internal/serve/complexity_test.go Tests nested Blend complexity.
internal/serve/graphql/schema/statechange.graphqls Documents lending state changes.
internal/serve/graphql/schema/queries.graphqls Adds Blend pool queries.
internal/serve/graphql/schema/blend.graphqls Revises Blend types and fields.
internal/serve/graphql/schema/account.graphqls Adds account Blend positions.
internal/serve/graphql/generated/generated.go Regenerates GraphQL execution code.
internal/serve/graphql/generated/models_gen.go Regenerates Blend models and enums.
internal/serve/graphql/resolvers/resolver.go Stores the configured Comet contract.
internal/serve/graphql/resolvers/queries.resolvers.go Adds pool query resolvers.
internal/serve/graphql/resolvers/account.resolvers.go Adds the positions resolver.
internal/serve/graphql/resolvers/blend.resolvers.go Removes superseded generated resolvers.
internal/serve/graphql/resolvers/blend_positions.go Updates positions, emissions, and pricing.
internal/serve/graphql/resolvers/blend_positions_test.go Tests position assembly and projection.
internal/serve/graphql/resolvers/blend_pools.go Adds status mapping and projected APRs.
internal/serve/graphql/resolvers/blend_pools_test.go Tests pool catalog behavior.
internal/serve/graphql/resolvers/blend_earn.go Removes the earn-options resolver.
internal/serve/graphql/resolvers/blend_earn_test.go Removes earn-options tests.
pkg/wbclient/client.go Adds Blend client methods.
pkg/wbclient/client_blend_test.go Tests Blend client requests.
pkg/wbclient/queries.go Adds Blend GraphQL selections.
pkg/wbclient/queries_test.go Tests query-field coverage.
pkg/wbclient/types/blend.go Adds Blend SDK response types.
pkg/wbclient/types/blend_test.go Tests Blend decoding.
pkg/wbclient/types/statechange.go Adds lending state-change decoding.
Files not reviewed (1)
  • internal/serve/graphql/resolvers/account.resolvers.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/wbclient/queries.go
Comment thread pkg/wbclient/queries.go
Comment thread internal/integrationtests/main_test.go Outdated
Comment thread internal/integrationtests/main_test.go
Comment thread pkg/wbclient/types/blend.go
Comment thread pkg/wbclient/types/blend.go
Comment thread internal/serve/graphql/schema/blend.graphqls
Comment thread internal/serve/graphql/schema/blend.graphqls
Comment thread internal/serve/graphql/schema/blend.graphqls
Comment thread internal/integrationtests/infrastructure/blend_operations.go
aditya1702 and others added 5 commits July 30, 2026 17:20
…or tables

Read blend_pool_claimed/blend_backstop_claimed via the new GetByAccount readers
after phase-2 live ingestion and assert the supplier's pool claim and whale's
backstop claim folded positive totals. Guard that phase-1 (no claims) leaves both
accumulator tables empty.
…s survive

The canonical-backstop pin resolves to empty on the standalone network,
which made the processor drop every backstop-shaped entry and event as a
non-canonical impostor — BlendMigrationTestSuite failed on the whale's
missing blend_backstop_positions row.

The suite deploys the backstop from the master account (keypair.Root of
the passphrase) with a fixed salt, so its address is a deterministic
function of the passphrase alone. Pin it in canonicalBackstopAddress the
same way blndTokenAddress pins the standalone BLND SAC: unit test + a
deploy-time assertion in SetupBlendStack.
Absorbs the review-round API changes on blend/pr5-graphql: drops the
GetBlendEarnOptions client method, query, and types (the query was
removed - earn discovery composes from blendPools); BlendPool.status
becomes the BlendPoolStatus enum string; BlendReservePosition's single
emissionsApr splits into emissionsSupplyApr/emissionsBorrowApr.
Claimable-emission assertions were already sign-based, so the
projected-to-now claimable math needs no test changes.
@aditya1702
aditya1702 force-pushed the blend/pr6-integration-tests branch from 0a45456 to 5622e37 Compare July 30, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants