From 4f78094a31dadd40c45d529e5c1d5076298e0510 Mon Sep 17 00:00:00 2001 From: Tsachi Herman <24438559+tsachiherman@users.noreply.github.com> Date: Tue, 19 Sep 2023 11:47:42 -0400 Subject: [PATCH 1/3] build: update integration testing to use the updated sdk ( rc2 ) (#5058) * update integration testing to use the updated sdk. * update contracts. --- .../internal/integration/contracts/Cargo.lock | 57 +++++++++--------- .../internal/integration/contracts/Cargo.toml | 4 +- .../integration/testdata/soroban_add_u64.wasm | Bin 618 -> 631 bytes .../testdata/soroban_increment_contract.wasm | Bin 697 -> 701 bytes .../testdata/soroban_sac_test.wasm | Bin 1904 -> 1924 bytes 5 files changed, 29 insertions(+), 32 deletions(-) diff --git a/services/horizon/internal/integration/contracts/Cargo.lock b/services/horizon/internal/integration/contracts/Cargo.lock index 07b698504d..ec405876da 100644 --- a/services/horizon/internal/integration/contracts/Cargo.lock +++ b/services/horizon/internal/integration/contracts/Cargo.lock @@ -919,8 +919,8 @@ checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" [[package]] name = "soroban-env-common" -version = "0.0.17" -source = "git+https://github.com/stellar/rs-soroban-env?rev=eb5a9ba053a7b64a8eff605db625525378f7bea0#eb5a9ba053a7b64a8eff605db625525378f7bea0" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c63bff68a15d79aca3a705ee6916a68db57b7e6#8c63bff68a15d79aca3a705ee6916a68db57b7e6" dependencies = [ "arbitrary", "crate-git-revision", @@ -936,8 +936,8 @@ dependencies = [ [[package]] name = "soroban-env-guest" -version = "0.0.17" -source = "git+https://github.com/stellar/rs-soroban-env?rev=eb5a9ba053a7b64a8eff605db625525378f7bea0#eb5a9ba053a7b64a8eff605db625525378f7bea0" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c63bff68a15d79aca3a705ee6916a68db57b7e6#8c63bff68a15d79aca3a705ee6916a68db57b7e6" dependencies = [ "soroban-env-common", "static_assertions", @@ -945,16 +945,13 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "0.0.17" -source = "git+https://github.com/stellar/rs-soroban-env?rev=eb5a9ba053a7b64a8eff605db625525378f7bea0#eb5a9ba053a7b64a8eff605db625525378f7bea0" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c63bff68a15d79aca3a705ee6916a68db57b7e6#8c63bff68a15d79aca3a705ee6916a68db57b7e6" dependencies = [ "backtrace", - "curve25519-dalek", "ed25519-dalek", "getrandom", - "hex", "k256", - "log", "num-derive", "num-integer", "num-traits", @@ -971,8 +968,8 @@ dependencies = [ [[package]] name = "soroban-env-macros" -version = "0.0.17" -source = "git+https://github.com/stellar/rs-soroban-env?rev=eb5a9ba053a7b64a8eff605db625525378f7bea0#eb5a9ba053a7b64a8eff605db625525378f7bea0" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c63bff68a15d79aca3a705ee6916a68db57b7e6#8c63bff68a15d79aca3a705ee6916a68db57b7e6" dependencies = [ "itertools", "proc-macro2", @@ -992,8 +989,8 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "0.9.2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=18b8fa1a358aa84afd196e2f6d44942798c8f335#18b8fa1a358aa84afd196e2f6d44942798c8f335" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=0992413f9b05e5bfb1f872bce99e89d9129b2e61#0992413f9b05e5bfb1f872bce99e89d9129b2e61" dependencies = [ "serde", "serde_json", @@ -1004,8 +1001,8 @@ dependencies = [ [[package]] name = "soroban-native-sdk-macros" -version = "0.0.17" -source = "git+https://github.com/stellar/rs-soroban-env?rev=eb5a9ba053a7b64a8eff605db625525378f7bea0#eb5a9ba053a7b64a8eff605db625525378f7bea0" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-env?rev=8c63bff68a15d79aca3a705ee6916a68db57b7e6#8c63bff68a15d79aca3a705ee6916a68db57b7e6" dependencies = [ "itertools", "proc-macro2", @@ -1022,8 +1019,8 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "0.9.2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=18b8fa1a358aa84afd196e2f6d44942798c8f335#18b8fa1a358aa84afd196e2f6d44942798c8f335" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=0992413f9b05e5bfb1f872bce99e89d9129b2e61#0992413f9b05e5bfb1f872bce99e89d9129b2e61" dependencies = [ "arbitrary", "bytes-lit", @@ -1039,8 +1036,8 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "0.9.2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=18b8fa1a358aa84afd196e2f6d44942798c8f335#18b8fa1a358aa84afd196e2f6d44942798c8f335" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=0992413f9b05e5bfb1f872bce99e89d9129b2e61#0992413f9b05e5bfb1f872bce99e89d9129b2e61" dependencies = [ "crate-git-revision", "darling", @@ -1058,8 +1055,8 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "0.9.2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=18b8fa1a358aa84afd196e2f6d44942798c8f335#18b8fa1a358aa84afd196e2f6d44942798c8f335" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=0992413f9b05e5bfb1f872bce99e89d9129b2e61#0992413f9b05e5bfb1f872bce99e89d9129b2e61" dependencies = [ "base64 0.13.1", "stellar-xdr", @@ -1069,8 +1066,8 @@ dependencies = [ [[package]] name = "soroban-spec-rust" -version = "0.9.2" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=18b8fa1a358aa84afd196e2f6d44942798c8f335#18b8fa1a358aa84afd196e2f6d44942798c8f335" +version = "20.0.0-rc2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=0992413f9b05e5bfb1f872bce99e89d9129b2e61#0992413f9b05e5bfb1f872bce99e89d9129b2e61" dependencies = [ "prettyplease", "proc-macro2", @@ -1084,8 +1081,8 @@ dependencies = [ [[package]] name = "soroban-wasmi" -version = "0.30.0-soroban" -source = "git+https://github.com/stellar/wasmi?rev=284c963ba080703061797e2a3cba0853edee0dd4#284c963ba080703061797e2a3cba0853edee0dd4" +version = "0.31.0-soroban1" +source = "git+https://github.com/stellar/wasmi?rev=7e63b4c9e08c4163f417d118d81f7ea34789d0be#7e63b4c9e08c4163f417d118d81f7ea34789d0be" dependencies = [ "smallvec", "spin", @@ -1134,8 +1131,8 @@ dependencies = [ [[package]] name = "stellar-xdr" -version = "0.0.17" -source = "git+https://github.com/stellar/rs-stellar-xdr?rev=39904e09941046dab61e6e35fc89e31bf2dea1cd#39904e09941046dab61e6e35fc89e31bf2dea1cd" +version = "20.0.0-rc1" +source = "git+https://github.com/stellar/rs-stellar-xdr?rev=d5ce0c9e7aa83461773a6e81662067f35d39e4c1#d5ce0c9e7aa83461773a6e81662067f35d39e4c1" dependencies = [ "arbitrary", "base64 0.13.1", @@ -1297,12 +1294,12 @@ checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" [[package]] name = "wasmi_arena" version = "0.4.0" -source = "git+https://github.com/stellar/wasmi?rev=284c963ba080703061797e2a3cba0853edee0dd4#284c963ba080703061797e2a3cba0853edee0dd4" +source = "git+https://github.com/stellar/wasmi?rev=7e63b4c9e08c4163f417d118d81f7ea34789d0be#7e63b4c9e08c4163f417d118d81f7ea34789d0be" [[package]] name = "wasmi_core" -version = "0.12.0" -source = "git+https://github.com/stellar/wasmi?rev=284c963ba080703061797e2a3cba0853edee0dd4#284c963ba080703061797e2a3cba0853edee0dd4" +version = "0.13.0" +source = "git+https://github.com/stellar/wasmi?rev=7e63b4c9e08c4163f417d118d81f7ea34789d0be#7e63b4c9e08c4163f417d118d81f7ea34789d0be" dependencies = [ "downcast-rs", "libm", diff --git a/services/horizon/internal/integration/contracts/Cargo.toml b/services/horizon/internal/integration/contracts/Cargo.toml index 7e413dfed7..1c65ebeb4d 100644 --- a/services/horizon/internal/integration/contracts/Cargo.toml +++ b/services/horizon/internal/integration/contracts/Cargo.toml @@ -22,6 +22,6 @@ codegen-units = 1 lto = true [workspace.dependencies.soroban-sdk] -version = "20.0.0-rc1" +version = "20.0.0-rc2" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "f743d6f9e49caa08924318907cd0588b60d7f187" +rev = "0992413f9b05e5bfb1f872bce99e89d9129b2e61" diff --git a/services/horizon/internal/integration/testdata/soroban_add_u64.wasm b/services/horizon/internal/integration/testdata/soroban_add_u64.wasm index 638cf8f7c04711e0d4c97aa8aa0845063ced5e7c..d8707674daa77dd316b9e6e83461a27278c61213 100755 GIT binary patch delta 90 zcmaFG@||TuJ4+7}YwW~sRZgeo2@MSmjEamCH~eKRp1h9H&cxWrKo1CYi;|6$4J<8< tObm_FERzgOQ%#f7k_^)<%#D(gQ!Oo1Ei6+k4UH_5j8e@EC(AJT0RS>b8yx@u delta 76 zcmey)@``0bJ4-VYYskcI)rmX*GUiX-&S+<#XP{@PXQXUskz|pUXqaehYLS>|VUn1Z gVrXfWYLsS{Vq#)xVq|VY;4LfS(C{R0L$AJzW@LL diff --git a/services/horizon/internal/integration/testdata/soroban_increment_contract.wasm b/services/horizon/internal/integration/testdata/soroban_increment_contract.wasm index aa304ecb1db1e7630fa93e918f414dbbad7fa3a1..37c5933e7cacb96df5c219990dd891d40ad88c90 100755 GIT binary patch delta 70 zcmdnVx|ems6-LJ5$yXWeOpJ{T^ng&eDA`Eaz|zvl#Lzg+GReR+)ifzB$uP~r+$bqI Y)zUK6!ZO9u(8w~$DAmkxvNKZ|0Od&(Bme*a delta 66 zcmdnXx|4Oo6-LJV$yXWe4D<~2EcJ|(4K0!^(h?05jZG~Q6D>><(^3pA%~Flh%u-BD WEKQ8eEiIBQ(u|Ew878|kl>q>qWD>pr diff --git a/services/horizon/internal/integration/testdata/soroban_sac_test.wasm b/services/horizon/internal/integration/testdata/soroban_sac_test.wasm index 48e2fcb1cc248af0dc15bc86c04ab87b070deed5..2beae584d69549bbf94f6e1f39412e0a87c5e7a5 100755 GIT binary patch delta 445 zcmZ9I&r8EF6vy+DcJ1hN-N`8ksoTK`O56R+MQvdSo)o+bot>;8h~8IW>O6SZjGpvA z@FMtE=)dB{vjg#EdYK6%-}mx;pO@rw{xUy0&i0@|2t<&KPsi{sDNNu-e#2wo3mBwY zAJWnV4idQXnJ&}4wtS-}V9F*dm&_!f_N_X#AJobraFg=X9@4ypp(#_gkR1Sp6#8^q zKC#8aojJluU?&{Htzna4fXYN==BUL+-p(H(~BdaB?T!2YVyYlXxC ztmYu8whu#jpzRih^#2oHw563IcDC;nhtmox?zQngG+0e43=t~D<%j0xZB98sGHyEd zk!!ls#!@4}grUr;xe=I&W8{csagApXQ%nLj^CfilOVA_M0FxnO6aWAK delta 446 zcmY*VJxjw-6utMoG>N3O!NHF~c(EPqQqneUlBJpqfO4%Ua0 z;3O1W-JDz?=L&7cS&L@Co9Ltl~&~kyEsVON&LD2gJNjRP!m>45f<~Q-4VEhWy*2N0-zt!9MAU z7rN5g%0Y-0%@V1G8v{#`pbsnzL6T@Bz|g!-;u6igNndC%neI|u0(B`c2u#itv8e3g ztvFJ4T6bi&?ifzi$bS{G$snBKW%vzyIbbBvxeR_x8&deni*@`<4of+fh8#YNfk}zSy~nhgDFgvqQ?U|a~2YeXU-xm;x!XvR~Ty3 wF56|lTrE_*wiid0s8;u)$aA8&Q}G)I)wt1d9N($BzPIniwOSqC&s7co0FjSoVgLXD From db5f25015c275ac6c008c6df013aada9c1f26ef3 Mon Sep 17 00:00:00 2001 From: marta-lokhova Date: Thu, 3 Aug 2023 10:43:54 -0700 Subject: [PATCH 2/3] Bump core to v19.14.0 --- .github/workflows/horizon.yml | 6 +++--- exp/tools/dump-ledger-state/Dockerfile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/horizon.yml b/.github/workflows/horizon.yml index 5720fbe7e7..d2cd0ccf04 100644 --- a/.github/workflows/horizon.yml +++ b/.github/workflows/horizon.yml @@ -36,8 +36,8 @@ jobs: PROTOCOL_20_CORE_DEBIAN_PKG_VERSION: 19.13.1-1481.3acf6dd26.focal PROTOCOL_20_CORE_DOCKER_IMG: stellar/stellar-core:19.13.1-1481.3acf6dd26.focal PROTOCOL_20_SOROBAN_RPC_DOCKER_IMG: stellar/soroban-rpc:20.0.0-rc1-35 - PROTOCOL_19_CORE_DEBIAN_PKG_VERSION: 19.12.0-1378.2109a168a.focal - PROTOCOL_19_CORE_DOCKER_IMG: stellar/stellar-core:19.12.0-1378.2109a168a.focal + PROTOCOL_19_CORE_DEBIAN_PKG_VERSION: 19.14.0-1500.5664eff4e.focal + PROTOCOL_19_CORE_DOCKER_IMG: stellar/stellar-core:19.14.0-1500.5664eff4e.focal PGHOST: localhost PGPORT: 5432 PGUSER: postgres @@ -133,7 +133,7 @@ jobs: name: Test (and push) verify-range image runs-on: ubuntu-22.04 env: - STELLAR_CORE_VERSION: 19.12.0-1378.2109a168a.focal + STELLAR_CORE_VERSION: 19.14.0-1500.5664eff4e.focal CAPTIVE_CORE_STORAGE_PATH: /tmp steps: - uses: actions/checkout@v3 diff --git a/exp/tools/dump-ledger-state/Dockerfile b/exp/tools/dump-ledger-state/Dockerfile index d19b668916..07a0da0128 100644 --- a/exp/tools/dump-ledger-state/Dockerfile +++ b/exp/tools/dump-ledger-state/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:20.04 -ENV STELLAR_CORE_VERSION=19.12.0-1378.2109a168a.focal +ENV STELLAR_CORE_VERSION=19.14.0-1500.5664eff4e.focal ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates curl wget gnupg apt-utils From 2b876cd781b6dd0c218dcdd4f300900f87b3889e Mon Sep 17 00:00:00 2001 From: urvisavla Date: Tue, 19 Sep 2023 22:47:25 -0700 Subject: [PATCH 3/3] services/horizon: Fixing Claimable Balances Query Limit Issue (#5032) --- .../db2/history/claimable_balances.go | 33 ++-- .../db2/history/claimable_balances_test.go | 181 ++++++++++++++++++ 2 files changed, 202 insertions(+), 12 deletions(-) diff --git a/services/horizon/internal/db2/history/claimable_balances.go b/services/horizon/internal/db2/history/claimable_balances.go index ece94c390b..48722a11c3 100644 --- a/services/horizon/internal/db2/history/claimable_balances.go +++ b/services/horizon/internal/db2/history/claimable_balances.go @@ -247,21 +247,30 @@ func (q *Q) GetClaimableBalances(ctx context.Context, query ClaimableBalancesQue return nil, errors.Wrap(err, "could not apply query to page") } - if query.Asset != nil { - // when search by asset, profiling has shown best performance to have the LIMIT on inner query - sql = sql.Where("cb.asset = ?", query.Asset) - } + if query.Asset != nil || query.Sponsor != nil { - if query.Sponsor != nil { - sql = sql.Where("cb.sponsor = ?", query.Sponsor.Address()) - } + // JOIN with claimable_balance_claimants table to query by claimants + if query.Claimant != nil { + sql = sql.Join("claimable_balance_claimants on claimable_balance_claimants.id = cb.id") + sql = sql.Where("claimable_balance_claimants.destination = ?", query.Claimant.Address()) + } + + // Apply filters for asset and sponsor + if query.Asset != nil { + sql = sql.Where("cb.asset = ?", query.Asset) + } + if query.Sponsor != nil { + sql = sql.Where("cb.sponsor = ?", query.Sponsor.Address()) + } + + } else if query.Claimant != nil { + // If only the claimant is provided without additional filters, a JOIN with claimable_balance_claimants + // does not perform efficiently. Instead, use a subquery (with LIMIT) to retrieve claimable balances based on + // the claimant's address. - if query.Claimant != nil { var selectClaimableBalanceClaimants = sq.Select("id").From("claimable_balance_claimants"). - Where("destination = ?", query.Claimant.Address()). - // Given that each destination can be a claimant for each balance maximum once - // we can LIMIT the subquery. - Limit(query.PageQuery.Limit) + Where("destination = ?", query.Claimant.Address()).Limit(query.PageQuery.Limit) + subSql, err := applyClaimableBalancesQueriesCursor(selectClaimableBalanceClaimants, l, r, query.PageQuery.Order) if err != nil { return nil, errors.Wrap(err, "could not apply subquery to page") diff --git a/services/horizon/internal/db2/history/claimable_balances_test.go b/services/horizon/internal/db2/history/claimable_balances_test.go index 49cc722f57..238b03da68 100644 --- a/services/horizon/internal/db2/history/claimable_balances_test.go +++ b/services/horizon/internal/db2/history/claimable_balances_test.go @@ -233,6 +233,187 @@ func TestFindClaimableBalancesByDestination(t *testing.T) { tt.Assert.Len(cbs, 1) } +func insertClaimants(q *Q, tt *test.T, cBalance ClaimableBalance) error { + claimantsInsertBuilder := q.NewClaimableBalanceClaimantBatchInsertBuilder(10) + for _, claimant := range cBalance.Claimants { + claimant := ClaimableBalanceClaimant{ + BalanceID: cBalance.BalanceID, + Destination: claimant.Destination, + LastModifiedLedger: cBalance.LastModifiedLedger, + } + err := claimantsInsertBuilder.Add(tt.Ctx, claimant) + if err != nil { + return err + } + } + return claimantsInsertBuilder.Exec(tt.Ctx) +} + +type claimableBalanceQueryResult struct { + Claimants []string + Asset string + Sponsor string +} + +func validateClaimableBalanceQuery(t *test.T, q *Q, query ClaimableBalancesQuery, expectedQueryResult []claimableBalanceQueryResult) { + cbs, err := q.GetClaimableBalances(t.Ctx, query) + t.Assert.NoError(err) + for i, expected := range expectedQueryResult { + for j, claimant := range expected.Claimants { + t.Assert.Equal(claimant, cbs[i].Claimants[j].Destination) + } + if expected.Asset != "" { + t.Assert.Equal(expected.Asset, cbs[i].Asset.String()) + } + if expected.Sponsor != "" { + t.Assert.Equal(expected.Sponsor, cbs[i].Sponsor.String) + } + } +} + +// TestFindClaimableBalancesByDestinationWithLimit tests querying claimable balances by destination and asset +func TestFindClaimableBalancesByDestinationWithLimit(t *testing.T) { + tt := test.Start(t) + defer tt.Finish() + + test.ResetHorizonDB(t, tt.HorizonDB) + q := &Q{tt.HorizonSession()} + + assetIssuer := "GA25GQLHJU3LPEJXEIAXK23AWEA5GWDUGRSHTQHDFT6HXHVMRULSQJUJ" + asset1 := xdr.MustNewCreditAsset("ASSET1", assetIssuer) + asset2 := xdr.MustNewCreditAsset("ASSET2", assetIssuer) + + sponsor1 := "GA25GQLHJU3LPEJXEIAXK23AWEA5GWDUGRSHTQHDFT6HXHVMRULSQJUJ" + sponsor2 := "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H" + + dest1 := "GC3C4AKRBQLHOJ45U4XG35ESVWRDECWO5XLDGYADO6DPR3L7KIDVUMML" + dest2 := "GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H" + + claimants := []Claimant{ + { + Destination: dest1, + Predicate: xdr.ClaimPredicate{ + Type: xdr.ClaimPredicateTypeClaimPredicateUnconditional, + }, + }, + { + Destination: dest2, + Predicate: xdr.ClaimPredicate{ + Type: xdr.ClaimPredicateTypeClaimPredicateUnconditional, + }, + }, + } + + balanceID1 := xdr.ClaimableBalanceId{ + Type: xdr.ClaimableBalanceIdTypeClaimableBalanceIdTypeV0, + V0: &xdr.Hash{1, 2, 3}, + } + id, err := xdr.MarshalHex(balanceID1) + tt.Assert.NoError(err) + cBalance1 := ClaimableBalance{ + BalanceID: id, + Claimants: claimants, + Asset: asset1, + Sponsor: null.StringFrom(sponsor1), + LastModifiedLedger: 123, + Amount: 10, + } + err = q.UpsertClaimableBalances(tt.Ctx, []ClaimableBalance{cBalance1}) + tt.Assert.NoError(err) + + claimants2 := []Claimant{ + { + Destination: dest2, + Predicate: xdr.ClaimPredicate{ + Type: xdr.ClaimPredicateTypeClaimPredicateUnconditional, + }, + }, + } + + balanceID2 := xdr.ClaimableBalanceId{ + Type: xdr.ClaimableBalanceIdTypeClaimableBalanceIdTypeV0, + V0: &xdr.Hash{4, 5, 6}, + } + id, err = xdr.MarshalHex(balanceID2) + tt.Assert.NoError(err) + cBalance2 := ClaimableBalance{ + BalanceID: id, + Claimants: claimants2, + Asset: asset2, + Sponsor: null.StringFrom(sponsor2), + + LastModifiedLedger: 456, + Amount: 10, + } + err = q.UpsertClaimableBalances(tt.Ctx, []ClaimableBalance{cBalance2}) + tt.Assert.NoError(err) + + err = insertClaimants(q, tt, cBalance1) + tt.Assert.NoError(err) + + err = insertClaimants(q, tt, cBalance2) + tt.Assert.NoError(err) + + pageQuery := db2.MustPageQuery("", false, "", 1) + + // no claimant parameter, no filters + query := ClaimableBalancesQuery{ + PageQuery: pageQuery, + } + validateClaimableBalanceQuery(tt, q, query, []claimableBalanceQueryResult{ + {Claimants: []string{dest1, dest2}}, + }) + + // invalid claimant parameter + query = ClaimableBalancesQuery{ + PageQuery: pageQuery, + Claimant: xdr.MustAddressPtr("GA25GQLHJU3LPEJXEIAXK23AWEA5GWDUGRSHTQHDFT6HXHVMRULSQJUJ"), + Asset: &asset2, + Sponsor: xdr.MustAddressPtr(sponsor1), + } + validateClaimableBalanceQuery(tt, q, query, []claimableBalanceQueryResult{}) + + // claimant parameter, no filters + query = ClaimableBalancesQuery{ + PageQuery: pageQuery, + Claimant: xdr.MustAddressPtr(dest1), + } + validateClaimableBalanceQuery(tt, q, query, []claimableBalanceQueryResult{ + {Claimants: []string{dest1, dest2}}, + }) + + // claimant parameter, asset filter + query = ClaimableBalancesQuery{ + PageQuery: pageQuery, + Claimant: xdr.MustAddressPtr(dest2), + Asset: &asset1, + } + validateClaimableBalanceQuery(tt, q, query, []claimableBalanceQueryResult{ + {Claimants: []string{dest1, dest2}, Asset: asset1.String()}, + }) + + // claimant parameter, sponsor filter + query = ClaimableBalancesQuery{ + PageQuery: pageQuery, + Claimant: xdr.MustAddressPtr(dest2), + Sponsor: xdr.MustAddressPtr(sponsor1), + } + validateClaimableBalanceQuery(tt, q, query, []claimableBalanceQueryResult{ + {Claimants: []string{dest1, dest2}, Sponsor: sponsor1}, + }) + + //claimant parameter, asset filter, sponsor filter + query = ClaimableBalancesQuery{ + PageQuery: pageQuery, + Claimant: xdr.MustAddressPtr(dest2), + Asset: &asset2, + Sponsor: xdr.MustAddressPtr(sponsor2), + } + validateClaimableBalanceQuery(tt, q, query, []claimableBalanceQueryResult{ + {Claimants: []string{dest2}, Asset: asset2.String(), Sponsor: sponsor2}, + }) +} + func TestUpdateClaimableBalance(t *testing.T) { tt := test.Start(t) defer tt.Finish()