|
| 1 | +@Timeout(const Duration(seconds: 300)) |
| 2 | + |
| 3 | +import 'package:flutter_test/flutter_test.dart'; |
| 4 | +import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart'; |
| 5 | + |
| 6 | +void main() { |
| 7 | + StellarSDK sdk = StellarSDK.TESTNET; |
| 8 | + |
| 9 | + test('submit fee bump transaction', () async { |
| 10 | + KeyPair sourceKeyPair = KeyPair.random(); |
| 11 | + String sourceId = sourceKeyPair.accountId; |
| 12 | + KeyPair destinationKeyPair = KeyPair.random(); |
| 13 | + String destinationId = destinationKeyPair.accountId; |
| 14 | + KeyPair payerKeyPair = KeyPair.random(); |
| 15 | + String payerId = payerKeyPair.accountId; |
| 16 | + |
| 17 | + await FriendBot.fundTestAccount(sourceId); |
| 18 | + await FriendBot.fundTestAccount(payerId); |
| 19 | + |
| 20 | + AccountResponse sourceAccount = await sdk.accounts.account(sourceId); |
| 21 | + |
| 22 | + // fund account C. |
| 23 | + Transaction innerTx = new TransactionBuilder(sourceAccount, Network.TESTNET) |
| 24 | + .addOperation( |
| 25 | + new CreateAccountOperationBuilder(destinationId, "10").build()) |
| 26 | + .build(); |
| 27 | + |
| 28 | + innerTx.sign(sourceKeyPair); |
| 29 | + |
| 30 | + FeeBumpTransaction feeBump = new FeeBumpTransactionBuilder(innerTx) |
| 31 | + .setBaseFee(200) |
| 32 | + .setFeeAccount(payerId) |
| 33 | + .build(); |
| 34 | + feeBump.sign(payerKeyPair); |
| 35 | + |
| 36 | + SubmitTransactionResponse response = |
| 37 | + await sdk.submitFeeBumpTransaction(feeBump); |
| 38 | + assert(response.success); |
| 39 | + |
| 40 | + AccountResponse destination = await sdk.accounts.account(destinationId); |
| 41 | + for (Balance balance in destination.balances) { |
| 42 | + if (balance.assetType == Asset.TYPE_NATIVE) { |
| 43 | + assert(double.parse(balance.balance) > 9); |
| 44 | + break; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + TransactionResponse transaction = |
| 49 | + await sdk.transactions.transaction(response.hash); |
| 50 | + assert(transaction.feeBumpTransaction != null); |
| 51 | + assert(transaction.feeBumpTransaction.signatures.length > 0); |
| 52 | + assert(transaction.innerTransaction.hash != null); |
| 53 | + assert(transaction.innerTransaction.maxFee == 100); |
| 54 | + |
| 55 | + transaction = |
| 56 | + await sdk.transactions.transaction(transaction.innerTransaction.hash); |
| 57 | + assert(transaction.sourceAccount == sourceId); |
| 58 | + }); |
| 59 | +} |
0 commit comments