-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #402 from ScorexFoundation/i401
serialize/bytesToSign fix
- Loading branch information
Showing
7 changed files
with
111 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/scala/org/ergoplatform/ErgoLikeTransactionSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.ergoplatform | ||
|
||
import org.scalatest.prop.GeneratorDrivenPropertyChecks | ||
import org.scalatest.{Matchers, PropSpec} | ||
import sigmastate.helpers.SigmaTestingCommons | ||
import sigmastate.serialization.SigmaSerializer | ||
import sigmastate.serialization.generators.ValueGenerators | ||
|
||
class ErgoLikeTransactionSpec extends PropSpec | ||
with GeneratorDrivenPropertyChecks | ||
with Matchers | ||
with ValueGenerators | ||
with SigmaTestingCommons { | ||
|
||
property("ErgoLikeTransaction: Serializer round trip") { | ||
forAll { t: ErgoLikeTransaction => roundTripTest(t)(ErgoLikeTransaction.serializer) } | ||
forAll { t: ErgoLikeTransaction => roundTripTestWithPos(t)(ErgoLikeTransaction.serializer) } | ||
} | ||
|
||
property("ErgoLikeTransaction with same token in different outputs : Serializer round trip") { | ||
forAll { txIn: ErgoLikeTransaction => | ||
whenever(txIn.outputCandidates.head.additionalTokens.nonEmpty) { | ||
val out = txIn.outputCandidates.head | ||
val outputs = (0 until 10).map { i => | ||
new ErgoBoxCandidate(out.value, out.ergoTree, i, out.additionalTokens, out.additionalRegisters) | ||
} | ||
val tx = ErgoLikeTransaction(txIn.inputs, txIn.outputCandidates ++ outputs) | ||
roundTripTestWithPos(tx)(ErgoLikeTransaction.serializer) | ||
|
||
// check that token id is written only once | ||
val w = SigmaSerializer.startWriter() | ||
ErgoLikeTransaction.serializer.serialize(tx, w) | ||
val bytes = w.toBytes | ||
|
||
tx.outputCandidates.flatMap(_.additionalTokens).foreach { token => | ||
bytes.indexOfSlice(token._1) should not be -1 | ||
bytes.indexOfSlice(token._1) shouldBe bytes.lastIndexOfSlice(token._1) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters