Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more upgrade test #19888

Draft
wants to merge 2 commits into
base: main-2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2410,15 +2410,7 @@ private[lf] object SBuiltin {

// In Validation mode, we always call validateContractInfo
// In Submission mode, we only call validateContractInfo when src != dest
val needValidationCall: Boolean =
if (machine.validating) {
upgradingIsEnabled
} else {
// we already check qualified names match
upgradingIsEnabled && (srcTmplId.packageId != dstTmplId.packageId)
}
if (needValidationCall) {

if (upgradingIsEnabled) {
validateContractInfo(machine, coid, srcTmplId, contract) { () =>
f(contract.packageName, contract.any)
}
Expand All @@ -2440,19 +2432,13 @@ private[lf] object SBuiltin {
contract: ContractInfo,
)(
continue: () => Control[Question.Update]
): Control[Question.Update] = {

val keyOpt: Option[GlobalKeyWithMaintainers] = contract.keyOpt match {
case None => None
case Some(cachedKey) =>
Some(cachedKey.globalKeyWithMaintainers)
}
): Control[Question.Update] =
machine.needUpgradeVerification(
location = NameOf.qualifiedNameOfCurrentFunc,
coid = coid,
signatories = contract.signatories,
observers = contract.observers,
keyOpt = keyOpt,
keyOpt = contract.gkeyWithMaintainers,
continue = {
case None =>
continue()
Expand All @@ -2467,15 +2453,14 @@ private[lf] object SBuiltin {
dstTemplateId = contract.templateId,
signatories = contract.signatories,
observers = contract.observers,
keyOpt = keyOpt,
keyOpt = contract.gkeyWithMaintainers,
msg = msg,
)
),
)
)
},
)
}

private def importValue[Q](machine: Machine[Q], templateId: TypeConName, coinstArg: V)(
f: SValue => Control[Q]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ private[lf] object Speedy {
private[speedy] val any = SValue.SAnyContract(templateId, value)
private[speedy] def arg = value.toNormalizedValue(version)
private[speedy] def gkeyOpt: Option[GlobalKey] = keyOpt.map(_.globalKey)
private[speedy] def gkeyWithMaintainers: Option[GlobalKeyWithMaintainers] =
keyOpt.map(_.globalKeyWithMaintainers)
private[speedy] def toCreateNode(coid: V.ContractId) =
Node.Create(
coid = coid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import value.Value
import scalautil.Statement.discard

import scala.annotation.tailrec
import scala.collection.immutable.VectorMap

private[speedy] object SpeedyTestLib {

Expand Down Expand Up @@ -115,7 +116,8 @@ private[speedy] object SpeedyTestLib {
): Either[SError.SError, (SValue, List[AuthRequest], List[UpgradeVerificationRequest])] = {

var authRequests: List[AuthRequest] = List.empty
var upgradeVerificationRequests: List[UpgradeVerificationRequest] = List.empty
var upgradeVerificationRequests =
VectorMap.empty[ContractId, UpgradeVerificationRequest]

def onQuestion(question: Question.Update): Unit = question match {
case Question.Update.NeedAuthority(holding @ _, requesting @ _, callback) =>
Expand All @@ -142,13 +144,18 @@ private[speedy] object SpeedyTestLib {
keyOpt,
callback,
) =>
upgradeVerificationRequests = UpgradeVerificationRequest(
coid,
signatories,
observers,
keyOpt,
) :: upgradeVerificationRequests
callback(None)
val request = UpgradeVerificationRequest(coid, signatories, observers, keyOpt)
val differentField = upgradeVerificationRequests.get(coid) match {
case Some(previous) =>
Iterator.range(0, request.productArity).collectFirst {
case i if request.productElement(i) != previous.productElement(i) =>
request.productElementName(i)
}
case None =>
upgradeVerificationRequests = upgradeVerificationRequests.updated(coid, request)
None
}
callback(differentField)

case Question.Update.NeedPackage(pkg, _, callback) =>
getPkg.lift(pkg) match {
Expand All @@ -165,7 +172,7 @@ private[speedy] object SpeedyTestLib {
}
runTxQ(onQuestion, machine) match {
case Left(e) => Left(e)
case Right(fv) => Right((fv, authRequests.reverse, upgradeVerificationRequests.reverse))
case Right(fv) => Right((fv, authRequests.reverse, upgradeVerificationRequests.values.toList))
}
}

Expand Down
Loading
Loading