Skip to content

Commit b511815

Browse files
committed
[ETCM-1095] Unify TransactionGen/ReceiptGen with other generators style
1 parent 9d24ebc commit b511815

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/test/scala/io/iohk/ethereum/ObjectGenerators.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ trait ObjectGenerators {
6969
arrayList <- Gen.nonEmptyListOf(byteArrayOfNItemsGen(size))
7070
} yield byteStringList.zip(arrayList)
7171

72-
def receiptGen(): Gen[Receipt] =
73-
Gen.oneOf(legacyReceiptGen(), type01ReceiptGen())
72+
def receiptGen: Gen[Receipt] =
73+
Gen.oneOf(legacyReceiptGen, type01ReceiptGen)
7474

75-
def legacyReceiptGen(): Gen[LegacyReceipt] = for {
75+
def legacyReceiptGen: Gen[LegacyReceipt] = for {
7676
postTransactionStateHash <- byteArrayOfNItemsGen(32)
7777
cumulativeGasUsed <- bigIntGen
7878
logsBloomFilter <- byteArrayOfNItemsGen(256)
@@ -83,19 +83,19 @@ trait ObjectGenerators {
8383
logs = Seq()
8484
)
8585

86-
def type01ReceiptGen(): Gen[Type01Receipt] = legacyReceiptGen().map(Type01Receipt(_))
86+
def type01ReceiptGen: Gen[Type01Receipt] = legacyReceiptGen.map(Type01Receipt(_))
8787

8888
def addressGen: Gen[Address] = byteArrayOfNItemsGen(20).map(Address(_))
8989

90-
def accessListItemGen(): Gen[AccessListItem] = for {
90+
def accessListItemGen: Gen[AccessListItem] = for {
9191
address <- addressGen
9292
storageKeys <- Gen.listOf(bigIntGen)
9393
} yield AccessListItem(address, storageKeys)
9494

95-
def transactionGen(): Gen[Transaction] =
96-
Gen.oneOf(legacyTransactionGen(), typedTransactionGen())
95+
def transactionGen: Gen[Transaction] =
96+
Gen.oneOf(legacyTransactionGen, typedTransactionGen)
9797

98-
def legacyTransactionGen(): Gen[LegacyTransaction] = for {
98+
def legacyTransactionGen: Gen[LegacyTransaction] = for {
9999
nonce <- bigIntGen
100100
gasPrice <- bigIntGen
101101
gasLimit <- bigIntGen
@@ -111,15 +111,15 @@ trait ObjectGenerators {
111111
payload
112112
)
113113

114-
def typedTransactionGen(): Gen[TransactionWithAccessList] = for {
114+
def typedTransactionGen: Gen[TransactionWithAccessList] = for {
115115
chainId <- bigIntGen
116116
nonce <- bigIntGen
117117
gasPrice <- bigIntGen
118118
gasLimit <- bigIntGen
119119
receivingAddress <- addressGen
120120
value <- bigIntGen
121121
payload <- byteStringOfLengthNGen(256)
122-
accessList <- Gen.listOf(accessListItemGen())
122+
accessList <- Gen.listOf(accessListItemGen)
123123
} yield TransactionWithAccessList(
124124
chainId,
125125
nonce,
@@ -131,7 +131,7 @@ trait ObjectGenerators {
131131
accessList
132132
)
133133

134-
def receiptsGen(n: Int): Gen[Seq[Seq[Receipt]]] = Gen.listOfN(n, Gen.listOf(receiptGen()))
134+
def receiptsGen(n: Int): Gen[Seq[Seq[Receipt]]] = Gen.listOfN(n, Gen.listOf(receiptGen))
135135

136136
def branchNodeGen: Gen[BranchNode] = for {
137137
children <- Gen
@@ -172,7 +172,7 @@ trait ObjectGenerators {
172172

173173
def signedTxSeqGen(length: Int, secureRandom: SecureRandom, chainId: Option[Byte]): Gen[Seq[SignedTransaction]] = {
174174
val senderKeys = crypto.generateKeyPair(secureRandom)
175-
val txsSeqGen = Gen.listOfN(length, transactionGen())
175+
val txsSeqGen = Gen.listOfN(length, transactionGen)
176176
txsSeqGen.map { txs =>
177177
txs.map { tx =>
178178
SignedTransaction.sign(tx, senderKeys, chainId)
@@ -183,7 +183,7 @@ trait ObjectGenerators {
183183
def signedTxGen(secureRandom: SecureRandom, chainId: Option[Byte]): Gen[SignedTransaction] = {
184184
val senderKeys = crypto.generateKeyPair(secureRandom)
185185
for {
186-
tx <- transactionGen()
186+
tx <- transactionGen
187187
} yield SignedTransaction.sign(tx, senderKeys, chainId)
188188
}
189189

src/test/scala/io/iohk/ethereum/domain/SignedLegacyTransactionSpec.scala

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,20 @@ class SignedLegacyTransactionSpec
1818
with ScalaCheckPropertyChecks
1919
with SecureRandomBuilder {
2020
"SignedTransaction" should "correctly set pointSign for chainId with chain specific signing schema" in {
21-
forAll(Generators.transactionGen(), Arbitrary.arbitrary[Unit].map(_ => generateKeyPair(secureRandom))) {
22-
(tx, key) =>
23-
val chainId: Byte = 0x3d
24-
val allowedPointSigns = Set((chainId * 2 + 35).toByte, (chainId * 2 + 36).toByte)
25-
//byte 0 of encoded ECC point indicates that it is uncompressed point, it is part of bouncycastle encoding
26-
val address = Address(
27-
crypto
28-
.kec256(key.getPublic.asInstanceOf[ECPublicKeyParameters].getQ.getEncoded(false).tail)
29-
.drop(FirstByteOfAddress)
30-
)
31-
val signedTransaction = SignedTransaction.sign(tx, key, Some(chainId))
32-
val result = SignedTransactionWithSender(signedTransaction, Address(key))
21+
forAll(Generators.transactionGen, Arbitrary.arbitrary[Unit].map(_ => generateKeyPair(secureRandom))) { (tx, key) =>
22+
val chainId: Byte = 0x3d
23+
val allowedPointSigns = Set((chainId * 2 + 35).toByte, (chainId * 2 + 36).toByte)
24+
//byte 0 of encoded ECC point indicates that it is uncompressed point, it is part of bouncycastle encoding
25+
val address = Address(
26+
crypto
27+
.kec256(key.getPublic.asInstanceOf[ECPublicKeyParameters].getQ.getEncoded(false).tail)
28+
.drop(FirstByteOfAddress)
29+
)
30+
val signedTransaction = SignedTransaction.sign(tx, key, Some(chainId))
31+
val result = SignedTransactionWithSender(signedTransaction, Address(key))
3332

34-
allowedPointSigns should contain(result.tx.signature.v)
35-
address shouldEqual result.senderAddress
33+
allowedPointSigns should contain(result.tx.signature.v)
34+
address shouldEqual result.senderAddress
3635
}
3736
}
3837
}

0 commit comments

Comments
 (0)