SPB Git

Repository Public

AuditRegressionTests.swift 3.5 KB 76 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project          : QYVORA7// File             : Tests/QyvoraEthereumTests/AuditRegressionTests.swift8// Module           : Tests9// Repository       : https://git.spboucher.ai/qyvora10// Project Website  : Not specified11// Created          : 2026-12-0412// Last Modified    : 2026-12-0413//14// Author           : Simon-Pierre Boucher15// Position         : Professor of Finance16// Institution      : Université du Québec en Outaouais (UQO)17// Organization     : SP Boucher18// Website          : https://spboucher.ai19// Git              : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development      : dev@spboucher.ai23// Support          : support@spboucher.ai24// Security/Admin   : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License          : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import QyvoraCore42import QyvoraMath43import Testing4445@testable import QyvoraEthereum4647/// Regression test of finding QYV-AUD-004: the raw encoding of a signed transaction is built from the signed48/// fields themselves (it used to re-decode its own payload with `try!`).49@Suite struct EthereumAuditRegressionTests {50    @Test func rawEncodingIsTheSignedFieldsFollowedByTheSignature() throws {51        let key = Bytes(repeating: 0, count: 31) + [7]52        let transactions = [53            EIP1559Transaction(54                chainID: 11_155_111, nonce: 0, maxPriorityFeePerGas: UInt256(1), maxFeePerGas: UInt256(2), gasLimit: 21_000,55                to: EthereumAddress(bytes: Bytes(repeating: 0x11, count: 20)), value: UInt256(0)),56            EIP1559Transaction(57                chainID: 1, nonce: .max, maxPriorityFeePerGas: UInt256(UInt64.max), maxFeePerGas: UInt256(UInt64.max), gasLimit: .max,58                to: nil, value: UInt256(bigEndian: Bytes(repeating: 0xff, count: 32))!, data: Bytes(repeating: 0xab, count: 300),59                accessList: [.init(address: .zero, storageKeys: [Bytes(repeating: 1, count: 32), Bytes(repeating: 2, count: 32)])]),60        ]61        for tx in transactions {62            let signed = try tx.sign(privateKey: key)63            let raw = signed.raw64            // type byte, then the RLP list of the unsigned fields with yParity, r, s appended65            #expect(raw.first == 0x02)66            let items = try #require(try RLP.decode(Bytes(raw.dropFirst())).listValue)67            let unsigned = try #require(try RLP.decode(Bytes(tx.unsignedPayload.dropFirst())).listValue)68            #expect(items.count == 12 && Array(items.prefix(9)) == unsigned)69            // and it decodes back to the same transaction and the same signer70            let decoded = try SignedEIP1559Transaction.decode(raw)71            #expect(decoded == signed)72            #expect(try decoded.sender() == signed.sender())73        }74    }75}76
Files main
Menu

Theme