Skip to content

Commit f512b7b

Browse files
committed
Add test for custom set values
1 parent 40dbebf commit f512b7b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Tests/web3swiftTests/remoteTests/PolicyResolverTests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import XCTest
9+
import BigInt
910
import Core
1011

1112
@testable import web3swift
@@ -52,4 +53,31 @@ final class PolicyResolverTests: XCTestCase {
5253
XCTAssertGreaterThan(tx.gasPrice ?? 0, 0)
5354
XCTAssertGreaterThan(tx.nonce, 0)
5455
}
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+
}
5583
}

0 commit comments

Comments
 (0)