Skip to content

Commit c71cf59

Browse files
Now node link for all localTest are assigns in one place.
1 parent 7510932 commit c71cf59

11 files changed

+49
-25
lines changed

Tests/web3swiftTests/localTests/AdvancedABIv2Tests.swift

Lines changed: 11 additions & 7 deletions
Large diffs are not rendered by default.

Tests/web3swiftTests/localTests/BasicLocalNodeTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Core
1414
class BasicLocalNodeTests: LocalTestCase {
1515

1616
func testDeployWithRemoteSigning() async throws {
17-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
17+
let web3 = try await Web3.new(LocalTestCase.url)
1818
let allAddresses = try await web3.eth.ownedAccounts()
1919

2020
let abiString = "[{\"constant\":true,\"inputs\":[],\"name\":\"getFlagData\",\"outputs\":[{\"name\":\"data\",\"type\":\"string\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"data\",\"type\":\"string\"}],\"name\":\"setFlagData\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
@@ -48,7 +48,7 @@ class BasicLocalNodeTests: LocalTestCase {
4848
}
4949

5050
func testEthSendExampleWithRemoteSigning() async throws {
51-
let web3 = try await Web3.new(URL(string: "http://127.0.0.1:8545")!)
51+
let web3 = try await Web3.new(LocalTestCase.url)
5252
let allAddresses = try await web3.eth.ownedAccounts()
5353
let sendToAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!
5454
let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2)!

Tests/web3swiftTests/localTests/DecodeSolidityErrorType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class DecodeSolidityErrorType: XCTestCase {
1616

1717
func testStructuredErrorTypeDecoding() async throws {
1818
let contractAbiWithErrorTypes = "[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"address\",\"name\":\"disallowedAddress\",\"type\":\"address\"}],\"name\":\"NotAllowedAddress\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"bytes4\",\"name\":\"disallowedFunction\",\"type\":\"bytes4\"}],\"name\":\"NotAllowedFunction\",\"type\":\"error\"},{\"inputs\":[{\"internalType\":\"address\",\"name\":\"from\",\"type\":\"address\"},{\"internalType\":\"string\",\"name\":\"permission\",\"type\":\"string\"}],\"name\":\"NotAuthorised\",\"type\":\"error\"}]"
19-
let web3Instance = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
19+
let web3Instance = try await Web3.new(LocalTestCase.url)
2020
let contract = web3.web3contract(web3: web3Instance, abiString: contractAbiWithErrorTypes)
2121
assert(contract != nil)
2222
}

Tests/web3swiftTests/localTests/ERC20Tests.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,24 @@ class ERC20Tests: LocalTestCase {
3636
print(String(bal))
3737
}
3838

39+
// func testERC20TokenSend() async throws {
40+
// let web3 = Web3.
41+
// let value: String = "1.0" // In Tokens
42+
// let walletAddress = EthereumAddress(wallet.address)! // Your wallet address
43+
// let toAddress = EthereumAddress(toAddressString)!
44+
// let erc20ContractAddress = EthereumAddress(token.address)!
45+
// let contract = web3.contract(Web3.Utils.erc20ABI, at: erc20ContractAddress, abiVersion: 2)!
46+
// let amount = Web3.Utils.parseToBigUInt(value, units: .eth)
47+
// var options = TransactionOptions.defaultOptions
48+
// options.value = amount
49+
// options.from = walletAddress
50+
// options.gasPrice = .automatic
51+
// options.gasLimit = .automatic
52+
// let method = "transfer"
53+
// let tx = contract.write(
54+
// method,
55+
// parameters: [toAddress, amount] as [AnyObject],
56+
// extraData: Data(),
57+
// transactionOptions: options)!
58+
// }
3959
}

Tests/web3swiftTests/localTests/EventloopTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class EventloopTests: XCTestCase {
2727
}
2828
}
2929

30-
let web3main = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
30+
let web3main = try await Web3.new(LocalTestCase.url)
3131
let functionToCall: web3.Eventloop.EventLoopCall = getBlockNumber
3232
let monitoredProperty = web3.Eventloop.MonitoredProperty.init(name: "onNewBlock", calledFunction: functionToCall)
3333
web3main.eventLoop.monitoredProperties.append(monitoredProperty)

Tests/web3swiftTests/localTests/PersonalSignatureTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Core
1414
class PersonalSignatureTests: XCTestCase {
1515

1616
func testPersonalSignature() async throws {
17-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
17+
let web3 = try await Web3.new(LocalTestCase.url)
1818
let tempKeystore = try! EthereumKeystoreV3(password: "")
1919
let keystoreManager = KeystoreManager([tempKeystore!])
2020
web3.addKeystoreManager(keystoreManager)
@@ -33,7 +33,7 @@ class PersonalSignatureTests: XCTestCase {
3333

3434
// TODO: - write contract
3535
func testPersonalSignatureOnContract() async throws {
36-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
36+
let web3 = try await Web3.new(LocalTestCase.url)
3737
// Deploying contract
3838
let abiString = "[{\"inputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"constant\":true,\"inputs\":[{\"name\":\"_message\",\"type\":\"string\"}],\"name\":\"hashPersonalMessage\",\"outputs\":[{\"name\":\"hash\",\"type\":\"bytes32\"}],\"payable\":false,\"stateMutability\":\"pure\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"_message\",\"type\":\"string\"},{\"name\":\"v\",\"type\":\"uint8\"},{\"name\":\"r\",\"type\":\"bytes32\"},{\"name\":\"s\",\"type\":\"bytes32\"}],\"name\":\"recoverSigner\",\"outputs\":[{\"name\":\"signer\",\"type\":\"address\"}],\"payable\":false,\"stateMutability\":\"pure\",\"type\":\"function\"}]"
3939
let bytecode = Data.fromHex("0x608060405234801561001057600080fd5b506105ba806100206000396000f30060806040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632785e93714610051578063d01ec9a514610123575b600080fd5b34801561005d57600080fd5b506100e1600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290803560ff169060200190929190803560001916906020019092919080356000191690602001909291905050506101a8565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561012f57600080fd5b5061018a600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610258565b60405180826000191660001916815260200191505060405180910390f35b6000806101b486610258565b9050601b8560ff1610156101c957601b850194505b600181868686604051600081526020016040526040518085600019166000191681526020018460ff1660ff1681526020018360001916600019168152602001826000191660001916815260200194505050505060206040516020810390808403906000865af1158015610240573d6000803e3d6000fd5b50505060206040510351915081915050949350505050565b600080825190506040805190810160405280601a81526020017f19457468657265756d205369676e6564204d6573736167653a0a00000000000081525061029e826103b4565b846040518084805190602001908083835b6020831015156102d457805182526020820191506020810190506020830392506102af565b6001836020036101000a03801982511681845116808217855250505050505090500183805190602001908083835b6020831015156103275780518252602082019150602081019050602083039250610302565b6001836020036101000a03801982511681845116808217855250505050505090500182805190602001908083835b60208310151561037a5780518252602082019150602081019050602083039250610355565b6001836020036101000a03801982511681845116808217855250505050505090500193505050506040518091039020915081915050919050565b606060006060600080600060649450846040519080825280601f01601f1916602001820160405280156103f65781602001602082028038833980820191505090505b509350600092505b60008714151561049557600a8781151561041457fe5b069150600a8781151561042357fe5b049650816030017f010000000000000000000000000000000000000000000000000000000000000002848480600101955081518110151561046057fe5b9060200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506103fe565b826040519080825280601f01601f1916602001820160405280156104c85781602001602082028038833980820191505090505b509550600090505b8281101561058157838160018503038151811015156104eb57fe5b9060200101517f010000000000000000000000000000000000000000000000000000000000000090047f010000000000000000000000000000000000000000000000000000000000000002868281518110151561054457fe5b9060200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535080806001019150506104d0565b85955050505050509190505600a165627a7a723058204b567e6628d988bde2e19a4e9a457bf84bbeac15069a74fe993aba215fb024330029")!

Tests/web3swiftTests/localTests/PromisesTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class web3swiftPromisesTests: XCTestCase {
1414
var urlSession : URLSession?
1515

1616
func testGetBalancePromise() async throws {
17-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
17+
let web3 = try await Web3.new(LocalTestCase.url)
1818
let balance = try await web3.eth.getBalance(for: "0xe22b8979739D724343bd002F9f432F5990879901")
1919
print(balance)
2020
}
2121

2222
func testEstimateGasPromise() async throws {
23-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
23+
let web3 = try await Web3.new(LocalTestCase.url)
2424
let sendToAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")
2525
let tempKeystore = try! EthereumKeystoreV3(password: "")
2626
let keystoreManager = KeystoreManager([tempKeystore!])
@@ -38,7 +38,7 @@ class web3swiftPromisesTests: XCTestCase {
3838
// Deploy contract
3939
let bytecode = Data.fromHex("0x608060405234801561001057600080fd5b50610100806100206000396000f30060806040526004361060525763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416630dbe671f8114605757806329e99f0714607b5780634df7e3d0146092575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50609060043560aa565b005b348015609d57600080fd5b50606960ce565b60005481565b803a111560ba57600160005560cb565b803a101560cb576001600081905580555b50565b600154815600a165627a7a723058200327a504a24f70cf740239fad2ad203f21caf0ef05f7870bd88482f6fa3cf1080029")!
4040

41-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
41+
let web3 = try await Web3.new(LocalTestCase.url)
4242
let allAddresses = try await web3.eth.ownedAccounts()
4343
let contract = web3.contract(Web3.Utils.estimateGasTestABI, at: nil, abiVersion: 2)!
4444

@@ -101,7 +101,7 @@ class web3swiftPromisesTests: XCTestCase {
101101
}
102102
// FIXME: Temporary deleted method `sendETH` should be restored.
103103
// func testSendETHPromise() async throws {
104-
// let web3 = try await Web3.new(URL(string: "http://127.0.0.1:8545")!)
104+
// let web3 = try await Web3.new(LocalTestCase.url)
105105
// let allAddresses = try await web3.eth.ownedAccounts()
106106
// let gasPrice = try await web3.eth.gasPrice()
107107
// let sendToAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!

Tests/web3swiftTests/localTests/TestHelpers.swift

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

Tests/web3swiftTests/localTests/TransactionsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ class TransactionsTests: XCTestCase {
626626

627627
func testEthSendExampleAndGetTransactionReceiptAndDetails() async {
628628
do {
629-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
629+
let web3 = try await Web3.new(LocalTestCase.url)
630630
let sendToAddress = EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!
631631
let allAddresses = try await web3.eth.ownedAccounts()
632632
let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2)

Tests/web3swiftTests/localTests/UncategorizedTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class UncategorizedTests: XCTestCase {
112112

113113
func testPublicMappingsAccess() async throws {
114114
let jsonString = "[{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"name\":\"users\",\"outputs\":[{\"name\":\"name\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[{\"name\":\"\",\"type\":\"address\"}],\"name\":\"userDeviceCount\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"totalUsers\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"stateMutability\":\"view\",\"type\":\"function\"}]"
115-
let web3 = try await Web3.new(URL.init(string: "http://127.0.0.1:8545")!)
115+
let web3 = try await Web3.new(LocalTestCase.url)
116116
guard let addr = EthereumAddress("0xdef61132a0c1259464b19e4590e33666aae38574") else {return XCTFail()}
117117
let contract = web3.contract(jsonString, at: addr, abiVersion: 2)
118118
XCTAssert(contract != nil)

0 commit comments

Comments
 (0)