-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WA-37]: Append method id to duplicate function names (#9)
- Loading branch information
Showing
4 changed files
with
139 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// SequenceExtension.swift | ||
// BivrostKit | ||
// | ||
// Created by Luis Reisewitz on 23.10.17. | ||
// | ||
|
||
// From https://stackoverflow.com/a/31220067/972993 | ||
|
||
public extension Sequence { | ||
func group<U: Hashable>(by key: (Iterator.Element) -> U) -> [U:[Iterator.Element]] { | ||
var categories: [U: [Iterator.Element]] = [:] | ||
for element in self { | ||
let key = key(element) | ||
if case nil = categories[key]?.append(element) { | ||
categories[key] = [element] | ||
} | ||
} | ||
return categories | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// | ||
// ContractTemplateModelSpec.swift | ||
// BivrostKitTests | ||
// | ||
// Created by Luis Reisewitz on 23.10.17. | ||
// Copyright © 2017 Gnosis. All rights reserved. | ||
// | ||
|
||
|
||
import Foundation | ||
import Quick | ||
import Nimble | ||
@testable import BivrostKit | ||
|
||
class ContractTemplateModelSpec: QuickSpec { | ||
override func spec() { | ||
describe("ContractTemplateModel") { | ||
it("should append method ids to generated function names in case of duplicates") { | ||
let json = jsonDict(from: Assets.duplicateMethodJson) | ||
let contract = try! ContractParser.parseContract(from: json) | ||
let model = ContractTemplateModel(contract: contract) | ||
model.functions.forEach { | ||
expect($0.name).to(contain($0.methodId)) | ||
} | ||
} | ||
|
||
it("should not append method ids to generated function names in case of no duplicates") { | ||
let json = jsonDict(from: Assets.standardTokenJson) | ||
let contract = try! ContractParser.parseContract(from: json) | ||
let model = ContractTemplateModel(contract: contract) | ||
model.functions.forEach { | ||
expect($0.name).toNot(contain($0.methodId)) | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
fileprivate func jsonDict(from jsonString: String) -> [String: Any] { | ||
return try! JSONSerialization.jsonObject(with: jsonString.data(using: .utf8)!, options: []) as! [String: Any] | ||
} |