-
Notifications
You must be signed in to change notification settings - Fork 0
/
StellarTest.swift
675 lines (523 loc) · 27.4 KB
/
StellarTest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
//
// StellarTest.swift
//
//
// Created by Christian Rogobete on 20.09.24.
//
import XCTest
@testable import stellar_wallet_sdk
final class StellarTest: XCTestCase {
let wallet = Wallet.testNet
let accountKeyPair = Wallet.testNet.stellar.account.createKeyPair()
override func setUp() async throws {
try await super.setUp()
try await wallet.stellar.fundTestNetAccount(address: accountKeyPair.address)
}
func testGetInfo() async throws {
let accountInfo = try await wallet.stellar.account.getInfo(accountAddress: accountKeyPair.address)
XCTAssertTrue(accountInfo.balances.count > 0)
}
func testCreateAccount() async throws {
let stellar = wallet.stellar
// create transaction builder
let txBuilder = try await stellar.transaction(sourceAddress: accountKeyPair)
// keypair identifying the new account to be created
let newAccountKeyPair = stellar.account.createKeyPair()
// create transaction
let tx = try txBuilder.createAccount(newAccount: newAccountKeyPair, startingBalance: 100.1).build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
// submit transaction
let success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
let accountInfo = try await stellar.account.getInfo(accountAddress: newAccountKeyPair.address)
let balances = accountInfo.balances
XCTAssertEqual(1, balances.count)
XCTAssertEqual("native", balances.first!.assetType)
XCTAssertEqual(Double(balances.first!.balance), 100.1)
}
func testCreateSponsoredAccount() async throws {
let stellar = wallet.stellar
let account = stellar.account
let sponsorKeyPair = accountKeyPair
// create transaction builder
let txBuilder = try await stellar.transaction(sourceAddress: sponsorKeyPair)
// keypair identifying the new account to be created
let newAccountKeyPair = account.createKeyPair()
// create transaction
let tx = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in builder.createAccount(newAccount: newAccountKeyPair)},
sponsoredAccount: newAccountKeyPair).build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
stellar.sign(tx: tx, keyPair: newAccountKeyPair)
// submit transaction
let success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
let accountInfo = try await account.getInfo(accountAddress: newAccountKeyPair.address)
let balances = accountInfo.balances
XCTAssertEqual(1, balances.count)
XCTAssertEqual("native", balances.first!.assetType)
XCTAssertEqual(Double(balances.first!.balance), 0.0)
}
func testLockMasterKey() async throws {
let stellar = wallet.stellar
let account = stellar.account
// keypairs & account id
let newAccountSigningKeyPair = account.createKeyPair()
let newAccountPublicKeyPair = newAccountSigningKeyPair.toPublicKeyPair()
let newAccountAddress = newAccountPublicKeyPair.address
// fund the new test account
try await stellar.fundTestNetAccount(address: newAccountAddress)
// create transaction
let tx = try await stellar.transaction(sourceAddress:newAccountPublicKeyPair).lockAccountMasterKey().build()
// sign transaction
stellar.sign(tx: tx, keyPair: newAccountSigningKeyPair)
// submit transaction
let success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
let accountInfo = try await account.getInfo(accountAddress: newAccountAddress)
let signers = accountInfo.signers
XCTAssertEqual(1, signers.count)
XCTAssertEqual(0, signers.first!.weight)
}
func testSponsoredLockMasterKey() async throws {
let stellar = wallet.stellar
let account = stellar.account
let sponsorKeyPair = accountKeyPair
// create transaction builder
let txBuilder = try await stellar.transaction(sourceAddress: sponsorKeyPair)
// keypairs identifying the new account to be locked
let newAccountSigningKeyPair = account.createKeyPair()
let newAccountPublicKeyPair = newAccountSigningKeyPair.toPublicKeyPair()
let newAccountAddress = newAccountPublicKeyPair.address
// fund the new test account
try await stellar.fundTestNetAccount(address: newAccountAddress)
// create transaction
let tx = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in builder.lockAccountMasterKey()},
sponsoredAccount: newAccountPublicKeyPair).build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
stellar.sign(tx: tx, keyPair: newAccountSigningKeyPair)
// submit transaction
let success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
let accountInfo = try await account.getInfo(accountAddress: newAccountAddress)
let signers = accountInfo.signers
XCTAssertEqual(1, signers.count)
XCTAssertEqual(0, signers.first!.weight)
}
func testAddAndRemoveAccountSigner() async throws {
let stellar = wallet.stellar
let account = stellar.account
// keypairs & account id
let newAccountSigningKeyPair = account.createKeyPair()
let newAccountPublicKeyPair = newAccountSigningKeyPair.toPublicKeyPair()
// create transaction (add signer)
var tx = try await stellar.transaction(sourceAddress:accountKeyPair)
.addAccountSigner(signerAddress: newAccountPublicKeyPair, signerWeight: 11)
.build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
// submit transaction
var success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
var accountInfo = try await account.getInfo(accountAddress: accountKeyPair.address)
var signers = accountInfo.signers
XCTAssertEqual(2, signers.count)
var signerFound = false
for signer in signers {
if (signer.weight == 11) {
signerFound = true
break
}
}
XCTAssertTrue(signerFound)
// create transaction (remove signer)
tx = try await stellar.transaction(sourceAddress:accountKeyPair)
.removeAccountSigner(signerAddress: newAccountPublicKeyPair)
.build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
// submit transaction
success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
accountInfo = try await account.getInfo(accountAddress: accountKeyPair.address)
signers = accountInfo.signers
XCTAssertEqual(1, signers.count)
XCTAssertNotEqual(11, signers.first!.weight)
}
func testSponsoredAddAndRemoveAccountSigner() async throws {
let stellar = wallet.stellar
let account = stellar.account
let sponsorKeyPair = accountKeyPair
// create transaction builder
let txBuilder = try await stellar.transaction(sourceAddress: sponsorKeyPair)
// keypairs identifying the new account to be locked
let newAccountSigningKeyPair = account.createKeyPair()
let newAccountPublicKeyPair = newAccountSigningKeyPair.toPublicKeyPair()
let newAccountAddress = newAccountPublicKeyPair.address
// fund the new test account
try await stellar.fundTestNetAccount(address: newAccountAddress)
// public keypair of new signer
let newSignerPublicKeyPair = account.createKeyPair().toPublicKeyPair()
// create sponsored transaction (add signer)
var tx = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in builder.addAccountSigner(signerAddress: newSignerPublicKeyPair, signerWeight: 11)},
sponsoredAccount: newAccountPublicKeyPair).build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
stellar.sign(tx: tx, keyPair: newAccountSigningKeyPair)
// submit transaction
var success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
var newAccountInfo = try await account.getInfo(accountAddress: newAccountAddress)
var signers = newAccountInfo.signers
XCTAssertEqual(2, signers.count)
var signerFound = false
for signer in signers {
if (signer.weight == 11) {
signerFound = true
break
}
}
XCTAssertTrue(signerFound)
// create sponsored transaction (remove signer)
tx = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in try! builder.removeAccountSigner(signerAddress: newSignerPublicKeyPair)},
sponsoredAccount: newAccountPublicKeyPair).build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
stellar.sign(tx: tx, keyPair: newAccountSigningKeyPair)
// submit transaction
success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
newAccountInfo = try await account.getInfo(accountAddress: newAccountAddress)
signers = newAccountInfo.signers
XCTAssertEqual(1, signers.count)
XCTAssertNotEqual(11, signers.first!.weight)
}
func testAddAndRemoveAssetSupport() async throws {
let stellar = wallet.stellar
let account = stellar.account
// define asset
let assetCode = "USDC"
let assetIssuerAccountId = "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
let asset = try IssuedAssetId(
code: assetCode,
issuer: assetIssuerAccountId)
// create transaction (add trustline)
var tx = try await stellar.transaction(sourceAddress:accountKeyPair)
.addAssetSupport(asset: asset, limit: 100)
.build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
// submit transaction
var success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
var accountInfo = try await account.getInfo(accountAddress: accountKeyPair.address)
var balances = accountInfo.balances
XCTAssertEqual(2, balances.count)
var trustlineFound = false
for balance in balances {
if (balance.assetCode == assetCode) {
XCTAssertEqual(balance.assetIssuer, assetIssuerAccountId)
XCTAssertEqual(100, Double(balance.limit))
trustlineFound = true
break
}
}
XCTAssertTrue(trustlineFound)
// create transaction (remove trustline)
tx = try await stellar.transaction(sourceAddress:accountKeyPair)
.removeAssetSupport(asset: asset)
.build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
// submit transaction
success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
accountInfo = try await account.getInfo(accountAddress: accountKeyPair.address)
balances = accountInfo.balances
XCTAssertEqual(1, balances.count)
}
func testSponsoredAddAndRemoveAssetSupport() async throws {
let stellar = wallet.stellar
let account = stellar.account
let sponsorKeyPair = accountKeyPair
// create transaction builder
let txBuilder = try await stellar.transaction(sourceAddress: sponsorKeyPair)
// keypairs identifying the new account to be sponsored
let newAccountSigningKeyPair = account.createKeyPair()
let newAccountPublicKeyPair = newAccountSigningKeyPair.toPublicKeyPair()
let newAccountAddress = newAccountPublicKeyPair.address
// fund the new test account
try await stellar.fundTestNetAccount(address: newAccountAddress)
// define asset
let assetCode = "USDC"
let assetIssuerAccountId = "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5"
let asset = try IssuedAssetId(
code: assetCode,
issuer: assetIssuerAccountId)
// create sponsored transaction (add trustline)
var tx = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in builder.addAssetSupport(asset: asset, limit: 100)},
sponsoredAccount: newAccountPublicKeyPair).build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
stellar.sign(tx: tx, keyPair: newAccountSigningKeyPair)
// submit transaction
var success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
var newAccountInfo = try await account.getInfo(accountAddress: newAccountAddress)
var balances = newAccountInfo.balances
XCTAssertEqual(2, balances.count)
var trustlineFound = false
for balance in balances {
if (balance.assetCode == assetCode) {
XCTAssertEqual(balance.assetIssuer, assetIssuerAccountId)
XCTAssertEqual(100, Double(balance.limit))
trustlineFound = true
break
}
}
XCTAssertTrue(trustlineFound)
// create sponsored transaction (remove trustline)
tx = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in builder.removeAssetSupport(asset: asset)},
sponsoredAccount: newAccountPublicKeyPair).build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
stellar.sign(tx: tx, keyPair: newAccountSigningKeyPair)
// submit transaction
success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
newAccountInfo = try await account.getInfo(accountAddress: newAccountAddress)
balances = newAccountInfo.balances
XCTAssertEqual(1, balances.count)
}
func testAccountMerge() async throws {
let stellar = wallet.stellar
// create 2 new accounts for testing and fund them
let sourceAccountKeyPair = stellar.account.createKeyPair()
let sourceAccountAddress = sourceAccountKeyPair.address
try await stellar.fundTestNetAccount(address: sourceAccountAddress)
let destinationAccountKeyPair = stellar.account.createKeyPair()
let destinationAccountAddress = destinationAccountKeyPair.address
try await stellar.fundTestNetAccount(address: destinationAccountAddress)
// create transaction builder
let txBuilder = try await stellar.transaction(
sourceAddress: accountKeyPair,
baseFee: 1000)
// create transaction
let mergeTxn = try txBuilder.accountMerge(
destinationAddress: destinationAccountAddress,
sourceAddress: sourceAccountAddress
).build()
// sign transaction
stellar.sign(tx: mergeTxn, keyPair: accountKeyPair)
stellar.sign(tx: mergeTxn, keyPair: sourceAccountKeyPair)
// submit transaction
let success = try await stellar.submitTransaction(signedTransaction: mergeTxn)
XCTAssertTrue(success)
// validate
let sourceExists = try await stellar.account.accountExists(accountAddress: sourceAccountAddress)
XCTAssertFalse(sourceExists)
let accountInfo = try await stellar.account.getInfo(accountAddress: destinationAccountAddress)
let balances = accountInfo.balances
XCTAssertEqual(1, balances.count)
XCTAssertEqual("native", balances.first!.assetType)
XCTAssertTrue(Double(balances.first!.balance)! > 10.000)
}
func testSetTreshold() async throws {
let stellar = wallet.stellar
let account = stellar.account
// create a new account for testing and fund it
let sourceAccountKeyPair = account.createKeyPair()
let sourceAccountAddress = sourceAccountKeyPair.address
try await stellar.fundTestNetAccount(address: sourceAccountAddress)
// create transaction builder
let txBuilder = try await stellar.transaction(
sourceAddress: sourceAccountKeyPair)
// create transaction
let tx = try txBuilder.setThreshold(low: 1, medium: 10, high: 30).build()
// sign transaction
stellar.sign(tx: tx, keyPair: sourceAccountKeyPair)
// submit transaction
let success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
let accountInfo = try await account.getInfo(accountAddress: sourceAccountAddress)
XCTAssertEqual(1, accountInfo.thresholds.lowThreshold)
XCTAssertEqual(10, accountInfo.thresholds.medThreshold)
XCTAssertEqual(30, accountInfo.thresholds.highThreshold)
}
func testSponsoredSetTreshold() async throws {
let stellar = wallet.stellar
let account = stellar.account
let sponsorKeyPair = accountKeyPair
// create transaction builder
let txBuilder = try await stellar.transaction(sourceAddress: sponsorKeyPair)
// keypairs identifying the new account to be used
let newAccountSigningKeyPair = account.createKeyPair()
let newAccountPublicKeyPair = newAccountSigningKeyPair.toPublicKeyPair()
let newAccountAddress = newAccountPublicKeyPair.address
// fund the new test account
try await stellar.fundTestNetAccount(address: newAccountAddress)
// create transaction
let tx = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in builder.setThreshold(low: 1, medium: 10, high: 30)},
sponsoredAccount: newAccountPublicKeyPair).build()
// sign transaction
stellar.sign(tx: tx, keyPair: accountKeyPair)
stellar.sign(tx: tx, keyPair: newAccountSigningKeyPair)
// submit transaction
let success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
// validate
let accountInfo = try await account.getInfo(accountAddress: newAccountAddress)
XCTAssertEqual(1, accountInfo.thresholds.lowThreshold)
XCTAssertEqual(10, accountInfo.thresholds.medThreshold)
XCTAssertEqual(30, accountInfo.thresholds.highThreshold)
}
func testMakeFeeBump() async throws {
let stellar = wallet.stellar
let account = stellar.account
let replaceWith = account.createKeyPair()
let sponsorKeyPair = account.createKeyPair()
let sponsorAddress = sponsorKeyPair.address
try await stellar.fundTestNetAccount(address: sponsorAddress)
let sponsoredKeyPair = account.createKeyPair()
let sponsoredAddress = sponsoredKeyPair.address
try await stellar.fundTestNetAccount(address: sponsoredAddress)
let txBuilder = try await stellar.transaction(sourceAddress: sponsoredKeyPair)
let transaction = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in builder.lockAccountMasterKey().addAccountSigner(
signerAddress: replaceWith,
signerWeight: 1)}).build()
stellar.sign(tx: transaction, keyPair: sponsorKeyPair)
stellar.sign(tx: transaction, keyPair: sponsoredKeyPair)
let feeBump = try stellar.makeFeeBump(feeAddress: sponsorKeyPair, transaction: transaction)
stellar.sign(feeBumpTx: feeBump, keyPair: sponsorKeyPair)
// submit transaction
let success = try await stellar.submitTransaction(signedFeeBumpTransaction: feeBump)
XCTAssertTrue(success)
// validate
let myAccount = try await account.getInfo(accountAddress: sponsoredAddress)
XCTAssertEqual(1, myAccount.balances.count)
XCTAssertEqual(10000, Double(myAccount.balances.first!.balance))
let signers = myAccount.signers
XCTAssertEqual(2, signers.count)
var newSignerFound = false
var masterKeySignerFound = false
for signer in signers {
if (signer.key == replaceWith.address) {
XCTAssertEqual(1, signer.weight)
newSignerFound = true
} else if (signer.key == sponsoredAddress) {
XCTAssertEqual(0, signer.weight)
masterKeySignerFound = true
} else {
XCTFail("should not have additional signers")
}
}
XCTAssertTrue(newSignerFound)
XCTAssertTrue(masterKeySignerFound)
// test base64 xdr encoding and decoding
guard let envelopeXdr = feeBump.toEnvelopeXdrBase64() else {
XCTFail("could not encode fee bump transaction")
return
}
let decodedTxEnum = stellar.decodeTransaction(xdr: envelopeXdr)
switch decodedTxEnum {
case .transaction(_):
XCTFail("should not be normal transaction")
case .feeBumpTransaction(let feeBumpTx):
XCTAssertEqual(feeBumpTx.toEnvelopeXdrBase64(), envelopeXdr)
case .invalidXdrErr:
XCTFail("sould not be invalid xdr")
}
}
func testUseXdrToSendTxData() async throws {
let stellar = wallet.stellar
let account = stellar.account
let sponsorKeyPair = try PublicKeyPair(accountId: "GBUTDNISXHXBMZE5I4U5INJTY376S5EW2AF4SQA2SWBXUXJY3OIZQHMV")
let newKeyPair = account.createKeyPair()
let txBuilder = try await stellar.transaction(sourceAddress: sponsorKeyPair)
let sponsorAccountCreationTx = try txBuilder.sponsoring(sponsorAccount: sponsorKeyPair,
buildingFunction: { (builder) in builder.createAccount(newAccount: newKeyPair)},
sponsoredAccount: newKeyPair).build()
stellar.sign(tx: sponsorAccountCreationTx, keyPair: newKeyPair)
guard let xdrString = sponsorAccountCreationTx.toEnvelopeXdrBase64() else {
XCTFail("could not encode transaction to base 64 xdr")
return
}
// Send xdr encoded transaction to your backend server to sign
let xdrStringFromBackend = try await sendTransactionToBackend(xdr:xdrString)
// Decode xdr to get the signed transaction
let signedTransactionEnum = stellar.decodeTransaction(xdr: xdrStringFromBackend)
switch signedTransactionEnum {
case .transaction(let tx):
// submit transaction
let success = try await stellar.submitTransaction(signedTransaction: tx)
XCTAssertTrue(success)
case .feeBumpTransaction(_):
XCTFail("should not be fee bump")
case .invalidXdrErr:
XCTFail("invalid xdr received from server")
}
// validate
let newAccount = try await account.getInfo(accountAddress: newKeyPair.address)
XCTAssertGreaterThan(newAccount.sequenceNumber, 0)
let balance = newAccount.balances.first!
XCTAssertEqual("native", balance.assetType)
XCTAssertEqual(0.0, Double(balance.balance))
}
private func sendTransactionToBackend(xdr:String) async throws -> String {
let serverSigner = try DomainSigner(url: "https://server-signer.replit.app/sign",
requestHeaders: ["Authorization": "Bearer 987654321"]);
return try await serverSigner.signWithDomainAccount(transactionXDR: xdr,
networkPassPhrase: "Test SDF Network ; September 2015")
}
func testSubmitTxWithFeeIncrease() async throws {
let stellar = wallet.stellar
let account = stellar.account
let account1KeyPair = account.createKeyPair()
try await stellar.fundTestNetAccount(address: account1KeyPair.address)
let account2KeyPair = account.createKeyPair()
try await stellar.fundTestNetAccount(address: account2KeyPair.address)
// this test is more effective on public net
// change wallet on top to: var wallet = Wallet.publicNet;
// uncomment and fill:
// let account1KeyPair = try SigningKeyPair(secretKey: "S...")
// let account2KeyPair = try PublicKeyPair(accountId: "GBH5Y77GMEOCYQOXGAMJY4C65RAMBXKZBDHA5XBNLJQUC3Z2HGQP5OC5")
let success =
try await stellar.submitWithFeeIncrease(sourceAddress: account1KeyPair,
timeout: 30,
baseFeeIncrease: 100,
maxBaseFee: 2000,
buildingFunction: {
(builder) in try! builder.transfer(destinationAddress: account2KeyPair.address,
assetId: NativeAssetId(),
amount: 10.0)})
XCTAssertTrue(success)
// validate
let newAccount = try await account.getInfo(accountAddress: account2KeyPair.address)
let balance = newAccount.balances.first!
XCTAssertEqual("native", balance.assetType)
XCTAssertEqual(10010.0, Double(balance.balance))
}
}