|
6 | 6 | //
|
7 | 7 |
|
8 | 8 | import XCTest
|
| 9 | +import BigInt |
9 | 10 | import Core
|
10 | 11 |
|
11 | 12 | @testable import web3swift
|
@@ -52,4 +53,31 @@ final class PolicyResolverTests: XCTestCase {
|
52 | 53 | XCTAssertGreaterThan(tx.gasPrice ?? 0, 0)
|
53 | 54 | XCTAssertGreaterThan(tx.nonce, 0)
|
54 | 55 | }
|
| 56 | + |
| 57 | + func testResolveExact() async throws { |
| 58 | + let expectedNonce = BigUInt(42) |
| 59 | + let expectedGasLimit = BigUInt(22_000) |
| 60 | + let expectedBaseFee = BigUInt(20) |
| 61 | + let expectedPriorityFee = BigUInt(9) |
| 62 | + let web3 = await Web3.InfuraMainnetWeb3(accessToken: Constants.infuraToken) |
| 63 | + let resolver = PolicyResolver(provider: web3.provider) |
| 64 | + var tx = CodableTransaction( |
| 65 | + type: .eip1559, |
| 66 | + to: EthereumAddress("0xb47292B7bBedA4447564B8336E4eD1f93735e7C7")!, |
| 67 | + chainID: web3.provider.network!.chainID, |
| 68 | + value: Utilities.parseToBigUInt("0.1", units: .eth)!, |
| 69 | + gasLimit: 21_000 |
| 70 | + ) |
| 71 | + // Vitalik's address |
| 72 | + tx.from = EthereumAddress("0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B")! |
| 73 | + tx.gasLimitPolicy = .manual(expectedGasLimit) |
| 74 | + tx.maxFeePerGasPolicy = .manual(expectedBaseFee) |
| 75 | + tx.maxPriorityFeePerGasPolicy = .manual(expectedPriorityFee) |
| 76 | + tx.noncePolicy = .exact(expectedNonce) |
| 77 | + try await resolver.resolveAll(for: &tx) |
| 78 | + XCTAssertEqual(tx.gasLimit, expectedGasLimit) |
| 79 | + XCTAssertEqual(tx.maxFeePerGas, expectedBaseFee) |
| 80 | + XCTAssertEqual(tx.maxPriorityFeePerGas, expectedPriorityFee) |
| 81 | + XCTAssertEqual(tx.nonce, expectedNonce) |
| 82 | + } |
55 | 83 | }
|
0 commit comments