diff --git a/src/benchmark/scala/io/iohk/ethereum/rlp/RLPSpeedSuite.scala b/src/benchmark/scala/io/iohk/ethereum/rlp/RLPSpeedSuite.scala index 1db6324656..e73ae05acf 100644 --- a/src/benchmark/scala/io/iohk/ethereum/rlp/RLPSpeedSuite.scala +++ b/src/benchmark/scala/io/iohk/ethereum/rlp/RLPSpeedSuite.scala @@ -11,8 +11,7 @@ import org.scalacheck.Gen import org.scalatest.funsuite.AnyFunSuite import org.scalatestplus.scalacheck.{ScalaCheckDrivenPropertyChecks, ScalaCheckPropertyChecks} -/** - * Tests based on +/** Tests based on * - https://github.com/cryptape/ruby-rlp/blob/master/test/speed.rb * - https://github.com/ethereum/pyrlp/blob/develop/tests/speed.py */ @@ -63,21 +62,21 @@ class RLPSpeedSuite } def doTestSerialize[T](toSerialize: T, encode: T => Array[Byte], rounds: Int): Array[Byte] = { - (1 until rounds).foreach(_ => { + (1 until rounds).foreach { _ => encode(toSerialize) - }) + } encode(toSerialize) } def doTestDeserialize[T](serialized: Array[Byte], decode: Array[Byte] => T, rounds: Int): T = { - (1 until rounds).foreach(_ => { + (1 until rounds).foreach { _ => decode(serialized) - }) + } decode(serialized) } val validTransaction = SignedTransaction( - Transaction( + LegacyTransaction( nonce = 172320, gasPrice = BigInt("50000000000"), gasLimit = 90000, diff --git a/src/main/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidator.scala b/src/main/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidator.scala index a3254743d8..2057234097 100644 --- a/src/main/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidator.scala +++ b/src/main/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidator.scala @@ -42,7 +42,7 @@ class StdSignedTransactionValidator(blockchainConfig: BlockchainConfig) extends * @return Either the validated transaction or TransactionSyntaxError if an error was detected */ private def checkSyntacticValidity(stx: SignedTransaction): Either[SignedTransactionError, SignedTransactionValid] = { - import Transaction._ + import LegacyTransaction._ import stx._ import stx.tx._ diff --git a/src/main/scala/io/iohk/ethereum/domain/SignedTransaction.scala b/src/main/scala/io/iohk/ethereum/domain/SignedTransaction.scala index 57b29444bb..9bab704e9d 100644 --- a/src/main/scala/io/iohk/ethereum/domain/SignedTransaction.scala +++ b/src/main/scala/io/iohk/ethereum/domain/SignedTransaction.scala @@ -50,7 +50,7 @@ object SignedTransaction { val valueForEmptyS = 0 def apply( - tx: Transaction, + tx: LegacyTransaction, pointSign: Byte, signatureRandom: ByteString, signature: ByteString, @@ -64,7 +64,12 @@ object SignedTransaction { SignedTransaction(tx, txSignature) } - def apply(tx: Transaction, pointSign: Byte, signatureRandom: ByteString, signature: ByteString): SignedTransaction = { + def apply( + tx: LegacyTransaction, + pointSign: Byte, + signatureRandom: ByteString, + signature: ByteString + ): SignedTransaction = { val txSignature = ECDSASignature( r = new BigInteger(1, signatureRandom.toArray), s = new BigInteger(1, signature.toArray), @@ -73,11 +78,14 @@ object SignedTransaction { SignedTransaction(tx, txSignature) } - def sign(tx: Transaction, keyPair: AsymmetricCipherKeyPair, chainId: Option[Byte]): SignedTransactionWithSender = { + def sign( + tx: LegacyTransaction, + keyPair: AsymmetricCipherKeyPair, + chainId: Option[Byte] + ): SignedTransaction = { val bytes = bytesToSign(tx, chainId) val sig = ECDSASignature.sign(bytes, keyPair, chainId) - val address = Address(keyPair) - SignedTransactionWithSender(tx, sig, address) + SignedTransaction(tx, sig) } private def bytesToSign(tx: Transaction, chainId: Option[Byte]): Array[Byte] = @@ -157,7 +165,7 @@ object SignedTransaction { } } -case class SignedTransaction(tx: Transaction, signature: ECDSASignature) { +case class SignedTransaction(tx: LegacyTransaction, signature: ECDSASignature) { def safeSenderIsEqualTo(address: Address): Boolean = SignedTransaction.getSender(this).contains(address) @@ -184,6 +192,6 @@ object SignedTransactionWithSender { sender.fold(acc)(addr => SignedTransactionWithSender(stx, addr) :: acc) } - def apply(transaction: Transaction, signature: ECDSASignature, sender: Address): SignedTransactionWithSender = + def apply(transaction: LegacyTransaction, signature: ECDSASignature, sender: Address): SignedTransactionWithSender = SignedTransactionWithSender(SignedTransaction(transaction, signature), sender) } diff --git a/src/main/scala/io/iohk/ethereum/domain/Transaction.scala b/src/main/scala/io/iohk/ethereum/domain/Transaction.scala index 6befb5c799..08be763b69 100644 --- a/src/main/scala/io/iohk/ethereum/domain/Transaction.scala +++ b/src/main/scala/io/iohk/ethereum/domain/Transaction.scala @@ -4,7 +4,32 @@ import akka.util.ByteString import org.bouncycastle.util.encoders.Hex +sealed trait Transaction { + def nonce: BigInt + def gasPrice: BigInt + def gasLimit: BigInt + def receivingAddress: Option[Address] + def value: BigInt + def payload: ByteString + + def isContractInit: Boolean = receivingAddress.isEmpty + + protected def receivingAddressString: String = + receivingAddress.map(_.toString).getOrElse("[Contract creation]") + + protected def payloadString: String = + s"${if (isContractInit) "ContractInit: " else "TransactionData: "}${Hex.toHexString(payload.toArray[Byte])}" +} + object Transaction { + val Type01: Int = 1 + val LegacyThresholdLowerBound: Int = 0xc0 + val LegacyThresholdUpperBound: Int = 0xfe +} + +sealed trait TypedTransaction extends Transaction + +object LegacyTransaction { val NonceLength = 32 val GasLength = 32 @@ -17,33 +42,49 @@ object Transaction { receivingAddress: Address, value: BigInt, payload: ByteString - ): Transaction = - Transaction(nonce, gasPrice, gasLimit, Some(receivingAddress), value, payload) + ): LegacyTransaction = + LegacyTransaction(nonce, gasPrice, gasLimit, Some(receivingAddress), value, payload) } -case class Transaction( +case class LegacyTransaction( nonce: BigInt, gasPrice: BigInt, gasLimit: BigInt, receivingAddress: Option[Address], value: BigInt, payload: ByteString -) { - - def isContractInit: Boolean = receivingAddress.isEmpty - - override def toString: String = { - val receivingAddressString = - receivingAddress.map(addr => Hex.toHexString(addr.toArray)).getOrElse("[Contract creation]") +) extends Transaction { + override def toString: String = + s"LegacyTransaction {" + + s"nonce: $nonce " + + s"gasPrice: $gasPrice " + + s"gasLimit: $gasLimit " + + s"receivingAddress: $receivingAddressString " + + s"value: $value wei " + + s"payload: $payloadString " + + s"}" +} - s"Transaction {" + +case class TransactionWithAccessList( + nonce: BigInt, + gasPrice: BigInt, + gasLimit: BigInt, + receivingAddress: Option[Address], + value: BigInt, + payload: ByteString, + accessList: List[AccessListItem] +) extends TypedTransaction { + override def toString: String = + s"TransactionWithAccessList {" + s"nonce: $nonce " + s"gasPrice: $gasPrice " + s"gasLimit: $gasLimit " + s"receivingAddress: $receivingAddressString " + s"value: $value wei " + - s"payload: ${if (isContractInit) "ContractInit: " else "TransactionData: "}${Hex.toHexString(payload.toArray[Byte])} " + + s"payload: $payloadString " + + s"accessList: $accessList" + s"}" - } } + +case class AccessListItem(address: Address, storageKeys: List[BigInt]) // bytes32 diff --git a/src/main/scala/io/iohk/ethereum/faucet/jsonrpc/WalletService.scala b/src/main/scala/io/iohk/ethereum/faucet/jsonrpc/WalletService.scala index 3f806fe418..07ed66d178 100644 --- a/src/main/scala/io/iohk/ethereum/faucet/jsonrpc/WalletService.scala +++ b/src/main/scala/io/iohk/ethereum/faucet/jsonrpc/WalletService.scala @@ -7,7 +7,7 @@ import cats.data.EitherT import monix.eval.Task import io.iohk.ethereum.domain.Address -import io.iohk.ethereum.domain.Transaction +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.faucet.FaucetConfig import io.iohk.ethereum.jsonrpc.client.RpcClient.RpcError import io.iohk.ethereum.keystore.KeyStore @@ -36,7 +36,7 @@ class WalletService(walletRpcClient: WalletRpcClient, keyStore: KeyStore, config private def prepareTx(wallet: Wallet, targetAddress: Address, nonce: BigInt): ByteString = { val transaction = - Transaction(nonce, config.txGasPrice, config.txGasLimit, Some(targetAddress), config.txValue, ByteString()) + LegacyTransaction(nonce, config.txGasPrice, config.txGasLimit, Some(targetAddress), config.txValue, ByteString()) val stx = wallet.signTx(transaction, None) ByteString(rlp.encode(stx.tx.toRLPEncodable)) diff --git a/src/main/scala/io/iohk/ethereum/jsonrpc/EthInfoService.scala b/src/main/scala/io/iohk/ethereum/jsonrpc/EthInfoService.scala index 94fc4b85c0..bfb104aab7 100644 --- a/src/main/scala/io/iohk/ethereum/jsonrpc/EthInfoService.scala +++ b/src/main/scala/io/iohk/ethereum/jsonrpc/EthInfoService.scala @@ -175,7 +175,7 @@ class EthInfoService( val toAddress = req.tx.to.map(Address.apply) - val tx = Transaction(0, req.tx.gasPrice, gasLimit, toAddress, req.tx.value, req.tx.data) + val tx = LegacyTransaction(0, req.tx.gasPrice, gasLimit, toAddress, req.tx.value, req.tx.data) val fakeSignature = ECDSASignature(0, 0, 0.toByte) SignedTransactionWithSender(tx, fakeSignature, fromAddress) } diff --git a/src/main/scala/io/iohk/ethereum/jsonrpc/TransactionRequest.scala b/src/main/scala/io/iohk/ethereum/jsonrpc/TransactionRequest.scala index a93a153f1c..05397751fd 100644 --- a/src/main/scala/io/iohk/ethereum/jsonrpc/TransactionRequest.scala +++ b/src/main/scala/io/iohk/ethereum/jsonrpc/TransactionRequest.scala @@ -3,7 +3,7 @@ package io.iohk.ethereum.jsonrpc import akka.util.ByteString import io.iohk.ethereum.domain.Address -import io.iohk.ethereum.domain.Transaction +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.utils.Config case class TransactionRequest( @@ -19,8 +19,8 @@ case class TransactionRequest( private val defaultGasPrice: BigInt = 2 * BigInt(10).pow(10) private val defaultGasLimit: BigInt = 90000 - def toTransaction(defaultNonce: BigInt): Transaction = - Transaction( + def toTransaction(defaultNonce: BigInt): LegacyTransaction = + LegacyTransaction( nonce = nonce.getOrElse(defaultNonce), gasPrice = gasPrice.getOrElse(defaultGasPrice), gasLimit = gasLimit.getOrElse(defaultGasLimit), diff --git a/src/main/scala/io/iohk/ethereum/keystore/Wallet.scala b/src/main/scala/io/iohk/ethereum/keystore/Wallet.scala index f8c8200804..37cb98ec5d 100644 --- a/src/main/scala/io/iohk/ethereum/keystore/Wallet.scala +++ b/src/main/scala/io/iohk/ethereum/keystore/Wallet.scala @@ -6,13 +6,13 @@ import org.bouncycastle.crypto.AsymmetricCipherKeyPair import io.iohk.ethereum.crypto._ import io.iohk.ethereum.domain.Address +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.domain.SignedTransaction import io.iohk.ethereum.domain.SignedTransactionWithSender -import io.iohk.ethereum.domain.Transaction case class Wallet(address: Address, prvKey: ByteString) { lazy val keyPair: AsymmetricCipherKeyPair = keyPairFromPrvKey(prvKey.toArray) - def signTx(tx: Transaction, chainId: Option[Byte]): SignedTransactionWithSender = - SignedTransaction.sign(tx, keyPair, chainId) + def signTx(tx: LegacyTransaction, chainId: Option[Byte]): SignedTransactionWithSender = + SignedTransactionWithSender(SignedTransaction.sign(tx, keyPair, chainId), Address(keyPair)) } diff --git a/src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala b/src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala index 1d569a63b1..34e6a5d575 100644 --- a/src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala +++ b/src/main/scala/io/iohk/ethereum/ledger/BlockPreparator.scala @@ -99,14 +99,14 @@ class BlockPreparator( * @param tx Target transaction * @return Upfront cost */ - private[ledger] def calculateUpfrontGas(tx: Transaction): UInt256 = UInt256(tx.gasLimit * tx.gasPrice) + private[ledger] def calculateUpfrontGas(tx: LegacyTransaction): UInt256 = UInt256(tx.gasLimit * tx.gasPrice) /** v0 ≡ Tg (Tx gas limit) * Tp (Tx gas price) + Tv (Tx value). See YP equation number (65) * * @param tx Target transaction * @return Upfront cost */ - private[ledger] def calculateUpfrontCost(tx: Transaction): UInt256 = + private[ledger] def calculateUpfrontCost(tx: LegacyTransaction): UInt256 = UInt256(calculateUpfrontGas(tx) + tx.value) /** Increments account nonce by 1 stated in YP equation (69) and diff --git a/src/main/scala/io/iohk/ethereum/network/p2p/messages/BaseETH6XMessages.scala b/src/main/scala/io/iohk/ethereum/network/p2p/messages/BaseETH6XMessages.scala index 20dc6e239f..349541fa2e 100644 --- a/src/main/scala/io/iohk/ethereum/network/p2p/messages/BaseETH6XMessages.scala +++ b/src/main/scala/io/iohk/ethereum/network/p2p/messages/BaseETH6XMessages.scala @@ -187,7 +187,7 @@ object BaseETH6XMessages { ) => val receivingAddressOpt = if (receivingAddress.bytes.isEmpty) None else Some(Address(receivingAddress.bytes)) SignedTransaction( - Transaction(nonce, gasPrice, gasLimit, receivingAddressOpt, value, payload), + LegacyTransaction(nonce, gasPrice, gasLimit, receivingAddressOpt, value, payload), (pointSign: Int).toByte, signatureRandom, signature, diff --git a/src/main/scala/io/iohk/ethereum/utils/Picklers.scala b/src/main/scala/io/iohk/ethereum/utils/Picklers.scala index 1da8e6506b..fa0f21e500 100644 --- a/src/main/scala/io/iohk/ethereum/utils/Picklers.scala +++ b/src/main/scala/io/iohk/ethereum/utils/Picklers.scala @@ -12,8 +12,8 @@ import io.iohk.ethereum.domain.BlockHeader import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields import io.iohk.ethereum.domain.BlockHeader.HeaderExtraFields._ import io.iohk.ethereum.domain.Checkpoint +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.domain.SignedTransaction -import io.iohk.ethereum.domain.Transaction object Picklers { implicit val byteStringPickler: Pickler[ByteString] = @@ -30,9 +30,9 @@ object Picklers { implicit val addressPickler: Pickler[Address] = transformPickler[Address, ByteString](bytes => Address(bytes))(address => address.bytes) - implicit val transactionPickler: Pickler[Transaction] = generatePickler[Transaction] + implicit val transactionPickler: Pickler[LegacyTransaction] = generatePickler[LegacyTransaction] implicit val signedTransactionPickler: Pickler[SignedTransaction] = - transformPickler[SignedTransaction, (Transaction, ECDSASignature)] { case (tx, signature) => + transformPickler[SignedTransaction, (LegacyTransaction, ECDSASignature)] { case (tx, signature) => new SignedTransaction(tx, signature) }(stx => (stx.tx, stx.signature)) diff --git a/src/test/scala/io/iohk/ethereum/BlockHelpers.scala b/src/test/scala/io/iohk/ethereum/BlockHelpers.scala index 14ff6e17e5..184f0ed6c3 100644 --- a/src/test/scala/io/iohk/ethereum/BlockHelpers.scala +++ b/src/test/scala/io/iohk/ethereum/BlockHelpers.scala @@ -23,7 +23,7 @@ object BlockHelpers extends SecureRandomBuilder { unixTimestamp = 0 ) - val defaultTx: Transaction = Transaction( + val defaultTx: LegacyTransaction = LegacyTransaction( nonce = 42, gasPrice = 1, gasLimit = 90000, @@ -62,7 +62,7 @@ object BlockHelpers extends SecureRandomBuilder { val tx = defaultTx.copy(payload = randomHash()) val stx = SignedTransaction.sign(tx, keyPair, None) - Block(header, BlockBody(List(stx.tx), List(ommer))) + Block(header, BlockBody(List(stx), List(ommer))) } def updateHeader(block: Block, updater: BlockHeader => BlockHeader): Block = diff --git a/src/test/scala/io/iohk/ethereum/Fixtures.scala b/src/test/scala/io/iohk/ethereum/Fixtures.scala index a1c4b2e428..54a8cfe64b 100644 --- a/src/test/scala/io/iohk/ethereum/Fixtures.scala +++ b/src/test/scala/io/iohk/ethereum/Fixtures.scala @@ -50,7 +50,7 @@ object Fixtures { val body: BlockBody = BlockBody( transactionList = Seq[SignedTransaction]( SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438550"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), @@ -65,7 +65,7 @@ object Fixtures { chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438551"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), @@ -80,7 +80,7 @@ object Fixtures { chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438552"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), @@ -95,7 +95,7 @@ object Fixtures { chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438553"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), @@ -172,7 +172,7 @@ object Fixtures { override val body: BlockBody = BlockBody( transactionList = Seq[SignedTransaction]( SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("1"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("21000"), @@ -187,7 +187,7 @@ object Fixtures { chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("1"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("21000"), @@ -202,7 +202,7 @@ object Fixtures { chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("1"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("21000"), @@ -217,7 +217,7 @@ object Fixtures { chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("1"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("21000"), @@ -266,7 +266,7 @@ object Fixtures { override lazy val body: BlockBody = BlockBody( transactionList = Seq[SignedTransaction]( SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("1"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("21000"), @@ -281,7 +281,7 @@ object Fixtures { chainId = 0x01.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("1"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("21000"), @@ -296,7 +296,7 @@ object Fixtures { chainId = 0x01.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("1"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("21000"), @@ -311,7 +311,7 @@ object Fixtures { chainId = 0x01.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("1"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("21000"), diff --git a/src/test/scala/io/iohk/ethereum/ObjectGenerators.scala b/src/test/scala/io/iohk/ethereum/ObjectGenerators.scala index 00b9912e18..72ccfadc09 100644 --- a/src/test/scala/io/iohk/ethereum/ObjectGenerators.scala +++ b/src/test/scala/io/iohk/ethereum/ObjectGenerators.scala @@ -82,14 +82,14 @@ trait ObjectGenerators { def addressGen: Gen[Address] = byteArrayOfNItemsGen(20).map(Address(_)) - def transactionGen(): Gen[Transaction] = for { + def transactionGen(): Gen[LegacyTransaction] = for { nonce <- bigIntGen gasPrice <- bigIntGen gasLimit <- bigIntGen receivingAddress <- addressGen value <- bigIntGen payload <- byteStringOfLengthNGen(256) - } yield Transaction( + } yield LegacyTransaction( nonce, gasPrice, gasLimit, @@ -142,7 +142,7 @@ trait ObjectGenerators { val txsSeqGen = Gen.listOfN(length, transactionGen()) txsSeqGen.map { txs => txs.map { tx => - SignedTransaction.sign(tx, senderKeys, chainId).tx + SignedTransaction.sign(tx, senderKeys, chainId) } } } diff --git a/src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala index 23c46a5c74..58c516c433 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/blocks/BlockGeneratorSpec.scala @@ -64,7 +64,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper it should "generate correct block with transactions" in new TestSetup { val pendingBlock = blockGenerator - .generateBlock(bestBlock.get, Seq(signedTransaction.tx), Address(testAddress), blockGenerator.emptyX, None) + .generateBlock(bestBlock.get, Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX, None) .pendingBlock //mined with mantis + ethminer @@ -91,7 +91,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper it should "be possible to simulate transaction, on world returned with pending block" in new TestSetup { val pendingBlock = blockGenerator - .generateBlock(bestBlock.get, Seq(signedTransaction.tx), Address(testAddress), blockGenerator.emptyX, None) + .generateBlock(bestBlock.get, Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX, None) .pendingBlock //mined with mantis + ethminer @@ -114,7 +114,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper // Create new pending block, with updated stateRootHash val pendBlockAndState = blockGenerator.generateBlock( blockchainReader.getBestBlock().get, - Seq(signedTransaction.tx), + Seq(signedTransaction), Address(testAddress), blockGenerator.emptyX, None @@ -122,12 +122,12 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper // Try to simulate transaction, on world with updated stateRootHash, but not updated storages assertThrows[MPTException] { - stxLedger.simulateTransaction(signedTransaction, pendBlockAndState.pendingBlock.block.header, None) + stxLedger.simulateTransaction(signedTransactionWithAddress, pendBlockAndState.pendingBlock.block.header, None) } // Try to simulate transaction, on world with all changes stored in caches val simulationResult = stxLedger.simulateTransaction( - signedTransaction, + signedTransactionWithAddress, pendBlockAndState.pendingBlock.block.header, Some(pendBlockAndState.worldState) ) @@ -141,7 +141,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper blockGenerator .generateBlock( bestBlock.get, - Seq(signedTransaction.tx, duplicatedSignedTransaction.tx), + Seq(signedTransaction, duplicatedSignedTransaction), Address(testAddress), blockGenerator.emptyX, None @@ -167,20 +167,19 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper ) shouldBe Right(BlockHeaderValid) blockExecution.executeAndValidateBlock(fullBlock) shouldBe a[Right[_, Seq[Receipt]]] - fullBlock.body.transactionList shouldBe Seq(signedTransaction.tx) + fullBlock.body.transactionList shouldBe Seq(signedTransaction) fullBlock.header.extraData shouldBe headerExtraData } it should "filter out transactions exceeding block gas limit and include correct transactions" in new TestSetup { val txWitGasTooBigGasLimit = SignedTransaction .sign( - transaction.copy(gasLimit = BigInt(2).pow(100000), nonce = signedTransaction.tx.tx.nonce + 1), + transaction.copy(gasLimit = BigInt(2).pow(100000), nonce = signedTransaction.tx.nonce + 1), keyPair, Some(0x3d.toByte) ) - .tx - val transactions = Seq(txWitGasTooBigGasLimit, signedTransaction.tx, duplicatedSignedTransaction.tx) + val transactions = Seq(txWitGasTooBigGasLimit, signedTransaction, duplicatedSignedTransaction) val pendingBlock = blockGenerator .generateBlock(bestBlock.get, transactions, Address(testAddress), blockGenerator.emptyX, None) @@ -205,7 +204,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper blockchainReader.getBlockHeaderByHash ) shouldBe Right(BlockHeaderValid) blockExecution.executeAndValidateBlock(fullBlock) shouldBe a[Right[_, Seq[Receipt]]] - fullBlock.body.transactionList shouldBe Seq(signedTransaction.tx) + fullBlock.body.transactionList shouldBe Seq(signedTransaction) fullBlock.header.extraData shouldBe headerExtraData } @@ -261,9 +260,8 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper blockValidation ) - val generalTx = SignedTransaction.sign(transaction, keyPair, None).tx - val specificTx = - SignedTransaction.sign(transaction.copy(nonce = transaction.nonce + 1), keyPair, Some(0x3d.toByte)).tx + val generalTx = SignedTransaction.sign(transaction, keyPair, None) + val specificTx = SignedTransaction.sign(transaction.copy(nonce = transaction.nonce + 1), keyPair, Some(0x3d.toByte)) val pendingBlock = blockGenerator @@ -345,7 +343,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper blockValidation ) - val transaction1 = Transaction( + val transaction1 = LegacyTransaction( nonce = 0, gasPrice = 1, gasLimit = 1000000, @@ -353,7 +351,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper value = 0, payload = ByteString.empty ) - val generalTx = SignedTransaction.sign(transaction1, keyPair, None).tx + val generalTx = SignedTransaction.sign(transaction1, keyPair, None) val generatedBlock = blockGenerator @@ -364,13 +362,13 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper } it should "generate block after eip155 and allow both chain specific and general transactions" in new TestSetup { - val generalTx = SignedTransaction.sign(transaction.copy(nonce = transaction.nonce + 1), keyPair, None).tx + val generalTx = SignedTransaction.sign(transaction.copy(nonce = transaction.nonce + 1), keyPair, None) val pendingBlock = blockGenerator .generateBlock( bestBlock.get, - Seq(generalTx, signedTransaction.tx), + Seq(generalTx, signedTransaction), Address(testAddress), blockGenerator.emptyX, None @@ -395,19 +393,19 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper BlockHeaderValid ) blockExecution.executeAndValidateBlock(fullBlock) shouldBe a[Right[_, Seq[Receipt]]] - fullBlock.body.transactionList shouldBe Seq(signedTransaction.tx, generalTx) + fullBlock.body.transactionList shouldBe Seq(signedTransaction, generalTx) fullBlock.header.extraData shouldBe headerExtraData } it should "include consecutive transactions from single sender" in new TestSetup { val nextTransaction = - SignedTransaction.sign(transaction.copy(nonce = signedTransaction.tx.tx.nonce + 1), keyPair, Some(0x3d.toByte)).tx + SignedTransaction.sign(transaction.copy(nonce = signedTransaction.tx.nonce + 1), keyPair, Some(0x3d.toByte)) val pendingBlock = blockGenerator .generateBlock( bestBlock.get, - Seq(nextTransaction, signedTransaction.tx), + Seq(nextTransaction, signedTransaction), Address(testAddress), blockGenerator.emptyX, None @@ -432,18 +430,18 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper BlockHeaderValid ) blockExecution.executeAndValidateBlock(fullBlock) shouldBe a[Right[_, Seq[Receipt]]] - fullBlock.body.transactionList shouldBe Seq(signedTransaction.tx, nextTransaction) + fullBlock.body.transactionList shouldBe Seq(signedTransaction, nextTransaction) fullBlock.header.extraData shouldBe headerExtraData } it should "filter out failing transaction from the middle of tx list" in new TestSetup { val nextTransaction = - SignedTransaction.sign(transaction.copy(nonce = signedTransaction.tx.tx.nonce + 1), keyPair, Some(0x3d.toByte)).tx + SignedTransaction.sign(transaction.copy(nonce = signedTransaction.tx.nonce + 1), keyPair, Some(0x3d.toByte)) val privateKeyWithNoEthere = BigInt(1, Hex.decode("584a31be275195585603ddd05a53d16fae9deafba67213b6060cec9f16e44cae")) - val failingTransaction = Transaction( + val failingTransaction = LegacyTransaction( nonce = 0, gasPrice = 1, gasLimit = txGasLimit, @@ -452,13 +450,13 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper payload = ByteString.empty ) val signedFailingTransaction = - SignedTransaction.sign(failingTransaction, keyPairFromPrvKey(privateKeyWithNoEthere), Some(0x3d.toByte)).tx + SignedTransaction.sign(failingTransaction, keyPairFromPrvKey(privateKeyWithNoEthere), Some(0x3d.toByte)) val pendingBlock = blockGenerator .generateBlock( bestBlock.get, - Seq(nextTransaction, signedFailingTransaction, signedTransaction.tx), + Seq(nextTransaction, signedFailingTransaction, signedTransaction), Address(testAddress), blockGenerator.emptyX, None @@ -482,20 +480,19 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper BlockHeaderValid ) blockExecution.executeAndValidateBlock(fullBlock) shouldBe a[Right[_, Seq[Receipt]]] - fullBlock.body.transactionList shouldBe Seq(signedTransaction.tx, nextTransaction) + fullBlock.body.transactionList shouldBe Seq(signedTransaction, nextTransaction) fullBlock.header.extraData shouldBe headerExtraData } it should "include transaction with higher gas price if nonce is the same" in new TestSetup { val txWitSameNonceButLowerGasPrice = SignedTransaction - .sign(transaction.copy(gasPrice = signedTransaction.tx.tx.gasPrice - 1), keyPair, Some(0x3d.toByte)) - .tx + .sign(transaction.copy(gasPrice = signedTransaction.tx.gasPrice - 1), keyPair, Some(0x3d.toByte)) val pendingBlock = blockGenerator .generateBlock( bestBlock.get, - Seq(txWitSameNonceButLowerGasPrice, signedTransaction.tx), + Seq(txWitSameNonceButLowerGasPrice, signedTransaction), Address(testAddress), blockGenerator.emptyX, None @@ -519,7 +516,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper BlockHeaderValid ) blockExecution.executeAndValidateBlock(fullBlock) shouldBe a[Right[_, Seq[Receipt]]] - fullBlock.body.transactionList shouldBe Seq(signedTransaction.tx) + fullBlock.body.transactionList shouldBe Seq(signedTransaction) fullBlock.header.extraData shouldBe headerExtraData } @@ -657,7 +654,7 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper val txGasLimit = 21000 val txTransfer = 9000 - val transaction: Transaction = Transaction( + val transaction: LegacyTransaction = LegacyTransaction( nonce = 0, gasPrice = 1, gasLimit = txGasLimit, @@ -670,11 +667,14 @@ class BlockGeneratorSpec extends AnyFlatSpec with Matchers with ScalaCheckProper val treasuryAccount: Address = Address(0xeeeeee) val maliciousAccount: Address = Address(0x123) - lazy val signedTransaction: SignedTransactionWithSender = + lazy val signedTransaction: SignedTransaction = SignedTransaction.sign(transaction, keyPair, Some(0x3d.toByte)) - lazy val duplicatedSignedTransaction: SignedTransactionWithSender = + lazy val duplicatedSignedTransaction: SignedTransaction = SignedTransaction.sign(transaction.copy(gasLimit = 2), keyPair, Some(0x3d.toByte)) + lazy val signedTransactionWithAddress: SignedTransactionWithSender = + SignedTransactionWithSender(signedTransaction, Address(keyPair)) + val baseBlockchainConfig: BlockchainConfig = BlockchainConfig( forkBlockNumbers = ForkBlockNumbers( frontierBlockNumber = 0, diff --git a/src/test/scala/io/iohk/ethereum/consensus/pow/MinerSpecSetup.scala b/src/test/scala/io/iohk/ethereum/consensus/pow/MinerSpecSetup.scala index 7a32c7fbb6..956afa522c 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/pow/MinerSpecSetup.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/pow/MinerSpecSetup.scala @@ -57,7 +57,7 @@ trait MinerSpecSetup extends ConsensusConfigBuilder with MockFactory { lazy val vm: VMImpl = new VMImpl val txToMine: SignedTransaction = SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438553"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), diff --git a/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdBlockValidatorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdBlockValidatorSpec.scala index 4434da014c..48b32a08c4 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdBlockValidatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdBlockValidatorSpec.scala @@ -106,7 +106,7 @@ class StdBlockValidatorSpec extends AnyFlatSpec with Matchers with SecureRandomB val validBlockBody: BlockBody = BlockBody( transactionList = Seq[SignedTransaction]( SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438550"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), @@ -120,7 +120,7 @@ class StdBlockValidatorSpec extends AnyFlatSpec with Matchers with SecureRandomB chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438551"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), @@ -134,7 +134,7 @@ class StdBlockValidatorSpec extends AnyFlatSpec with Matchers with SecureRandomB chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438552"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), @@ -148,7 +148,7 @@ class StdBlockValidatorSpec extends AnyFlatSpec with Matchers with SecureRandomB chainId = 0x3d.toByte ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt("438553"), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), diff --git a/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidatorSpec.scala b/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedLegacyTransactionValidatorSpec.scala similarity index 94% rename from src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidatorSpec.scala rename to src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedLegacyTransactionValidatorSpec.scala index f843b0ec66..9b5e776e7d 100644 --- a/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedTransactionValidatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/consensus/validators/std/StdSignedLegacyTransactionValidatorSpec.scala @@ -20,14 +20,14 @@ import io.iohk.ethereum.domain._ import io.iohk.ethereum.utils.Config import io.iohk.ethereum.vm.EvmConfig -class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { +class StdSignedLegacyTransactionValidatorSpec extends AnyFlatSpec with Matchers { val blockchainConfig = Config.blockchains.blockchainConfig val signedTransactionValidator = new StdSignedTransactionValidator(blockchainConfig) //From block 0x228943f4ef720ac91ca09c08056d7764c2a1650181925dfaeb484f27e544404e with number 1100000 (tx index 0) - val txBeforeHomestead: Transaction = Transaction( + val txBeforeHomestead: LegacyTransaction = LegacyTransaction( nonce = 81, gasPrice = BigInt("60000000000"), gasLimit = 21000, @@ -44,7 +44,7 @@ class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { ) //From block 0xdc7874d8ea90b63aa0ba122055e514db8bb75c0e7d51a448abd12a31ca3370cf with number 1200003 (tx index 0) - val txAfterHomestead: Transaction = Transaction( + val txAfterHomestead: LegacyTransaction = LegacyTransaction( nonce = 1631, gasPrice = BigInt("30000000000"), gasLimit = 21000, @@ -111,7 +111,7 @@ class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { } it should "report as syntactic invalid a tx with long nonce" in { - val invalidNonce = (0 until Transaction.NonceLength + 1).map(_ => 1.toByte).toArray + val invalidNonce = (0 until LegacyTransaction.NonceLength + 1).map(_ => 1.toByte).toArray val signedTxWithInvalidNonce = signedTxBeforeHomestead.copy(tx = txBeforeHomestead.copy(nonce = BigInt(invalidNonce))) validateStx(signedTxWithInvalidNonce, fromBeforeHomestead = true) match { @@ -121,7 +121,7 @@ class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { } it should "report as syntactic invalid a tx with long gas limit" in { - val invalidGasLimit = (0 until Transaction.GasLength + 1).map(_ => 1.toByte).toArray + val invalidGasLimit = (0 until LegacyTransaction.GasLength + 1).map(_ => 1.toByte).toArray val signedTxWithInvalidGasLimit = signedTxBeforeHomestead.copy(tx = txBeforeHomestead.copy(gasLimit = BigInt(invalidGasLimit))) validateStx(signedTxWithInvalidGasLimit, fromBeforeHomestead = true) match { @@ -131,7 +131,7 @@ class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { } it should "report as syntactic invalid a tx with long gas price" in { - val invalidGasPrice = (0 until Transaction.GasLength + 1).map(_ => 1.toByte).toArray + val invalidGasPrice = (0 until LegacyTransaction.GasLength + 1).map(_ => 1.toByte).toArray val signedTxWithInvalidGasPrice = signedTxBeforeHomestead.copy(tx = txBeforeHomestead.copy(gasPrice = BigInt(invalidGasPrice))) validateStx(signedTxWithInvalidGasPrice, fromBeforeHomestead = true) match { @@ -141,7 +141,7 @@ class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { } it should "report as syntactic invalid a tx with long value" in { - val invalidValue = (0 until Transaction.ValueLength + 1).map(_ => 1.toByte).toArray + val invalidValue = (0 until LegacyTransaction.ValueLength + 1).map(_ => 1.toByte).toArray val signedTxWithInvalidValue = signedTxBeforeHomestead.copy(tx = txBeforeHomestead.copy(value = BigInt(invalidValue))) validateStx(signedTxWithInvalidValue, fromBeforeHomestead = true) match { @@ -239,7 +239,7 @@ class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { val keyPair = crypto.generateKeyPair(new SecureRandom) val stx = SignedTransaction.sign(txBeforeHomestead, keyPair, Some(0x03.toByte)) signedTransactionValidator.validate( - stx.tx, + stx, senderAccount = senderAccountAfterHomestead, blockHeader = blockHeaderAfterHomestead, upfrontGasCost = upfrontGasCost, @@ -254,7 +254,7 @@ class StdSignedTransactionValidatorSpec extends AnyFlatSpec with Matchers { val keyPair = crypto.generateKeyPair(new SecureRandom) val stx = SignedTransaction.sign(txAfterHomestead, keyPair, Some(0x03.toByte)) signedTransactionValidator.validate( - stx.tx, + stx, senderAccount = senderAccountAfterHomestead, blockHeader = blockHeaderAfterHomestead.copy(number = blockchainConfig.forkBlockNumbers.eip155BlockNumber), upfrontGasCost = upfrontGasCost, diff --git a/src/test/scala/io/iohk/ethereum/db/storage/TransactionMappingStorageSuite.scala b/src/test/scala/io/iohk/ethereum/db/storage/LegacyTransactionMappingStorageSuite.scala similarity index 95% rename from src/test/scala/io/iohk/ethereum/db/storage/TransactionMappingStorageSuite.scala rename to src/test/scala/io/iohk/ethereum/db/storage/LegacyTransactionMappingStorageSuite.scala index a2f0c03563..ad7a901f71 100644 --- a/src/test/scala/io/iohk/ethereum/db/storage/TransactionMappingStorageSuite.scala +++ b/src/test/scala/io/iohk/ethereum/db/storage/LegacyTransactionMappingStorageSuite.scala @@ -8,7 +8,7 @@ import io.iohk.ethereum.ObjectGenerators import io.iohk.ethereum.db.dataSource.EphemDataSource import io.iohk.ethereum.db.storage.TransactionMappingStorage.TransactionLocation -class TransactionMappingStorageSuite extends AnyFunSuite with ScalaCheckPropertyChecks with ObjectGenerators { +class LegacyTransactionMappingStorageSuite extends AnyFunSuite with ScalaCheckPropertyChecks with ObjectGenerators { test("TransactionMappingStorage insert") { forAll(Gen.listOf(byteStringOfLengthNGen(32))) { txByteArrayHashes => val txHashes = txByteArrayHashes.distinct diff --git a/src/test/scala/io/iohk/ethereum/domain/SignedTransactionSpec.scala b/src/test/scala/io/iohk/ethereum/domain/SignedLegacyTransactionSpec.scala similarity index 81% rename from src/test/scala/io/iohk/ethereum/domain/SignedTransactionSpec.scala rename to src/test/scala/io/iohk/ethereum/domain/SignedLegacyTransactionSpec.scala index 98687ad9c6..178f13dca2 100644 --- a/src/test/scala/io/iohk/ethereum/domain/SignedTransactionSpec.scala +++ b/src/test/scala/io/iohk/ethereum/domain/SignedLegacyTransactionSpec.scala @@ -12,7 +12,11 @@ import io.iohk.ethereum.domain.SignedTransaction.FirstByteOfAddress import io.iohk.ethereum.security.SecureRandomBuilder import io.iohk.ethereum.vm.Generators -class SignedTransactionSpec extends AnyFlatSpec with Matchers with ScalaCheckPropertyChecks with SecureRandomBuilder { +class SignedLegacyTransactionSpec + extends AnyFlatSpec + with Matchers + with ScalaCheckPropertyChecks + with SecureRandomBuilder { "SignedTransaction" should "correctly set pointSign for chainId with chain specific signing schema" in { forAll(Generators.transactionGen(), Arbitrary.arbitrary[Unit].map(_ => generateKeyPair(secureRandom))) { (tx, key) => @@ -24,7 +28,8 @@ class SignedTransactionSpec extends AnyFlatSpec with Matchers with ScalaCheckPro .kec256(key.getPublic.asInstanceOf[ECPublicKeyParameters].getQ.getEncoded(false).tail) .drop(FirstByteOfAddress) ) - val result = SignedTransaction.sign(tx, key, Some(chainId)) + val signedTransaction = SignedTransaction.sign(tx, key, Some(chainId)) + val result = SignedTransactionWithSender(signedTransaction, Address(key)) allowedPointSigns should contain(result.tx.signature.v) address shouldEqual result.senderAddress diff --git a/src/test/scala/io/iohk/ethereum/faucet/jsonrpc/WalletServiceSpec.scala b/src/test/scala/io/iohk/ethereum/faucet/jsonrpc/WalletServiceSpec.scala index 1767672728..51e02b41db 100644 --- a/src/test/scala/io/iohk/ethereum/faucet/jsonrpc/WalletServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/faucet/jsonrpc/WalletServiceSpec.scala @@ -18,7 +18,7 @@ import org.scalatest.matchers.should.Matchers import io.iohk.ethereum.crypto import io.iohk.ethereum.crypto._ import io.iohk.ethereum.domain.Address -import io.iohk.ethereum.domain.Transaction +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.faucet.FaucetConfig import io.iohk.ethereum.faucet.RpcClientConfig import io.iohk.ethereum.faucet.SupervisorConfig @@ -37,7 +37,14 @@ class WalletServiceSpec extends AnyFlatSpec with Matchers with MockFactory { val currentNonce = 2 val tx = wallet.signTx( - Transaction(currentNonce, config.txGasPrice, config.txGasLimit, receivingAddress, config.txValue, ByteString()), + LegacyTransaction( + currentNonce, + config.txGasPrice, + config.txGasLimit, + receivingAddress, + config.txValue, + ByteString() + ), None ) diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/EthTxServiceSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/EthTxServiceSpec.scala index 0e8eedc510..c6f0650c8b 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/EthTxServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/EthTxServiceSpec.scala @@ -337,7 +337,7 @@ class EthTxServiceSpec it should "send message to pendingTransactionsManager and return GetPendingTransactionsResponse with two transactions" in new TestSetup { val transactions = (0 to 1).map { _ => val fakeTransaction = SignedTransactionWithSender( - Transaction( + LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, @@ -411,7 +411,7 @@ class EthTxServiceSpec // //tx 0xb7b8cc9154896b25839ede4cd0c2ad193adf06489fdd9c0a9dfce05620c04ec1 val contractCreatingTransaction: SignedTransaction = SignedTransaction( - Transaction( + LegacyTransaction( nonce = 2550, gasPrice = BigInt("20000000000"), gasLimit = 3000000, diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/FilterManagerSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/FilterManagerSpec.scala index 15847341c9..7544c18d06 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/FilterManagerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/FilterManagerSpec.scala @@ -82,7 +82,7 @@ class FilterManagerSpec val bb2 = BlockBody( transactionList = Seq( SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, @@ -160,7 +160,7 @@ class FilterManagerSpec val bb4 = BlockBody( transactionList = Seq( SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, @@ -171,7 +171,7 @@ class FilterManagerSpec signature = ECDSASignature(0, 0, 0.toByte) ), SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, @@ -246,7 +246,7 @@ class FilterManagerSpec val bb = BlockBody( transactionList = Seq( SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, @@ -286,7 +286,7 @@ class FilterManagerSpec val bh2 = blockHeader.copy(number = 2, logsBloom = BloomFilter.create(logs2)) val blockTransactions2 = Seq( SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = 0, gasPrice = 321, gasLimit = 321, @@ -392,7 +392,7 @@ class FilterManagerSpec (blockchainReader.getBestBlockNumber _).expects().returning(3) - val tx = Transaction( + val tx = LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, @@ -401,7 +401,7 @@ class FilterManagerSpec payload = ByteString() ) - val stx = SignedTransaction.sign(tx, keyPair, None) + val stx = SignedTransactionWithSender(SignedTransaction.sign(tx, keyPair, None), Address(keyPair)) val pendingTxs = Seq( stx ) @@ -433,7 +433,7 @@ class FilterManagerSpec (blockchainReader.getBestBlockNumber _).expects().returning(3) - val tx = Transaction( + val tx = LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, @@ -442,7 +442,7 @@ class FilterManagerSpec payload = ByteString() ) - val stx = SignedTransaction.sign(tx, keyPair, None) + val stx = SignedTransactionWithSender(SignedTransaction.sign(tx, keyPair, None), Address(keyPair)) val pendingTxs = Seq(stx) (keyStore.listAccounts _).expects().returning(Right(List(stx.senderAddress))) diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerEthTransactionSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerEthLegacyTransactionSpec.scala similarity index 99% rename from src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerEthTransactionSpec.scala rename to src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerEthLegacyTransactionSpec.scala index 0933d66da7..38a5193452 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerEthTransactionSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/JsonRpcControllerEthLegacyTransactionSpec.scala @@ -35,7 +35,7 @@ import io.iohk.ethereum.jsonrpc.serialization.JsonSerializers.UnformattedDataJso import io.iohk.ethereum.transactions.PendingTransactionsManager.PendingTransaction // scalastyle:off magic.number -class JsonRpcControllerEthTransactionSpec +class JsonRpcControllerEthLegacyTransactionSpec extends TestKit(ActorSystem("JsonRpcControllerEthTransactionSpec_System")) with AnyFlatSpecLike with WithActorSystemShutDown @@ -537,7 +537,7 @@ class JsonRpcControllerEthTransactionSpec it should "request pending transactions and return valid response when mempool has transactions" in new JsonRpcControllerFixture { val transactions = (0 to 1).map { _ => val fakeTransaction = SignedTransactionWithSender( - Transaction( + LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, diff --git a/src/test/scala/io/iohk/ethereum/jsonrpc/MantisServiceSpec.scala b/src/test/scala/io/iohk/ethereum/jsonrpc/MantisServiceSpec.scala index b218c9d99d..e68009042c 100644 --- a/src/test/scala/io/iohk/ethereum/jsonrpc/MantisServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/jsonrpc/MantisServiceSpec.scala @@ -18,8 +18,8 @@ import io.iohk.ethereum.blockchain.sync.EphemBlockchainTestSetup import io.iohk.ethereum.crypto.ECDSASignature import io.iohk.ethereum.domain.Address import io.iohk.ethereum.domain.BlockBody +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.domain.SignedTransactionWithSender -import io.iohk.ethereum.domain.Transaction import io.iohk.ethereum.jsonrpc.MantisService.GetAccountTransactionsRequest import io.iohk.ethereum.jsonrpc.MantisService.GetAccountTransactionsResponse import io.iohk.ethereum.nodebuilder.ApisBuilder @@ -54,7 +54,7 @@ class MantisServiceSpec "should get account's transaction history" in { class TxHistoryFixture extends Fixture { val fakeTransaction = SignedTransactionWithSender( - Transaction( + LegacyTransaction( nonce = 0, gasPrice = 123, gasLimit = 123, diff --git a/src/test/scala/io/iohk/ethereum/ledger/BlockExecutionSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/BlockExecutionSpec.scala index a3bc84a0cf..e2beae972c 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/BlockExecutionSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/BlockExecutionSpec.scala @@ -42,7 +42,7 @@ class BlockExecutionSpec extends AnyWordSpec with Matchers with ScalaCheckProper val block1BodyWithTxs: BlockBody = validBlockBodyWithNoTxs.copy(transactionList = Seq(invalidStx)) val block1 = Block(validBlockHeader, block1BodyWithTxs) val block2BodyWithTxs: BlockBody = - validBlockBodyWithNoTxs.copy(transactionList = Seq(validStxSignedByOrigin.tx)) + validBlockBodyWithNoTxs.copy(transactionList = Seq(validStxSignedByOrigin)) val block2 = Block( validBlockHeader.copy(parentHash = validBlockHeader.hash, number = validBlockHeader.number + 1), block2BodyWithTxs @@ -84,7 +84,7 @@ class BlockExecutionSpec extends AnyWordSpec with Matchers with ScalaCheckProper "two blocks with txs (that last one has invalid tx)" in new BlockchainSetup { val invalidStx = SignedTransaction(validTx, ECDSASignature(1, 2, 3.toByte)) val block1BodyWithTxs: BlockBody = - validBlockBodyWithNoTxs.copy(transactionList = Seq(validStxSignedByOrigin.tx)) + validBlockBodyWithNoTxs.copy(transactionList = Seq(validStxSignedByOrigin)) val block1 = Block(validBlockHeader, block1BodyWithTxs) val block2BodyWithTxs: BlockBody = validBlockBodyWithNoTxs.copy(transactionList = Seq(invalidStx)) val block2 = Block( @@ -211,7 +211,7 @@ class BlockExecutionSpec extends AnyWordSpec with Matchers with ScalaCheckProper "block with one tx (that produces OutOfGas)" in new BlockchainSetup { - val blockBodyWithTxs: BlockBody = validBlockBodyWithNoTxs.copy(transactionList = Seq(validStxSignedByOrigin.tx)) + val blockBodyWithTxs: BlockBody = validBlockBodyWithNoTxs.copy(transactionList = Seq(validStxSignedByOrigin)) val block = Block(validBlockHeader, blockBodyWithTxs) val mockVm = new MockVM(c => @@ -247,7 +247,7 @@ class BlockExecutionSpec extends AnyWordSpec with Matchers with ScalaCheckProper txsExecResult.isRight shouldBe true val BlockResult(resultingWorldState, resultingGasUsed, resultingReceipts) = txsExecResult.toOption.get - val transaction: Transaction = validStxSignedByOrigin.tx.tx + val transaction: LegacyTransaction = validStxSignedByOrigin.tx // Check valid world val minerPaymentForTxs = UInt256(transaction.gasLimit * transaction.gasPrice) val changes = Seq( @@ -284,7 +284,10 @@ class BlockExecutionSpec extends AnyWordSpec with Matchers with ScalaCheckProper forAll(table) { (gasLimit, logs, addressesToDelete, txValidAccordingToValidators) => val tx = validTx.copy(gasLimit = gasLimit) - val stx = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) + val stx = SignedTransactionWithSender( + SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)), + Address(originKeyPair) + ) val blockHeader: BlockHeader = validBlockHeader.copy(gasLimit = gasLimit) val blockBodyWithTxs: BlockBody = validBlockBodyWithNoTxs.copy(transactionList = Seq(stx.tx)) @@ -351,7 +354,7 @@ class BlockExecutionSpec extends AnyWordSpec with Matchers with ScalaCheckProper "last one wasn't executed correctly" in new BlockExecutionTestSetup { val invalidStx = SignedTransaction(validTx, ECDSASignature(1, 2, 3.toByte)) val blockBodyWithTxs: BlockBody = - validBlockBodyWithNoTxs.copy(transactionList = Seq(validStxSignedByOrigin.tx, invalidStx)) + validBlockBodyWithNoTxs.copy(transactionList = Seq(validStxSignedByOrigin, invalidStx)) val block = Block(validBlockHeader, blockBodyWithTxs) val txsExecResult: Either[BlockExecutionError, BlockResult] = @@ -363,7 +366,7 @@ class BlockExecutionSpec extends AnyWordSpec with Matchers with ScalaCheckProper "first one wasn't executed correctly" in new BlockExecutionTestSetup { val invalidStx = SignedTransaction(validTx, ECDSASignature(1, 2, 3.toByte)) val blockBodyWithTxs: BlockBody = - validBlockBodyWithNoTxs.copy(transactionList = Seq(invalidStx, validStxSignedByOrigin.tx)) + validBlockBodyWithNoTxs.copy(transactionList = Seq(invalidStx, validStxSignedByOrigin)) val block = Block(validBlockHeader, blockBodyWithTxs) val txsExecResult: Either[BlockExecutionError, BlockResult] = @@ -564,8 +567,14 @@ class BlockExecutionSpec extends AnyWordSpec with Matchers with ScalaCheckProper gasLimit = defaultGasLimit * 2, nonce = validTx.nonce + (if (origin1Address == origin2Address) 1 else 0) ) - val stx1 = SignedTransaction.sign(tx1, keyPair(origin1Address), Some(blockchainConfig.chainId)) - val stx2 = SignedTransaction.sign(tx2, keyPair(origin2Address), Some(blockchainConfig.chainId)) + val keyPair1 = keyPair(origin1Address) + val keyPair2 = keyPair(origin2Address) + + val st1 = SignedTransaction.sign(tx1, keyPair1, Some(blockchainConfig.chainId)) + val st2 = SignedTransaction.sign(tx2, keyPair2, Some(blockchainConfig.chainId)) + + val stx1 = SignedTransactionWithSender(st1, Address(keyPair1)) + val stx2 = SignedTransactionWithSender(st2, Address(keyPair2)) val validBlockBodyWithTxs: BlockBody = validBlockBodyWithNoTxs.copy(transactionList = Seq(stx1.tx, stx2.tx)) val block = Block(validBlockHeader, validBlockBodyWithTxs) diff --git a/src/test/scala/io/iohk/ethereum/ledger/BlockPreparatorSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/BlockPreparatorSpec.scala index 1340ccd72a..605e187c8a 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/BlockPreparatorSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/BlockPreparatorSpec.scala @@ -39,7 +39,7 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope "correctly change the nonce" when { "executing a tx that results in contract creation" in new TestSetup { - val tx: Transaction = + val tx: LegacyTransaction = defaultTx.copy( gasPrice = defaultGasPrice, gasLimit = defaultGasLimit, @@ -47,7 +47,10 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope payload = ByteString.empty ) - val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) + val stx: SignedTransactionWithSender = SignedTransactionWithSender( + SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)), + Address(originKeyPair) + ) val header: BlockHeader = defaultBlockHeader.copy(beneficiary = minerAddress.bytes) @@ -61,14 +64,17 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope "executing a tx that results in a message call" in new TestSetup { - val tx: Transaction = defaultTx.copy( + val tx: LegacyTransaction = defaultTx.copy( gasPrice = defaultGasPrice, gasLimit = defaultGasLimit, receivingAddress = Some(originAddress), payload = ByteString.empty ) - val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) + val stx: SignedTransactionWithSender = SignedTransactionWithSender( + SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)), + Address(originKeyPair) + ) val header: BlockHeader = defaultBlockHeader.copy(beneficiary = minerAddress.bytes) @@ -84,13 +90,16 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope "properly assign stateRootHash" when { "before byzantium block (exclusive)" in new TestSetup { - val tx: Transaction = defaultTx.copy( + val tx: LegacyTransaction = defaultTx.copy( gasPrice = defaultGasPrice, gasLimit = defaultGasLimit, receivingAddress = None, payload = ByteString.empty ) - val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) + val stx: SignedTransactionWithSender = SignedTransactionWithSender( + SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)), + Address(originKeyPair) + ) val header: BlockHeader = defaultBlockHeader.copy(number = blockchainConfig.forkBlockNumbers.byzantiumBlockNumber - 1) @@ -105,13 +114,13 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope "after byzantium block (inclusive) if operation is a success" in new TestSetup { - val tx: Transaction = defaultTx.copy( + val tx: LegacyTransaction = defaultTx.copy( gasPrice = defaultGasPrice, gasLimit = defaultGasLimit, receivingAddress = None, payload = ByteString.empty ) - val stx: SignedTransaction = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)).tx + val stx: SignedTransaction = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) val header: BlockHeader = defaultBlockHeader.copy( beneficiary = minerAddress.bytes, @@ -134,13 +143,16 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope val testConsensus: Consensus = newTestConsensus(vm = mockVM) - val tx: Transaction = defaultTx.copy( + val tx: LegacyTransaction = defaultTx.copy( gasPrice = defaultGasLimit, gasLimit = defaultGasLimit, receivingAddress = None, payload = ByteString.empty ) - val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) + val stx: SignedTransactionWithSender = SignedTransactionWithSender( + SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)), + Address(originKeyPair) + ) val header: BlockHeader = defaultBlockHeader.copy( beneficiary = minerAddress.bytes, @@ -172,7 +184,10 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope val tx = defaultTx.copy(gasPrice = defaultGasPrice, gasLimit = defaultGasLimit) - val stx = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) + val stx = SignedTransactionWithSender( + SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)), + Address(originKeyPair) + ) val header = defaultBlockHeader.copy(beneficiary = minerAddress.bytes) @@ -222,7 +237,10 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope val initialWorld = emptyWorld .saveAccount(originAddress, Account(nonce = UInt256(initialOriginNonce), balance = initialOriginBalance)) - val stx = SignedTransaction.sign(defaultTx, originKeyPair, Some(blockchainConfig.chainId)) + val stx = SignedTransactionWithSender( + SignedTransaction.sign(defaultTx, originKeyPair, Some(blockchainConfig.chainId)), + Address(originKeyPair) + ) val mockVM = new MockVM(createResult(_, defaultGasLimit, defaultGasLimit, 0, maybeError, bEmpty, defaultsLogs)) @@ -247,12 +265,12 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope createResult(pc, defaultGasLimit, defaultGasLimit, 0, None, returnData = ByteString("contract code")) ) - val tx: Transaction = defaultTx.copy(gasPrice = 0, receivingAddress = None, payload = inputData) - val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, newAccountKeyPair, Some(blockchainConfig.chainId)) + val tx: LegacyTransaction = defaultTx.copy(gasPrice = 0, receivingAddress = None, payload = inputData) + val stx = SignedTransaction.sign(tx, newAccountKeyPair, Some(blockchainConfig.chainId)) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = consensus.blockPreparator.executeTransactions( - Seq(stx.tx), + Seq(stx), initialWorld, defaultBlockHeader ) @@ -279,26 +297,22 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope } } - val tx1: Transaction = defaultTx.copy(gasPrice = 42, receivingAddress = Some(Address(42))) - val tx2: Transaction = defaultTx.copy(gasPrice = 43, receivingAddress = Some(Address(43))) - val tx3: Transaction = defaultTx.copy(gasPrice = 43, receivingAddress = Some(Address(43))) - val tx4: Transaction = defaultTx.copy(gasPrice = 42, receivingAddress = Some(Address(42))) - val stx1: SignedTransactionWithSender = - SignedTransaction.sign(tx1, newAccountKeyPair, Some(blockchainConfig.chainId)) - val stx2: SignedTransactionWithSender = - SignedTransaction.sign(tx2, newAccountKeyPair, Some(blockchainConfig.chainId)) - val stx3: SignedTransactionWithSender = - SignedTransaction.sign(tx3, newAccountKeyPair, Some(blockchainConfig.chainId)) - val stx4: SignedTransactionWithSender = - SignedTransaction.sign(tx4, newAccountKeyPair, Some(blockchainConfig.chainId)) + val tx1: LegacyTransaction = defaultTx.copy(gasPrice = 42, receivingAddress = Some(Address(42))) + val tx2: LegacyTransaction = defaultTx.copy(gasPrice = 43, receivingAddress = Some(Address(43))) + val tx3: LegacyTransaction = defaultTx.copy(gasPrice = 43, receivingAddress = Some(Address(43))) + val tx4: LegacyTransaction = defaultTx.copy(gasPrice = 42, receivingAddress = Some(Address(42))) + val stx1 = SignedTransaction.sign(tx1, newAccountKeyPair, Some(blockchainConfig.chainId)) + val stx2 = SignedTransaction.sign(tx2, newAccountKeyPair, Some(blockchainConfig.chainId)) + val stx3 = SignedTransaction.sign(tx3, newAccountKeyPair, Some(blockchainConfig.chainId)) + val stx4 = SignedTransaction.sign(tx4, newAccountKeyPair, Some(blockchainConfig.chainId)) val result: (BlockResult, Seq[SignedTransaction]) = consensus.blockPreparator.executePreparedTransactions( - Seq(stx1.tx, stx2.tx, stx3.tx, stx4.tx), + Seq(stx1, stx2, stx3, stx4), initialWorld, defaultBlockHeader ) - result match { case (_, executedTxs) => executedTxs shouldBe Seq(stx1.tx, stx4.tx) } + result match { case (_, executedTxs) => executedTxs shouldBe Seq(stx1, stx4) } } "produce empty block if all txs fail" in new TestSetup { @@ -315,15 +329,13 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope } } - val tx1: Transaction = defaultTx.copy(gasPrice = 42, receivingAddress = Some(Address(42))) - val tx2: Transaction = defaultTx.copy(gasPrice = 42, receivingAddress = Some(Address(42))) - val stx1: SignedTransactionWithSender = - SignedTransaction.sign(tx1, newAccountKeyPair, Some(blockchainConfig.chainId)) - val stx2: SignedTransactionWithSender = - SignedTransaction.sign(tx2, newAccountKeyPair, Some(blockchainConfig.chainId)) + val tx1: LegacyTransaction = defaultTx.copy(gasPrice = 42, receivingAddress = Some(Address(42))) + val tx2: LegacyTransaction = defaultTx.copy(gasPrice = 42, receivingAddress = Some(Address(42))) + val stx1 = SignedTransaction.sign(tx1, newAccountKeyPair, Some(blockchainConfig.chainId)) + val stx2 = SignedTransaction.sign(tx2, newAccountKeyPair, Some(blockchainConfig.chainId)) val result: (BlockResult, Seq[SignedTransaction]) = - consensus.blockPreparator.executePreparedTransactions(Seq(stx1.tx, stx2.tx), initialWorld, defaultBlockHeader) + consensus.blockPreparator.executePreparedTransactions(Seq(stx1, stx2), initialWorld, defaultBlockHeader) result match { case (_, executedTxs) => executedTxs shouldBe Seq.empty } } @@ -331,18 +343,18 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope // migrated from old LedgerSpec "properly assign stateRootHash before byzantium block (exclusive)" in new TestSetup { - val tx: Transaction = defaultTx.copy( + val tx: LegacyTransaction = defaultTx.copy( gasPrice = defaultGasPrice, gasLimit = defaultGasLimit, receivingAddress = None, payload = ByteString.empty ) - val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) + val stx = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) val header: BlockHeader = defaultBlockHeader.copy(number = blockchainConfig.forkBlockNumbers.byzantiumBlockNumber - 1) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = - consensus.blockPreparator.executeTransactions(Seq(stx.tx), initialWorld, header) + consensus.blockPreparator.executeTransactions(Seq(stx), initialWorld, header) result shouldBe a[Right[_, BlockResult]] result.map { br => @@ -352,13 +364,13 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope "properly assign stateRootHash after byzantium block (inclusive) if operation is a success" in new TestSetup { - val tx: Transaction = defaultTx.copy( + val tx: LegacyTransaction = defaultTx.copy( gasPrice = defaultGasPrice, gasLimit = defaultGasLimit, receivingAddress = None, payload = ByteString.empty ) - val stx: SignedTransaction = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)).tx + val stx: SignedTransaction = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) val header: BlockHeader = defaultBlockHeader.copy( beneficiary = minerAddress.bytes, @@ -381,13 +393,13 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope val testConsensus: Consensus = newTestConsensus(vm = mockVM) - val tx: Transaction = defaultTx.copy( + val tx: LegacyTransaction = defaultTx.copy( gasPrice = defaultGasLimit, gasLimit = defaultGasLimit, receivingAddress = None, payload = ByteString.empty ) - val stx: SignedTransactionWithSender = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) + val stx = SignedTransaction.sign(tx, originKeyPair, Some(blockchainConfig.chainId)) val header: BlockHeader = defaultBlockHeader.copy( beneficiary = minerAddress.bytes, @@ -395,7 +407,7 @@ class BlockPreparatorSpec extends AnyWordSpec with Matchers with ScalaCheckPrope ) val result: Either[BlockExecutionError.TxsExecutionError, BlockResult] = - testConsensus.blockPreparator.executeTransactions(Seq(stx.tx), initialWorld, header) + testConsensus.blockPreparator.executeTransactions(Seq(stx), initialWorld, header) result shouldBe a[Right[_, BlockResult]] result.map(_.receipts.last.postTransactionStateHash shouldBe FailureOutcome) diff --git a/src/test/scala/io/iohk/ethereum/ledger/BlockValidationSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/BlockValidationSpec.scala index e73f8d3c7a..90c1afcdbc 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/BlockValidationSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/BlockValidationSpec.scala @@ -61,7 +61,7 @@ class BlockValidationSpec extends AnyWordSpec with Matchers with MockFactory { def hash2ByteString(hash: String): ByteString = ByteString(Hex.decode(hash)) - def mkTransaction(nonce: String, address: String, value: String): Transaction = Transaction( + def mkTransaction(nonce: String, address: String, value: String): LegacyTransaction = LegacyTransaction( nonce = BigInt(nonce), gasPrice = BigInt("20000000000"), gasLimit = BigInt("50000"), @@ -70,7 +70,7 @@ class BlockValidationSpec extends AnyWordSpec with Matchers with MockFactory { payload = ByteString.empty ) - def mkStx(tx: Transaction, random: String, signature: String): SignedTransaction = SignedTransaction( + def mkStx(tx: LegacyTransaction, random: String, signature: String): SignedTransaction = SignedTransaction( tx = tx, pointSign = 0x9d.toByte, signatureRandom = hash2ByteString(random), diff --git a/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala b/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala index 7843588b54..cc46fc6338 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/LedgerTestSetup.scala @@ -71,7 +71,7 @@ trait TestSetup extends SecureRandomBuilder with EphemBlockchainTestSetup { unixTimestamp = 1486752441 ) - val defaultTx: Transaction = Transaction( + val defaultTx: LegacyTransaction = LegacyTransaction( nonce = 42, gasPrice = 1, gasLimit = 90000, @@ -204,12 +204,12 @@ trait BlockchainSetup extends TestSetup { .and(storagesInstance.storages.chainWeightStorage.put(validBlockParentHeader.hash, ChainWeight.zero)) .commit() - val validTx: Transaction = defaultTx.copy( + val validTx: LegacyTransaction = defaultTx.copy( nonce = initialOriginNonce, gasLimit = defaultGasLimit, value = defaultValue ) - val validStxSignedByOrigin: SignedTransactionWithSender = + val validStxSignedByOrigin: SignedTransaction = SignedTransaction.sign(validTx, originKeyPair, Some(blockchainConfig.chainId)) } diff --git a/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala b/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala index 1d80e44f6d..c4cad08659 100644 --- a/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/ledger/StxLedgerSpec.scala @@ -27,7 +27,7 @@ class StxLedgerSpec extends AnyFlatSpec with Matchers with Logger { * parity and geth) */ - val tx = Transaction(0, 0, lastBlockGasLimit, existingAddress, 0, sendData) + val tx = LegacyTransaction(0, 0, lastBlockGasLimit, existingAddress, 0, sendData) val fakeSignature = ECDSASignature(0, 0, 0.toByte) val stx = SignedTransaction(tx, fakeSignature) val stxFromAddress = SignedTransactionWithSender(stx, fromAddress) @@ -60,7 +60,7 @@ class StxLedgerSpec extends AnyFlatSpec with Matchers with Logger { it should "correctly estimate gasLimit for value transfer transaction" in new ScenarioSetup { val transferValue = 2 - val tx = Transaction(0, 0, lastBlockGasLimit, existingEmptyAccountAddres, transferValue, ByteString.empty) + val tx = LegacyTransaction(0, 0, lastBlockGasLimit, existingEmptyAccountAddres, transferValue, ByteString.empty) val fakeSignature = ECDSASignature(0, 0, 0.toByte) val stx = SignedTransaction(tx, fakeSignature) @@ -75,7 +75,7 @@ class StxLedgerSpec extends AnyFlatSpec with Matchers with Logger { it should "correctly simulate transaction on pending block when supplied prepared world" in new ScenarioSetup { val transferValue = 2 - val tx = Transaction(0, 0, lastBlockGasLimit, existingEmptyAccountAddres, transferValue, ByteString.empty) + val tx = LegacyTransaction(0, 0, lastBlockGasLimit, existingEmptyAccountAddres, transferValue, ByteString.empty) val fakeSignature = ECDSASignature(0, 0, 0.toByte) val stxFromAddress = SignedTransactionWithSender(SignedTransaction(tx, fakeSignature), fromAddress) diff --git a/src/test/scala/io/iohk/ethereum/network/p2p/messages/TransactionSpec.scala b/src/test/scala/io/iohk/ethereum/network/p2p/messages/LegacyTransactionSpec.scala similarity index 95% rename from src/test/scala/io/iohk/ethereum/network/p2p/messages/TransactionSpec.scala rename to src/test/scala/io/iohk/ethereum/network/p2p/messages/LegacyTransactionSpec.scala index a32ea4bb3b..1833081916 100644 --- a/src/test/scala/io/iohk/ethereum/network/p2p/messages/TransactionSpec.scala +++ b/src/test/scala/io/iohk/ethereum/network/p2p/messages/LegacyTransactionSpec.scala @@ -9,11 +9,11 @@ import org.scalatest.matchers.should.Matchers import io.iohk.ethereum.crypto import io.iohk.ethereum.domain.Address +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.domain.SignedTransaction -import io.iohk.ethereum.domain.Transaction import io.iohk.ethereum.utils.Config -class TransactionSpec extends AnyFlatSpec with Matchers { +class LegacyTransactionSpec extends AnyFlatSpec with Matchers { val blockchainConfig = Config.blockchains.blockchainConfig @@ -24,7 +24,7 @@ class TransactionSpec extends AnyFlatSpec with Matchers { val publicKey: ECPoint = crypto.curve.getCurve.decodePoint(rawPublicKey) val address: Address = Address(crypto.kec256(rawPublicKey.tail).slice(12, 32)) - val validTx: Transaction = Transaction( + val validTx: LegacyTransaction = LegacyTransaction( nonce = 172320, gasPrice = BigInt("50000000000"), gasLimit = 90000, @@ -64,7 +64,7 @@ class TransactionSpec extends AnyFlatSpec with Matchers { val publicKeyForNewSigningScheme: ECPoint = crypto.curve.getCurve.decodePoint(rawPublicKeyForNewSigningScheme) val addreesForNewSigningScheme: Address = Address(crypto.kec256(rawPublicKeyForNewSigningScheme.tail).slice(12, 32)) - val validTransactionForNewSigningScheme: Transaction = Transaction( + val validTransactionForNewSigningScheme: LegacyTransaction = LegacyTransaction( nonce = 587440, gasPrice = BigInt("20000000000"), gasLimit = 90000, @@ -111,7 +111,7 @@ class TransactionSpec extends AnyFlatSpec with Matchers { it should "recover the correct sender for tx in block 46147" in { val stx: SignedTransaction = SignedTransaction( - tx = Transaction( + tx = LegacyTransaction( nonce = BigInt(0), gasPrice = BigInt("50000000000000"), gasLimit = BigInt(21000), diff --git a/src/test/scala/io/iohk/ethereum/transactions/TransactionHistoryServiceSpec.scala b/src/test/scala/io/iohk/ethereum/transactions/LegacyTransactionHistoryServiceSpec.scala similarity index 86% rename from src/test/scala/io/iohk/ethereum/transactions/TransactionHistoryServiceSpec.scala rename to src/test/scala/io/iohk/ethereum/transactions/LegacyTransactionHistoryServiceSpec.scala index 85164e5048..b073de9d6a 100644 --- a/src/test/scala/io/iohk/ethereum/transactions/TransactionHistoryServiceSpec.scala +++ b/src/test/scala/io/iohk/ethereum/transactions/LegacyTransactionHistoryServiceSpec.scala @@ -21,7 +21,7 @@ import io.iohk.ethereum.transactions.TransactionHistoryService.MinedTransactionD import io.iohk.ethereum.transactions.testing.PendingTransactionsManagerAutoPilot import io.iohk.ethereum.{blockchain => _, _} -class TransactionHistoryServiceSpec +class LegacyTransactionHistoryServiceSpec extends TestKit(ActorSystem("TransactionHistoryServiceSpec-system")) with FreeSpecBase with SpecFixtures @@ -44,9 +44,9 @@ class TransactionHistoryServiceSpec val keyPair = generateKeyPair(secureRandom) - val tx1 = SignedTransaction.sign(Transaction(0, 123, 456, Some(address), 1, ByteString()), keyPair, None).tx - val tx2 = SignedTransaction.sign(Transaction(0, 123, 456, Some(address), 2, ByteString()), keyPair, None).tx - val tx3 = SignedTransaction.sign(Transaction(0, 123, 456, Some(address), 3, ByteString()), keyPair, None).tx + val tx1 = SignedTransaction.sign(LegacyTransaction(0, 123, 456, Some(address), 1, ByteString()), keyPair, None) + val tx2 = SignedTransaction.sign(LegacyTransaction(0, 123, 456, Some(address), 2, ByteString()), keyPair, None) + val tx3 = SignedTransaction.sign(LegacyTransaction(0, 123, 456, Some(address), 3, ByteString()), keyPair, None) val blockWithTx1 = Block(Fixtures.Blocks.Block3125369.header, Fixtures.Blocks.Block3125369.body.copy(transactionList = Seq(tx1))) @@ -100,17 +100,18 @@ class TransactionHistoryServiceSpec val keyPair = generateKeyPair(secureRandom) - val tx = Transaction(0, 123, 456, None, 99, ByteString()) + val tx = LegacyTransaction(0, 123, 456, None, 99, ByteString()) val signedTx = SignedTransaction.sign(tx, keyPair, None) + val txWithSender = SignedTransactionWithSender(signedTx, Address(keyPair)) val expectedSent = - Seq(ExtendedTransactionData(signedTx.tx, isOutgoing = true, None)) + Seq(ExtendedTransactionData(signedTx, isOutgoing = true, None)) for { _ <- Task(blockchainWriter.storeBlock(blockWithTx).commit()) - _ <- Task(pendingTransactionManager.ref ! PendingTransactionsManager.AddTransactions(signedTx)) + _ <- Task(pendingTransactionManager.ref ! PendingTransactionsManager.AddTransactions(txWithSender)) response <- transactionHistoryService.getAccountTransactions( - signedTx.senderAddress, + txWithSender.senderAddress, BigInt(3125371) to BigInt(3125381) ) } yield assert(response === expectedSent) @@ -124,15 +125,15 @@ class TransactionHistoryServiceSpec val senderAddress = Address(keyPair) val checkpointKey = generateKeyPair(secureRandom) - val txToBeCheckpointed = Transaction(0, 123, 456, None, 99, ByteString()) + val txToBeCheckpointed = LegacyTransaction(0, 123, 456, None, 99, ByteString()) val signedTxToBeCheckpointed = SignedTransaction.sign(txToBeCheckpointed, keyPair, None) val txNotToBeCheckpointed = - Transaction(1, 123, 456, Address("ee4439beb5c71513b080bbf9393441697a29f478"), 99, ByteString()) + LegacyTransaction(1, 123, 456, Address("ee4439beb5c71513b080bbf9393441697a29f478"), 99, ByteString()) val signedTxNotToBeCheckpointed = SignedTransaction.sign(txNotToBeCheckpointed, keyPair, None) val block1 = BlockHelpers - .generateBlock(BlockHelpers.genesis) |> (BlockHelpers.withTransactions(_, List(signedTxToBeCheckpointed.tx))) + .generateBlock(BlockHelpers.genesis) |> (BlockHelpers.withTransactions(_, List(signedTxToBeCheckpointed))) val block2 = BlockHelpers.generateBlock(block1) |> ( BlockHelpers.updateHeader( _, @@ -144,15 +145,15 @@ class TransactionHistoryServiceSpec ) ) val block3 = - BlockHelpers.generateBlock(block2) |> (BlockHelpers.withTransactions(_, List(signedTxNotToBeCheckpointed.tx))) + BlockHelpers.generateBlock(block2) |> (BlockHelpers.withTransactions(_, List(signedTxNotToBeCheckpointed))) val expectedCheckpointedTxData = ExtendedTransactionData( - signedTxToBeCheckpointed.tx, + signedTxToBeCheckpointed, isOutgoing = true, Some(MinedTransactionData(block1.header, 0, 21000, isCheckpointed = true)) ) val expectedNonCheckpointedTxData = ExtendedTransactionData( - signedTxNotToBeCheckpointed.tx, + signedTxNotToBeCheckpointed, isOutgoing = true, Some(MinedTransactionData(block3.header, 0, 21000, isCheckpointed = false)) ) diff --git a/src/test/scala/io/iohk/ethereum/transactions/PendingTransactionsManagerSpec.scala b/src/test/scala/io/iohk/ethereum/transactions/PendingTransactionsManagerSpec.scala index b831dc0193..8c6deb49dd 100644 --- a/src/test/scala/io/iohk/ethereum/transactions/PendingTransactionsManagerSpec.scala +++ b/src/test/scala/io/iohk/ethereum/transactions/PendingTransactionsManagerSpec.scala @@ -19,9 +19,9 @@ import io.iohk.ethereum.NormalPatience import io.iohk.ethereum.Timeouts import io.iohk.ethereum.crypto import io.iohk.ethereum.domain.Address +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.domain.SignedTransaction import io.iohk.ethereum.domain.SignedTransactionWithSender -import io.iohk.ethereum.domain.Transaction import io.iohk.ethereum.network.EtcPeerManagerActor import io.iohk.ethereum.network.Peer import io.iohk.ethereum.network.PeerActor.Status.Handshaked @@ -216,14 +216,14 @@ class PendingTransactionsManagerSpec extends AnyFlatSpec with Matchers with Scal val keyPair1: AsymmetricCipherKeyPair = crypto.generateKeyPair(secureRandom) val keyPair2: AsymmetricCipherKeyPair = crypto.generateKeyPair(secureRandom) - val tx: Transaction = Transaction(1, 1, 1, Some(Address(42)), 10, ByteString("")) + val tx: LegacyTransaction = LegacyTransaction(1, 1, 1, Some(Address(42)), 10, ByteString("")) def newStx( nonce: BigInt = 0, - tx: Transaction = tx, + tx: LegacyTransaction = tx, keyPair: AsymmetricCipherKeyPair = crypto.generateKeyPair(secureRandom) ): SignedTransactionWithSender = - SignedTransaction.sign(tx, keyPair, Some(0x3d)) + SignedTransactionWithSender(SignedTransaction.sign(tx, keyPair, Some(0x3d)), Address(keyPair)) val peer1TestProbe: TestProbe = TestProbe() val peer1: Peer = Peer(PeerId("peer1"), new InetSocketAddress("127.0.0.1", 9000), peer1TestProbe.ref, false) diff --git a/src/test/scala/io/iohk/ethereum/vm/utils/MockVmInput.scala b/src/test/scala/io/iohk/ethereum/vm/utils/MockVmInput.scala index a370b74f26..5cdc7e033a 100644 --- a/src/test/scala/io/iohk/ethereum/vm/utils/MockVmInput.scala +++ b/src/test/scala/io/iohk/ethereum/vm/utils/MockVmInput.scala @@ -6,13 +6,13 @@ import io.iohk.ethereum.Fixtures.{Blocks => BlockFixtures} import io.iohk.ethereum.crypto.ECDSASignature import io.iohk.ethereum.domain.Address import io.iohk.ethereum.domain.BlockHeader +import io.iohk.ethereum.domain.LegacyTransaction import io.iohk.ethereum.domain.SignedTransaction -import io.iohk.ethereum.domain.Transaction object MockVmInput { class MockTransaction( - tx: Transaction, + tx: LegacyTransaction, senderAddress: Address, pointSign: Byte = 0, signatureRandom: BigInt = 0, @@ -33,7 +33,7 @@ object MockVmInput { receivingAddress: Option[Address] = None, nonce: BigInt = 0 ): SignedTransaction = - new MockTransaction(Transaction(nonce, gasPrice, gasLimit, receivingAddress, value, payload), senderAddress) + new MockTransaction(LegacyTransaction(nonce, gasPrice, gasLimit, receivingAddress, value, payload), senderAddress) def blockHeader: BlockHeader = BlockFixtures.ValidBlock.header