Skip to content

Commit

Permalink
test: uncomment account balance e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Ricky Saechao <[email protected]>
  • Loading branch information
RickyLB committed Jun 3, 2024
1 parent 1637bab commit 8944b55
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 50 deletions.
6 changes: 0 additions & 6 deletions Sources/Hedera/Account/AccountBalanceQuery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,6 @@ public final class AccountBalanceQuery: Query<AccountBalance> {
let accountId = try AccountId.fromProtobuf(proto.accountID)
let tokenBalanceProto = try await mirrorNodeService.getTokenBalancesForAccount(String(accountId.num))

// var tokenBalances: [TokenId: UInt64] = [:]

// for balance in tokenBalanceProto {
// tokenBalances[.fromProtobuf(balance.tokenID)] = balance.balance
// }

return AccountBalance(
accountId: accountId, hbars: .fromTinybars(Int64(proto.balance)),
tokensInner: .fromProtobuf(tokenBalanceProto))
Expand Down
86 changes: 42 additions & 44 deletions Tests/HederaE2ETests/Account/AccountBalance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,48 +114,46 @@ internal final class AccountBalance: XCTestCase {
}
}

// disabled because swift doesn't have a way to ignore deprecated warnings.
// internal func testQueryTokenBalances() async throws {
// let testEnv = try TestEnvironment.nonFree

// let account = try await Account.create(testEnv, balance: 10)

// addTeardownBlock { try await account.delete(testEnv) }

// let receipt = try await TokenCreateTransaction()
// .name("ffff")
// .symbol("f")
// .initialSupply(10000)
// .decimals(50)
// .treasuryAccountId(account.id)
// .expirationTime(.now + .minutes(5))
// .adminKey(.single(account.key.publicKey))
// .supplyKey(.single(account.key.publicKey))
// .freezeDefault(false)
// .sign(account.key)
// .execute(testEnv.client)
// .getReceipt(testEnv.client)

// let tokenId = try XCTUnwrap(receipt.tokenId)

// addTeardownBlock {
// _ = try await TokenBurnTransaction()
// .tokenId(tokenId)
// .amount(10000)
// .sign(account.key)
// .execute(testEnv.client)
// .getReceipt(testEnv.client)

// _ = try await TokenDeleteTransaction()
// .tokenId(tokenId)
// .sign(account.key)
// .execute(testEnv.client)
// .getReceipt(testEnv.client)
// }

// let _ = try await AccountBalanceQuery().accountId(account.id).execute(testEnv.client)

// // XCTAssertEqual(balance.tokenBalances[tokenId], 10000)
// // XCTAssertEqual(balance.tokenDecimals[tokenId], 50)
// }
internal func testQueryTokenBalances() async throws {
let testEnv = try TestEnvironment.nonFree

let account = try await Account.create(testEnv, balance: 10)

addTeardownBlock { try await account.delete(testEnv) }

let receipt = try await TokenCreateTransaction()
.name("ffff")
.symbol("f")
.initialSupply(10000)
.decimals(50)
.treasuryAccountId(account.id)
.expirationTime(.now + .minutes(5))
.adminKey(.single(account.key.publicKey))
.supplyKey(.single(account.key.publicKey))
.freezeDefault(false)
.sign(account.key)
.execute(testEnv.client)
.getReceipt(testEnv.client)

let tokenId = try XCTUnwrap(receipt.tokenId)

addTeardownBlock {
_ = try await TokenBurnTransaction()
.tokenId(tokenId)
.amount(10000)
.sign(account.key)
.execute(testEnv.client)
.getReceipt(testEnv.client)

_ = try await TokenDeleteTransaction()
.tokenId(tokenId)
.sign(account.key)
.execute(testEnv.client)
.getReceipt(testEnv.client)
}

let balance = try await AccountBalanceQuery().accountId(account.id).execute(testEnv.client)

XCTAssertEqual(balance.hbars, 10)
}
}

0 comments on commit 8944b55

Please sign in to comment.