diff --git a/Documentation/Usage.md b/Documentation/Usage.md index b030ec8f0..d622ad339 100755 --- a/Documentation/Usage.md +++ b/Documentation/Usage.md @@ -359,8 +359,8 @@ let result = try! transaction.call() ##### Other Transaction Types By default a `legacy` transaction will be created which is compatible across all chains, regardless of which fork. -To create one of the new transaction types introduced with the `london` fork you will need to set some additonal parameters -in the `TransactionOptions` object. Note you should only try to send one of tehse new types of transactions if you are on a chain +To create one of the new transaction types introduced with the `london` fork you will need to set some additional parameters +in the `TransactionOptions` object. Note you should only try to send one of these new types of transactions if you are on a chain that supports them. To send an EIP-2930 style transacton with an access list you need to set the transaction type, and the access list, @@ -385,10 +385,10 @@ To send an EIP-1559 style transaction you set the transaction type, and the new (you may also send an AccessList with an EIP-1559 transaction) When sending an EIP-1559 transaction, the older `gasPrice` parameter is ignored. ```swift options.type = .eip1559 -options.maxFeePerGas = .manual(...) // the maximum price per unit of gas, inclusive of baseFee and tip -options.maxPriorityFeePerGas = .manual(...) // the tip to be paid to the miner, per unit of gas +options.maxFeePerGas = .automatic // the maximum price per unit of gas, inclusive of baseFee and tip +options.maxPriorityFeePerGas = .automatic // the 'tip' to be paid to the miner, per unit of gas ``` -Note there is a new `Oracle` object available that can be used to assist with estimating the new gas fees +Note: There is a new `Oracle` object available that can be used to assist with estimating the new gas fees if you wish to set them manually. ### Chain state diff --git a/Sources/web3swift/Web3/Web3+GasOracle.swift b/Sources/web3swift/Web3/Web3+GasOracle.swift index 61f57a3a3..65aa16f7d 100644 --- a/Sources/web3swift/Web3/Web3+GasOracle.swift +++ b/Sources/web3swift/Web3/Web3+GasOracle.swift @@ -128,7 +128,10 @@ extension Web3 { case let .exact(number): latestBlockNumber = number } - guard latestBlockNumber != 0 else { return [] } + /// checking if latest block number is greather than number of blocks to take in account + /// we're ignoring case when `latestBlockNumber` == `blockCount` since it's unlikely case + /// which we could neglect + guard latestBlockNumber > blockCount else { return [] } // TODO: Make me work with cache let blocks = try await withThrowingTaskGroup(of: Block.self, returning: [Block].self) { group in diff --git a/Tests/web3swiftTests/localTests/ABIEncoderSoliditySha3Test.swift b/Tests/web3swiftTests/localTests/ABIEncoderSoliditySha3Test.swift index a6ceda15d..5d59d356e 100644 --- a/Tests/web3swiftTests/localTests/ABIEncoderSoliditySha3Test.swift +++ b/Tests/web3swiftTests/localTests/ABIEncoderSoliditySha3Test.swift @@ -10,7 +10,7 @@ import Foundation import XCTest @testable import web3swift -class ABIEncoderSoliditySha3Test: XCTestCase { +class ABIEncoderSoliditySha3Test: LocalTestCase { func test_soliditySha3() throws { var hex = try ABIEncoder.soliditySha3(true).toHexString().addHexPrefix() diff --git a/Tests/web3swiftTests/localTests/DataConversionTests.swift b/Tests/web3swiftTests/localTests/DataConversionTests.swift index 224f1db0a..a0f43dc29 100644 --- a/Tests/web3swiftTests/localTests/DataConversionTests.swift +++ b/Tests/web3swiftTests/localTests/DataConversionTests.swift @@ -16,7 +16,7 @@ import XCTest // Some base58 test vectors pulled from: https://tools.ietf.org/id/draft-msporny-base58-01.html // note that one of the return values is incorrect in the reference above, it is corrected here -class DataConversionTests: XCTestCase { +class DataConversionTests: LocalTestCase { // test an empty input for the base58 decoder & decoder func testBase58() throws { let vector = "" diff --git a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift index 6ee30db02..e60ef23b9 100644 --- a/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift +++ b/Tests/web3swiftTests/localTests/EIP1559BlockTests.swift @@ -4,7 +4,7 @@ import BigInt @testable import web3swift -class EIP1559BlockTests: XCTestCase { +class EIP1559BlockTests: LocalTestCase { let uselessBlockPart = ( number: BigUInt(12_965_000), hash: Data(fromHex: "0xef95f2f1ed3ca60b048b4bf67cde2195961e0bba6f70bcbea9a2c4e133e34b46")!, // "hash": diff --git a/Tests/web3swiftTests/localTests/EIP712Tests.swift b/Tests/web3swiftTests/localTests/EIP712Tests.swift index a3192e959..f5a323d8f 100644 --- a/Tests/web3swiftTests/localTests/EIP712Tests.swift +++ b/Tests/web3swiftTests/localTests/EIP712Tests.swift @@ -1,15 +1,15 @@ import XCTest @testable import web3swift -class EIP712Tests: XCTestCase { +class EIP712Tests: LocalTestCase { func testWithoutChainId() throws { - + let to = EthereumAddress("0x3F06bAAdA68bB997daB03d91DBD0B73e196c5A4d")! - + let value = EIP712.UInt256(0) - + let amountLinen = EIP712.UInt256("0001000000000000000")// - + let function = ABI.Element.Function( name: "approveAndMint", inputs: [ @@ -18,22 +18,22 @@ class EIP712Tests: XCTestCase { outputs: [.init(name: "", type: .bool)], constant: false, payable: false) - + let object = ABI.Element.function(function) - + let safeTxData = object.encodeParameters([ EthereumAddress("0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72")! as AnyObject, amountLinen as AnyObject ])! - + let operation: EIP712.UInt8 = 1 - + let safeTxGas = EIP712.UInt256(250000) - + let baseGas = EIP712.UInt256(60000) - + let gasPrice = EIP712.UInt256("20000000000") - + let gasToken = EthereumAddress("0x0000000000000000000000000000000000000000")! print(1) let refundReceiver = EthereumAddress("0x7c07D32e18D6495eFDC487A32F8D20daFBa53A5e")! @@ -76,13 +76,13 @@ class EIP712Tests: XCTestCase { } func testWithChainId() throws { - + let to = EthereumAddress("0x3F06bAAdA68bB997daB03d91DBD0B73e196c5A4d")! - + let value = EIP712.UInt256(0) - + let amount = EIP712.UInt256("0001000000000000000") - + let function = ABI.Element.Function( name: "approveAndMint", inputs: [ @@ -91,28 +91,28 @@ class EIP712Tests: XCTestCase { outputs: [.init(name: "", type: .bool)], constant: false, payable: false) - + let object = ABI.Element.function(function) - + let safeTxData = object.encodeParameters([ EthereumAddress("0x41B5844f4680a8C38fBb695b7F9CFd1F64474a72")! as AnyObject, amount as AnyObject ])! - + let operation: EIP712.UInt8 = 1 - + let safeTxGas = EIP712.UInt256(250000) - + let baseGas = EIP712.UInt256(60000) - + let gasPrice = EIP712.UInt256("20000000000") - + let gasToken = EthereumAddress("0x0000000000000000000000000000000000000000")! - + let refundReceiver = EthereumAddress("0x7c07D32e18D6495eFDC487A32F8D20daFBa53A5e")! - + let nonce: EIP712.UInt256 = .init(0) - + let safeTX = SafeTx( to: to, value: value, @@ -124,16 +124,16 @@ class EIP712Tests: XCTestCase { gasToken: gasToken, refundReceiver: refundReceiver, nonce: nonce) - + let mnemonic = "normal dune pole key case cradle unfold require tornado mercy hospital buyer" let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "")! - + let verifyingContract = EthereumAddress("0x76106814dc6150b0fe510fbda4d2d877ac221270")! - + let account = keystore.addresses?[0] let password = "" let chainId: EIP712.UInt256? = EIP712.UInt256(42) - + let signature = try Web3Signer.signEIP712( safeTx: safeTX, keystore: keystore, @@ -141,8 +141,7 @@ class EIP712Tests: XCTestCase { account: account!, password: password, chainId: chainId) - + XCTAssertEqual(signature.toHexString(), "f1f423cb23efad5035d4fb95c19cfcd46d4091f2bd924680b88c4f9edfa1fb3a4ce5fc5d169f354e3b464f45a425ed3f6203af06afbacdc5c8224a300ce9e6b21b") } } - diff --git a/Tests/web3swiftTests/localTests/LocalTestCase.swift b/Tests/web3swiftTests/localTests/LocalTestCase.swift new file mode 100644 index 000000000..404818eb9 --- /dev/null +++ b/Tests/web3swiftTests/localTests/LocalTestCase.swift @@ -0,0 +1,45 @@ +import Foundation +import XCTest +import BigInt + +import web3swift + +// SuperClass that all local tests should be derived from +// while this class does show up in the navigator, it has no associated tests +class LocalTestCase: XCTestCase { + static let url = URL.init(string: "http://127.0.0.1:8545")! + static var isSetUp = false + + override class func setUp() { + super.setUp() + + Task { + // check to see if we need to run the one-time setup + if isSetUp { return } + isSetUp = true + + let web3 = try! await Web3.new(LocalTestCase.url) + + let block = try! await web3.eth.getBlockNumber() + if block >= 25 { return } + + print("\n ****** Preloading Ganache (\(25 - block) blocks) *****\n") + + let allAddresses = try! await web3.eth.getAccounts() + let sendToAddress = allAddresses[0] + let contract = web3.contract(Web3.Utils.coldWalletABI, at: sendToAddress, abiVersion: 2) + let value = Web3.Utils.parseToBigUInt("1.0", units: .eth) + + let from = allAddresses[0] + let writeTX = contract!.write("fallback")! + writeTX.transactionOptions.from = from + writeTX.transactionOptions.value = value + writeTX.transactionOptions.gasLimit = .manual(78423) + writeTX.transactionOptions.gasPrice = .manual(20000000000) + + for _ in block..<25 { + let _ = try! await writeTX.send(password: "") + } + } + } +} diff --git a/Tests/web3swiftTests/localTests/LocalTests.xctestplan b/Tests/web3swiftTests/localTests/LocalTests.xctestplan index 5af7facc1..349bc4b42 100644 --- a/Tests/web3swiftTests/localTests/LocalTests.xctestplan +++ b/Tests/web3swiftTests/localTests/LocalTests.xctestplan @@ -21,7 +21,8 @@ "RemoteParsingTests", "RemoteTests", "ST20AndSecurityTokenTests", - "WebsocketTests" + "WebsocketTests", + "LocalTestCase" ], "target" : { "containerPath" : "container:web3swift.xcodeproj", diff --git a/Tests/web3swiftTests/localTests/web3swiftEIP67Tests.swift b/Tests/web3swiftTests/localTests/web3swiftEIP67Tests.swift index 1cebc28b3..722bd0ed6 100755 --- a/Tests/web3swiftTests/localTests/web3swiftEIP67Tests.swift +++ b/Tests/web3swiftTests/localTests/web3swiftEIP67Tests.swift @@ -10,8 +10,8 @@ import BigInt @testable import web3swift -class web3swiftEIP67Tests: XCTestCase { - +class web3swiftEIP67Tests: LocalTestCase { + func testEIP67encoding() throws { var eip67Data = Web3.EIP67Code.init(address: EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!) eip67Data.gasLimit = BigUInt(21000) @@ -20,7 +20,7 @@ class web3swiftEIP67Tests: XCTestCase { let encoding = eip67Data.toString() print(encoding) } - + func testEIP67codeGeneration() throws { var eip67Data = Web3.EIP67Code.init(address: EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!) eip67Data.gasLimit = BigUInt(21000) @@ -29,18 +29,17 @@ class web3swiftEIP67Tests: XCTestCase { let encoding = eip67Data.toImage(scale: 5.0) XCTAssert(encoding != CIImage()) } - + func testEIP67decoding() throws { var eip67Data = Web3.EIP67Code.init(address: EthereumAddress("0xe22b8979739D724343bd002F9f432F5990879901")!) eip67Data.gasLimit = BigUInt(21000) eip67Data.amount = BigUInt("1000000000000000000") // eip67Data.data = let encoding = eip67Data.toString() - guard let code = Web3.EIP67CodeParser.parse(encoding) else {return XCTFail()} + guard let code = Web3.EIP67CodeParser.parse(encoding) else { return XCTFail() } XCTAssert(code.address == eip67Data.address) XCTAssert(code.gasLimit == eip67Data.gasLimit) XCTAssert(code.amount == eip67Data.amount) } - -} +} diff --git a/Tests/web3swiftTests/localTests/web3swiftKeystoresTests.swift b/Tests/web3swiftTests/localTests/web3swiftKeystoresTests.swift index 1ef769a51..4d8245c43 100755 --- a/Tests/web3swiftTests/localTests/web3swiftKeystoresTests.swift +++ b/Tests/web3swiftTests/localTests/web3swiftKeystoresTests.swift @@ -9,10 +9,10 @@ import CryptoSwift @testable import web3swift -class web3swiftKeystoresTests: XCTestCase { - +class web3swiftKeystoresTests: LocalTestCase { + let mnemonic = "fruit wave dwarf banana earth journey tattoo true farm silk olive fence" - + func testBIP39 () throws { var entropy = Data.fromHex("00000000000000000000000000000000")! var phrase = BIP39.generateMnemonicsFromEntropy(entropy: entropy) @@ -25,7 +25,7 @@ class web3swiftKeystoresTests: XCTestCase { seed = BIP39.seedFromMmemonics(phrase!, password: "TREZOR") XCTAssert(seed?.toHexString() == "64c87cde7e12ecf6704ab95bb1408bef047c22db4cc7491c4271d170a1b213d20b385bc1588d9c7b38f1b39d415665b8a9030c9ec653d75e65f847d8fc1fc440") } - + func testBIP39SeedAndMnemConversions() throws { let seed = Data.randomBytes(length: 32)! let mnemonics = BIP39.generateMnemonicsFromEntropy(entropy: seed) @@ -69,33 +69,33 @@ class web3swiftKeystoresTests: XCTestCase { let mnemonic_27 = "clock venue style demise net float differ click object poet afraid october hurry organ faint inject cart trade test immense gentle speak almost rude success drip spoon" XCTAssertNil(BIP39.mnemonicsToEntropy(mnemonic_27, language: .english)) } - + func testHMAC() throws { let seed = Data.fromHex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")! let data = Data.fromHex("4869205468657265")! let hmac = try! HMAC.init(key: seed.bytes, variant: HMAC.Variant.sha2(.sha512)).authenticate(data.bytes) XCTAssert(Data(hmac).toHexString() == "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854") } - + func testV3keystoreExportPrivateKey() throws { - let keystore = try! EthereumKeystoreV3(password: ""); + let keystore = try! EthereumKeystoreV3(password: "") XCTAssertNotNil(keystore) let account = keystore!.addresses![0] print(account) let data = try! keystore!.serialize() - print(try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions(rawValue:0))) + print(try! JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions(rawValue: 0))) let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "", account: account) XCTAssertNotNil(key) } - + func testV3keystoreSerialization() throws { - let keystore = try! EthereumKeystoreV3(password: ""); + let keystore = try! EthereumKeystoreV3(password: "") XCTAssertNotNil(keystore) let account = keystore!.addresses![0] let data = try! keystore!.serialize() let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "", account: account) XCTAssertNotNil(key) - + let restored = EthereumKeystoreV3(data!) XCTAssertNotNil(restored) XCTAssertEqual(keystore!.addresses!.first!, restored!.addresses!.first!) @@ -103,20 +103,20 @@ class web3swiftKeystoresTests: XCTestCase { XCTAssertNotNil(restoredKey) XCTAssertEqual(key, restoredKey) } - + func testNewBIP32keystore() throws { let mnemonic = try! BIP39.generateMnemonics(bitsOfEntropy: 256)! let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "") XCTAssert(keystore != nil) } - + func testSameAddressesFromTheSameMnemonics() throws { let mnemonic = try! BIP39.generateMnemonics(bitsOfEntropy: 256)! let keystore1 = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "") let keystore2 = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "") XCTAssert(keystore1?.addresses?.first == keystore2?.addresses?.first) } - + func testBIP32keystoreExportPrivateKey() throws { let mnemonic = "normal dune pole key case cradle unfold require tornado mercy hospital buyer" let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "") @@ -125,32 +125,32 @@ class web3swiftKeystoresTests: XCTestCase { let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "", account: account) XCTAssertNotNil(key) } - + func testBIP32keystoreMatching() throws { let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "banana") XCTAssertNotNil(keystore) let account = keystore!.addresses![0] let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "", account: account) - let pubKey = Web3.Utils.privateToPublic(key, compressed: true); + let pubKey = Web3.Utils.privateToPublic(key, compressed: true) XCTAssert(pubKey?.toHexString() == "027160bd3a4d938cac609ff3a11fe9233de7b76c22a80d2b575e202cbf26631659") } - + func testBIP32keystoreMatchingRootNode() throws { let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "banana") XCTAssertNotNil(keystore) let rootNode = try! keystore!.serializeRootNodeToString(password: "") XCTAssert(rootNode == "xprvA2KM71v838kPwE8Lfr12m9DL939TZmPStMnhoFcZkr1nBwDXSG7c3pjYbMM9SaqcofK154zNSCp7W7b4boEVstZu1J3pniLQJJq7uvodfCV") } - + func testBIP32keystoreCustomPathMatching() throws { - let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "banana", prefixPath:"m/44'/60'/0'/0") + let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "banana", prefixPath: "m/44'/60'/0'/0") XCTAssertNotNil(keystore) let account = keystore!.addresses![0] let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "", account: account) - let pubKey = Web3.Utils.privateToPublic(key, compressed: true); + let pubKey = Web3.Utils.privateToPublic(key, compressed: true) XCTAssert(pubKey?.toHexString() == "027160bd3a4d938cac609ff3a11fe9233de7b76c22a80d2b575e202cbf26631659") } - + func testByBIP32keystoreCreateChildAccount() throws { let mnemonic = "normal dune pole key case cradle unfold require tornado mercy hospital buyer" let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "") @@ -162,7 +162,7 @@ class web3swiftKeystoresTests: XCTestCase { let key = try! keystore!.UNSAFE_getPrivateKeyData(password: "", account: account) XCTAssertNotNil(key) } - + func testByBIP32keystoreCreateCustomChildAccount() throws { let mnemonic = "normal dune pole key case cradle unfold require tornado mercy hospital buyer" let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "") @@ -175,7 +175,7 @@ class web3swiftKeystoresTests: XCTestCase { XCTAssertNotNil(key) print(keystore!.addressStorage.paths) } - + func testByBIP32keystoreSaveAndDeriva() throws { let mnemonic = "normal dune pole key case cradle unfold require tornado mercy hospital buyer" let keystore = try! BIP32Keystore(mnemonics: mnemonic, password: "", mnemonicsPassword: "", prefixPath: "m/44'/60'/0'") @@ -194,20 +194,20 @@ class web3swiftKeystoresTests: XCTestCase { XCTAssert(keystore?.addresses![0] == recreatedStore?.addresses![0]) XCTAssert(keystore?.addresses![1] == recreatedStore?.addresses![1]) } - + func testPBKDF2() throws { let pass = "passDATAb00AB7YxDTTl".data(using: .utf8)! let salt = "saltKEYbcTcXHCBxtjD2".data(using: .utf8)! let dataArray = try? PKCS5.PBKDF2(password: pass.bytes, salt: salt.bytes, iterations: 100000, keyLength: 65, variant: HMAC.Variant.sha2(.sha512)).calculate() XCTAssert(Data(dataArray!).toHexString().addHexPrefix().lowercased() == "0x594256B0BD4D6C9F21A87F7BA5772A791A10E6110694F44365CD94670E57F1AECD797EF1D1001938719044C7F018026697845EB9AD97D97DE36AB8786AAB5096E7".lowercased()) } - + func testRIPEMD() throws { let data = "message digest".data(using: .ascii) let hash = try! RIPEMD160.hash(message: data!) XCTAssert(hash.toHexString() == "5d0689ef49d2fae572b881b123a85ffa21595f36") } - + func testHD32() throws { let seed = Data.fromHex("000102030405060708090a0b0c0d0e0f")! let node = HDNode(seed: seed)! @@ -216,7 +216,7 @@ class web3swiftKeystoresTests: XCTestCase { let serializedPriv = node.serializeToString(serializePublic: false) XCTAssert(serialized == "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8") XCTAssert(serializedPriv == "xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi") - + let deserializedNode = HDNode(serializedPriv!) XCTAssert(deserializedNode != nil) XCTAssert(deserializedNode?.depth == 0) @@ -226,7 +226,7 @@ class web3swiftKeystoresTests: XCTestCase { XCTAssert(deserializedNode?.privateKey == node.privateKey) XCTAssert(deserializedNode?.publicKey == node.publicKey) XCTAssert(deserializedNode?.chaincode == node.chaincode) - + let nextNode = node.derive(index: 0, derivePrivateKey: true) XCTAssert(nextNode?.depth == 1) XCTAssert(nextNode?.index == UInt32(0)) @@ -235,7 +235,7 @@ class web3swiftKeystoresTests: XCTestCase { XCTAssert(nextNode?.publicKey.toHexString() == "027c4b09ffb985c298afe7e5813266cbfcb7780b480ac294b0b43dc21f2be3d13c") XCTAssert(nextNode?.serializeToString() == "xpub68Gmy5EVb2BdFbj2LpWrk1M7obNuaPTpT5oh9QCCo5sRfqSHVYWex97WpDZzszdzHzxXDAzPLVSwybe4uPYkSk4G3gnrPqqkV9RyNzAcNJ1") XCTAssert(nextNode?.serializeToString(serializePublic: false) == "xprv9uHRZZhbkedL37eZEnyrNsQPFZYRAvjy5rt6M1nbEkLSo378x1CQQLo2xxBvREwiK6kqf7GRNvsNEchwibzXaV6i5GcsgyjBeRguXhKsi4R") - + let nextNodeHardened = node.derive(index: 0, derivePrivateKey: true, hardened: true) XCTAssert(nextNodeHardened?.depth == 1) XCTAssert(nextNodeHardened?.index == UInt32(0)) @@ -244,14 +244,14 @@ class web3swiftKeystoresTests: XCTestCase { XCTAssert(nextNodeHardened?.publicKey.toHexString() == "035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56") XCTAssert(nextNodeHardened?.serializeToString() == "xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw") XCTAssert(nextNodeHardened?.serializeToString(serializePublic: false) == "xprv9uHRZZhk6KAJC1avXpDAp4MDc3sQKNxDiPvvkX8Br5ngLNv1TxvUxt4cV1rGL5hj6KCesnDYUhd7oWgT11eZG7XnxHrnYeSvkzY7d2bhkJ7") - + let treeNode = node.derive(path: HDNode.defaultPath) XCTAssert(treeNode != nil) XCTAssert(treeNode?.depth == 4) XCTAssert(treeNode?.serializeToString() == "xpub6DZ3xpo1ixWwwNDQ7KFTamRVM46FQtgcDxsmAyeBpTHEo79E1n1LuWiZSMSRhqMQmrHaqJpek2TbtTzbAdNWJm9AhGdv7iJUpDjA6oJD84b") XCTAssert(treeNode?.serializeToString(serializePublic: false) == "xprv9zZhZKG7taxeit8w1HiTDdUko2Fm1RxkrjxANbEaG7kFvJp5UEh6MiQ5b5XvwWg8xdHMhueagettVG2AbfqSRDyNpxRDBLyMSbNq1KhZ8ai") } - + func testBIP32derivation2() throws { let seed = Data.fromHex("fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542")! let node = HDNode(seed: seed)! @@ -262,7 +262,7 @@ class web3swiftKeystoresTests: XCTestCase { XCTAssert(treeNode?.serializeToString() == "xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt") XCTAssert(treeNode?.serializeToString(serializePublic: false) == "xprvA2nrNbFZABcdryreWet9Ea4LvTJcGsqrMzxHx98MMrotbir7yrKCEXw7nadnHM8Dq38EGfSh6dqA9QWTyefMLEcBYJUuekgW4BYPJcr9E7j") } - + func testKeystoreDerivationTime() throws { let privateKey = Data.randomBytes(length: 32)! measure { @@ -271,10 +271,10 @@ class web3swiftKeystoresTests: XCTestCase { let _ = try! ks.UNSAFE_getPrivateKeyData(password: "TEST", account: account) } } - + func testSingleScryptDerivation() throws { let privateKey = Data.randomBytes(length: 32)! let _ = try! EthereumKeystoreV3(privateKey: privateKey, password: "TEST")! } - + } diff --git a/Tests/web3swiftTests/localTests/web3swiftNumberFormattingUtilTests.swift b/Tests/web3swiftTests/localTests/web3swiftNumberFormattingUtilTests.swift index 8c4dfadaa..1282a6f09 100755 --- a/Tests/web3swiftTests/localTests/web3swiftNumberFormattingUtilTests.swift +++ b/Tests/web3swiftTests/localTests/web3swiftNumberFormattingUtilTests.swift @@ -10,61 +10,61 @@ import BigInt @testable import web3swift -class web3swiftNumberFormattingUtilTests: XCTestCase { - +class web3swiftNumberFormattingUtilTests: LocalTestCase { + func testNumberFormattingUtil() throws { let balance = BigInt("-1000000000000000000") print("this is print") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 4, decimalSeparator: ",") XCTAssert(formatted == "-1") } - + func testNumberFormattingUtil2() throws { let balance = BigInt("-1000000000000000") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 4, decimalSeparator: ",") XCTAssert(formatted == "-0,0010") } - + func testNumberFormattingUtil3() throws { let balance = BigInt("-1000000000000") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 4, decimalSeparator: ",") XCTAssert(formatted == "-0,0000") } - + func testNumberFormattingUtil4() throws { let balance = BigInt("-1000000000000") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 9, decimalSeparator: ",") XCTAssert(formatted == "-0,000001000") } - + func testNumberFormattingUtil5() throws { let balance = BigInt("-1") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 9, decimalSeparator: ",", fallbackToScientific: true) XCTAssert(formatted == "-1e-18") } - + func testNumberFormattingUtil6() throws { let balance = BigInt("0") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 9, decimalSeparator: ",") XCTAssert(formatted == "0") } - + func testNumberFormattingUtil7() throws { let balance = BigInt("-1100000000000000000") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 4, decimalSeparator: ",") XCTAssert(formatted == "-1,1000") } - + func testNumberFormattingUtil8() throws { let balance = BigInt("100") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 4, decimalSeparator: ",", fallbackToScientific: true) XCTAssert(formatted == "1,00e-16") } - + func testNumberFormattingUtil9() throws { let balance = BigInt("1000000") let formatted = Web3.Utils.formatToPrecision(balance, numberDecimals: 18, formattingDecimals: 4, decimalSeparator: ",", fallbackToScientific: true) XCTAssert(formatted == "1,0000e-12") } - + } diff --git a/Tests/web3swiftTests/localTests/web3swiftObjCTests.swift b/Tests/web3swiftTests/localTests/web3swiftObjCTests.swift index aaadf0172..167345181 100755 --- a/Tests/web3swiftTests/localTests/web3swiftObjCTests.swift +++ b/Tests/web3swiftTests/localTests/web3swiftObjCTests.swift @@ -8,7 +8,7 @@ // @testable import web3swift -// class web3swiftObjCTests: XCTestCase { +// class web3swiftObjCTests: LocalTestCase { // func testBalance() { // let web3 = _ObjCWeb3.InfuraMainnetWeb3() // let address = _ObjCEthereumAddress(address: "0xe22b8979739D724343bd002F9f432F5990879901") @@ -17,16 +17,16 @@ // XCTAssert(err?.pointee == nil) // XCTAssert(balance != nil) // } - + // func testGettingBlockNumber() { // let web3 = _ObjCWeb3.InfuraMainnetWeb3() // let err: NSErrorPointer = NSErrorPointer(nilLiteral: ()) // let blockNumber = web3.web3Eth.getBlockNumber(error: err) // XCTAssert(err?.pointee == nil) // XCTAssert(blockNumber != nil) - + // } - + // func testGasPrice(){ // let web3 = _ObjCWeb3.InfuraMainnetWeb3() // let err: NSErrorPointer = NSErrorPointer(nilLiteral: ()) diff --git a/Tests/web3swiftTests/localTests/web3swiftRLPTests.swift b/Tests/web3swiftTests/localTests/web3swiftRLPTests.swift index cb70f8f11..2f28d5e11 100755 --- a/Tests/web3swiftTests/localTests/web3swiftRLPTests.swift +++ b/Tests/web3swiftTests/localTests/web3swiftRLPTests.swift @@ -9,8 +9,8 @@ import BigInt @testable import web3swift -class web3swiftRLPTests: XCTestCase { - +class web3swiftRLPTests: LocalTestCase { + func testRLPdecodeTransaction() throws { let input = Data.fromHex("0xf90890558504e3b292008309153a8080b9083d6060604052336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550341561004f57600080fd5b60405160208061081d83398101604052808051906020019091905050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141515156100a757600080fd5b80600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050610725806100f86000396000f300606060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680638da5cb5b14610067578063b2b2c008146100bc578063d59ba0df146101eb578063d8ffdcc414610247575b600080fd5b341561007257600080fd5b61007a61029c565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156100c757600080fd5b61019460048080359060200190820180359060200190808060200260200160405190810160405280939291908181526020018383602002808284378201915050505050509190803590602001908201803590602001908080602002602001604051908101604052809392919081815260200183836020028082843782019150505050505091908035906020019082018035906020019080806020026020016040519081016040528093929190818152602001838360200280828437820191505050505050919050506102c1565b6040518080602001828103825283818151815260200191508051906020019060200280838360005b838110156101d75780820151818401526020810190506101bc565b505050509050019250505060405180910390f35b34156101f657600080fd5b61022d600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919080351515906020019091905050610601565b604051808215151515815260200191505060405180910390f35b341561025257600080fd5b61025a6106bf565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6102c96106e5565b6102d16106e5565b6000806000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151561032e57600080fd5b8651885114151561033e57600080fd5b875160405180591061034d5750595b9080825280602002602001820160405250935060009250600091505b87518210156105f357600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166323b872dd87848151811015156103be57fe5b906020019060200201518a858151811015156103d657fe5b906020019060200201518a868151811015156103ee57fe5b906020019060200201516000604051602001526040518463ffffffff167c0100000000000000000000000000000000000000000000000000000000028152600401808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020018281526020019350505050602060405180830381600087803b15156104b857600080fd5b6102c65a03f115156104c957600080fd5b50505060405180519050905080156105e65787828151811015156104e957fe5b90602001906020020151848481518110151561050157fe5b9060200190602002019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508280600101935050868281518110151561055357fe5b90602001906020020151888381518110151561056b57fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff16878481518110151561059957fe5b9060200190602002015173ffffffffffffffffffffffffffffffffffffffff167f334b3b1d4ad406523ee8e24beb689f5adbe99883a662c37d43275de52389da1460405160405180910390a45b8180600101925050610369565b839450505050509392505050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614151561065e57600080fd5b81600260008573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506001905092915050565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6020604051908101604052806000815250905600a165627a7a723058200618093d895b780d4616f24638637da0e0f9767e6d3675a9525fee1d6ed7f431002900000000000000000000000045245bc59219eeaaf6cd3f382e078a461ff9de7b25a0d1efc3c97d1aa9053aa0f59bf148d73f59764343bf3cae576c8769a14866948da0613d0265634fddd436397bc858e2672653833b57a05cfc8b93c14a6c05166e4a")! let transaction = EthereumTransaction(rawValue: input) diff --git a/Tests/web3swiftTests/remoteTests/RemoteTests.xctestplan b/Tests/web3swiftTests/remoteTests/RemoteTests.xctestplan index 6f7f05fa1..216a81766 100644 --- a/Tests/web3swiftTests/remoteTests/RemoteTests.xctestplan +++ b/Tests/web3swiftTests/remoteTests/RemoteTests.xctestplan @@ -49,7 +49,8 @@ "web3swift_numberFormattingUtil_Tests", "web3swift_personalSignature_Tests", "web3swift_promises_Tests", - "web3swift_transactions_Tests" + "web3swift_transactions_Tests", + "LocalTestCase" ], "target" : { "containerPath" : "container:web3swift.xcodeproj", diff --git a/Tests/web3swiftTests/web3swift.xctestplan b/Tests/web3swiftTests/web3swift.xctestplan index 0ce49df4f..3ca33455a 100644 --- a/Tests/web3swiftTests/web3swift.xctestplan +++ b/Tests/web3swiftTests/web3swift.xctestplan @@ -19,6 +19,9 @@ "testTargets" : [ { "parallelizable" : true, + "skippedTests" : [ + "LocalTestCase" + ], "target" : { "containerPath" : "container:web3swift.xcodeproj", "identifier" : "139751B6219AF76D0044D2B0", diff --git a/web3swift.podspec b/web3swift.podspec index 538d803f3..abab8a109 100755 --- a/web3swift.podspec +++ b/web3swift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'web3swift' - spec.version = '2.6.2' + spec.version = '2.6.3' spec.ios.deployment_target = "9.0" spec.osx.deployment_target = "10.12" spec.license = { :type => 'Apache License 2.0', :file => 'LICENSE.md' } diff --git a/web3swift.xcodeproj/project.pbxproj b/web3swift.xcodeproj/project.pbxproj index 8dd93ff7e..2ed872a68 100755 --- a/web3swift.xcodeproj/project.pbxproj +++ b/web3swift.xcodeproj/project.pbxproj @@ -191,6 +191,7 @@ 5CF7E8B0276B792A0009900F /* web3swiftEventloopTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF7E89F276B79280009900F /* web3swiftEventloopTests.swift */; }; 5CF7E8B1276B792A0009900F /* web3swiftAdvancedABIv2Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF7E8A0276B79290009900F /* web3swiftAdvancedABIv2Tests.swift */; }; 5CF7E8B2276B792A0009900F /* web3swiftEIP67Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CF7E8A1276B79290009900F /* web3swiftEIP67Tests.swift */; }; + 6029BE722817A4A8006FA0DF /* LocalTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6029BE712817A4A8006FA0DF /* LocalTestCase.swift */; }; 6049F410280616FC00DFE624 /* AbstractEnvelope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6049F409280616FC00DFE624 /* AbstractEnvelope.swift */; }; 6049F411280616FC00DFE624 /* EIP1559Envelope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6049F40A280616FC00DFE624 /* EIP1559Envelope.swift */; }; 6049F412280616FC00DFE624 /* EIP2718Envelope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6049F40B280616FC00DFE624 /* EIP2718Envelope.swift */; }; @@ -301,7 +302,6 @@ 3AA815372276E44100F5DB52 /* EthereumKeystoreV3.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EthereumKeystoreV3.swift; sourceTree = ""; }; 3AA815392276E44100F5DB52 /* PlainKeystore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlainKeystore.swift; sourceTree = ""; }; 3AA8153A2276E44100F5DB52 /* AbstractKeystore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AbstractKeystore.swift; sourceTree = ""; }; - 3AA8153B2276E44100F5DB52 /* KeystoreV3JSONStructure.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeystoreV3JSONStructure.swift; sourceTree = ""; }; 3AA8153D2276E44100F5DB52 /* BloomFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BloomFilter.swift; sourceTree = ""; }; 3AA8153F2276E44100F5DB52 /* EthereumTransaction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EthereumTransaction.swift; sourceTree = ""; }; 3AA815412276E44100F5DB52 /* Web3+Wallet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Web3+Wallet.swift"; sourceTree = ""; }; @@ -419,6 +419,7 @@ 5CF7E89F276B79280009900F /* web3swiftEventloopTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = web3swiftEventloopTests.swift; sourceTree = ""; }; 5CF7E8A0276B79290009900F /* web3swiftAdvancedABIv2Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = web3swiftAdvancedABIv2Tests.swift; sourceTree = ""; }; 5CF7E8A1276B79290009900F /* web3swiftEIP67Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = web3swiftEIP67Tests.swift; sourceTree = ""; }; + 6029BE712817A4A8006FA0DF /* LocalTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalTestCase.swift; sourceTree = ""; }; 6049F409280616FC00DFE624 /* AbstractEnvelope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AbstractEnvelope.swift; sourceTree = ""; }; 6049F40A280616FC00DFE624 /* EIP1559Envelope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EIP1559Envelope.swift; sourceTree = ""; }; 6049F40B280616FC00DFE624 /* EIP2718Envelope.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EIP2718Envelope.swift; sourceTree = ""; }; @@ -695,7 +696,6 @@ 3AA815372276E44100F5DB52 /* EthereumKeystoreV3.swift */, 3AA815392276E44100F5DB52 /* PlainKeystore.swift */, 3AA8153A2276E44100F5DB52 /* AbstractKeystore.swift */, - 3AA8153B2276E44100F5DB52 /* KeystoreV3JSONStructure.swift */, ); path = KeystoreManager; sourceTree = ""; @@ -1012,6 +1012,7 @@ E252E68126B542D000717C16 /* localTests */ = { isa = PBXGroup; children = ( + 6029BE712817A4A8006FA0DF /* LocalTestCase.swift */, 5C26D89F27F3725500431EB0 /* EIP1559BlockTests.swift */, 604FA4FE27ECBDC80021108F /* DataConversionTests.swift */, 5CF7E8A0276B79290009900F /* web3swiftAdvancedABIv2Tests.swift */, @@ -1435,6 +1436,7 @@ 5CF7E8B2276B792A0009900F /* web3swiftEIP67Tests.swift in Sources */, 5CF7E8AE276B792A0009900F /* web3swiftPromisesTests.swift in Sources */, 5CF7E8A2276B79290009900F /* web3swiftEIP681Tests.swift in Sources */, + 6029BE722817A4A8006FA0DF /* LocalTestCase.swift in Sources */, 5CC0333A28023387006AD710 /* ST20AndSecurityTokenTests.swift in Sources */, 604FA4FF27ECBDC80021108F /* DataConversionTests.swift in Sources */, 5CF7E8B1276B792A0009900F /* web3swiftAdvancedABIv2Tests.swift in Sources */,