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

Refactor 04-channel/keeper tests to ibc testing pkg #6400

Merged
merged 56 commits into from
Jun 26, 2020

Conversation

colin-axner
Copy link
Contributor

@colin-axner colin-axner commented Jun 11, 2020

Description

  • keeper_test
  • handshake_test
  • querier_test
  • packet_test
  • timeout_test

ref: #5558


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 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.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

@codecov
Copy link

codecov bot commented Jun 11, 2020

Codecov Report

Merging #6400 into master will increase coverage by 0.06%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #6400      +/-   ##
==========================================
+ Coverage   56.68%   56.74%   +0.06%     
==========================================
  Files         478      478              
  Lines       28777    28820      +43     
==========================================
+ Hits        16313    16355      +42     
- Misses      11306    11316      +10     
+ Partials     1158     1149       -9     

@colin-axner
Copy link
Contributor Author

current issue here is simapp.Setup doesn't allow for a validator set to be set upon genesis. So the validator set being put into the tm header results in a self consensus state that doesnt equal the counterparty's client consensus state. The self consensus state has a nil validator set as tracked by historical info.

somehow a helper func needs to be added to simapp to allow setting a valset at genesis

@colin-axner
Copy link
Contributor Author

I think the solution here is to add a SetupWithValidators func in simapp which takes in a validator set and swaps out the default genesis state in staking for a genesis state with appropriate validators/delegations. I'm not 100% sure if that will be enough or if changes need to be made elsewhere as well

@colin-axner
Copy link
Contributor Author

It seems like the current issue here is handling querying of proofs and submission of the correct proof height. When querying for a proof, we are returned the IAVL height of the proof, which actually corresponds to proofHeight + 1 of the tenderminet consensus. So if I want a proof at block height 6, in theory I should be able to query at IAVL height 5 and submit the proof along with the returned proofHeight + 1.

This is quite confusing and it should be explored ways to remedy this as well as document this in the IBC specs.

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

Awesome! thanks @colin-axner. Minor comments only

simapp/test_helpers.go Outdated Show resolved Hide resolved
x/ibc/testing/types.go Outdated Show resolved Hide resolved
x/ibc/testing/types.go Outdated Show resolved Hide resolved
x/ibc/testing/coordinator.go Show resolved Hide resolved
x/ibc/testing/coordinator.go Show resolved Hide resolved
x/ibc/testing/chain.go Outdated Show resolved Hide resolved
x/ibc/testing/chain.go Outdated Show resolved Hide resolved
x/ibc/testing/chain.go Outdated Show resolved Hide resolved
x/ibc/04-channel/keeper/handshake_test.go Show resolved Hide resolved
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.

Great work!! Have some suggested changes

x/ibc/04-channel/keeper/handshake_test.go Outdated Show resolved Hide resolved
)
suite.Require().NoError(err, "could not create capability")
// run test for all types of ordering
for _, order := range []types.Order{types.UNORDERED, types.ORDERED} {
Copy link
Member

Choose a reason for hiding this comment

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

Nice touch!

x/ibc/04-channel/keeper/handshake_test.go Outdated Show resolved Hide resolved
x/ibc/04-channel/keeper/handshake_test.go Show resolved Hide resolved
x/ibc/04-channel/keeper/handshake_test.go Outdated Show resolved Hide resolved
Comment on lines +164 to +167
// proof height + 1 is returned as the proof created corresponds to the height the proof
// was created in the IAVL tree. Tendermint and subsequently the clients that rely on it
// have heights 1 above the IAVL tree. Thus we return proof height + 1
return proof, uint64(res.Height) + 1
Copy link
Member

Choose a reason for hiding this comment

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

Note for reviewers @cwgoes @fedekunze : This is an issue that me and @jackzampolin repeatedly ran into when working with the relayer. We fixed the problem by incrementing the query height before passing into proof height.

We should consider whether we want to make this a requirement for relayers to handle correctly or if we want to deal with this peculiarity on the SDK side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we should open up an issue to discuss this

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah let's create an issue 👍

Time: chain.CurrentHeader.Time,
Height: chain.App.LastBlockHeight() + 1,
AppHash: chain.App.LastCommitID().Hash,
Time: chain.CurrentHeader.Time,
Copy link
Member

Choose a reason for hiding this comment

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

Is time not getting increased at all?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah I’d add 7 seconds

Copy link
Contributor Author

@colin-axner colin-axner Jun 26, 2020

Choose a reason for hiding this comment

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

it is, but in the coordinator. Increasing time here would cause updating clients to use headers from the future. I'll add a comment

x/ibc/testing/types.go Outdated Show resolved Hide resolved
}

// NextTestChannel returns the next test channel to be created on this connection
func (conn *TestConnection) NextTestChannel() TestChannel {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (conn *TestConnection) NextTestChannel() TestChannel {
func (conn *TestConnection) NewTestChannel() TestChannel {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, so my issue with this naming is calling NewTestChannel would result in the same test channel being returned


// FirstOrNextTestChannel returns the first test channel if it exists, otherwise it
// returns the next test channel to be created.
func (conn *TestConnection) FirstOrNextTestChannel() TestChannel {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func (conn *TestConnection) FirstOrNextTestChannel() TestChannel {
func (conn *TestConnection) GetTestChannel() TestChannel {

Other options, GetOrCreateTestChannel, FetchTestChannel

Copy link
Contributor Author

@colin-axner colin-axner Jun 26, 2020

Choose a reason for hiding this comment

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

A test channel isn't created. In fact just using this func or NextTestChannel would result in referencing a channel that doesn't exist on the chain. I'll update the docs to be more clear with the intention of these funcs.

I like including First since this func is not meant to be used with the creation of multiple test channels on the same connection.

Copy link
Collaborator

@fedekunze fedekunze left a comment

Choose a reason for hiding this comment

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

ACK 👍

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.

Great work @colin-axner !

Still don't like NextTestChannel and FirstOrNextTestChannel. Maybe @fedekunze can be the tiebreaker here, but don't think it needs to block the entire PR. Approved 🎉

err := suite.coordinator.SendPacket(suite.chainA, suite.chainB, packet, clientB)
suite.Require().NoError(err)
// set sequence to 2
packet = types.NewPacket(validPacketData, 2, channelA.PortID, channelA.ID, channelB.PortID, channelB.ID, timeoutHeight, disabledTimeoutTimestamp)
Copy link
Member

Choose a reason for hiding this comment

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

good way to test this!

@AdityaSripal AdityaSripal added the A:automerge Automatically merge PR once all prerequisites pass. label Jun 26, 2020
@mergify mergify bot merged commit 43837b1 into master Jun 26, 2020
@mergify mergify bot deleted the colin/5558-remove-dup-channel branch June 26, 2020 16:36
larry0x pushed a commit to larry0x/cosmos-sdk that referenced this pull request May 22, 2023
* update testing pkg and first keeper test

* fix version bug

* add more helper testing funcs

* move create header to testing pkg

* fix connection state bug

* add staking genesis state

* update simapp with setting validator helper func

* update simapp with valset helper

* fix app hash issue

* update to query from correct iavl proof height

* first keeper test passing

* second test passing 🎉

* fix build

* update tests in all keeper_test

* fix lint

* begin refactoring querier test

* update first querier test and update testing helpers

* finish updating rest of querier tests

* rename ChannelID in TestChannel to ID

* remove usage of chain id for calling helper funcs

* update openinit and opentry tests

* finish opening channel handshake tests

* finish handshake tests

* general testing pkg cleanup

* finish packetsend refactor

* update recvpacket

* packet executed refactored

* finish packet test 🎉

* all tests passing

* cleanup and increase code cov

* remove todos in favor of opened issue #6509

* bump invalid id to meet validation requirements

* bubble up proof height + 1

* Apply suggestions from code review

Co-authored-by: Aditya <[email protected]>
Co-authored-by: Federico Kunze <[email protected]>

* fix uninit conn test

* fix compile and address various pr review issues

* Update x/ibc/04-channel/keeper/handshake_test.go

Co-authored-by: Aditya <[email protected]>

* Update x/ibc/04-channel/keeper/handshake_test.go

Co-authored-by: Aditya <[email protected]>

* address @AdityaSripal comments and increase cov

Co-authored-by: Aditya <[email protected]>
Co-authored-by: Federico Kunze <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass. T: Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants