Skip to content

Commit fcf29bc

Browse files
danwtDaniel
and
Daniel
authored
#533 Adds normal operation diff testing
* reb * reb * Del unused Co-authored-by: Daniel <[email protected]>
1 parent 9d1b6bf commit fcf29bc

File tree

6 files changed

+53
-11
lines changed

6 files changed

+53
-11
lines changed

tests/difference/core/driver/core_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ func (s *CoreSuite) matchState() {
240240
// TODO: delegations
241241
s.Require().Equalf(int64(s.traces.DelegatorTokens()), s.delegatorBalance(), diagnostic+"P del balance mismatch")
242242
for j := 0; j < initState.NumValidators; j++ {
243-
s.Require().Equalf(s.traces.Jailed(j) != nil, s.isJailed(int64(j)), diagnostic+"P jail status mismatch for val %d", j)
243+
a := s.traces.Jailed(j) != nil
244+
b := s.isJailed(int64(j))
245+
s.Require().Equalf(a, b, diagnostic+"P jail status mismatch for val %d", j)
244246
}
245247
}
246248
if chain == C {
@@ -259,6 +261,7 @@ func (s *CoreSuite) matchState() {
259261
}
260262

261263
func (s *CoreSuite) executeTrace() {
264+
262265
for i := range s.traces.Actions() {
263266
s.traces.CurrentActionIx = i
264267

@@ -310,6 +313,8 @@ func (s *CoreSuite) TestAssumptions() {
310313
s.T().Fatal(FAIL_MSG)
311314
}
312315

316+
// TODO: write assumption that checks that throttle params are appropriate
317+
313318
// Delegator balance is correct
314319
s.Require().Equal(int64(initState.InitialDelegatorTokens), s.delegatorBalance())
315320

@@ -428,9 +433,10 @@ func (s *CoreSuite) TestTraces() {
428433
s.traces = Traces{
429434
Data: LoadTraces("traces.json"),
430435
}
431-
// s.traces.Data = []TraceData{s.traces.Data[69]}
436+
shortest := -1
437+
shortestLen := 10000000000
432438
for i := range s.traces.Data {
433-
s.Run(fmt.Sprintf("Trace num: %d", i), func() {
439+
if !s.Run(fmt.Sprintf("Trace num: %d", i), func() {
434440
// Setup a new pair of chains for each trace
435441
s.SetupTest()
436442

@@ -448,13 +454,19 @@ func (s *CoreSuite) TestTraces() {
448454
// Record information about the trace, for debugging
449455
// diagnostics.
450456
s.executeTrace()
451-
})
457+
}) {
458+
if s.traces.CurrentActionIx < shortestLen {
459+
shortest = s.traces.CurrentTraceIx
460+
shortestLen = s.traces.CurrentActionIx
461+
}
462+
}
452463
}
464+
fmt.Println("Shortest [traceIx, actionIx]:", shortest, shortestLen)
465+
453466
}
454467

455468
func TestCoreSuite(t *testing.T) {
456-
// TODO: Reenable diff tests once model is updated
457-
// suite.Run(t, new(CoreSuite))
469+
suite.Run(t, new(CoreSuite))
458470
}
459471

460472
// SetupTest sets up the test suite in a 'zero' state which matches

tests/difference/core/driver/setup.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,13 @@ func (b *Builder) build() {
678678

679679
b.setSlashParams()
680680

681+
// TODO: tidy up before merging into main
682+
prams := b.providerKeeper().GetParams(b.ctx(P))
683+
prams.SlashMeterReplenishFraction = "1.0"
684+
prams.SlashMeterReplenishPeriod = time.Second * 1
685+
b.providerKeeper().SetParams(b.ctx(P), prams)
686+
b.providerKeeper().InitializeSlashMeter(b.ctx(P))
687+
681688
// Set light client params to match model
682689
tmConfig := ibctesting.NewTendermintConfig()
683690
tmConfig.UnbondingPeriod = b.initState.UnbondingP

tests/difference/core/driver/traces.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

tests/difference/core/model/src/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ type ModelInitState = {
181181
downtimeSlashAcks: number[];
182182
tombstoned: boolean[];
183183
matureUnbondingOps: number[];
184+
queue: (Slash | VscMatured)[];
184185
};
185186
};
186187

tests/difference/core/model/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const MODEL_INIT_STATE: ModelInitState = {
5656
downtimeSlashAcks: [],
5757
tombstoned: [false, false, false, false],
5858
matureUnbondingOps: [],
59+
queue: [],
5960
},
6061
staking: {
6162
delegation: [4000, 3000, 2000, 1000],

tests/difference/core/model/src/model.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ class CCVProvider {
374374
tombstoned: boolean[];
375375
// unbonding operations to be completed in EndBlock
376376
matureUnbondingOps: number[];
377+
// queue
378+
queue: (Slash | VscMatured)[];
377379

378380
constructor(model: Model, { ccvP }: ModelInitState) {
379381
this.m = model;
@@ -382,6 +384,7 @@ class CCVProvider {
382384

383385
endBlockCIS = () => {
384386
this.vscIDtoH[this.vscID] = this.m.h[P] + 1;
387+
this.processPackets();
385388
};
386389

387390
endBlockVSU = () => {
@@ -420,14 +423,32 @@ class CCVProvider {
420423
};
421424

422425
onReceive = (data: PacketData) => {
423-
// It's sufficient to use isDowntime field as differentiator
424-
if ('isDowntime' in data) {
425-
this.onReceiveSlash(data);
426+
/*
427+
TODO: tidy up before merging to main
428+
This is some quick prototyping to get the tests passing
429+
We have 1 consumer chain so the slash queue is the global queue
430+
if the queue is empty we can just process the packet.
431+
*/
432+
if (this.queue.length == 0 && !('isDowntime' in data)) {
433+
// Skip the queue
434+
this.onReceiveVSCMatured(data as VscMatured);
426435
} else {
427-
this.onReceiveVSCMatured(data);
436+
this.queue.push(data);
428437
}
429438
};
430439

440+
processPackets = () => {
441+
this.queue.forEach((data) => {
442+
// It's sufficient to use isDowntime field as differentiator
443+
if ('isDowntime' in data) {
444+
this.onReceiveSlash(data);
445+
} else {
446+
this.onReceiveVSCMatured(data);
447+
}
448+
});
449+
this.queue = [];
450+
};
451+
431452
onReceiveVSCMatured = (data: VscMatured) => {
432453
if (this.vscIDtoOpIDs.has(data.vscID)) {
433454
this.vscIDtoOpIDs.get(data.vscID)!.forEach((opID: number) => {

0 commit comments

Comments
 (0)