diff --git a/example/lib/stellar_quest/series_2/05_claim_claimable_balance.dart b/example/lib/stellar_quest/series_2/05_claim_claimable_balance.dart index f880dfa..4defaf2 100644 --- a/example/lib/stellar_quest/series_2/05_claim_claimable_balance.dart +++ b/example/lib/stellar_quest/series_2/05_claim_claimable_balance.dart @@ -40,7 +40,7 @@ Future getLatestClaimbaleBalance( .forClaimant(sourceKeyPair.accountId) .order(RequestBuilderOrder.DESC) .execute(); - assert(claimableBalances.records!.isNotEmpty); + assert(claimableBalances.records.isNotEmpty); - return claimableBalances.records!.first; + return claimableBalances.records.first; } diff --git a/lib/src/responses/response.dart b/lib/src/responses/response.dart index bb8b2b5..df0359b 100644 --- a/lib/src/responses/response.dart +++ b/lib/src/responses/response.dart @@ -6,7 +6,6 @@ import 'package:http/http.dart' as http; import 'claimable_balance_response.dart'; import 'liquidity_pool_response.dart'; import 'dart:async'; -import '../util.dart'; import '../requests/request_builder.dart'; import 'effects/effect_responses.dart'; import 'operations/operation_responses.dart'; @@ -79,7 +78,8 @@ class Link { return Link(json['href'], json['templated']); } - Map toJson() => {'href': href, 'templated': templated}; + Map toJson() => + {'href': href, 'templated': templated}; } /// Links connected to page response. @@ -113,28 +113,28 @@ abstract class TypedResponse { /// Represents page of objects. class Page extends Response implements TypedResponse> { - List? records; - // List? records; + List records; + PageLinks? links; - late TypeToken> type; + TypeToken> type; - Page(); + Page(this.records, this.links, this.type); ///The next page of results or null when there is no link for the next page of results Future?> getNextPage(http.Client httpClient) async { - if (this.links!.next == null) { + if (this.links?.next == null) { return null; } - checkNotNull( - this.type, - "type cannot be null, is it being correctly set after the creation of this " + - this.runtimeType.toString() + - "?"); - ResponseHandler> responseHandler = ResponseHandler>(this.type); - String? url = this.links!.next!.href; - return await httpClient.get(Uri.parse(url), headers: RequestBuilder.headers).then((response) { + ResponseHandler> responseHandler = + ResponseHandler>(this.type); + + String url = this.links!.next!.href; + + return await httpClient + .get(Uri.parse(url), headers: RequestBuilder.headers) + .then((response) { return responseHandler.handleResponse(response); }); } @@ -144,16 +144,16 @@ class Page extends Response implements TypedResponse> { this.type = type; } - factory Page.fromJson(Map json) => Page() + factory Page.fromJson(Map json) => Page( + json["_embedded"]['records'] != null + ? List.from(json["_embedded"]['records'] + .map((e) => ResponseConverter.fromJson(e) as T)) + : [], + json['_links'] == null ? null : PageLinks.fromJson(json['_links']), + TypeToken>()) ..rateLimitLimit = convertInt(json['rateLimitLimit']) ..rateLimitRemaining = convertInt(json['rateLimitRemaining']) - ..rateLimitReset = convertInt(json['rateLimitReset']) - ..records = json["_embedded"]['records'] != null - ? List.from( - json["_embedded"]['records'].map((e) => ResponseConverter.fromJson(e) as T)) - : null - ..links = json['_links'] == null ? null : PageLinks.fromJson(json['_links']) - ..setType(TypeToken>()); + ..rateLimitReset = convertInt(json['rateLimitReset']); } class ResponseConverter { diff --git a/test/account_test.dart b/test/account_test.dart index 7aa3e75..12f3b5c 100644 --- a/test/account_test.dart +++ b/test/account_test.dart @@ -76,13 +76,20 @@ void main() { // Find account for signer. Page accounts = await sdk.accounts.forSigner(keyPairB.accountId).execute(); aFound = false; - for (AccountResponse? account in accounts.records!) { + for (AccountResponse? account in accounts.records) { if (account!.accountId == keyPairA.accountId) { aFound = true; break; } } assert(aFound); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations.forAccount(accountAId).execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects.forAccount(accountAId).execute(); + assert(effectsPage.records.isNotEmpty); + }); test('test find accounts for asset', () async { @@ -124,12 +131,22 @@ void main() { AccountsRequestBuilder ab = sdk.accounts.forAsset(iomAsset); Page accounts = await ab.execute(); bool cFound = false; - for (AccountResponse? account in accounts.records!) { - if (account!.accountId == keyPairC.accountId) { + for (AccountResponse account in accounts.records) { + if (account.accountId == keyPairC.accountId) { cFound = true; } } assert(cFound); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations.forAccount(accountAId).execute(); + assert(operationsPage.records.isNotEmpty); + operationsPage = await sdk.operations.forAccount(accountCId).execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects.forAccount(accountAId).execute(); + assert(effectsPage.records.isNotEmpty); + effectsPage = await sdk.effects.forAccount(accountCId).execute(); + assert(effectsPage.records.isNotEmpty); }); test('test account merge', () async { @@ -160,6 +177,17 @@ void main() { print(error.toString()); assert(error is ErrorResponse && error.code == 404); }); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations.forAccount(accountXId).execute(); + assert(operationsPage.records.isNotEmpty); + operationsPage = await sdk.operations.forAccount(accountYId).execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects.forAccount(accountXId).execute(); + assert(effectsPage.records.isNotEmpty); + effectsPage = await sdk.effects.forAccount(accountYId).execute(); + assert(effectsPage.records.isNotEmpty); + }); test('test account merge muxed source and destination account', () async { @@ -198,6 +226,16 @@ void main() { print(error.toString()); assert(error is ErrorResponse && error.code == 404); }); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations.forAccount(accountXId).execute(); + assert(operationsPage.records.isNotEmpty); + operationsPage = await sdk.operations.forAccount(accountYId).execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects.forAccount(accountXId).execute(); + assert(effectsPage.records.isNotEmpty); + effectsPage = await sdk.effects.forAccount(accountYId).execute(); + assert(effectsPage.records.isNotEmpty); }); test('test bump sequence', () async { @@ -224,6 +262,12 @@ void main() { account = await sdk.accounts.account(accountId); assert(startSequence + 10 == account.sequenceNumber); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations.forAccount(accountId).execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects.forAccount(accountId).execute(); + assert(effectsPage.records.isNotEmpty); }); test('test manage data', () async { @@ -268,6 +312,13 @@ void main() { account = await sdk.accounts.account(accountId); assert(!account.data.keys.contains(key)); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations.forAccount(accountId).execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects.forAccount(accountId).execute(); + assert(effectsPage.records.isNotEmpty); + }); test('test muxed account ID (M..)', () { diff --git a/test/amm_test.dart b/test/amm_test.dart index d127283..506aa9f 100644 --- a/test/amm_test.dart +++ b/test/amm_test.dart @@ -27,10 +27,10 @@ void main() { String sourceAccountId = testAccountKeyPair.accountId; AccountResponse sourceAccount = await sdk.accounts.account(sourceAccountId); - ChangeTrustOperationBuilder ctOpB1 = - ChangeTrustOperationBuilder(assetA, ChangeTrustOperationBuilder.MAX_LIMIT); - ChangeTrustOperationBuilder ctOpB2 = - ChangeTrustOperationBuilder(assetB, ChangeTrustOperationBuilder.MAX_LIMIT); + ChangeTrustOperationBuilder ctOpB1 = ChangeTrustOperationBuilder( + assetA, ChangeTrustOperationBuilder.MAX_LIMIT); + ChangeTrustOperationBuilder ctOpB2 = ChangeTrustOperationBuilder( + assetB, ChangeTrustOperationBuilder.MAX_LIMIT); Transaction transaction = TransactionBuilder(sourceAccount) .addOperation(ctOpB1.build()) .addOperation(ctOpB2.build()) @@ -58,6 +58,16 @@ void main() { await sdk.submitTransaction(transaction); assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(assetAIssueAccountKeyPair.accountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(assetAIssueAccountKeyPair.accountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); group('all tests', () { @@ -68,8 +78,8 @@ void main() { AssetTypePoolShare poolShareAsset = AssetTypePoolShare(assetA: assetA, assetB: assetB); - ChangeTrustOperationBuilder chOp = - ChangeTrustOperationBuilder(poolShareAsset, ChangeTrustOperationBuilder.MAX_LIMIT); + ChangeTrustOperationBuilder chOp = ChangeTrustOperationBuilder( + poolShareAsset, ChangeTrustOperationBuilder.MAX_LIMIT); Transaction transaction = TransactionBuilder(sourceAccount).addOperation(chOp.build()).build(); @@ -91,9 +101,19 @@ void main() { .limit(4) .order(RequestBuilderOrder.ASC) .execute(); - List pools = myPage.records!; + List pools = myPage.records; nonNativeLiquidityPoolId = pools.first.poolId; print("NNPID: " + nonNativeLiquidityPoolId); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(sourceAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(sourceAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('create pool share trustline native', () async { @@ -102,8 +122,8 @@ void main() { AssetTypePoolShare poolShareAsset = AssetTypePoolShare(assetA: assetNative, assetB: assetB); - ChangeTrustOperationBuilder chOp = - ChangeTrustOperationBuilder(poolShareAsset, ChangeTrustOperationBuilder.MAX_LIMIT); + ChangeTrustOperationBuilder chOp = ChangeTrustOperationBuilder( + poolShareAsset, ChangeTrustOperationBuilder.MAX_LIMIT); AccountResponse sourceAccount = await sdk.accounts.account(sourceAccountId); @@ -128,9 +148,19 @@ void main() { .limit(4) .order(RequestBuilderOrder.ASC) .execute(); - List pools = myPage.records!; + List pools = myPage.records; nativeLiquidityPoolId = pools.first.poolId; print("NATPID: " + nativeLiquidityPoolId); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(sourceAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(sourceAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('deposit non native', () async { @@ -163,6 +193,16 @@ void main() { await sdk.submitTransaction(transaction); assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(sourceAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(sourceAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('deposit native', () async { KeyPair sourceAccountKeyPair = KeyPair.fromSecretSeed(seed); @@ -193,6 +233,16 @@ void main() { await sdk.submitTransaction(transaction); assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(sourceAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(sourceAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('withdraw non native', () async { @@ -223,6 +273,16 @@ void main() { await sdk.submitTransaction(transaction); assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(sourceAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(sourceAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('withdraw native', () async { @@ -253,6 +313,16 @@ void main() { await sdk.submitTransaction(transaction); assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(sourceAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(sourceAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('test liquidity pool queries', () async { @@ -261,7 +331,7 @@ void main() { .limit(4) .order(RequestBuilderOrder.ASC) .execute(); - List effects = effectsPage.records!; + List effects = effectsPage.records; assert(effects.length == 4); assert(effects[0] is TrustlineCreatedEffectResponse); assert(effects[1] is LiquidityPoolCreatedEffectResponse); @@ -273,8 +343,8 @@ void main() { .limit(1) .order(RequestBuilderOrder.DESC) .execute(); - assert(transactionsPage.records!.length == 1); - TransactionResponse transaction = transactionsPage.records!.first; + assert(transactionsPage.records.length == 1); + TransactionResponse transaction = transactionsPage.records.first; effectsPage = await sdk.effects .forTransaction(transaction.hash) .limit(3) @@ -288,7 +358,7 @@ void main() { .order(RequestBuilderOrder.ASC) .execute(); - List operations = operationsPage.records!; + List operations = operationsPage.records; assert(operations.length == 3); assert(operations[0] is ChangeTrustOperationResponse); assert(operations[1] is LiquidityPoolDepositOperationResponse); @@ -299,7 +369,7 @@ void main() { .order(RequestBuilderOrder.ASC) .execute(); - List pools = poolsPage.records!; + List pools = poolsPage.records; assert(pools.length == 4); LiquidityPoolResponse nonNativeLiquidityPool = @@ -312,7 +382,7 @@ void main() { .limit(4) .order(RequestBuilderOrder.ASC) .execute(); - pools = myPage.records!; + pools = myPage.records; assert(pools.first.poolId == nonNativeLiquidityPoolId); KeyPair accXKp = KeyPair.random(); @@ -323,11 +393,11 @@ void main() { await FriendBot.fundTestAccount(accYId); AccountResponse accX = await sdk.accounts.account(accXId); - ChangeTrustOperationBuilder ctOpB1 = - ChangeTrustOperationBuilder(assetA, ChangeTrustOperationBuilder.MAX_LIMIT); + ChangeTrustOperationBuilder ctOpB1 = ChangeTrustOperationBuilder( + assetA, ChangeTrustOperationBuilder.MAX_LIMIT); ctOpB1.setSourceAccount(accXId); - ChangeTrustOperationBuilder ctOpB2 = - ChangeTrustOperationBuilder(assetB, ChangeTrustOperationBuilder.MAX_LIMIT); + ChangeTrustOperationBuilder ctOpB2 = ChangeTrustOperationBuilder( + assetB, ChangeTrustOperationBuilder.MAX_LIMIT); ctOpB2.setSourceAccount(accYId); Transaction tx = TransactionBuilder(accX) .addOperation(ctOpB1.build()) @@ -366,7 +436,7 @@ void main() { .order(RequestBuilderOrder.ASC) .execute(); - List trades = tradesPage.records!; + List trades = tradesPage.records; assert(trades.first.baseLiquidityPoolId == nonNativeLiquidityPoolId); Page trades2Page = await sdk.liquidityPoolTrades @@ -374,15 +444,30 @@ void main() { .order(RequestBuilderOrder.ASC) .execute(); - List trades2 = trades2Page.records!; + List trades2 = trades2Page.records; assert(trades2.first.baseLiquidityPoolId == nonNativeLiquidityPoolId); + + // test operation & effects responses can be parsed + operationsPage = await sdk.operations + .forAccount(accXId) + .execute(); + assert(operationsPage.records.isNotEmpty); + effectsPage = await sdk.effects + .forAccount(accXId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); - test("parse liquidity pool resultXdr", (){ - final input = XdrDataInputStream(base64Decode("AAAAAAAAAGT/////AAAAAQAAAAAAAAAW/////AAAAAA=")); + test("parse liquidity pool resultXdr", () { + final input = XdrDataInputStream( + base64Decode("AAAAAAAAAGT/////AAAAAQAAAAAAAAAW/////AAAAAA=")); final result = XdrTransactionResult.decode(input); - final operationResult = (result.result.results.first as XdrOperationResult).tr!.liquidityPoolDepositResult; - assert(operationResult!.discriminant == XdrLiquidityPoolDepositResultCode.LIQUIDITY_POOL_DEPOSIT_UNDERFUNDED); + final operationResult = + (result.result.results.first as XdrOperationResult) + .tr! + .liquidityPoolDepositResult; + assert(operationResult!.discriminant == + XdrLiquidityPoolDepositResultCode.LIQUIDITY_POOL_DEPOSIT_UNDERFUNDED); }); }); } diff --git a/test/claimable_balance_test.dart b/test/claimable_balance_test.dart index 02b3dd6..a7b4d01 100644 --- a/test/claimable_balance_test.dart +++ b/test/claimable_balance_test.dart @@ -18,19 +18,24 @@ void main() { String fistClaimantId = firstClaimantKp.accountId; KeyPair secondClaimantKp = KeyPair.random(); - Claimant firstClaimant = Claimant(fistClaimantId, Claimant.predicateUnconditional()); + Claimant firstClaimant = + Claimant(fistClaimantId, Claimant.predicateUnconditional()); XdrClaimPredicate predicateA = Claimant.predicateBeforeRelativeTime(100); - XdrClaimPredicate predicateB = Claimant.predicateBeforeAbsoluteTime(1634000400); + XdrClaimPredicate predicateB = + Claimant.predicateBeforeAbsoluteTime(1634000400); XdrClaimPredicate predicateC = Claimant.predicateNot(predicateA); - XdrClaimPredicate predicateD = Claimant.predicateAnd(predicateC, predicateB); - XdrClaimPredicate predicateE = Claimant.predicateBeforeAbsoluteTime(1601671345); + XdrClaimPredicate predicateD = + Claimant.predicateAnd(predicateC, predicateB); + XdrClaimPredicate predicateE = + Claimant.predicateBeforeAbsoluteTime(1601671345); XdrClaimPredicate predicateF = Claimant.predicateOr(predicateD, predicateE); Claimant secondClaimant = Claimant(secondClaimantKp.accountId, predicateF); List claimants = []; claimants.add(firstClaimant); claimants.add(secondClaimant); CreateClaimableBalanceOperationBuilder opb = - CreateClaimableBalanceOperationBuilder(claimants, Asset.NATIVE, "12.33"); + CreateClaimableBalanceOperationBuilder( + claimants, Asset.NATIVE, "12.33"); Transaction transaction = new TransactionBuilder(sourceAccount) .addOperation(opb.build()) @@ -39,7 +44,8 @@ void main() { transaction.sign(sourceAccountKeyxPair, Network.TESTNET); - SubmitTransactionResponse response = await sdk.submitTransaction(transaction); + SubmitTransactionResponse response = + await sdk.submitTransaction(transaction); assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); @@ -48,8 +54,10 @@ void main() { .limit(5) .order(RequestBuilderOrder.DESC) .execute(); - List effects = effectsPage.records!; - assert(effects.length > 0); + + var effects = effectsPage.records; + assert(effects.isNotEmpty); + String? bid; for (EffectResponse res in effects) { if (res is ClaimableBalanceCreatedEffectResponse) { @@ -60,17 +68,24 @@ void main() { } } assert(bid != null); - print("bid: " + bid!); - Page claimableBalances = - await sdk.claimableBalances.forClaimant(firstClaimantKp.accountId).execute(); - assert(claimableBalances.records!.length == 1); - ClaimableBalanceResponse cb = claimableBalances.records![0]; + var operationsPage = + await sdk.operations.forAccount(sourceAccountId).execute(); + assert(operationsPage.records.isNotEmpty); + + Page claimableBalances = await sdk + .claimableBalances + .forClaimant(firstClaimantKp.accountId) + .execute(); + assert(claimableBalances.records.length == 1); + ClaimableBalanceResponse cb = claimableBalances.records[0]; await FriendBot.fundTestAccount(fistClaimantId); - ClaimClaimableBalanceOperationBuilder opc = ClaimClaimableBalanceOperationBuilder(cb.balanceId); + ClaimClaimableBalanceOperationBuilder opc = + ClaimClaimableBalanceOperationBuilder(cb.balanceId); - AccountResponse claimant = await sdk.accounts.account(firstClaimantKp.accountId); + AccountResponse claimant = + await sdk.accounts.account(firstClaimantKp.accountId); transaction = new TransactionBuilder(claimant) .addOperation(opc.build()) .addMemo(Memo.text("claimclaimablebalance")) @@ -83,5 +98,12 @@ void main() { response = await sdk.submitTransaction(transaction); assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); + + operationsPage = + await sdk.operations.forAccount(firstClaimantKp.accountId).execute(); + assert(operationsPage.records.isNotEmpty); + effectsPage = + await sdk.effects.forAccount(firstClaimantKp.accountId).execute(); + assert(effectsPage.records.isNotEmpty); }); } diff --git a/test/clawback_test.dart b/test/clawback_test.dart index 55f5556..fe7b628 100644 --- a/test/clawback_test.dart +++ b/test/clawback_test.dart @@ -182,8 +182,8 @@ void main() { Page claimableBalances = await sdk.claimableBalances.forClaimant(claimantAccountId).execute(); - assert(claimableBalances.records!.length == 1); - ClaimableBalanceResponse cb = claimableBalances.records![0]; + assert(claimableBalances.records.length == 1); + ClaimableBalanceResponse cb = claimableBalances.records[0]; String balanceId = cb.balanceId; print("claimable balance created: " + balanceId); @@ -203,16 +203,16 @@ void main() { print("claimable balance clawed back"); claimableBalances = await sdk.claimableBalances.forClaimant(claimantAccountId).execute(); - assert(claimableBalances.records!.length == 0); + assert(claimableBalances.records.length == 0); print("clawback claimable balance success"); - Page effectsPage = await sdk.effects + var effectsPage = await sdk.effects .forAccount(skyIssuerAccountId) .limit(5) .order(RequestBuilderOrder.DESC) .execute(); - List effects = effectsPage.records!; - assert(effects.length > 0); + var effects = effectsPage.records; + assert(effects.isNotEmpty); String? bid; for (EffectResponse res in effects) { if (res is ClaimableBalanceClawedBackEffectResponse) { @@ -243,7 +243,7 @@ void main() { .limit(5) .order(RequestBuilderOrder.DESC) .execute(); - effects = effectsPage.records!; + effects = effectsPage.records; assert(effects.length > 0); bool ok = false; @@ -269,5 +269,10 @@ void main() { } assert(ok); print("cleared trustline flag"); + + var operationsPage = await sdk.operations + .forAccount(skyIssuerAccountKeyPair.accountId) + .execute(); + assert(operationsPage.records.isNotEmpty); }); } diff --git a/test/examples_test.dart b/test/examples_test.dart index e3997c4..7fb3b32 100644 --- a/test/examples_test.dart +++ b/test/examples_test.dart @@ -351,7 +351,7 @@ void main() { .destinationAssets([ecoAsset]).execute(); // Here is our payment path. - List path = strictSendPaths.records!.first.path; + List path = strictSendPaths.records.first.path; // First path payment strict send. Send exactly 10 ONDE, receive minimum 38 ECO (it will be 40). PathPaymentStrictSendOperation strictSend = @@ -387,7 +387,7 @@ void main() { .execute(); // Here is our payment path. - path = strictReceivePaths.records!.first.path; + path = strictReceivePaths.records.first.path; // The sender sends max 2 ONDE. PathPaymentStrictReceiveOperation strictReceive = @@ -669,7 +669,7 @@ void main() { // Now let's load the offers of our account to see if the offer has been created. Page offers = await sdk.offers.forAccount(buyerAccountId).execute(); - OfferResponse offer = offers.records!.first; + OfferResponse offer = offers.records.first; String? buyingAssetCode = offer.buying is AssetTypeCreditAlphaNum ? (offer.buying as AssetTypeCreditAlphaNum).code @@ -706,7 +706,7 @@ void main() { // Load the offer from stellar. offers = (await sdk.offers.forAccount(buyerAccountId).execute()); - offer = offers.records!.first; + offer = offers.records.first; buyingAssetCode = offer.buying is AssetTypeCreditAlphaNum ? (offer.buying as AssetTypeCreditAlphaNum).code @@ -741,7 +741,7 @@ void main() { // check if the offer has been deleted. offers = await sdk.offers.forAccount(buyerAccountId).execute(); - if (offers.records!.length == 0) { + if (offers.records.length == 0) { print("success"); } }); @@ -800,7 +800,7 @@ void main() { // Now let's load the offers of our account to see if the offer has been created. Page offers = await sdk.offers.forAccount(sellerAccountId).execute(); - OfferResponse offer = offers.records!.first; + OfferResponse offer = offers.records.first; String? sellingAssetCode = offer.selling is AssetTypeCreditAlphaNum ? (offer.selling as AssetTypeCreditAlphaNum).code @@ -835,7 +835,7 @@ void main() { // Load again to see if it has been modified. offers = await sdk.offers.forAccount(sellerAccountId).execute(); - offer = offers.records!.first; + offer = offers.records.first; sellingAssetCode = offer.selling is AssetTypeCreditAlphaNum ? (offer.selling as AssetTypeCreditAlphaNum).code : "XLM"; @@ -865,7 +865,7 @@ void main() { // Check if the offer has been deleted. offers = await sdk.offers.forAccount(sellerAccountId).execute(); - if (offers.records!.length == 0) { + if (offers.records.length == 0) { print("success"); } }); @@ -925,7 +925,7 @@ void main() { // Now let's load the offers of our account to see if the offer has been created. Page offers = (await sdk.offers.forAccount(sellerAccountId).execute()); - OfferResponse offer = offers.records!.first; + OfferResponse offer = offers.records.first; String? sellingAssetCode = offer.selling is AssetTypeCreditAlphaNum ? (offer.selling as AssetTypeCreditAlphaNum).code @@ -962,7 +962,7 @@ void main() { // Load again to see if it has been modified. offers = await sdk.offers.forAccount(sellerAccountId).execute(); - offer = offers.records!.first; + offer = offers.records.first; sellingAssetCode = offer.selling is AssetTypeCreditAlphaNum ? (offer.selling as AssetTypeCreditAlphaNum).code @@ -993,7 +993,7 @@ void main() { // Check if the offer has been deleted. offers = await sdk.offers.forAccount(sellerAccountId).execute(); - if (offers.records!.length == 0) { + if (offers.records.length == 0) { print("success"); } }); @@ -1202,7 +1202,7 @@ void main() { // Check if the offer has been added. List? offers = (await sdk.offers.forAccount(trustorAccountId).execute()).records; - OfferResponse offer = offers!.first!; + OfferResponse offer = offers.first!; if (offer.buying == Asset.NATIVE && offer.selling == astroDollar) { print("offer found"); } @@ -1216,7 +1216,7 @@ void main() { // Check if the offer has been deleted. offers = (await sdk.offers.forAccount(trustorAccountId).execute()).records; - if (offers!.length == 0) { + if (offers.isEmpty) { print("success, offer has been deleted"); } @@ -1235,7 +1235,7 @@ void main() { // Check that the offer has been created. offers = (await sdk.offers.forAccount(trustorAccountId).execute()).records; - if (offers!.length == 1) { + if (offers.length == 1) { print("offer has been created"); } @@ -1249,7 +1249,7 @@ void main() { // Load the offers to see if our offer is still there. offers = (await sdk.offers.forAccount(trustorAccountId).execute()).records; - if (offers!.length == 1) { + if (offers.length == 1) { print("success, offer exists"); } diff --git a/test/fee_bump_transaction_test.dart b/test/fee_bump_transaction_test.dart index 79587b7..fa03255 100644 --- a/test/fee_bump_transaction_test.dart +++ b/test/fee_bump_transaction_test.dart @@ -51,6 +51,24 @@ void main() { transaction = await sdk.transactions.transaction(transaction.innerTransaction!.hash); assert(transaction.sourceAccount == sourceId); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(sourceId) + .execute(); + assert(operationsPage.records.isNotEmpty); + operationsPage = await sdk.operations + .forAccount(payerId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(sourceId) + .execute(); + assert(effectsPage.records.isNotEmpty); + effectsPage = await sdk.effects + .forAccount(payerId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('submit fee bump transaction - muxed accounts', () async { @@ -108,5 +126,23 @@ void main() { transaction = await sdk.transactions.transaction(transaction.innerTransaction!.hash); assert(transaction.sourceAccount == sourceId); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(sourceId) + .execute(); + assert(operationsPage.records.isNotEmpty); + operationsPage = await sdk.operations + .forAccount(payerId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(sourceId) + .execute(); + assert(effectsPage.records.isNotEmpty); + effectsPage = await sdk.effects + .forAccount(payerId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); } diff --git a/test/payments_test.dart b/test/payments_test.dart index b73fd2b..7c3848f 100644 --- a/test/payments_test.dart +++ b/test/payments_test.dart @@ -53,7 +53,7 @@ void main() { .forAccount(accountCId) .order(RequestBuilderOrder.DESC) .execute(); - for (OperationResponse? payment in payments.records!) { + for (OperationResponse payment in payments.records) { if (payment is PaymentOperationResponse) { assert(payment.sourceAccount == accountAId); found = true; @@ -61,6 +61,17 @@ void main() { } } assert(found); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(accountAId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); + }); test('send native payment with preconditions', () async { @@ -137,7 +148,7 @@ void main() { .forAccount(accountCId) .order(RequestBuilderOrder.DESC) .execute(); - for (OperationResponse? payment in payments.records!) { + for (OperationResponse payment in payments.records) { if (payment is PaymentOperationResponse) { assert(payment.sourceAccount == accountAId); found = true; @@ -145,6 +156,16 @@ void main() { } } assert(found); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(accountAId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('send native payment - muxed source and muxed destination account', @@ -200,7 +221,7 @@ void main() { .forAccount(accountCId) .order(RequestBuilderOrder.DESC) .execute(); - for (OperationResponse? payment in payments.records!) { + for (OperationResponse payment in payments.records) { if (payment is PaymentOperationResponse) { assert(payment.sourceAccount == accountAId); found = true; @@ -214,12 +235,22 @@ void main() { .forAccount(accountCId) .order(RequestBuilderOrder.DESC) .execute(); - for (TransactionResponse? transaction in transactions.records!) { - if (transaction!.hash == transactionHash) { + for (TransactionResponse transaction in transactions.records) { + if (transaction.hash == transactionHash) { found = true; } } assert(found); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(accountAId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('send native payment with max operation fee', () async { @@ -368,6 +399,16 @@ void main() { } } assert(found); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(accountAId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('send non native payment with muxed accounts', () async { @@ -639,9 +680,9 @@ void main() { .sourceAmount("10") .destinationAccount(accountEId) .execute(); - assert(strictSendPaths.records!.length > 0); + assert(strictSendPaths.records.isNotEmpty); - PathResponse pathResponse = strictSendPaths.records!.first; + PathResponse pathResponse = strictSendPaths.records.first; assert(double.parse(pathResponse.destinationAmount) == 40); assert(pathResponse.destinationAssetType == "credit_alphanum4"); assert(pathResponse.destinationAssetCode == "MOON"); @@ -661,9 +702,9 @@ void main() { .sourceAmount("10") .destinationAssets(destinationAssets) .execute(); - assert(strictSendPaths.records!.length > 0); + assert(strictSendPaths.records.isNotEmpty); - pathResponse = strictSendPaths.records!.first; + pathResponse = strictSendPaths.records.first; assert(double.parse(pathResponse.destinationAmount) == 40); assert(pathResponse.destinationAssetType == "credit_alphanum4"); assert(pathResponse.destinationAssetCode == "MOON"); @@ -722,9 +763,9 @@ void main() { .destinationAmount("8") .sourceAssets(sourceAssets) .execute(); - assert(strictReceivePaths.records!.length > 0); + assert(strictReceivePaths.records.isNotEmpty); - pathResponse = strictReceivePaths.records!.first; + pathResponse = strictReceivePaths.records.first; assert(double.parse(pathResponse.destinationAmount) == 8); assert(pathResponse.destinationAssetType == "credit_alphanum4"); assert(pathResponse.destinationAssetCode == "MOON"); @@ -744,9 +785,9 @@ void main() { .destinationAmount("8") .sourceAccount(accountCId) .execute(); - assert(strictReceivePaths.records!.length > 0); + assert(strictReceivePaths.records.isNotEmpty); - pathResponse = strictReceivePaths.records!.first; + pathResponse = strictReceivePaths.records.first; assert(double.parse(pathResponse.destinationAmount) == 8); assert(pathResponse.destinationAssetType == "credit_alphanum4"); assert(pathResponse.destinationAssetCode == "MOON"); @@ -786,6 +827,40 @@ void main() { } } assert(found); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(accountAId) + .execute(); + assert(operationsPage.records.isNotEmpty); + operationsPage = await sdk.operations + .forAccount(accountBId) + .execute(); + assert(operationsPage.records.isNotEmpty); + operationsPage = await sdk.operations + .forAccount(accountCId) + .execute(); + assert(operationsPage.records.isNotEmpty); + operationsPage = await sdk.operations + .forAccount(accountDId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); + effectsPage = await sdk.effects + .forAccount(accountBId) + .execute(); + assert(effectsPage.records.isNotEmpty); + effectsPage = await sdk.effects + .forAccount(accountCId) + .execute(); + assert(effectsPage.records.isNotEmpty); + effectsPage = await sdk.effects + .forAccount(accountDId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('path payment strict send and strict receive - muxed accounts', @@ -987,11 +1062,11 @@ void main() { .forAccount(accountAId) .order(RequestBuilderOrder.DESC) .execute(); - assert(payments.records!.length > 6); + assert(payments.records.length > 6); String? createAccTransactionHash; String? paymentTransactionHash; - for (OperationResponse? response in payments.records!) { + for (OperationResponse? response in payments.records) { if (response is PaymentOperationResponse && paymentTransactionHash == null) { PaymentOperationResponse por = response; @@ -1011,16 +1086,16 @@ void main() { payments = await sdk.payments.forTransaction(paymentTransactionHash!).execute(); - assert(payments.records!.length > 0); + assert(payments.records.isNotEmpty); payments = await sdk.payments.forTransaction(createAccTransactionHash!).execute(); - assert(payments.records!.length > 0); + assert(payments.records.isNotEmpty); TransactionResponse tran = await sdk.transactions.transaction(paymentTransactionHash); payments = await sdk.payments.forLedger(tran.ledger).execute(); - assert(payments.records!.length > 0); + assert(payments.records.isNotEmpty); }); test('stream payments', () async { diff --git a/test/query_test.dart b/test/query_test.dart index efc29be..e285da9 100644 --- a/test/query_test.dart +++ b/test/query_test.dart @@ -14,7 +14,7 @@ void main() { AccountResponse account = await sdk.accounts.account(accountId); Page accountsForSigner = await sdk.accounts.forSigner(accountId).execute(); - assert(accountsForSigner.records!.first.accountId == accountId); + assert(accountsForSigner.records.first.accountId == accountId); List testKeyPairs = []; for (int i = 0; i < 3; i++) { @@ -59,10 +59,10 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); accountsForSigner = await sdk.accounts.forSigner(accountId).execute(); - assert(accountsForSigner.records!.length == 4); + assert(accountsForSigner.records.length == 4); accountsForSigner = await sdk.accounts.forSigner(accountId).limit(2).order(RequestBuilderOrder.DESC).execute(); - assert(accountsForSigner.records!.length == 2); + assert(accountsForSigner.records.length == 2); Asset astroDollar = AssetTypeCreditAlphaNum12("ASTRO", issuerAccountId); tb = TransactionBuilder(account); @@ -81,32 +81,32 @@ void main() { assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); Page accountsForAsset = await sdk.accounts.forAsset(astroDollar).execute(); - assert(accountsForAsset.records!.length == 4); + assert(accountsForAsset.records.length == 4); accountsForAsset = await sdk.accounts.forAsset(astroDollar).limit(2).order(RequestBuilderOrder.DESC).execute(); - assert(accountsForAsset.records!.length == 2); + assert(accountsForAsset.records.length == 2); }); test('test query assets', () async { Page assetsPage = await sdk.assets.assetCode("ASTRO").limit(5).order(RequestBuilderOrder.DESC).execute(); - List? assets = assetsPage.records; + var assets = assetsPage.records; - assert(assets!.length > 0 && assets.length < 6); - for (AssetResponse? asset in assets!) { - print("asset issuer: " + asset!.assetIssuer); + assert(assets.isNotEmpty && assets.length < 6); + for (AssetResponse asset in assets) { + print("asset issuer: " + asset.assetIssuer); } - String assetIssuer = assets.last!.assetIssuer; + String assetIssuer = assets.last.assetIssuer; assetsPage = await sdk.assets .assetIssuer(assetIssuer) .limit(5) .order(RequestBuilderOrder.DESC) .execute(); assets = assetsPage.records; - assert(assets!.length > 0 && assets.length < 6); - for (AssetResponse? asset in assets!) { + assert(assets.isNotEmpty && assets.length < 6); + for (AssetResponse asset in assets) { print("asset code: " + - asset!.assetCode + + asset.assetCode + " amount:${asset.amount} " + "num accounts:${asset.numAccounts} " + "num claimable Balances: ${asset.numClaimableBalances} " + @@ -126,27 +126,27 @@ void main() { test('test query effects', () async { Page assetsPage = await sdk.assets.assetCode("USD").limit(5).order(RequestBuilderOrder.DESC).execute(); - List? assets = assetsPage.records; - assert(assets!.length > 0 && assets.length < 6); + var assets = assetsPage.records; + assert(assets.isNotEmpty && assets.length < 6); - String assetIssuer = assets!.first!.assetIssuer; + String assetIssuer = assets.first.assetIssuer; Page effectsPage = await sdk.effects.forAccount(assetIssuer).limit(3).order(RequestBuilderOrder.ASC).execute(); - List effects = effectsPage.records!; - assert(effects.length > 0 && effects.length < 4); + List effects = effectsPage.records; + assert(effects.isNotEmpty && effects.length < 4); assert(effects.first is AccountCreatedEffectResponse); Page ledgersPage = await sdk.ledgers.limit(1).order(RequestBuilderOrder.DESC).execute(); - assert(ledgersPage.records!.length == 1); - LedgerResponse ledger = ledgersPage.records!.first; + assert(ledgersPage.records.length == 1); + LedgerResponse ledger = ledgersPage.records.first; effectsPage = await sdk.effects .forLedger(ledger.sequence) .limit(3) .order(RequestBuilderOrder.ASC) .execute(); - effects = effectsPage.records!; + effects = effectsPage.records; assert(effects.length > 0); Page transactionsPage = await sdk.transactions @@ -154,8 +154,8 @@ void main() { .limit(1) .order(RequestBuilderOrder.DESC) .execute(); - assert(transactionsPage.records!.length == 1); - TransactionResponse transaction = transactionsPage.records!.first; + assert(transactionsPage.records.length == 1); + TransactionResponse transaction = transactionsPage.records.first; effectsPage = await sdk.effects .forTransaction(transaction.hash) .limit(3) @@ -168,8 +168,8 @@ void main() { .limit(1) .order(RequestBuilderOrder.DESC) .execute(); - assert(operationsPage.records!.length == 1); - OperationResponse operation = operationsPage.records!.first; + assert(operationsPage.records.length == 1); + OperationResponse operation = operationsPage.records.first; effectsPage = await sdk.effects .forOperation(operation.id) .limit(3) @@ -186,8 +186,8 @@ void main() { .limit(1) .order(RequestBuilderOrder.DESC) .execute(); - assert(operationsPage.records!.length == 1); - OperationResponse operation = operationsPage.records!.first; + assert(operationsPage.records.length == 1); + OperationResponse operation = operationsPage.records.first; assert(operation.transactionSuccessful); }); @@ -199,14 +199,14 @@ void main() { .limit(1) .order(RequestBuilderOrder.DESC) .execute(); - assert(transactionsPage.records!.length == 1); + assert(transactionsPage.records.length == 1); }); test('test query ledgers', () async { Page ledgersPage = await sdk.ledgers.limit(1).order(RequestBuilderOrder.DESC).execute(); - assert(ledgersPage.records!.length == 1); - LedgerResponse ledger = ledgersPage.records!.first; + assert(ledgersPage.records.length == 1); + LedgerResponse ledger = ledgersPage.records.first; // print("tx_set_operation_count: ${ledger.txSetOperationCount}"); LedgerResponse ledger2 = await sdk.ledgers.ledger(ledger.sequence); @@ -288,9 +288,9 @@ void main() { assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); - List? offers = (await sdk.offers.forAccount(buyerAccountId).execute()).records; - assert(offers!.length == 1); - OfferResponse offer = offers!.first!; + var offers = (await sdk.offers.forAccount(buyerAccountId).execute()).records; + assert(offers.length == 1); + OfferResponse offer = offers.first; assert(offer.buying == astroDollar); assert(offer.selling == Asset.NATIVE); @@ -303,8 +303,8 @@ void main() { assert(offer.seller == buyerKeipair.accountId); offers = (await sdk.offers.forBuyingAsset(astroDollar).execute()).records; - assert(offers!.length == 1); - OfferResponse offer2 = offers!.first!; + assert(offers.length == 1); + OfferResponse offer2 = offers.first; assert(offer.id == offer2.id); OrderBookResponse orderBook = @@ -466,9 +466,9 @@ void main() { .sourceAmount("10") .destinationAccount(accountEId) .execute(); - assert(strictSendPaths.records!.length > 0); + assert(strictSendPaths.records.length > 0); - PathResponse pathResponse = strictSendPaths.records!.first; + PathResponse pathResponse = strictSendPaths.records.first; assert(double.parse(pathResponse.destinationAmount) == 40); assert(pathResponse.destinationAssetType == "credit_alphanum4"); assert(pathResponse.destinationAssetCode == "MOON"); @@ -488,9 +488,9 @@ void main() { .sourceAmount("10") .destinationAssets(destinationAssets) .execute(); - assert(strictSendPaths.records!.length > 0); + assert(strictSendPaths.records.length > 0); - pathResponse = strictSendPaths.records!.first; + pathResponse = strictSendPaths.records.first; assert(double.parse(pathResponse.destinationAmount) == 40); assert(pathResponse.destinationAssetType == "credit_alphanum4"); assert(pathResponse.destinationAssetCode == "MOON"); @@ -554,9 +554,9 @@ void main() { .destinationAmount("8") .sourceAssets(sourceAssets) .execute(); - assert(strictReceivePaths.records!.length > 0); + assert(strictReceivePaths.records.length > 0); - pathResponse = strictReceivePaths.records!.first; + pathResponse = strictReceivePaths.records.first; assert(double.parse(pathResponse.destinationAmount) == 8); assert(pathResponse.destinationAssetType == "credit_alphanum4"); assert(pathResponse.destinationAssetCode == "MOON"); @@ -576,9 +576,9 @@ void main() { .destinationAmount("8") .sourceAccount(accountCId) .execute(); - assert(strictReceivePaths.records!.length > 0); + assert(strictReceivePaths.records.length > 0); - pathResponse = strictReceivePaths.records!.first; + pathResponse = strictReceivePaths.records.first; assert(double.parse(pathResponse.destinationAmount) == 8); assert(pathResponse.destinationAssetType == "credit_alphanum4"); assert(pathResponse.destinationAssetCode == "MOON"); @@ -617,8 +617,8 @@ void main() { assert(found); Page trades = await sdk.trades.forAccount(accountBId).execute(); - assert(trades.records!.length == 2); - TradeResponse trade = trades.records!.first; + assert(trades.records.length == 2); + TradeResponse trade = trades.records.first; assert(trade.baseIsSeller); assert(trade.baseAccount == accountBId); @@ -636,7 +636,7 @@ void main() { assert(trade.price.numerator == 1); assert(trade.price.denominator == 2); - trade = trades.records!.last; + trade = trades.records.last; assert(trade.baseIsSeller); assert(trade.baseAccount == accountBId); diff --git a/test/soroban_test.dart b/test/soroban_test.dart index 727424f..918c3e5 100644 --- a/test/soroban_test.dart +++ b/test/soroban_test.dart @@ -141,6 +141,16 @@ void main() { await pollStatus(sendResponse.hash!); assert( GetTransactionResponse.STATUS_SUCCESS == rpcTransactionResponse.status); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(accountAId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); } Future extendContractCodeFootprintTTL(String wasmId, int extendTo) async { @@ -222,14 +232,19 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is ExtendFootprintTTLOperationResponse) { assert("extend_footprint_ttl" == operationResponse.type); } else { assert(false); } + + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); } group('all tests', () { @@ -350,8 +365,8 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is InvokeHostFunctionOperationResponse) { assert("HostFunctionTypeHostFunctionTypeUploadContractWasm" == @@ -360,6 +375,11 @@ void main() { assert(false); } await extendContractCodeFootprintTTL(helloContractWasmId!, 100000); + + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('test create contract', () async { @@ -441,14 +461,19 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is InvokeHostFunctionOperationResponse) { assert("HostFunctionTypeHostFunctionTypeCreateContract" == operationResponse.function); } else { assert(false); } + + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('test invoke contract', () async { @@ -545,8 +570,8 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is InvokeHostFunctionOperationResponse) { assert("HostFunctionTypeHostFunctionTypeInvokeContract" == operationResponse.function); @@ -554,6 +579,11 @@ void main() { assert(false); } + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); + await Future.delayed(Duration(seconds: 5)); // test contract data fetching print(StrKey.encodeContractIdHex(helloContractId!)); @@ -810,14 +840,19 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is InvokeHostFunctionOperationResponse) { assert("HostFunctionTypeHostFunctionTypeCreateContract" == operationResponse.function); } else { assert(false); } + + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('test SAC with asset', () async { @@ -915,14 +950,19 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is InvokeHostFunctionOperationResponse) { assert("HostFunctionTypeHostFunctionTypeCreateContract" == operationResponse.function); } else { assert(false); } + + var effectsPage = await sdk.effects + .forAccount(accountAId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('test StrKey contractId', () async { diff --git a/test/soroban_test_atomic_swap.dart b/test/soroban_test_atomic_swap.dart index 9df8e44..0f2a330 100644 --- a/test/soroban_test_atomic_swap.dart +++ b/test/soroban_test_atomic_swap.dart @@ -507,8 +507,8 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is ExtendFootprintTTLOperationResponse) { assert("extend_footprint_ttl" == operationResponse.type); diff --git a/test/soroban_test_auth.dart b/test/soroban_test_auth.dart index c693263..a633246 100644 --- a/test/soroban_test_auth.dart +++ b/test/soroban_test_auth.dart @@ -219,8 +219,8 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is ExtendFootprintTTLOperationResponse) { assert("extend_footprint_ttl" == operationResponse.type); @@ -421,8 +421,8 @@ void main() { // check operation response from horizon Page operations = await sdk.operations.forTransaction(sendResponse.hash!).execute(); - assert(operations.records != null && operations.records!.length > 0); - OperationResponse operationResponse = operations.records!.first; + assert(operations.records.isNotEmpty); + OperationResponse operationResponse = operations.records.first; if (operationResponse is InvokeHostFunctionOperationResponse) { assert("HostFunctionTypeHostFunctionTypeInvokeContract" == operationResponse.function); diff --git a/test/sponsorship_test.dart b/test/sponsorship_test.dart index 720f257..570dfc5 100644 --- a/test/sponsorship_test.dart +++ b/test/sponsorship_test.dart @@ -97,5 +97,15 @@ void main() { await sdk.submitTransaction(transaction); assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forTransaction(response.hash!) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forTransaction(response.hash!) + .execute(); + assert(effectsPage.records.isNotEmpty); }); } diff --git a/test/trading_test.dart b/test/trading_test.dart index e133c75..b1a931d 100644 --- a/test/trading_test.dart +++ b/test/trading_test.dart @@ -48,9 +48,9 @@ void main() { assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); - List? offers = (await sdk.offers.forAccount(buyerAccountId).execute()).records; - assert(offers!.length == 1); - OfferResponse offer = offers!.first; + var offers = (await sdk.offers.forAccount(buyerAccountId).execute()).records; + assert(offers.length == 1); + OfferResponse offer = offers.first; assert(offer.buying == astroDollar); assert(offer.selling == Asset.NATIVE); @@ -65,8 +65,8 @@ void main() { String offerId = offer.id; offers = (await sdk.offers.forBuyingAsset(astroDollar).execute()).records; - assert(offers!.length == 1); - offer = offers!.first; + assert(offers.length == 1); + offer = offers.first; String offerId2 = offer.id; assert(offerId == offerId2); @@ -108,8 +108,8 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(buyerAccountId).execute()).records; - assert(offers!.length == 1); - offer = offers!.first; + assert(offers.length == 1); + offer = offers.first; assert(offer.buying == astroDollar); assert(offer.selling == Asset.NATIVE); @@ -150,12 +150,22 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(buyerAccountId).execute()).records; - assert(offers!.length == 0); + assert(offers.isEmpty); orderBook = await sdk.orderBook.buyingAsset(astroDollar).sellingAsset(Asset.NATIVE).limit(1).execute(); assert(orderBook.asks.length == 0); assert(orderBook.bids.length == 0); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(buyerAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(buyerAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('manage sell offer', () async { @@ -209,8 +219,8 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); List? offers = (await sdk.offers.forAccount(sellerAccountId).execute()).records; - assert(offers!.length == 1); - OfferResponse offer = offers!.first; + assert(offers.length == 1); + OfferResponse offer = offers.first; assert(offer.buying == Asset.NATIVE); assert(offer.selling == moonDollar); @@ -227,8 +237,8 @@ void main() { String offerId = offer.id; offers = (await sdk.offers.forSellingAsset(moonDollar).execute()).records; - assert(offers!.length == 1); - offer = offers!.first; + assert(offers.length == 1); + offer = offers.first; String offerId2 = offer.id; assert(offerId == offerId2); @@ -268,8 +278,8 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(sellerAccountId).execute()).records; - assert(offers!.length == 1); - offer = offers!.first; + assert(offers.length == 1); + offer = offers.first; assert(offer.buying == Asset.NATIVE); assert(offer.selling == moonDollar); @@ -295,7 +305,7 @@ void main() { assert(response.success); TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(sellerAccountId).execute()).records; - assert(offers!.length == 0); + assert(offers.length == 0); }); test('create passive sell offer', () async { @@ -348,8 +358,8 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); List? offers = (await sdk.offers.forAccount(sellerAccountId).execute()).records; - assert(offers!.length == 1); - OfferResponse offer = offers!.first; + assert(offers.length == 1); + OfferResponse offer = offers.first; assert(offer.buying == Asset.NATIVE); assert(offer.selling == marsDollar); @@ -379,8 +389,8 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(sellerAccountId).execute()).records; - assert(offers!.length == 1); - offer = offers!.first; + assert(offers.length == 1); + offer = offers.first; assert(offer.buying == Asset.NATIVE); assert(offer.selling == marsDollar); @@ -407,6 +417,6 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(sellerAccountId).execute()).records; - assert(offers!.length == 0); + assert(offers.length == 0); }); } diff --git a/test/trust_test.dart b/test/trust_test.dart index d956326..ab7397a 100644 --- a/test/trust_test.dart +++ b/test/trust_test.dart @@ -95,6 +95,16 @@ void main() { } } assert(!found); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(trustorAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(trustorAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); test('test max trust amount', () async { @@ -227,8 +237,8 @@ void main() { List? offers = (await sdk.offers.forAccount(trustorAccountId).execute()).records; - assert(offers!.length == 1); - OfferResponse offer = offers!.first; + assert(offers.length == 1); + OfferResponse offer = offers.first; assert(offer.buying == Asset.NATIVE); assert(offer.selling == astroDollar); @@ -242,7 +252,7 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(trustorAccountId).execute()).records; - assert(offers!.length == 0); + assert(offers.length == 0); trustorAccount = await sdk.accounts.account(trustorAccountId); found = false; @@ -273,7 +283,7 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(trustorAccountId).execute()).records; - assert(offers!.length == 1); + assert(offers.length == 1); aop = AllowTrustOperationBuilder(trustorAccountId, assetCode, 2) .build(); // authorized to maintain liabilities. @@ -284,7 +294,7 @@ void main() { TestUtils.resultDeAndEncodingTest(transaction, response); offers = (await sdk.offers.forAccount(trustorAccountId).execute()).records; - assert(offers!.length == 1); + assert(offers.length == 1); po = PaymentOperationBuilder(trustorAccountId, astroDollar, "100").build(); transaction = TransactionBuilder(issuerAccount).addOperation(po).build(); @@ -293,5 +303,24 @@ void main() { response = await sdk.submitTransaction(transaction); assert(!response.success); // is not authorized for new funds TestUtils.resultDeAndEncodingTest(transaction, response); + + // test operation & effects responses can be parsed + var operationsPage = await sdk.operations + .forAccount(trustorAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + var effectsPage = await sdk.effects + .forAccount(trustorAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); + + operationsPage = await sdk.operations + .forAccount(issuerAccountId) + .execute(); + assert(operationsPage.records.isNotEmpty); + effectsPage = await sdk.effects + .forAccount(issuerAccountId) + .execute(); + assert(effectsPage.records.isNotEmpty); }); }