Skip to content

Commit

Permalink
Start working on diff test (unfinished) confirm all pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel committed Oct 26, 2022
1 parent 9cf0596 commit 682fe1f
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/difference/core/driver/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ import (

slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper"
consumerkeeper "github.com/cosmos/interchain-security/x/ccv/consumer/keeper"
providerkeeper "github.com/cosmos/interchain-security/x/ccv/provider/keeper"
)

type KeyMapHelp struct {
}

type CoreSuite struct {
suite.Suite

Expand All @@ -40,6 +44,9 @@ type CoreSuite struct {
// so offsets are needed for comparisons.
offsetTimeUnix int64
offsetHeight int64

// Maps vscid to data needed to check keymapping
keymapHelp map[uint64]KeyMapHelp
}

// ctx returns the sdk.Context for the chain
Expand Down Expand Up @@ -72,10 +79,34 @@ func (b *CoreSuite) providerSlashingKeeper() slashingkeeper.Keeper {
return b.providerChain().App.(*appProvider.App).SlashingKeeper
}

func (b *CoreSuite) providerKeeper() providerkeeper.Keeper {
return b.providerChain().App.(*appProvider.App).ProviderKeeper
}

func (b *CoreSuite) consumerKeeper() consumerkeeper.Keeper {
return b.consumerChain().App.(*appConsumer.App).ConsumerKeeper
}

func (b *CoreSuite) consumerGreatestVscIDReceived() uint64 {
/*
TODO:
I know that the consumer slash will use the the provider validator address
and that that address should have been known to the consumer and should
not have already matured.
Therefore I can take any vscid that is still maturing on the consumer
and find a provider block, with one of those vscids,
where that validator had non 0 power, and
take the mapping from that block to get the consumer address which
should actually be used as argument.
I can just do random mapping actions whenever.
I should query the mapping after provider EndBlock.
*/

k := b.consumerKeeper()
h := uint64(b.height(C) + 1) // TODO: is this height queried from the right place?
return k.GetHeightValsetUpdateID(b.ctx(C), h)
}

// height returns the height of the current header of chain
func (s *CoreSuite) height(chain string) int64 {
return s.chain(chain).CurrentHeader.GetHeight()
Expand Down Expand Up @@ -208,9 +239,25 @@ func (s *CoreSuite) deliver(chain string, numPackets int) {
s.simibc.DeliverPackets(s.chainID(chain), numPackets)
}

func (s *CoreSuite) fillKeymapHelp(chain string) {
if chain == P {
// If the provider ended a block then we should query the current vscid
k := s.providerKeeper()
vscid := k.GetValidatorSetUpdateId(s.ctx(P))
vscid -= 1 // The provider EndBlock does +=1 as a final step
mapping := map[string]providerkeeper.ConsumerPubKey{}
k.KeyMap(s.ctx(P), s.chainID(C)).Store.IteratePcaToCk(func(pca providerkeeper.ProviderConsAddr, ck providerkeeper.ConsumerPubKey) bool {
mapping[string(pca)] = ck
return false
})

}
}

func (s *CoreSuite) endAndBeginBlock(chain string) {
s.simibc.EndAndBeginBlock(s.chainID(chain), initState.BlockSeconds, func() {
s.matchState()
s.fillKeymapHelp(chain)
})
}

Expand Down

0 comments on commit 682fe1f

Please sign in to comment.