Skip to content

Commit 3fbb3dc

Browse files
committed
Fixes after rebase
1 parent 4b4a0ed commit 3fbb3dc

File tree

6 files changed

+50
-53
lines changed

6 files changed

+50
-53
lines changed

Sources/Core/Transaction/CodableTransaction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ extension CodableTransaction: Codable {
231231
if let accessList = accessList, !accessList.isEmpty {
232232
try containier.encode(accessList, forKey: .accessList)
233233
}
234-
234+
235235
if !gasLimit.isZero {
236236
try containier.encode(gasLimit.hexString, forKey: .gasLimit)
237237
}

Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class AdvancedABIv2Tests: LocalTestCase {
2626
// MARK: Sending Data flow
2727
let policies = Policies(gasLimitPolicy: .manual(3000000))
2828
let result = try await deployTx.writeToChain(password: "web3swift", policies: policies)
29-
let txHash = result.hash
29+
let txHash = result.hash.stripHexPrefix()
3030

3131
Thread.sleep(forTimeInterval: 1.0)
3232

33-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
33+
let receipt = try await web3.eth.transactionReceipt(Data.fromHex(txHash)!)
3434
print(receipt)
3535

3636
switch receipt.status {
@@ -62,11 +62,11 @@ class AdvancedABIv2Tests: LocalTestCase {
6262
deployTx.transaction.from = allAddresses[0]
6363
let policies = Policies(gasLimitPolicy: .manual(3000000))
6464
let result = try await deployTx.writeToChain(password: "web3swift", policies: policies)
65-
let txHash = result.hash
65+
let txHash = result.hash.stripHexPrefix()
6666

6767
Thread.sleep(forTimeInterval: 1.0)
6868

69-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
69+
let receipt = try await web3.eth.transactionReceipt(Data.fromHex(txHash)!)
7070
print(receipt)
7171

7272
switch receipt.status {
@@ -98,11 +98,11 @@ class AdvancedABIv2Tests: LocalTestCase {
9898
deployTx.transaction.from = allAddresses[0]
9999
let policies = Policies(gasLimitPolicy: .manual(3000000))
100100
let result = try await deployTx.writeToChain(password: "web3swift", policies: policies)
101-
let txHash = result.hash
101+
let txHash = result.hash.stripHexPrefix()
102102

103103
Thread.sleep(forTimeInterval: 1.0)
104104

105-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
105+
let receipt = try await web3.eth.transactionReceipt(Data.fromHex(txHash)!)
106106
print(receipt)
107107

108108
switch receipt.status {
@@ -133,11 +133,11 @@ class AdvancedABIv2Tests: LocalTestCase {
133133
deployTx.transaction.from = allAddresses[0]
134134
let policies = Policies(gasLimitPolicy: .manual(3000000))
135135
let result = try await deployTx.writeToChain(password: "web3swift", policies: policies)
136-
let txHash = result.hash
136+
let txHash = result.hash.stripHexPrefix()
137137

138138
Thread.sleep(forTimeInterval: 1.0)
139139

140-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
140+
let receipt = try await web3.eth.transactionReceipt(Data.fromHex(txHash)!)
141141
print(receipt)
142142

143143
switch receipt.status {
@@ -169,11 +169,11 @@ class AdvancedABIv2Tests: LocalTestCase {
169169
deployTx.transaction.from = allAddresses[0]
170170
let policies = Policies(gasLimitPolicy: .manual(3000000))
171171
let result = try await deployTx.writeToChain(password: "web3swift", policies: policies)
172-
let txHash = result.hash
172+
let txHash = result.hash.stripHexPrefix()
173173

174174
Thread.sleep(forTimeInterval: 1.0)
175175

176-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
176+
let receipt = try await web3.eth.transactionReceipt(Data.fromHex(txHash)!)
177177
print(receipt)
178178

179179
switch receipt.status {
@@ -201,7 +201,7 @@ class AdvancedABIv2Tests: LocalTestCase {
201201
// MARK: - Encoding ABI Data flow
202202
let tx = contract?.createReadOperation("empty")
203203
XCTAssertNotNil(tx)
204-
let _ = try await tx!.callContractMethod()
204+
_ = try await tx!.callContractMethod()
205205
}
206206

207207
func testUserCase() async throws {
@@ -214,7 +214,7 @@ class AdvancedABIv2Tests: LocalTestCase {
214214
// MARK: - Encoding ABI Data flow
215215
let tx = contract?.createReadOperation("getFlagData")
216216
XCTAssertNotNil(tx)
217-
let _ = try await tx!.callContractMethod()
217+
_ = try await tx!.callContractMethod()
218218
}
219219

220220
}

Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,20 @@ class BasicLocalNodeTests: LocalTestCase {
2727
deployTx.transaction.from = allAddresses[0]
2828
let policies = Policies(gasLimitPolicy: .manual(3000000))
2929
let result = try await deployTx.writeToChain(password: "web3swift", policies: policies)
30-
let txHash = result.hash
31-
32-
Thread.sleep(forTimeInterval: 1.0)
33-
34-
let receipt = try await web3.eth.transactionReceipt(txHash.stripHexPrefix().data(using: .utf8)!)
35-
print(receipt)
36-
37-
switch receipt.status {
38-
case .notYetProcessed:
39-
return
40-
default:
41-
break
30+
let txHash = result.hash.stripHexPrefix()
31+
32+
while true {
33+
let receipt = try await web3.eth.transactionReceipt(Data.fromHex(txHash)!)
34+
switch receipt.status {
35+
case .notYetProcessed:
36+
continue
37+
case .failed:
38+
XCTFail("Failed to deploy a contract!")
39+
case .ok:
40+
XCTAssertNotNil(receipt.contractAddress)
41+
return
42+
}
4243
}
43-
44-
let details = try await web3.eth.transactionDetails(txHash.stripHexPrefix().data(using: .utf8)!)
45-
print(details)
4644
}
4745

4846
func testEthSendExampleWithRemoteSigning() async throws {
@@ -64,11 +62,11 @@ class BasicLocalNodeTests: LocalTestCase {
6462
print("Balance before from: " + balanceBeforeFrom.description)
6563

6664
let result = try await sendTx.writeToChain(password: "web3swift")
67-
let txHash = result.hash
65+
let txHash = Data.fromHex(result.hash.stripHexPrefix())!
6866

6967
Thread.sleep(forTimeInterval: 1.0)
7068

71-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
69+
let receipt = try await web3.eth.transactionReceipt(txHash)
7270
print(receipt)
7371

7472
switch receipt.status {
@@ -78,10 +76,9 @@ class BasicLocalNodeTests: LocalTestCase {
7876
break
7977
}
8078

81-
let details = try await web3.eth.transactionDetails(txHash.data(using: .utf8)!)
79+
let details = try await web3.eth.transactionDetails(txHash)
8280
print(details)
8381

84-
8582
let balanceAfterTo = try await web3.eth.getBalance(for: sendToAddress)
8683
let balanceAfterFrom = try await web3.eth.getBalance(for: allAddresses[0])
8784
print("Balance after to: " + balanceAfterTo.description)

Tests/web3swiftTests/localTests/PersonalSignatureTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Core
1111
@testable import web3swift
1212

1313
class PersonalSignatureTests: XCTestCase {
14-
14+
1515
func testPersonalSignature() async throws {
1616
let web3 = try await Web3.new(LocalTestCase.url)
1717
let tempKeystore = try! EthereumKeystoreV3(password: "")
@@ -29,7 +29,7 @@ class PersonalSignatureTests: XCTestCase {
2929
let signer = try web3.personal.ecrecover(personalMessage: message.data(using: .utf8)!, signature: signature)
3030
XCTAssert(expectedAddress == signer, "Failed to sign personal message")
3131
}
32-
32+
3333
// TODO: - write contract
3434
func testPersonalSignatureOnContract() async throws {
3535
let web3 = try await Web3.new(LocalTestCase.url)
@@ -43,20 +43,20 @@ class PersonalSignatureTests: XCTestCase {
4343
deployTx.transaction.from = allAddresses[0]
4444
let policies = Policies(gasLimitPolicy: .manual(3000000))
4545
let deployResult = try await deployTx.writeToChain(password: "web3swift", policies: policies)
46-
let txHash = deployResult.hash
47-
46+
let txHash = Data.fromHex(deployResult.hash.stripHexPrefix())!
47+
4848
Thread.sleep(forTimeInterval: 1.0)
49-
50-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
49+
50+
let receipt = try await web3.eth.transactionReceipt(txHash)
5151
print(receipt)
52-
52+
5353
switch receipt.status {
5454
case .notYetProcessed:
5555
return
5656
default:
5757
break
5858
}
59-
59+
6060
// Signing
6161
let tempKeystore = try! EthereumKeystoreV3(password: "")
6262
let keystoreManager = KeystoreManager([tempKeystore!])
@@ -70,20 +70,20 @@ class PersonalSignatureTests: XCTestCase {
7070
print("R = " + Data(unmarshalledSignature.r).toHexString())
7171
print("S = " + Data(unmarshalledSignature.s).toHexString())
7272
print("Personal hash = " + Utilities.hashPersonalMessage(message.data(using: .utf8)!)!.toHexString())
73-
73+
7474
// Calling contract
7575
contract = web3.contract(abiString, at: receipt.contractAddress!)!
7676
var tx = contract.createReadOperation("hashPersonalMessage", parameters: [message as AnyObject])
7777
tx?.transaction.from = expectedAddress
7878
var result = try await tx!.callContractMethod()
79-
guard let hash = result["hash"]! as? Data else {return XCTFail()}
79+
guard let hash = result["hash"]! as? Data else { return XCTFail() }
8080
XCTAssert(Utilities.hashPersonalMessage(message.data(using: .utf8)!)! == hash)
81-
81+
8282
tx = contract.createReadOperation("recoverSigner", parameters: [message, unmarshalledSignature.v, Data(unmarshalledSignature.r), Data(unmarshalledSignature.s)] as [AnyObject])
8383
tx?.transaction.from = expectedAddress
8484
result = try await tx!.callContractMethod()
85-
guard let signer = result["signer"]! as? EthereumAddress else {return XCTFail()}
85+
guard let signer = result["signer"]! as? EthereumAddress else { return XCTFail() }
8686
XCTAssert(signer == expectedAddress)
8787
}
88-
88+
8989
}

Tests/web3swiftTests/localTests/TransactionsTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,12 +639,12 @@ class TransactionsTests: XCTestCase {
639639
writeTX.transaction.value = value!
640640
let policies = Policies(gasLimitPolicy: .manual(78423))
641641
let result = try await writeTX.writeToChain(password: "", policies: policies)
642-
let txHash = result.hash
643-
print("Transaction with hash " + txHash)
642+
let txHash = Data.fromHex(result.hash.stripHexPrefix())!
643+
print("Transaction with hash ", txHash)
644644

645645
Thread.sleep(forTimeInterval: 1.0)
646646

647-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
647+
let receipt = try await web3.eth.transactionReceipt(txHash)
648648
print(receipt)
649649
XCTAssert(receipt.status == .ok)
650650

@@ -655,7 +655,7 @@ class TransactionsTests: XCTestCase {
655655
break
656656
}
657657

658-
let details = try await web3.eth.transactionDetails(txHash.data(using: .utf8)!)
658+
let details = try await web3.eth.transactionDetails(txHash)
659659
print(details)
660660
// FIXME: Reenable this test.
661661
// XCTAssertEqual(details.transaction.gasLimit, BigUInt(78423))

Tests/web3swiftTests/localTests/UserCases.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class UserCases: XCTestCase {
2222
let (web3, _, receipt, abiString) = try await TestHelpers.localDeployERC20()
2323
let account = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!
2424
let contract = web3.contract(abiString, at: receipt.contractAddress!)!
25-
let readTransaction = contract.createReadOperation("balanceOf", parameters:[account] as [AnyObject])!
25+
let readTransaction = contract.createReadOperation("balanceOf", parameters: [account] as [AnyObject])!
2626
readTransaction.transaction.from = account
2727
let response = try await readTransaction.callContractMethod()
2828
let balance = response["0"] as? BigUInt
@@ -81,11 +81,11 @@ class UserCases: XCTestCase {
8181
deployTx.transaction.from = allAddresses[0]
8282
let policies = Policies(gasLimitPolicy: .manual(3000000))
8383
let result = try await deployTx.writeToChain(password: "web3swift", policies: policies)
84-
let txHash = result.hash
84+
let txHash = Data.fromHex(result.hash.stripHexPrefix())!
8585

8686
Thread.sleep(forTimeInterval: 1.0)
8787

88-
let receipt = try await web3.eth.transactionReceipt(txHash.data(using: .utf8)!)
88+
let receipt = try await web3.eth.transactionReceipt(txHash)
8989
print(receipt)
9090
XCTAssert(receipt.contractAddress != nil)
9191

@@ -96,7 +96,7 @@ class UserCases: XCTestCase {
9696
break
9797
}
9898

99-
let details = try await web3.eth.transactionDetails(txHash.data(using: .utf8)!)
99+
let details = try await web3.eth.transactionDetails(txHash)
100100
print(details)
101101
XCTAssert(details.transaction.to == .contractDeploymentAddress())
102102
}

0 commit comments

Comments
 (0)