Skip to content

Commit a3850c6

Browse files
Fixed one more test
1 parent 6d8ea4c commit a3850c6

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Sources/Core/Transaction/EncodableTransaction.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ public struct EncodableTransaction {
5555
}
5656

5757
/// the native value of the transaction
58-
public var value: BigUInt
58+
public var value: BigUInt {
59+
get { return envelope.value }
60+
set { envelope.value = newValue }
61+
}
5962

63+
// MARK: - Ruins signing and decoding tests if tied to envelop
6064
/// any additional data for the transaction
6165
public var data: Data
6266

@@ -169,7 +173,7 @@ public struct EncodableTransaction {
169173
public init?(rawValue: Data) {
170174
guard let env = EnvelopeFactory.createEnvelope(rawValue: rawValue) else { return nil }
171175
self.envelope = env
172-
value = 0
176+
// FIXME: This is duplication and should be fixed.
173177
data = Data()
174178
}
175179

@@ -216,7 +220,7 @@ extension EncodableTransaction: Codable {
216220
public init(from decoder: Decoder) throws {
217221
guard let env = try EnvelopeFactory.createEnvelope(from: decoder) else { throw Web3Error.dataError }
218222
self.envelope = env
219-
value = 0
223+
// FIXME: This is duplication and should be fixed.
220224
data = Data()
221225

222226
// capture any metadata that might be present
@@ -289,10 +293,8 @@ extension EncodableTransaction {
289293
public init(type: TransactionType? = nil, to: EthereumAddress, nonce: BigUInt = 0,
290294
chainID: BigUInt? = nil, value: BigUInt? = nil, data: Data = Data(),
291295
v: BigUInt = 1, r: BigUInt = 0, s: BigUInt = 0) {
292-
293-
self.value = value ?? 0
296+
// FIXME: This is duplication and should be fixed.
294297
self.data = data
295-
296298
self.envelope = EnvelopeFactory.createEnvelope(type: type, to: to, nonce: nonce, v: v, r: r, s: s)
297299
}
298300
}

Tests/web3swiftTests/localTests/TransactionsTests.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,13 @@ class TransactionsTests: XCTestCase {
598598

599599
func testDirectTransaction() throws {
600600
do {
601-
var params = EncodableTransaction.emptyTransaction
602-
params.gasPrice = 20000000000
603-
params.gasLimit = 21000
604601
var transaction = EncodableTransaction(
605602
to: EthereumAddress("0x3535353535353535353535353535353535353535")!,
606-
nonce: 9, value: 1000000000000000000, data: Data(),
603+
nonce: 9, value: 1_000_000_000_000_000_000, data: Data(),
607604
// FIXME: Return parameters here
608605
v: 0, r: 0, s: 0)
606+
transaction.gasPrice = 20_000_000_000
607+
transaction.gasLimit = 21_000
609608
let privateKeyData = Data.fromHex("0x4646464646464646464646464646464646464646464646464646464646464646")!
610609
let publicKey = Utilities.privateToPublic(privateKeyData, compressed: false)
611610
let sender = Utilities.publicToAddress(publicKey!)

0 commit comments

Comments
 (0)