Skip to content

Commit

Permalink
Merge pull request #58 from argentlabs/develop
Browse files Browse the repository at this point in the history
Version 0.1
  • Loading branch information
th3m477 authored Apr 15, 2019
2 parents 8b2ed36 + f1771c7 commit 1d358e3
Show file tree
Hide file tree
Showing 26 changed files with 249 additions and 134 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
source "https://rubygems.org"

#iOS
gem 'cocoapods'
gem 'cocoapods', '1.5.3'
30 changes: 15 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ GEM
remote: https://rubygems.org/
specs:
CFPropertyList (3.0.0)
activesupport (4.2.10)
activesupport (4.2.11.1)
i18n (~> 0.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
atomos (0.1.2)
atomos (0.1.3)
claide (1.0.2)
cocoapods (1.5.3)
activesupport (>= 4.0.2, < 5)
Expand All @@ -32,45 +32,45 @@ GEM
activesupport (>= 4.0.2, < 6)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
cocoapods-deintegrate (1.0.2)
cocoapods-downloader (1.2.1)
cocoapods-deintegrate (1.0.4)
cocoapods-downloader (1.2.2)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.0)
cocoapods-stats (1.0.0)
cocoapods-trunk (1.3.0)
cocoapods-stats (1.1.0)
cocoapods-trunk (1.3.1)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.1.0)
colored2 (3.1.2)
concurrent-ruby (1.0.5)
concurrent-ruby (1.1.5)
escape (0.0.4)
fourflusher (2.0.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
minitest (5.11.3)
molinillo (0.6.5)
nanaimo (0.2.5)
molinillo (0.6.6)
nanaimo (0.2.6)
nap (1.1.0)
netrc (0.11.0)
ruby-macho (1.2.0)
ruby-macho (1.4.0)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
xcodeproj (1.5.9)
xcodeproj (1.8.2)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.2)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.2.5)
nanaimo (~> 0.2.6)

PLATFORMS
ruby

DEPENDENCIES
cocoapods
cocoapods (= 1.5.3)

BUNDLED WITH
1.16.1
1.17.3
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def all_pods
pod 'BigInt', '~> 3.0.1'
pod 'BigInt', '3.1.0'
end

target 'web3swift' do
Expand Down
14 changes: 7 additions & 7 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
PODS:
- BigInt (3.0.1):
- BigInt (3.1.0):
- SipHash (~> 1.2)
- SipHash (1.2.0)
- SipHash (1.2.2)

DEPENDENCIES:
- BigInt (~> 3.0.1)
- BigInt (= 3.1.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- BigInt
- SipHash

SPEC CHECKSUMS:
BigInt: 8e8a52161c745cd3ab78e3dc346a9fbee51e6cf6
SipHash: c6e9e43e9c531b5bc6602545130c26194a6d31ce
BigInt: 76b5dfdfa3e2e478d4ffdf161aeede5502e2742f
SipHash: fad90a4683e420c52ef28063063dbbce248ea6d4

PODFILE CHECKSUM: 67f19944c0b15799d71ad44aab63ca30fcbd5189
PODFILE CHECKSUM: 7d6817b2b66ca961a4ac6f21b073018916aa7067

COCOAPODS: 1.5.2
COCOAPODS: 1.5.3
14 changes: 7 additions & 7 deletions web3.swift.podspec
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
Pod::Spec.new do |s|
s.name = 'web3.swift'
s.version = '0.0.5'
s.version = '0.1.0'
s.license = 'MIT'
s.summary = 'Ethereum API for Swift'
s.homepage = 'https://github.com/argentlabs/web3.swift'
s.authors = { 'Julien Niset' => 'julien@argent.im', 'Matt Marshall' => 'matt@argent.im' }
s.authors = { 'Julien Niset' => 'julien@argent.xyz', 'Matt Marshall' => 'matt@argent.xyz', 'Miguel Angel Quiñones' => 'miguel@argent.xyz' }
s.source = { :git => 'https://github.com/argentlabs/web3.swift.git', :tag => s.version.to_s }
s.module_name = 'web3'

s.swift_version = '4.1'
s.swift_version = '4.2'
s.ios.deployment_target = '9.0'

s.source_files = 'web3swift/web3swift.h', 'web3swift/src/**/*.swift', 'web3swift/lib/**/*.{c,h}'
s.pod_target_xcconfig = {
'SWIFT_INCLUDE_PATHS[sdk=iphonesimulator*]' => '$(PODS_TARGET_SRCROOT)/web3swift/lib/** $(PODS_TARGET_SRCROOT)/web3swift/frameworks/CommonCrypto/iphonesimulator/',
'SWIFT_INCLUDE_PATHS[sdk=iphoneos*]' => '$(PODS_TARGET_SRCROOT)/web3swift/lib/** $(PODS_TARGET_SRCROOT)/web3swift/frameworks/CommonCrypto/iphoneos/'
'SWIFT_INCLUDE_PATHS[sdk=iphonesimulator*]' => '$(PODS_TARGET_SRCROOT)/web3swift/lib/**',
'SWIFT_INCLUDE_PATHS[sdk=iphoneos*]' => '$(PODS_TARGET_SRCROOT)/web3swift/lib/**'
}
s.preserve_paths = 'web3swift/lib/**/module.map', 'web3swift/frameworks/CommonCrypto/**/*'
s.preserve_paths = 'web3swift/lib/**/module.map'


# Do not include the C libs in export
s.public_header_files = 'web3swift/web3swift.h'

s.dependency 'BigInt', '~> 3.0.1'
s.dependency 'BigInt', '~> 3.1.0'

end
22 changes: 22 additions & 0 deletions web3sTests/Contract/ABIDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,26 @@ class ABIDecoderTests: XCTestCase {
XCTFail()
}
}

func testDecodeEmptyDynamicData() {
do {
let decoded = try ABIDecoder.decodeData("0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000", types: [.DynamicBytes]) as! [String]
XCTAssertEqual(decoded.first, "")
} catch let error {
print(error.localizedDescription)
XCTFail()
}
}

func testDecodeDynamicData() {
do {
let decoded = try ABIDecoder.decodeData("0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d48656c6c6f2c20776f726c642100000000000000000000000000000000000000", types: [.DynamicBytes]) as! [String]

XCTAssertEqual(decoded.first, "0x48656c6c6f2c20776f726c6421")
} catch let error {
print(error.localizedDescription)
XCTFail()
}
}

}
44 changes: 44 additions & 0 deletions web3sTests/Contract/ABIFunctionEncoderTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// ABIFunctionEncoderTests.swift
// web3swift
//
// Created by Miguel on 28/11/2018.
// Copyright © 2018 Argent Labs Limited. All rights reserved.
//

import XCTest
import BigInt
@testable import web3swift

class ABIFuncionEncoderTests: XCTestCase {
var encoder: ABIFunctionEncoder!

override func setUp() {
encoder = ABIFunctionEncoder("test")

}

func testGivenEmptyString_ThenEncodesCorrectly() {
try! encoder.encode("")
let encoded = try! encoder.encoded()
XCTAssertEqual(String(hexFromBytes: encoded.bytes), "0xf9fbd554000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
}

func testGivenNonEmptyString_ThenEncodesCorrectly() {
try! encoder.encode("hi")
let encoded = try! encoder.encoded()
XCTAssertEqual(String(hexFromBytes: encoded.bytes), "0xf9fbd554000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000026869000000000000000000000000000000000000000000000000000000000000")
}

func testGivenEmptyData_ThenEncodesCorrectly() {
try! encoder.encode(Data())
let encoded = try! encoder.encoded()
XCTAssertEqual(String(hexFromBytes: encoded.bytes), "0x2f570a2300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000")
}

func testGivenNonEmptyData_ThenEncodesCorrectly() {
try! encoder.encode(Data(bytes: "hi".bytes))
let encoded = try! encoder.encoded()
XCTAssertEqual(String(hexFromBytes: encoded.bytes), "0x2f570a23000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000026869000000000000000000000000000000000000000000000000000000000000")
}
}
66 changes: 57 additions & 9 deletions web3sTests/ENS/ENSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ class ENSTests: XCTestCase {
self.client = EthereumClient(url: URL(string: TestConfig.clientUrl)!)
}

override func tearDown() {
super.tearDown()
}

func testNameHash() {
func testGivenName_ThenResolvesNameHash() {
let name = "argent.test"
let nameHash = EthereumNameService.nameHash(name: name)
XCTAssertEqual(nameHash, "0x3e58ef7a2e196baf0b9d36a65cc590ac9edafb3395b7cdeb8f39206049b4534c")
}

func testOwner() {
func testGivenRopstenRegistry_WhenExistingDomainName_ResolvesOwnerAddressCorrectly() {
let expect = expectation(description: "Get the ENS owner")

do {
let contract = ENSRegistryContract(chainId: EthereumNetwork.Ropsten.intValue)
let contract = ENSRegistryContract(chainId: EthereumNetwork.Ropsten.intValue, registryAddress: nil)
let tx = try contract?.owner(name: "test")

client?.eth_call(tx!, block: .Latest, completion: { (error, dataStr) in
Expand All @@ -49,7 +45,7 @@ class ENSTests: XCTestCase {
waitForExpectations(timeout: 20)
}

func testResolveAddress() {
func testGivenRopstenRegistry_WhenExistingAddress_ThenResolvesCorrectly() {
let expect = expectation(description: "Get the ENS address")

let nameService = EthereumNameService(client: client!)
Expand All @@ -61,7 +57,33 @@ class ENSTests: XCTestCase {
waitForExpectations(timeout: 20)
}

func testResolveAlias() {
func testGivenRopstenRegistry_WhenNotExistingAddress_ThenFailsCorrectly() {
let expect = expectation(description: "Get the ENS address")

let nameService = EthereumNameService(client: client!)
nameService.resolve(address: EthereumAddress("0xb0b874220ff95d62a676f58d186c832b3e6529c9"), completion: { (error, ens) in
XCTAssertNil(ens)
XCTAssertEqual(error, .ensUnknown)
expect.fulfill()
})

waitForExpectations(timeout: 20)
}

func testGivenCustomRegistry_WhenNotExistingAddress_ThenResolvesFailsCorrectly() {
let expect = expectation(description: "Get the ENS address")

let nameService = EthereumNameService(client: client!, registryAddress: EthereumAddress("0x7D7C04B7A05539a92541105806e0971E45969F85"))
nameService.resolve(address: EthereumAddress("0xb0b874220ff95d62a676f58d186c832b3e6529c9"), completion: { (error, ens) in
XCTAssertNil(ens)
XCTAssertEqual(error, .ensUnknown)
expect.fulfill()
})

waitForExpectations(timeout: 20)
}

func testGivenRopstenRegistry_WhenExistingENS_ThenResolvesAddressCorrectly() {
let expect = expectation(description: "Get the ENS reverse lookup address")

let nameService = EthereumNameService(client: client!)
Expand All @@ -73,4 +95,30 @@ class ENSTests: XCTestCase {
waitForExpectations(timeout: 20)
}

func testGivenRopstenRegistry_WhenInvalidENS_ThenErrorsRequest() {
let expect = expectation(description: "Get the ENS reverse lookup address")

let nameService = EthereumNameService(client: client!)
nameService.resolve(ens: "**somegarbage)_!!", completion: { (error, ens) in
XCTAssertNil(ens)
XCTAssertEqual(error, .ensUnknown)
expect.fulfill()
})

waitForExpectations(timeout: 20)
}

func testGivenCustomRegistry_WhenInvalidENS_ThenErrorsRequest() {
let expect = expectation(description: "Get the ENS reverse lookup address")

let nameService = EthereumNameService(client: client!, registryAddress: EthereumAddress("0x7D7C04B7A05539a92541105806e0971E45969F85"))
nameService.resolve(ens: "**somegarbage)_!!", completion: { (error, ens) in
XCTAssertNil(ens)
XCTAssertEqual(error, .ensUnknown)
expect.fulfill()
})

waitForExpectations(timeout: 20)
}

}
Loading

0 comments on commit 1d358e3

Please sign in to comment.