Skip to content

Commit fff111c

Browse files
Merge pull request #755 from JeneaVranceanu/feat/git-hooks
feat: git hooks implementation
2 parents 70202c1 + ce274a2 commit fff111c

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v3.2.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-case-conflict
10+
- id: check-json
11+
- id: mixed-line-ending
12+
- id: no-commit-to-branch
13+
args: [--branch, staging, --branch, main, --branch, master, --branch, develop-4.0, --branch, develop-upstream]
14+
- repo: https://github.com/codespell-project/codespell
15+
rev: v2.2.2
16+
hooks:
17+
- id: codespell
18+
args: ["--count --ignore-words-list=ans,deriver,inout,packag --skip=\"*.js,*WordLists.swift,.git,Carthage,.build,build\""]
19+
# SwiftLint is commented out until we fix all SwiftLint warnings and errors.
20+
# https://github.com/web3swift-team/web3swift/pull/756
21+
#- repo: https://github.com/realm/SwiftLint
22+
# rev: 0.50.3
23+
# hooks:
24+
# - id: swiftlint
25+
# args: [--fix, Sources, Tests]

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ $ ganache
193193
This will create a local blockchain and also some test accounts that are used throughout our tests.
194194
Make sure that `ganache` is running on its default port `8546`. To change the port in test cases locate `LocalTestCase.swift` and modify the static `url` variable.
195195

196+
### Before you commit
197+
198+
We are using [pre-commit](https://pre-commit.com) to run validations locally before a commit is created. Please, install pre-commit and run `pre-commit install` from project's root directory. After that before every commit git hook will run and execute `codespell`, `swiftlint` and other checks.
199+
196200
## Contribute
197201
Want to improve? It's awesome:
198202
Then good news for you: **We are ready to pay for your contribution via [@gitcoin bot](https://gitcoin.co/grants/358/web3swift)!**

Tests/web3swiftTests/localTests/TransactionsTests.swift

100755100644
Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class TransactionsTests: XCTestCase {
195195
// check that we recovered the address correctly
196196
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
197197
} catch {
198-
198+
199199
return XCTFail(String(describing: error))
200200
}
201201
}
@@ -243,7 +243,7 @@ class TransactionsTests: XCTestCase {
243243
// check that we recovered the address correctly
244244
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
245245
} catch {
246-
246+
247247
return XCTFail(String(describing: error))
248248
}
249249
}
@@ -264,7 +264,7 @@ class TransactionsTests: XCTestCase {
264264
// check that we recovered the address correctly
265265
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
266266
} catch {
267-
267+
268268
return XCTFail(String(describing: error))
269269
}
270270
}
@@ -312,7 +312,7 @@ class TransactionsTests: XCTestCase {
312312
// check that we recovered the address correctly
313313
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
314314
} catch {
315-
315+
316316
return XCTFail(String(describing: error))
317317
}
318318
}
@@ -333,7 +333,7 @@ class TransactionsTests: XCTestCase {
333333
// check that we recovered the address correctly
334334
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
335335
} catch {
336-
336+
337337
return XCTFail(String(describing: error))
338338
}
339339
}
@@ -381,7 +381,7 @@ class TransactionsTests: XCTestCase {
381381
// check that we recovered the address correctly
382382
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
383383
} catch {
384-
384+
385385
return XCTFail(String(describing: error))
386386
}
387387
}
@@ -402,7 +402,7 @@ class TransactionsTests: XCTestCase {
402402
// check that we recovered the address correctly
403403
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
404404
} catch {
405-
405+
406406
return XCTFail(String(describing: error))
407407
}
408408
}
@@ -450,7 +450,7 @@ class TransactionsTests: XCTestCase {
450450
// check that we recovered the address correctly
451451
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
452452
} catch {
453-
453+
454454
return XCTFail(String(describing: error))
455455
}
456456
}
@@ -518,7 +518,7 @@ class TransactionsTests: XCTestCase {
518518
// check that we recovered the address correctly
519519
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
520520
} catch {
521-
521+
522522
return XCTFail(String(describing: error))
523523
}
524524
}
@@ -539,7 +539,7 @@ class TransactionsTests: XCTestCase {
539539
// check that we recovered the address correctly
540540
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
541541
} catch {
542-
542+
543543
return XCTFail(String(describing: error))
544544
}
545545
}
@@ -587,7 +587,7 @@ class TransactionsTests: XCTestCase {
587587
// check that we recovered the address correctly
588588
XCTAssertEqual(jsonTxn.sender!.address, expectedAddress.address, "Recovered Address Mismatch")
589589
} catch {
590-
590+
591591
return XCTFail(String(describing: error))
592592
}
593593
}
@@ -611,16 +611,16 @@ class TransactionsTests: XCTestCase {
611611
let publicKey = Utilities.privateToPublic(privateKeyData, compressed: false)
612612
let sender = Utilities.publicToAddress(publicKey!)
613613
transaction.chainID = 1
614-
614+
615615
let hash = transaction.hashForSignature()
616616
let expectedHash = "0xdaf5a779ae972f972197303d7b574746c7ef83eadac0f2791ad23db92e4c8e53".stripHexPrefix()
617617
XCTAssertEqual(hash!.toHexString(), expectedHash, "Transaction signature failed")
618618
try transaction.sign(privateKey: privateKeyData, useExtraEntropy: false)
619-
619+
620620
XCTAssertEqual(transaction.v, 37, "Transaction signature failed")
621621
XCTAssertEqual(sender, transaction.sender)
622622
} catch {
623-
623+
624624
XCTFail()
625625
}
626626
}
@@ -639,12 +639,12 @@ class TransactionsTests: XCTestCase {
639639
let policies = Policies(gasLimitPolicy: .manual(78423))
640640
let result = try await writeTX.writeToChain(password: "", policies: policies, sendRaw: false)
641641
let txHash = Data.fromHex(result.hash.stripHexPrefix())!
642-
642+
643643

644644
Thread.sleep(forTimeInterval: 1.0)
645645

646646
let receipt = try await web3.eth.transactionReceipt(txHash)
647-
647+
648648
XCTAssert(receipt.status == .ok)
649649

650650
switch receipt.status {
@@ -655,13 +655,13 @@ class TransactionsTests: XCTestCase {
655655
}
656656

657657
let details = try await web3.eth.transactionDetails(txHash)
658-
658+
659659
// FIXME: Re-enable this test.
660660
// XCTAssertEqual(details.transaction.gasLimit, BigUInt(78423))
661661
} catch Web3Error.nodeError(let descr) {
662662
guard descr == "insufficient funds for gas * price + value" else {return XCTFail()}
663663
} catch {
664-
664+
665665
XCTFail()
666666
}
667667
}

0 commit comments

Comments
 (0)