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

Engine: Remove optionality of contract ID Seeding. #5966

Merged
merged 5 commits into from
May 13, 2020
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address Stephen's review
  • Loading branch information
remyhaemmerle-da committed May 13, 2020
commit fbf6a21d99fd6be6ecf3bc60452db4af793c9228
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ object ValueGenerators {
else (variantId: Identifier) => Some(variantId))
value <- Gen.lzy(valueGen(nesting))
} yield ValueVariant(toOption(id), variantName, value)

def variantGen: Gen[ValueVariant[ContractId]] = variantGen(0)

private def recordGen(nesting: Int): Gen[ValueRecord[ContractId]] =
Expand All @@ -118,16 +119,19 @@ object ValueGenerators {
labelledValues <- Gen.listOf(nameGen.flatMap(label =>
Gen.lzy(valueGen(nesting)).map(x => if (label.isEmpty) (None, x) else (Some(label), x))))
} yield ValueRecord[ContractId](toOption(id), ImmArray(labelledValues))

def recordGen: Gen[ValueRecord[ContractId]] = recordGen(0)

private def valueOptionalGen(nesting: Int): Gen[ValueOptional[ContractId]] =
Gen.option(valueGen(nesting)).map(v => ValueOptional(v))

def valueOptionalGen: Gen[ValueOptional[ContractId]] = valueOptionalGen(0)

private def valueListGen(nesting: Int): Gen[ValueList[ContractId]] =
for {
values <- Gen.listOf(Gen.lzy(valueGen(nesting)))
} yield ValueList[ContractId](FrontStack(values))

def valueListGen: Gen[ValueList[ContractId]] = valueListGen(0)

private def valueMapGen(nesting: Int) =
Expand All @@ -136,6 +140,7 @@ object ValueGenerators {
k <- Gen.asciiPrintableStr; v <- Gen.lzy(valueGen(nesting))
} yield k -> v)
} yield ValueTextMap[ContractId](SortedLookupList(Map(list: _*)))

def valueMapGen: Gen[ValueTextMap[ContractId]] = valueMapGen(0)

private def valueGenMapGen(nesting: Int) =
Expand All @@ -150,11 +155,15 @@ object ValueGenerators {
private val genHash: Gen[crypto.Hash] =
Gen
.containerOfN[Array, Byte](crypto.Hash.underlyingHashLength, arbitrary[Byte]) map crypto.Hash.assertFromByteArray
private val genBytes: Gen[Bytes] = arbitrary[Array[Byte]] map Bytes.fromByteArray
private val genSuffixes: Gen[Bytes] = for {
sz <- Gen.chooseNum(0, AbsoluteContractId.V1.maxSuffixLength)
ab <- Gen.containerOfN[Array, Byte](sz, arbitrary[Byte])
} yield Bytes fromByteArray ab

val absCoidV0Gen: Gen[AbsoluteContractId.V0] =
Gen.alphaStr.map(t => Value.AbsoluteContractId.V0.assertFromString('#' +: t))
private val genAbsCidV1: Gen[AbsoluteContractId.V1] =
Gen.zip(genHash, genBytes.filter(_.length <= AbsoluteContractId.V1.maxSuffixLength)) map {
Gen.zip(genHash, genSuffixes) map {
case (h, b) => AbsoluteContractId.V1.assertBuild(h, b)
}

Expand All @@ -170,9 +179,8 @@ object ValueGenerators {
AbsoluteContractId.V1
.assertBuild(
b1.discriminator,
b1.suffix
.slice(0, b1.suffix.length min (AbsoluteContractId.V1.maxSuffixLength - 1)) ++ Bytes
.fromByteArray(Array(b)))
if (b1.suffix.nonEmpty) b1.suffix else Bytes fromByteArray Array(b)
)
}
),
Gen.oneOf(absCoidV0Gen, genAbsCidV1 map (cid => AbsoluteContractId.V1(cid.discriminator))),
Expand Down