Skip to content

Commit

Permalink
Fix tests for signed tx init
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian-S-A-W committed Feb 19, 2024
1 parent 4019913 commit 2e2d366
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Tests/Web3Tests/TransactionTests/TransactionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,16 @@ class TransactionTests: QuickSpec {
expect(newTx).toNot(beNil())
}
let rlpEncoder = RLPEncoder()
let rlpEncodedBasicTxBytes = try rlpEncoder.encode(newTx!.rlp())
let rlpEncodedBasicTxBytes = try? rlpEncoder.encode(newTx!.rlp())
let rlpDecoder = RLPDecoder()
let rlpEncodedBasicTx = try rlpDecoder.decode(rlpEncodedBasicTxBytes)
let rlpEncodedBasicTx = try? rlpDecoder.decode(rlpEncodedBasicTxBytes!)

let expectedSignedBasicTx = try EthereumSignedTransaction(rlp: rlpEncodedBasicTx)
let expectedSignedBasicTx = try? EthereumSignedTransaction(rlp: rlpEncodedBasicTx!)

let expectedTransaction = "0xf86c808504e3b2920082520894867aeeeed428ed9ba7f97fc7e16f16dfcf02f375880de0b6b3a76400008029a099060c9146c68716da3a79533866dc941a03b171911d675f518c97a73882f7a6a0019167adb26b602501c954e7793e798407836f524b9778f5be6ebece5fc998c6"

it("should produce the expected transaction") {
expect(try? expectedSignedBasicTx.rawTransaction().bytes.hexString(prefix: true)) == expectedTransaction
expect(try? expectedSignedBasicTx!.rawTransaction().bytes.hexString(prefix: true)) == expectedTransaction
}

// Modern Tx
Expand All @@ -179,19 +179,19 @@ class TransactionTests: QuickSpec {
)
let extendedSignature = try? extendedTx.sign(with: privateKey, chainId: 3)

let rlpEncodedTxBytes = try rlpEncoder.encode(extendedSignature!.rlp())
let rlpEncodedTx = try rlpDecoder.decode(rlpEncodedTxBytes)
let rlpEncodedTxBytes = try? rlpEncoder.encode(extendedSignature!.rlp())
let rlpEncodedTx = try? rlpDecoder.decode(rlpEncodedTxBytes!)

let expectedSignedTx = try EthereumSignedTransaction(rlp: rlpEncodedTx)
let expectedSignedTx = try? EthereumSignedTransaction(rlp: rlpEncodedTx!)

let expectedExtendedTx = "0x02f8f70380843b9aca008504e3b2920082520894867aeeeed428ed9ba7f97fc7e16f16dfcf02f375880de0b6b3a76400009102f8730180843b9aca008504e3b2920082f872f85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a00000000000000000000000000000000000000000000000000000000000000007d694bb9bc244d798123fde783fcc1c72d3bb8c189413c080a0e0cd5f5e03d10e3d792fb652f6d1ea470cb6cdf745462980dff1652904cc4ed5a06f8b372427d15b68158597cd547c0f77165563da6a0b954d575920888edaf36c"

it("should produce the expected transaction") {
expect(try? expectedSignedTx.rawTransaction().bytes.hexString(prefix: true)) == expectedExtendedTx
expect(try? expectedSignedTx!.rawTransaction().bytes.hexString(prefix: true)) == expectedExtendedTx
}

it("should be a valid tx") {
expect(expectedSignedTx.verifySignature()) == true
expect(expectedSignedTx!.verifySignature()) == true
}

// Invalid RLP Item
Expand Down

0 comments on commit 2e2d366

Please sign in to comment.