Skip to content

Commit

Permalink
action boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Sep 26, 2023
1 parent 5522b7c commit 0d0709c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
23 changes: 15 additions & 8 deletions tests/e2e/action_rapid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ func GetActionGen() *rapid.Generator[any] {
GetRegisterRepresentativeActionGen().AsAny(),
GetDoublesignSlashActionGen().AsAny(),
GetAssignConsumerPubKeyActionGen().AsAny(),
GetSlashThrottleDequeueActionGen().AsAny(),
GetCreateIbcClientsActionGen().AsAny(),
GetSlashMeterReplenishmentAction().AsAny(),
GetWaitTimeAction().AsAny(),
CreateCancelUnbondTokensActionGen().AsAny(),
CreateLightClientEquivocationAttackActionGen().AsAny(),
CreateLightClientAmnesiaAttackActionGen().AsAny(),
Expand Down Expand Up @@ -489,13 +490,19 @@ func GetAssignConsumerPubKeyActionGen() *rapid.Generator[assignConsumerPubKeyAct
})
}

func GetSlashThrottleDequeueActionGen() *rapid.Generator[slashThrottleDequeueAction] {
return rapid.Custom(func(t *rapid.T) slashThrottleDequeueAction {
return slashThrottleDequeueAction{
Chain: GetChainIDGen().Draw(t, "Chain"),
CurrentQueueSize: rapid.Int().Draw(t, "CurrentQueueSize"),
NextQueueSize: rapid.Int().Draw(t, "NextQueueSize"),
Timeout: time.Duration(rapid.Int().Draw(t, "Timeout")) * time.Millisecond,
func GetSlashMeterReplenishmentAction() *rapid.Generator[slashMeterReplenishmentAction] {
return rapid.Custom(func(t *rapid.T) slashMeterReplenishmentAction {
return slashMeterReplenishmentAction{
TargetValue: rapid.Int64().Draw(t, "TargetValue"),
Timeout: time.Duration(rapid.Int().Draw(t, "Timeout")) * time.Millisecond,
}
})
}

func GetWaitTimeAction() *rapid.Generator[waitTimeAction] {
return rapid.Custom(func(t *rapid.T) waitTimeAction {
return waitTimeAction{
WaitTime: time.Duration(rapid.Int().Draw(t, "Timeout")) * time.Millisecond,
}
})
}
10 changes: 8 additions & 2 deletions tests/e2e/json_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,14 @@ func UnmarshalMapToActionType(rawAction json.RawMessage, actionTypeString string
if err == nil {
return a, nil
}
case "main.slashThrottleDequeueAction":
var a slashThrottleDequeueAction
case "main.slashMeterReplenishmentAction":
var a slashMeterReplenishmentAction
err := json.Unmarshal(rawAction, &a)
if err == nil {
return a, nil
}
case "main.waitTimeAction":
var a waitTimeAction
err := json.Unmarshal(rawAction, &a)
if err == nil {
return a, nil
Expand Down
12 changes: 5 additions & 7 deletions tests/e2e/state_rapid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ func GetChainStateGen() *rapid.Generator[ChainState] {
consumerChains := GetConsumerChainsGen().Draw(t, "ConsumerChains")
assignedKeys := GetAssignedKeysGen().Draw(t, "AssignedKeys")
providerKeys := GetProviderKeysGen().Draw(t, "ProviderKeys")
consumerChainQueueSizes := GetConsumerChainQueueSizesGen().Draw(t, "ConsumerChainQueueSizes")
globalSlashQueueSize := rapid.Uint().Draw(t, "GlobalSlashQueueSize")
consumerPacketQueueSize := GetConsumerChainQueueSizesGen().Draw(t, "ConsumerChainQueueSizes")
registeredConsumerRewardDenoms := GetRegisteredConsumerRewardDenomsGen().Draw(t, "RegisteredConsumerRewardDenoms")

return ChainState{
Expand All @@ -59,8 +58,7 @@ func GetChainStateGen() *rapid.Generator[ChainState] {
ConsumerChains: &consumerChains,
AssignedKeys: &assignedKeys,
ProviderKeys: &providerKeys,
ConsumerChainQueueSizes: &consumerChainQueueSizes,
GlobalSlashQueueSize: &globalSlashQueueSize,
ConsumerPendingPacketQueueSize: &consumerPacketQueueSize,
RegisteredConsumerRewardDenoms: &registeredConsumerRewardDenoms,
}
})
Expand All @@ -72,9 +70,9 @@ func GetRegisteredConsumerRewardDenomsGen() *rapid.Generator[[]string] {
})
}

func GetConsumerChainQueueSizesGen() *rapid.Generator[map[ChainID]uint] {
return rapid.Custom(func(t *rapid.T) map[ChainID]uint {
return rapid.MapOf(GetChainIDGen(), rapid.Uint()).Draw(t, "ConsumerChainQueueSizes")
func GetConsumerChainQueueSizesGen() *rapid.Generator[uint] {
return rapid.Custom(func(t *rapid.T) uint {
return rapid.Uint().Draw(t, "ConsumerChainQueueSizes")
})
}

Expand Down

0 comments on commit 0d0709c

Please sign in to comment.