Skip to content

Commit 684da19

Browse files
author
abebeos
committed
reproducer for issue #2114
1 parent a6d288a commit 684da19

File tree

1 file changed

+62
-21
lines changed

1 file changed

+62
-21
lines changed

src/test/scala/org/ergoplatform/nodeView/state/ErgoStateContextSpec.scala

+62-21
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,40 @@ import org.ergoplatform.utils.HistoryTestHelpers
88

99
class ErgoStateContextSpec extends HistoryTestHelpers {
1010

11+
// copy from 'Extension validation'
12+
property("Extension validation, reproducer i2114") {
13+
val chain = genChain(2)
14+
val sc = emptyStateContext.appendFullBlock(chain.head).get
15+
val fb = chain.last
16+
val extension = fb.extension
17+
val oldFields = extension.fields
18+
19+
def fbWithFields(newFields: Seq[(Array[Byte], Array[Byte])]): ErgoFullBlock = {
20+
val newExtension = extension.copy(fields = newFields)
21+
fb.copy(extension = newExtension)
22+
}
23+
24+
println("\n stressing sc.appendFullBlock() \n")
25+
val validMKV = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize).sample.get
26+
for (i <- 1 to 1000) {
27+
printf("%d ", i)
28+
sc.appendFullBlock(fbWithFields(validMKV +: oldFields)) shouldBe 'success
29+
}
30+
31+
println("\n\n stressing extensionKvGen() \n")
32+
// this will fail, which means that the problems is with 'extensionKvGen()'
33+
// the randomness potentially generates now and then invalid data
34+
for (i <- 1 to 1000) {
35+
val validMKV_looped = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize).sample.get
36+
printf("%d ", i)
37+
sc.appendFullBlock(fbWithFields(validMKV_looped +: oldFields)) shouldBe 'success
38+
}
39+
40+
// locate "Interlinks improperly packed" within 'NipopowAlgos.scala', and set a breakpoint to review
41+
// the invalid data ('value' has a length of 64 instead of 33)
42+
43+
}
44+
1145
property("Header votes") {
1246
val fb = genChain(1).head
1347
val header = fb.header
@@ -58,27 +92,34 @@ class ErgoStateContextSpec extends HistoryTestHelpers {
5892
fb.copy(extension = newExtension)
5993
}
6094

61-
// checks, specific for extension
62-
// validation of field keys size
63-
val imvKey = extensionKvGen(Extension.FieldKeySize - 1, Extension.FieldValueMaxSize).sample.get
64-
sc.appendFullBlock(fbWithFields(imvKey +: oldFields)) shouldBe 'failure
65-
66-
// validation of field value sizes
67-
val imvValue = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize + 1).sample.get
68-
sc.appendFullBlock(fbWithFields(imvValue +: oldFields)) shouldBe 'failure
69-
70-
// validation of incorrect interlinks
71-
val invalidInterlinks = nipopowAlgos.interlinksToExtension(
72-
NipopowAlgos.unpackInterlinks(fb.extension.fields).get ++ Seq(fb.header.id)
73-
).fields
74-
sc.appendFullBlock(fbWithFields(invalidInterlinks ++ oldFields)) shouldBe 'failure
75-
76-
// validation of key duplicates in fields
77-
val validMKV = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize).sample.get
78-
sc.appendFullBlock(fbWithFields(Seq(validMKV, validMKV) ++ oldFields)) shouldBe 'failure
79-
80-
// valid application of correct extension
81-
sc.appendFullBlock(fbWithFields(validMKV +: oldFields)) shouldBe 'success
95+
// increase loop to 1000 to trigger failure https://github.com/ergoplatform/ergo/issues/2114
96+
for (i <- 1 to 1000) {
97+
printf("%d ", i)
98+
99+
// checks, specific for extension
100+
// validation of field keys size
101+
val imvKey = extensionKvGen(Extension.FieldKeySize - 1, Extension.FieldValueMaxSize).sample.get
102+
sc.appendFullBlock(fbWithFields(imvKey +: oldFields)) shouldBe 'failure
103+
104+
// validation of field value sizes
105+
val imvValue = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize + 1).sample.get
106+
// 1st failure (disable to reach 2nd failure)
107+
sc.appendFullBlock(fbWithFields(imvValue +: oldFields)) shouldBe 'failure
108+
109+
// validation of incorrect interlinks
110+
val invalidInterlinks = nipopowAlgos.interlinksToExtension(
111+
NipopowAlgos.unpackInterlinks(fb.extension.fields).get ++ Seq(fb.header.id)
112+
).fields
113+
sc.appendFullBlock(fbWithFields(invalidInterlinks ++ oldFields)) shouldBe 'failure
114+
115+
// validation of key duplicates in fields
116+
val validMKV = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize).sample.get
117+
sc.appendFullBlock(fbWithFields(Seq(validMKV, validMKV) ++ oldFields)) shouldBe 'failure
118+
119+
// valid application of correct extension
120+
// 2nd failure
121+
sc.appendFullBlock(fbWithFields(validMKV +: oldFields)) shouldBe 'success
122+
}
82123

83124
}
84125

0 commit comments

Comments
 (0)