Expose Asset initialiser and improve call signature
This commit is contained in:
parent
411941d982
commit
f7a3db3df9
|
@ -51,7 +51,7 @@ public struct Asset: Equatable {
|
|||
/// Create a new `Asset`.
|
||||
/// - Parameter value: Amount of tokens.
|
||||
/// - Parameter symbol: Token symbol.
|
||||
init(_ value: Double, symbol: Symbol = .steem) {
|
||||
public init(_ value: Double, _ symbol: Symbol = .steem) {
|
||||
self.amount = Int64(round(value * pow(10, Double(symbol.precision))))
|
||||
self.symbol = symbol
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ public struct Asset: Equatable {
|
|||
guard let val = Double(parts[0]) else {
|
||||
return nil
|
||||
}
|
||||
self.init(val, symbol: symbol)
|
||||
self.init(val, symbol)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,19 +5,19 @@ import XCTest
|
|||
|
||||
class AssetTest: XCTestCase {
|
||||
func testEncodable() {
|
||||
AssertEncodes(Asset(10, symbol: .steem), Data("102700000000000003535445454d0000"))
|
||||
AssertEncodes(Asset(123_456.789, symbol: .vests), Data("081a99be1c0000000656455354530000"))
|
||||
AssertEncodes(Asset(10, symbol: .steem), "10.000 STEEM")
|
||||
AssertEncodes(Asset(123_456.789, symbol: .vests), "123456.789000 VESTS")
|
||||
AssertEncodes(Asset(42, symbol: .custom(name: "TOWELS", precision: 0)), "42 TOWELS")
|
||||
AssertEncodes(Asset(0.001, symbol: .sbd), "0.001 SBD")
|
||||
AssertEncodes(Asset(10, .steem), Data("102700000000000003535445454d0000"))
|
||||
AssertEncodes(Asset(123_456.789, .vests), Data("081a99be1c0000000656455354530000"))
|
||||
AssertEncodes(Asset(10, .steem), "10.000 STEEM")
|
||||
AssertEncodes(Asset(123_456.789, .vests), "123456.789000 VESTS")
|
||||
AssertEncodes(Asset(42, .custom(name: "TOWELS", precision: 0)), "42 TOWELS")
|
||||
AssertEncodes(Asset(0.001, .sbd), "0.001 SBD")
|
||||
}
|
||||
|
||||
func testDecodable() throws {
|
||||
AssertDecodes(string: "10.000 STEEM", Asset(10, symbol: .steem))
|
||||
AssertDecodes(string: "0.001 SBD", Asset(0.001, symbol: .sbd))
|
||||
AssertDecodes(string: "1.20 DUCKS", Asset(1.2, symbol: .custom(name: "DUCKS", precision: 2)))
|
||||
AssertDecodes(string: "0 BOO", Asset(0, symbol: .custom(name: "BOO", precision: 0)))
|
||||
AssertDecodes(string: "123456789.999999 VESTS", Asset(123_456_789.999999, symbol: .vests))
|
||||
AssertDecodes(string: "10.000 STEEM", Asset(10, .steem))
|
||||
AssertDecodes(string: "0.001 SBD", Asset(0.001, .sbd))
|
||||
AssertDecodes(string: "1.20 DUCKS", Asset(1.2, .custom(name: "DUCKS", precision: 2)))
|
||||
AssertDecodes(string: "0 BOO", Asset(0, .custom(name: "BOO", precision: 0)))
|
||||
AssertDecodes(string: "123456789.999999 VESTS", Asset(123_456_789.999999, .vests))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ fileprivate let vote = (
|
|||
)
|
||||
|
||||
fileprivate let transfer = (
|
||||
Operation.Transfer(from: "foo", to: "bar", amount: Asset(10, symbol: .steem), memo: "baz"),
|
||||
Operation.Transfer(from: "foo", to: "bar", amount: Asset(10, .steem), memo: "baz"),
|
||||
"{\"from\":\"foo\",\"to\":\"bar\",\"amount\":\"10.000 STEEM\",\"memo\":\"baz\"}"
|
||||
)
|
||||
|
||||
fileprivate let commentOptions = (
|
||||
Operation.CommentOptions(author: "foo", permlink: "bar", maxAcceptedPayout: Asset(10, symbol: .sbd), percentSteemDollars: 41840, allowVotes: true, allowCurationRewards: true, extensions: [.commentPayoutBeneficiaries([Operation.CommentOptions.BeneficiaryRoute(account: "baz", weight: 5000)])]),
|
||||
Operation.CommentOptions(author: "foo", permlink: "bar", maxAcceptedPayout: Asset(10, .sbd), percentSteemDollars: 41840, allowVotes: true, allowCurationRewards: true, extensions: [.commentPayoutBeneficiaries([Operation.CommentOptions.BeneficiaryRoute(account: "baz", weight: 5000)])]),
|
||||
"{\"author\":\"foo\",\"permlink\":\"bar\",\"max_accepted_payout\":\"10.000 SBD\",\"percent_steem_dollars\":41840,\"allow_votes\":true,\"allow_curation_rewards\":true,\"extensions\":[[0,{\"beneficiaries\":[{\"account\":\"baz\",\"weight\":5000}]}]]}"
|
||||
)
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class SeemURLTest: XCTestCase {
|
|||
func testParams() throws {
|
||||
let operations: [OperationType] = [
|
||||
Operation.Vote(voter: "foo", author: "bar", permlink: "baz"),
|
||||
Operation.Transfer(from: "foo", to: "bar", amount: Asset(10, symbol: .steem), memo: "baz"),
|
||||
Operation.Transfer(from: "foo", to: "bar", amount: Asset(10, .steem), memo: "baz"),
|
||||
]
|
||||
var params = SteemURL.Params()
|
||||
params.signer = "foo"
|
||||
|
|
|
@ -20,7 +20,7 @@ class TransactionTest: XCTestCase {
|
|||
let vote = tx.operations.first as? Steem.Operation.Vote
|
||||
let transfer = tx.operations.last as? Steem.Operation.Transfer
|
||||
XCTAssertEqual(vote, Steem.Operation.Vote(voter: "foo", author: "bar", permlink: "baz", weight: 1000))
|
||||
XCTAssertEqual(transfer, Steem.Operation.Transfer(from: "foo", to: "bar", amount: Asset(10, symbol: .steem), memo: "baz"))
|
||||
XCTAssertEqual(transfer, Steem.Operation.Transfer(from: "foo", to: "bar", amount: Asset(10, .steem), memo: "baz"))
|
||||
}
|
||||
|
||||
func testSigning() throws {
|
||||
|
@ -29,7 +29,7 @@ class TransactionTest: XCTestCase {
|
|||
}
|
||||
let operations: [OperationType] = [
|
||||
Operation.Vote(voter: "foo", author: "foo", permlink: "baz", weight: 1000),
|
||||
Operation.Transfer(from: "foo", to: "bar", amount: Asset(10, symbol: .steem), memo: "baz"),
|
||||
Operation.Transfer(from: "foo", to: "bar", amount: Asset(10, .steem), memo: "baz"),
|
||||
]
|
||||
let expiration = Date(timeIntervalSince1970: 0)
|
||||
let transaction = Transaction(refBlockNum: 0, refBlockPrefix: 0, expiration: expiration, operations: operations)
|
||||
|
|
Loading…
Reference in New Issue