Skip to content

Commit

Permalink
reproducer for issue #2114
Browse files Browse the repository at this point in the history
  • Loading branch information
abebeos committed Feb 21, 2024
1 parent a6d288a commit 684da19
Showing 1 changed file with 62 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,40 @@ import org.ergoplatform.utils.HistoryTestHelpers

class ErgoStateContextSpec extends HistoryTestHelpers {

// copy from 'Extension validation'
property("Extension validation, reproducer i2114") {
val chain = genChain(2)
val sc = emptyStateContext.appendFullBlock(chain.head).get
val fb = chain.last
val extension = fb.extension
val oldFields = extension.fields

def fbWithFields(newFields: Seq[(Array[Byte], Array[Byte])]): ErgoFullBlock = {
val newExtension = extension.copy(fields = newFields)
fb.copy(extension = newExtension)
}

println("\n stressing sc.appendFullBlock() \n")
val validMKV = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize).sample.get
for (i <- 1 to 1000) {
printf("%d ", i)
sc.appendFullBlock(fbWithFields(validMKV +: oldFields)) shouldBe 'success
}

println("\n\n stressing extensionKvGen() \n")
// this will fail, which means that the problems is with 'extensionKvGen()'
// the randomness potentially generates now and then invalid data
for (i <- 1 to 1000) {
val validMKV_looped = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize).sample.get
printf("%d ", i)
sc.appendFullBlock(fbWithFields(validMKV_looped +: oldFields)) shouldBe 'success
}

// locate "Interlinks improperly packed" within 'NipopowAlgos.scala', and set a breakpoint to review
// the invalid data ('value' has a length of 64 instead of 33)

}

property("Header votes") {
val fb = genChain(1).head
val header = fb.header
Expand Down Expand Up @@ -58,27 +92,34 @@ class ErgoStateContextSpec extends HistoryTestHelpers {
fb.copy(extension = newExtension)
}

// checks, specific for extension
// validation of field keys size
val imvKey = extensionKvGen(Extension.FieldKeySize - 1, Extension.FieldValueMaxSize).sample.get
sc.appendFullBlock(fbWithFields(imvKey +: oldFields)) shouldBe 'failure

// validation of field value sizes
val imvValue = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize + 1).sample.get
sc.appendFullBlock(fbWithFields(imvValue +: oldFields)) shouldBe 'failure

// validation of incorrect interlinks
val invalidInterlinks = nipopowAlgos.interlinksToExtension(
NipopowAlgos.unpackInterlinks(fb.extension.fields).get ++ Seq(fb.header.id)
).fields
sc.appendFullBlock(fbWithFields(invalidInterlinks ++ oldFields)) shouldBe 'failure

// validation of key duplicates in fields
val validMKV = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize).sample.get
sc.appendFullBlock(fbWithFields(Seq(validMKV, validMKV) ++ oldFields)) shouldBe 'failure

// valid application of correct extension
sc.appendFullBlock(fbWithFields(validMKV +: oldFields)) shouldBe 'success
// increase loop to 1000 to trigger failure https://github.com/ergoplatform/ergo/issues/2114
for (i <- 1 to 1000) {
printf("%d ", i)

// checks, specific for extension
// validation of field keys size
val imvKey = extensionKvGen(Extension.FieldKeySize - 1, Extension.FieldValueMaxSize).sample.get
sc.appendFullBlock(fbWithFields(imvKey +: oldFields)) shouldBe 'failure

// validation of field value sizes
val imvValue = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize + 1).sample.get
// 1st failure (disable to reach 2nd failure)
sc.appendFullBlock(fbWithFields(imvValue +: oldFields)) shouldBe 'failure

// validation of incorrect interlinks
val invalidInterlinks = nipopowAlgos.interlinksToExtension(
NipopowAlgos.unpackInterlinks(fb.extension.fields).get ++ Seq(fb.header.id)
).fields
sc.appendFullBlock(fbWithFields(invalidInterlinks ++ oldFields)) shouldBe 'failure

// validation of key duplicates in fields
val validMKV = extensionKvGen(Extension.FieldKeySize, Extension.FieldValueMaxSize).sample.get
sc.appendFullBlock(fbWithFields(Seq(validMKV, validMKV) ++ oldFields)) shouldBe 'failure

// valid application of correct extension
// 2nd failure
sc.appendFullBlock(fbWithFields(validMKV +: oldFields)) shouldBe 'success
}

}

Expand Down

0 comments on commit 684da19

Please sign in to comment.