diff --git a/src/main/scala/rosen/bridge/scripts/RwtRepo.es b/src/main/scala/rosen/bridge/scripts/RwtRepo.es index f3f2f89..6a41e03 100644 --- a/src/main/scala/rosen/bridge/scripts/RwtRepo.es +++ b/src/main/scala/rosen/bridge/scripts/RwtRepo.es @@ -55,10 +55,9 @@ allOf( Coll( permitCreation, - repoOut.R4[Coll[Coll[Byte]]].get.size == widListSize + 1, + widOutListSize == widListSize + 1, repoOut.R4[Coll[Coll[Byte]]].get.slice(0, widOutListSize - 1) == repo.R4[Coll[Coll[Byte]]].get, repoOut.R4[Coll[Coll[Byte]]].get(widOutListSize - 1) == repo.id, - repoOut.R5[Coll[Long]].get.size == widListSize + 1, repoOut.R5[Coll[Long]].get.slice(0, widOutListSize - 1) == repo.R5[Coll[Long]].get, repoOut.R5[Coll[Long]].get(widOutListSize - 1) == RWTOut, permit.R4[Coll[Coll[Byte]]].get == Coll(repo.id), @@ -105,7 +104,6 @@ val permit = INPUTS(1) val RWTIn = repoOut.tokens(1)._2 - repo.tokens(1)._2 val WIDIndex = repoOut.R7[Int].get - val watcherCount = repo.R5[Coll[Long]].get.size val WIDCheckInRepo = if(repo.R5[Coll[Long]].get(WIDIndex) > RWTIn) { // Returning some RWTs // [repo, Permit, WIDToken] => [repo, Permit(Optional), WIDToken(+userChange)] @@ -115,7 +113,7 @@ repo.R5[Coll[Long]].get(WIDIndex) == repoOut.R5[Coll[Long]].get(WIDIndex) + RWTIn, repo.R4[Coll[Coll[Byte]]].get == repoOut.R4[Coll[Coll[Byte]]].get, repo.R5[Coll[Long]].get.slice(0, WIDIndex) == repoOut.R5[Coll[Long]].get.slice(0, WIDIndex), - repo.R5[Coll[Long]].get.slice(WIDIndex + 1, watcherCount) == repoOut.R5[Coll[Long]].get.slice(WIDIndex + 1, watcherCount) + repo.R5[Coll[Long]].get.slice(WIDIndex + 1, widListSize) == repoOut.R5[Coll[Long]].get.slice(WIDIndex + 1, widListSize) ) ) }else{ @@ -124,11 +122,12 @@ val watcherCollateral = INPUTS(3); allOf( Coll( + widOutListSize == widListSize - 1, repo.R5[Coll[Long]].get(WIDIndex) == RWTIn, repo.R4[Coll[Coll[Byte]]].get.slice(0, WIDIndex) == repoOut.R4[Coll[Coll[Byte]]].get.slice(0, WIDIndex), - repo.R4[Coll[Coll[Byte]]].get.slice(WIDIndex + 1, watcherCount) == repoOut.R4[Coll[Coll[Byte]]].get.slice(WIDIndex, watcherCount - 1), + repo.R4[Coll[Coll[Byte]]].get.slice(WIDIndex + 1, widListSize) == repoOut.R4[Coll[Coll[Byte]]].get.slice(WIDIndex, widOutListSize), repo.R5[Coll[Long]].get.slice(0, WIDIndex) == repoOut.R5[Coll[Long]].get.slice(0, WIDIndex), - repo.R5[Coll[Long]].get.slice(WIDIndex + 1, watcherCount) == repoOut.R5[Coll[Long]].get.slice(WIDIndex, watcherCount - 1), + repo.R5[Coll[Long]].get.slice(WIDIndex + 1, widListSize) == repoOut.R5[Coll[Long]].get.slice(WIDIndex, widOutListSize), blake2b256(watcherCollateral.propositionBytes) == watcherCollateralScriptHash, ) ) diff --git a/src/test/scala/contracts/ContractTest.scala b/src/test/scala/contracts/ContractTest.scala index ac52cda..fdfcbe2 100644 --- a/src/test/scala/contracts/ContractTest.scala +++ b/src/test/scala/contracts/ContractTest.scala @@ -353,6 +353,87 @@ class ContractTest extends TestSuite { }) } + property("test complete return permit while extending the wid list in repo") { + networkConfig._1.ergoClient.execute(ctx => { + assertThrows[AnyRef] { + val prover = getProver() + val WIDs = generateRandomWIDList(6) + val amounts = Seq(100L, 120L, 140L, 20L, 40L, 250L) + val userIndex = 0 + val userWID = WIDs(userIndex) + val totalPermitOut = amounts.sum + val repoBox = Boxes.createRepo(ctx, 100000L, totalPermitOut + 1L, WIDs, amounts).convertToInputWith(Boxes.getRandomHexString(), 0) + val permitBox = Boxes.createPermitBox(ctx, amounts(userIndex), userWID).convertToInputWith(Boxes.getRandomHexString(), 0) + val WIDBox = Boxes.createBoxForUser(ctx, prover.getAddress, 1e9.toLong, new ErgoToken(userWID, 1L)) + val outputWIDs = WIDs.take(userIndex) ++ WIDs.drop(userIndex + 1) ++ Seq(WIDs(userIndex)) + val outAmounts = amounts.take(userIndex) ++ amounts.drop(userIndex + 1) + val repoOut = Boxes.createRepoWithR7(ctx, 100000L + amounts(userIndex), (totalPermitOut - amounts(userIndex)) + 1, outputWIDs, outAmounts, userIndex + 1) // 4 + first element in WID list is chain name + val userOut = Boxes.createBoxCandidateForUser(ctx, prover.getAddress, 1e8.toLong, new ErgoToken(userWID, 1), new ErgoToken(networkConfig._3.RSN, amounts(userIndex))) + val watcherCollateral = Boxes.createWatcherCollateralBoxInput(ctx,1e9.toLong, 100, userWID) + val tx = ctx.newTxBuilder().addInputs(repoBox, permitBox, WIDBox, watcherCollateral) + .fee(Configs.fee) + .addOutputs(repoOut, userOut) + .sendChangeTo(prover.getAddress) + .build() + prover.sign(tx) + } + }) + } + + property("test complete return permit while extending the rwt count list in repo") { + networkConfig._1.ergoClient.execute(ctx => { + assertThrows[AnyRef] { + val prover = getProver() + val WIDs = generateRandomWIDList(6) + val amounts = Seq(100L, 120L, 140L, 20L, 40L, 250L) + val userIndex = 0 + val userWID = WIDs(userIndex) + val totalPermitOut = amounts.sum + val repoBox = Boxes.createRepo(ctx, 100000L, totalPermitOut + 1L, WIDs, amounts).convertToInputWith(Boxes.getRandomHexString(), 0) + val permitBox = Boxes.createPermitBox(ctx, amounts(userIndex), userWID).convertToInputWith(Boxes.getRandomHexString(), 0) + val WIDBox = Boxes.createBoxForUser(ctx, prover.getAddress, 1e9.toLong, new ErgoToken(userWID, 1L)) + val outputWIDs = WIDs.take(userIndex) ++ WIDs.drop(userIndex + 1) + val outAmounts = amounts.take(userIndex) ++ amounts.drop(userIndex + 1) ++ Seq(100L) + val repoOut = Boxes.createRepoWithR7(ctx, 100000L + amounts(userIndex), (totalPermitOut - amounts(userIndex)) + 1, outputWIDs, outAmounts, userIndex + 1) // 4 + first element in WID list is chain name + val userOut = Boxes.createBoxCandidateForUser(ctx, prover.getAddress, 1e8.toLong, new ErgoToken(userWID, 1), new ErgoToken(networkConfig._3.RSN, amounts(userIndex))) + val watcherCollateral = Boxes.createWatcherCollateralBoxInput(ctx, 1e9.toLong, 100, userWID) + val tx = ctx.newTxBuilder().addInputs(repoBox, permitBox, WIDBox, watcherCollateral) + .fee(Configs.fee) + .addOutputs(repoOut, userOut) + .sendChangeTo(prover.getAddress) + .build() + prover.sign(tx) + } + }) + } + + property("test complete return permit while extending both rwt count and wid list in repo") { + networkConfig._1.ergoClient.execute(ctx => { + assertThrows[AnyRef] { + val prover = getProver() + val WIDs = generateRandomWIDList(6) + val amounts = Seq(100L, 120L, 140L, 20L, 40L, 250L) + val userIndex = 0 + val userWID = WIDs(userIndex) + val totalPermitOut = amounts.sum + val repoBox = Boxes.createRepo(ctx, 100000L, totalPermitOut + 1L, WIDs, amounts).convertToInputWith(Boxes.getRandomHexString(), 0) + val permitBox = Boxes.createPermitBox(ctx, amounts(userIndex), userWID).convertToInputWith(Boxes.getRandomHexString(), 0) + val WIDBox = Boxes.createBoxForUser(ctx, prover.getAddress, 1e9.toLong, new ErgoToken(userWID, 1L)) + val outputWIDs = WIDs.take(userIndex) ++ WIDs.drop(userIndex + 1) ++ Seq(WIDs(userIndex)) + val outAmounts = amounts.take(userIndex) ++ amounts.drop(userIndex + 1) ++ Seq(100L) + val repoOut = Boxes.createRepoWithR7(ctx, 100000L + amounts(userIndex), (totalPermitOut - amounts(userIndex)) + 1, outputWIDs, outAmounts, userIndex + 1) // 4 + first element in WID list is chain name + val userOut = Boxes.createBoxCandidateForUser(ctx, prover.getAddress, 1e8.toLong, new ErgoToken(userWID, 1), new ErgoToken(networkConfig._3.RSN, amounts(userIndex))) + val watcherCollateral = Boxes.createWatcherCollateralBoxInput(ctx, 1e9.toLong, 100, userWID) + val tx = ctx.newTxBuilder().addInputs(repoBox, permitBox, WIDBox, watcherCollateral) + .fee(Configs.fee) + .addOutputs(repoOut, userOut) + .sendChangeTo(prover.getAddress) + .build() + prover.sign(tx) + } + }) + } + property("test complete return of last permit") { networkConfig._1.ergoClient.execute(ctx => { try {