forked from cosmos/interchain-security
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_driver.go
145 lines (134 loc) · 5.21 KB
/
test_driver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"fmt"
"log"
"reflect"
"github.com/kylelemons/godebug/pretty"
)
// TestCaseDriver knows how different TC can be executed
type TestCaseDriver interface {
Run(steps []Step, target ExecutionTarget, verbose bool) error
}
func GetTestCaseDriver(testCfg TestConfig) TestCaseDriver {
return &DefaultDriver{testCfg: testCfg}
}
type DefaultDriver struct {
testCfg TestConfig
target ExecutionTarget
verbose bool
}
// Execute tests
func (td *DefaultDriver) Run(steps []Step, target ExecutionTarget, verbose bool) error {
td.target = target
td.verbose = verbose
for i, step := range steps {
fmt.Printf("running %s: step %d/%d == %s \n",
td.testCfg.name, i+1, len(steps), reflect.TypeOf(step.Action).Name())
err := td.runStep(step)
if err != nil {
return err
}
}
return nil
}
// runStep executes an action and evaluates the result against expected state
func (td *DefaultDriver) runStep(step Step) error {
err := td.runAction(step.Action)
if err != nil {
return err
}
modelState := step.State
actualState := td.testCfg.getState(modelState, td.verbose)
// Check state
if !reflect.DeepEqual(actualState, modelState) {
fmt.Printf("=============== %s FAILED ===============\n", td.testCfg.name)
fmt.Println("FAILED action", reflect.TypeOf(step.Action).Name())
pretty.Print("actual state", actualState)
pretty.Print("model state", modelState)
log.Fatal(`actual state (-) not equal to model state (+): ` + pretty.Compare(actualState, modelState))
}
return nil
}
func (td *DefaultDriver) runAction(action interface{}) error {
switch action := action.(type) {
case StartChainAction:
td.testCfg.startChain(action, td.target, td.verbose)
case StartSovereignChainAction:
td.testCfg.startSovereignChain(action, td.target, td.verbose)
case LegacyUpgradeProposalAction:
td.testCfg.submitLegacyUpgradeProposal(action, td.target, td.verbose)
case WaitUntilBlockAction:
td.testCfg.waitUntilBlockOnChain(action)
case ChangeoverChainAction:
td.testCfg.changeoverChain(action, td.target, td.verbose)
case SendTokensAction:
td.testCfg.sendTokens(action, td.target, td.verbose)
case SubmitTextProposalAction:
td.testCfg.submitTextProposal(action, td.target, td.verbose)
case SubmitConsumerAdditionProposalAction:
td.testCfg.submitConsumerAdditionProposal(action, td.target, td.verbose)
case SubmitConsumerRemovalProposalAction:
td.testCfg.submitConsumerRemovalProposal(action, td.target, td.verbose)
case SubmitParamChangeLegacyProposalAction:
td.testCfg.submitParamChangeProposal(action, td.target, td.verbose)
case VoteGovProposalAction:
td.testCfg.voteGovProposal(action, td.target, td.verbose)
case StartConsumerChainAction:
td.testCfg.startConsumerChain(action, td.target, td.verbose)
case AddChainToRelayerAction:
td.testCfg.addChainToRelayer(action, td.target, td.verbose)
case CreateIbcClientsAction:
td.testCfg.createIbcClientsHermes(action, td.target, td.verbose)
case AddIbcConnectionAction:
td.testCfg.addIbcConnection(action, td.target, td.verbose)
case AddIbcChannelAction:
td.testCfg.addIbcChannel(action, td.target, td.verbose)
case TransferChannelCompleteAction:
td.testCfg.transferChannelComplete(action, td.target, td.verbose)
case RelayPacketsAction:
td.testCfg.relayPackets(action, td.target, td.verbose)
case RelayRewardPacketsToProviderAction:
td.testCfg.relayRewardPacketsToProvider(action, td.target, td.verbose)
case DelegateTokensAction:
td.testCfg.delegateTokens(action, td.target, td.verbose)
case UnbondTokensAction:
td.testCfg.unbondTokens(action, td.target, td.verbose)
case CancelUnbondTokensAction:
td.testCfg.cancelUnbondTokens(action, td.target, td.verbose)
case RedelegateTokensAction:
td.testCfg.redelegateTokens(action, td.target, td.verbose)
case DowntimeSlashAction:
td.testCfg.invokeDowntimeSlash(action, td.target, td.verbose)
case UnjailValidatorAction:
td.testCfg.unjailValidator(action, td.target, td.verbose)
case DoublesignSlashAction:
td.testCfg.invokeDoublesignSlash(action, td.target, td.verbose)
case LightClientAmnesiaAttackAction:
td.testCfg.lightClientAmnesiaAttack(action, td.verbose)
case LightClientEquivocationAttackAction:
td.testCfg.lightClientEquivocationAttack(action, td.verbose)
case LightClientLunaticAttackAction:
td.testCfg.lightClientLunaticAttack(action, td.verbose)
case RegisterRepresentativeAction:
td.testCfg.registerRepresentative(action, td.target, td.verbose)
case AssignConsumerPubKeyAction:
td.testCfg.assignConsumerPubKey(action, td.target, td.verbose)
case SlashMeterReplenishmentAction:
td.testCfg.waitForSlashMeterReplenishment(action, td.verbose)
case WaitTimeAction:
td.testCfg.waitForTime(action, td.verbose)
case StartRelayerAction:
td.testCfg.startRelayer(action, td.target, td.verbose)
case ForkConsumerChainAction:
td.testCfg.forkConsumerChain(action, td.verbose)
case UpdateLightClientAction:
td.testCfg.updateLightClient(action, td.verbose)
case StartConsumerEvidenceDetectorAction:
td.testCfg.startConsumerEvidenceDetector(action, td.target, td.verbose)
case SubmitChangeRewardDenomsProposalAction:
td.testCfg.submitChangeRewardDenomsProposal(action, td.target, td.verbose)
default:
log.Fatalf("unknown action in testRun %s: %#v", td.testCfg.name, action)
}
return nil
}