Skip to content

Commit

Permalink
applies review comments - removes two tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinczenko committed Oct 2, 2024
1 parent aea4f41 commit 1459644
Showing 1 changed file with 0 additions and 109 deletions.
109 changes: 0 additions & 109 deletions tests/codex/testvalidation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,6 @@ asyncchecksuite "validation":
check validationConfig.error.msg == "The value of maxSlots must " &
fmt"be greater than or equal to 0! (got: {maxSlots})"

test "group index is irrelevant if validation groups are not set":
randomize()
let groupIndex = rand(uint16.high.int).uint16
let validationConfig = ValidationConfig.init(
maxSlots, groups=ValidationGroups.none, groupIndex)
check validationConfig.isSuccess

test "slot is not observed if it is not in the validation group":
let validationConfig = initValidationConfig(maxSlots, validationGroups,
(groupIndex + 1) mod uint16(!validationGroups))
Expand Down Expand Up @@ -156,105 +149,3 @@ asyncchecksuite "validation":
await market.fillSlot(slot.request.id, slot.slotIndex, proof, collateral)
await validation.stop()
check validation.slots.len == maxSlots

proc setupAndStartValidation(maxSlots: MaxSlots,
validationGroups: ?ValidationGroups,
groupIndex: uint16
): Future[Validation] {.async.} =
let validationConfig = initValidationConfig(
maxSlots, validationGroups, groupIndex)
let validation = Validation.new(clock, market, validationConfig)
await validation.start()
validation

proc setupValidationGroup(slotId: SlotId,
maxSlots: MaxSlots,
groups: ?ValidationGroups,
groupIndex: uint16,
slotsInSelectedGroup: var int,
slots: var HashSet) =
if validationGroups =? groups:
if groupIndexForSlotId(slotId, validationGroups) == groupIndex:
slotsInSelectedGroup += 1
if maxSlots == 0:
slots.incl(slotId)
elif slotsInSelectedGroup <= maxSlots:
slots.incl(slotId)
else:
if maxSlots == 0:
slots.incl(slotId)
elif slots.len < maxSlots:
slots.incl(slotId)

func calculateExpectedSlots(maxSlots: MaxSlots,
groups: ?ValidationGroups,
slots: HashSet): int =
if validationGroups.isNone:
return if maxSlots == 0: 100 else: maxSlots

if maxSlots == 0 or slots.len < maxSlots:
return slots.len
else:
return maxSlots

proc printExtraTestInfo(maxSlots: MaxSlots,
validationGroups: ?ValidationGroups,
groupIndex: uint16,
slotsInSelectedGroup: int,
expectedSlots: int) =
echo "---------------------------------------------------------" &
"---------------------------------------------------------"
if validationGroups.isNone:
echo fmt" ⬇︎ {maxSlots=}, {validationGroups=}, " &
fmt"{groupIndex=}: {expectedSlots=} ⬇︎"
else:
echo fmt" ⬇︎ {maxSlots=}, {validationGroups=}, " &
fmt"{groupIndex=}: {slotsInSelectedGroup=}, {expectedSlots=} ⬇︎"

# This test is a bit more complex, but it allows us to test the
# assignment of slots to different validation groups in combination with
# the maxSlots constraint.
# It is not pragmatic to generate a slot with id that will go to the
# intended group. In other tests, after creating an example slot, we
# compute the group id it is expected to be in, and dependeing on if
# we want to test that it is observed or not, we create validation params
# with the computed expected groupIndex or with groupIndex+1 respectively.
# In those tests we test only one slot and one groupIndex. In this test
# we can test multiple slots going to specific group in one test.
# Moreover for the selected group we can also test that maxSlots
# constraint is respected also when groups are enabled (the other test we
# have defined earlier, tests that the maxSlots constraint only for
# the case when groups are not enabled). Finally, this tests should also
# allow us to document better what happens when maxSlots is set to 0.
for (maxSlots, validationGroups, groupIndex) in [
(0, ValidationGroups.none, 0),
(0, ValidationGroups.none, 1),
(0, ValidationGroups(2).some, 0),
(0, ValidationGroups(2).some, 1),
(10, ValidationGroups.none, 0),
(10, ValidationGroups.none, 1),
(10, ValidationGroups(2).some, 0),
(10, ValidationGroups(2).some, 1)]:
test fmt"slots should be observed ({maxSlots=}, {validationGroups=}, " &
fmt"{groupIndex=})":
let validation = await setupAndStartValidation(
maxSlots, validationGroups, groupIndex.uint16)
var slotsInSelectedGroup = 0
var slots = initHashSet[SlotId]()
# The number of slots should be big enough so that we are
# sure that at least some of them endup in the intended group.
# By probability, it is expected that they will distribute
# evenly between the groups.
for i in 0..<100:
let slot = Slot.example
setupValidationGroup(slot.id, maxSlots, validationGroups,
groupIndex.uint16, slotsInSelectedGroup, slots)
await market.fillSlot(slot.request.id, slot.slotIndex,
proof, collateral)
await validation.stop()
let expectedSlots = calculateExpectedSlots(
maxSlots, validationGroups, slots)
printExtraTestInfo(maxSlots, validationGroups, groupIndex.uint16,
slotsInSelectedGroup, expectedSlots)
check validation.slots.len == expectedSlots
check slots == toHashSet(validation.slots)

0 comments on commit 1459644

Please sign in to comment.