Skip to content

Commit

Permalink
Merge branch '31-bugfix-commitment-tx-evaluation-error' into 'dev'
Browse files Browse the repository at this point in the history
Fix commitment tx fee box evaluation error

Closes #31

See merge request ergo/rosen-bridge/contract!67
  • Loading branch information
vorujack committed Nov 18, 2023
2 parents 68cfcc1 + a44faed commit a3d28e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/scala/rosen/bridge/scripts/Permit.es
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
// Event Commitment Creation
// [Permit(s), WID] => [Permit, Commitment, WID]
val totalPermits = INPUTS.filter{(box:Box)
=> box.tokens(0)._1 == SELF.tokens(0)._1
=> box.tokens.size > 0 && box.tokens(0)._1 == SELF.tokens(0)._1
}
.map{(box:Box) => box.tokens(0)._2}
.fold(0L, { (a: Long, b: Long) => a + b })
Expand Down
27 changes: 27 additions & 0 deletions src/test/scala/contracts/ContractTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.ergoplatform.appkit.{ErgoProver, ErgoToken}
import rosen.bridge.Contracts
import scorex.util.encode.Base16
import testUtils.{Boxes, Commitment, TestSuite}
import java.io.{PrintWriter, StringWriter}


class ContractTest extends TestSuite {
Expand Down Expand Up @@ -544,6 +545,32 @@ class ContractTest extends TestSuite {
})
}

property("test create new commitment with extra fee box") {
networkConfig._1.ergoClient.execute(ctx => {
try {
val commitment = new Commitment()
val prover = getProver()
val WID = Base16.decode(Boxes.getRandomHexString()).get
val box1 = Boxes.createBoxForUser(ctx, prover.getAddress, 1e5.toLong, new ErgoToken(WID, 1))
val box2 = Boxes.createBoxForUser(ctx, prover.getAddress, 1e9.toLong)
val permit = Boxes.createPermitBox(ctx, 10L, WID).convertToInputWith(Boxes.getRandomHexString(), 0)
val permitOut = Boxes.createPermitBox(ctx, 9L, WID)
val commitmentBox = Boxes.createCommitment(ctx, WID, commitment.requestId(), commitment.hash(WID), 1l)
val WIDOut = Boxes.createBoxCandidateForUser(ctx, prover.getAddress, 1e8.toLong, new ErgoToken(WID, 1))
val tx = ctx.newTxBuilder().addInputs(permit, box1, box2)
.fee(Configs.fee)
.sendChangeTo(prover.getAddress)
.addOutputs(permitOut, commitmentBox, WIDOut)
.build()
prover.sign(tx)
} catch {
case exp: Throwable =>
println(exp.toString)
fail("transaction not signed")
}
})
}

property("test create new commitment with RWT second place of permit tokens") {
networkConfig._1.ergoClient.execute(ctx => {
assertThrows[AnyRef] {
Expand Down

0 comments on commit a3d28e0

Please sign in to comment.