Skip to content

Commit

Permalink
Change return type of getCreate2Address to EthereumAddress (#138)
Browse files Browse the repository at this point in the history
* Change return type of getCreate2Address to EthereumAddress

* Update EthereumUtisl tests to changed return type
  • Loading branch information
Florian-S-A-W authored Oct 30, 2022
1 parent 6a6394b commit 61d72b4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions Sources/Core/Toolbox/EthereumUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public struct EthereumUtils {
case initCodeHashNot32BytesError
}

public static func getCreate2Address(from: EthereumAddress, salt: [UInt8], initCodeHash: [UInt8]) throws -> String {
public static func getCreate2Address(from: EthereumAddress, salt: [UInt8], initCodeHash: [UInt8]) throws -> EthereumAddress {
if salt.count != 32 {
throw Error.saltNot32BytesError
}
Expand All @@ -23,10 +23,10 @@ public struct EthereumUtils {
let hash = concat.sha3(.keccak256)
let hexSlice = Array(hash[12...])

return try EthereumAddress(hex: hexSlice.toHexString(), eip55: false).hex(eip55: true)
return try EthereumAddress(hex: hexSlice.toHexString(), eip55: false)
}

public static func getCreate2Address(from: EthereumAddress, salt: [UInt8], initCode: [UInt8]) throws -> String {
public static func getCreate2Address(from: EthereumAddress, salt: [UInt8], initCode: [UInt8]) throws -> EthereumAddress {
let initCodeHash = initCode.sha3(.keccak256)
return try getCreate2Address(from: from, salt: salt, initCodeHash: initCodeHash)
}
Expand Down
14 changes: 7 additions & 7 deletions Tests/Web3Tests/ToolboxTests/EthereumUtilsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,43 @@ final class EthereumUtilsTests: QuickSpec {
it("should be 0x4D1A2e2bB4F88F0250f26Ffff098B0b30B26BF38") {
let result = try EthereumUtils.getCreate2Address(
from: address0, salt: salt0, initCodeHash: init_code_hash0)
expect(result) == "0x4D1A2e2bB4F88F0250f26Ffff098B0b30B26BF38"
try expect(result) == EthereumAddress(hex: "0x4D1A2e2bB4F88F0250f26Ffff098B0b30B26BF38", eip55: false)
}

it("should be 0xB928f69Bb1D91Cd65274e3c79d8986362984fDA3") {
let result = try EthereumUtils.getCreate2Address(
from: address1, salt: salt0, initCodeHash: init_code_hash0)
expect(result) == "0xB928f69Bb1D91Cd65274e3c79d8986362984fDA3"
try expect(result) == EthereumAddress(hex: "0xB928f69Bb1D91Cd65274e3c79d8986362984fDA3", eip55: false)
}

it("should be 0xD04116cDd17beBE565EB2422F2497E06cC1C9833") {
let result = try EthereumUtils.getCreate2Address(
from: address1, salt: salt1, initCodeHash: init_code_hash0)
expect(result) == "0xD04116cDd17beBE565EB2422F2497E06cC1C9833"
try expect(result) == EthereumAddress(hex: "0xD04116cDd17beBE565EB2422F2497E06cC1C9833", eip55: false)
}

it("should be 0x70f2b2914A2a4b783FaEFb75f459A580616Fcb5e") {
let result = try EthereumUtils.getCreate2Address(
from: address0, salt: salt0, initCodeHash: init_code_hash1)
expect(result) == "0x70f2b2914A2a4b783FaEFb75f459A580616Fcb5e"
try expect(result) == EthereumAddress(hex: "0x70f2b2914A2a4b783FaEFb75f459A580616Fcb5e", eip55: false)
}

it("should be 0x60f3f640a8508fC6a86d45DF051962668E1e8AC7") {
let result = try EthereumUtils.getCreate2Address(
from: address2, salt: salt2, initCodeHash: init_code_hash1)
expect(result) == "0x60f3f640a8508fC6a86d45DF051962668E1e8AC7"
try expect(result) == EthereumAddress(hex: "0x60f3f640a8508fC6a86d45DF051962668E1e8AC7", eip55: false)
}

it("should be 0x1d8bfDC5D46DC4f61D6b6115972536eBE6A8854C") {
let result = try EthereumUtils.getCreate2Address(
from: address2, salt: salt2, initCode: init_code0)
expect(result) == "0x1d8bfDC5D46DC4f61D6b6115972536eBE6A8854C"
try expect(result) == EthereumAddress(hex: "0x1d8bfDC5D46DC4f61D6b6115972536eBE6A8854C", eip55: false)
}

it("should be 0xE33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0") {
let result = try EthereumUtils.getCreate2Address(
from: address0, salt: salt0, initCode: init_code1)
expect(result) == "0xE33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0"
try expect(result) == EthereumAddress(hex: "0xE33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0", eip55: false)
}
}
}
Expand Down

0 comments on commit 61d72b4

Please sign in to comment.