Skip to content

Commit

Permalink
modify erc20 token interface
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzushioh committed Jun 16, 2018
1 parent e997c87 commit fdbecf5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions EthereumKit/Helper/ERC20.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public struct ERC20 {
/// Generate transaction data for ERC20 token
///
/// - Parameter:
/// - to: address you are transfering to
/// - toAddress: address you are transfering to
/// - amount: amount to send
/// - Returns: transaction data
public func generateDataParameter(with to: String, amount: String) throws -> Data {
public func generateDataParameter(toAddress: String, amount: String) throws -> Data {
let method = transferSigniture.toHexString()
let address = pad(string: to.stripHexPrefix())
let address = pad(string: toAddress.stripHexPrefix())

let poweredAmount = try power(amount: amount)
let amount = pad(string: poweredAmount.serialize().toHexString())
Expand Down
10 changes: 5 additions & 5 deletions EthereumKitTests/ERC20Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ final class ERC20Tests: XCTestCase {
let erc20Token = ERC20(contractAddress: "test", decimal: 18, symbol: "TEST")

let address = "0x88b44BC83add758A3642130619D61682282850Df"
let data1 = try! erc20Token.generateDataParameter(with: address, amount: "3")
let data1 = try! erc20Token.generateDataParameter(toAddress: address, amount: "3")
XCTAssertEqual(
data1.toHexString().addHexPrefix(),
"0xa9059cbb00000000000000000000000088b44bc83add758a3642130619d61682282850df00000000000000000000000000000000000000000000000029a2241af62c0000"
)

let data2 = try! erc20Token.generateDataParameter(with: address, amount: "0.25")
let data2 = try! erc20Token.generateDataParameter(toAddress: address, amount: "0.25")
XCTAssertEqual(
data2.toHexString().addHexPrefix(),
"0xa9059cbb00000000000000000000000088b44bc83add758a3642130619d61682282850df00000000000000000000000000000000000000000000000003782dace9d90000"
)

let data3 = try! erc20Token.generateDataParameter(with: address, amount: "0.155555")
let data3 = try! erc20Token.generateDataParameter(toAddress: address, amount: "0.155555")
XCTAssertEqual(
data3.toHexString().addHexPrefix(),
"0xa9059cbb00000000000000000000000088b44bc83add758a3642130619d61682282850df0000000000000000000000000000000000000000000000000228a472c6093000"
)

let data4 = try! erc20Token.generateDataParameter(with: address, amount: "3000")
let data4 = try! erc20Token.generateDataParameter(toAddress: address, amount: "3000")
XCTAssertEqual(
data4.toHexString().addHexPrefix(),
"0xa9059cbb00000000000000000000000088b44bc83add758a3642130619d61682282850df0000000000000000000000000000000000000000000000a2a15d09519be00000"
)

let data5 = try! erc20Token.generateDataParameter(with: address, amount: "9000")
let data5 = try! erc20Token.generateDataParameter(toAddress: address, amount: "9000")
XCTAssertEqual(
data5.toHexString().addHexPrefix(),
"0xa9059cbb00000000000000000000000088b44bc83add758a3642130619d61682282850df0000000000000000000000000000000000000000000001e7e4171bf4d3a00000"
Expand Down

0 comments on commit fdbecf5

Please sign in to comment.