Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tests): add helper functions, keeper test suite. #7052

Merged
merged 2 commits into from
Aug 6, 2024

Conversation

DimitrisJim
Copy link
Contributor

Description

should probably do trick for keeper funcs for time being, testing package should need additional tweaks in future

closes: #XXXX


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

testing/path.go Outdated
@@ -162,6 +162,20 @@ func (path *Path) SetupClients() {
}
}

// SetupEurekaClients is a helper function to create clients supporting ibc-eureka on both
// chains. It assumes the caller does not anticipate any errors.
func (path *Path) SetupEurekaClients() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to reduce overall diffs, just named this with Eureka, think we just rename old function to Classic and change occurrences afterwards

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like naming suggestion below SetupCounterparties, nice to avoid introducing Eureka when possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, Aditya will push that suggestion, ideally wanted a single setup function to get things ready but fair counterpoint re Eureka getting disseminated through-out code

}

// TODO: Remove, just testing the testing setup.
func (suite *KeeperTestSuite) TestCreateEurekaClients() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will rm before merge

Comment on lines +30 to +31
suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1))
suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should probably be fine with two chains for handler testing. can be changed if necessary

Copy link
Member

@AdityaSripal AdityaSripal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restructuring suggestion.

Also let's remove reference to Eureka in function names and use V2 instead

testing/path.go Outdated
@@ -162,6 +162,20 @@ func (path *Path) SetupClients() {
}
}

// SetupEurekaClients is a helper function to create clients supporting ibc-eureka on both
// chains. It assumes the caller does not anticipate any errors.
func (path *Path) SetupEurekaClients() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than doing this all in one step, let's keep SetupClients unchanged, and add a new function called SetupCounterparties that does the provide counterparty for each side.

Then in our tests, we can setup like so:

path.SetupClients()
path.SetupCounterparties()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eventually path.Setup() will just do both

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a SetupV2 that does both

@AdityaSripal
Copy link
Member

Also we need the Packet-server keeper to be wired up in the app and made a public field so we can call it from suite.chainA for example.

We can modify IBCKeeper later, but let's keep it a top level field of the testing app for now

@@ -165,6 +165,18 @@ func (endpoint *Endpoint) UpdateClient() (err error) {
return endpoint.Chain.sendMsgs(msg)
}

// ProvideCounterparty will construct and execute a MsgProvideCounterparty on the associated endpoint.
func (endpoint *Endpoint) ProvideCounterparty() (err error) {
merklePath := commitmenttypes.NewMerklePath([]byte("ibc"), []byte(""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Endpoint should probably be modified to have the merkle prefix now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, let's create an issue and do this later.

Think it should be added as a new field but this should be the default value that can then be malleated later by test writer

suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2))

// commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1)
suite.coordinator.CommitNBlocks(suite.chainA, 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? I think it might be legacy code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, good question, I see this through-out, might make sense to trim off through-out later in single PR.

@AdityaSripal AdityaSripal requested a review from srdtrk as a code owner August 5, 2024 23:02
@@ -8,14 +8,14 @@ import (

type Keeper struct {
cdc codec.BinaryCodec
channelKeeper types.ChannelKeeper
clientKeeper types.ClientKeeper
ChannelKeeper types.ChannelKeeper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made this public so they were retrievable in testchains through the packetserver.

We already do this with IBCKeeper

@@ -16,7 +16,7 @@ type ChannelKeeper interface {
GetPacketCommitment(ctx sdk.Context, portID string, channelID string, sequence uint64) []byte

// DeletePacketCommitment deletes the packet commitment hash under the commitment path
DeletePacketCommitment(ctx sdk.Context, portID string, channelID string, sequence uint64)
// DeletePacketCommitment(ctx sdk.Context, portID string, channelID string, sequence uint64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this for now. Can be readded in future PR that needs it

@@ -370,6 +372,9 @@ func NewSimApp(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), ibctm.NewConsensusHost(app.StakingKeeper), app.UpgradeKeeper, scopedIBCKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Setup packet server to call on Eureka tests
app.PacketServer = packetserverkeeper.NewKeeper(appCodec, app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ClientKeeper)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed this so that we can call into these functions from the TestChain struct

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we could also always create the PacketServer.Keeper struct on the fly using the IBCKeeper fields...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea but think this is perfectly fine for now, lets just add the testing boilerplate and refactor it later when needed

Copy link

sonarqubecloud bot commented Aug 5, 2024

@@ -162,6 +169,18 @@ func (path *Path) SetupClients() {
}
}

// SetupCounterparties is a helper function to set the counterparties supporting ibc-eureka on both
// chains. It assumes the caller does not anticipate any errors.
func (path *Path) SetupCounterparties() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this make sense as standalone func? I.e can't see where we'd invoke it separately without it being preceded by SetupClients. We could possibly inline in SetupV2, leaving as potential follow up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... yea I did it in case you wanted to SetupClients, test X, Y, Z, then call SetCounterparties after and do some more testing

@DimitrisJim
Copy link
Contributor Author

thanks for follow up tweaks @AdityaSripal! Gonna merge this in a bit so we have it in handler branches. Think any follow ups can be addressed later to not block.

@DimitrisJim DimitrisJim merged commit dcff30b into feat/ibc-eureka Aug 6, 2024
63 of 65 checks passed
@DimitrisJim DimitrisJim deleted the jim/eureka-testing-setup branch August 6, 2024 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants