Skip to content

Commit

Permalink
add changes from review
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Jun 28, 2022
1 parent 467525b commit a8a6073
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 49 deletions.
37 changes: 16 additions & 21 deletions testing/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ func (chain *TestChain) GetSentPacket(sequence uint64) (packet channeltypes.Pack
return
}

// setSentPacketsFromEvents stores the sent packet reconstructed
// from emitted events of type SendPacketEvent
func (chain *TestChain) setSentPacketsFromEvents(events []abci.Event) {
for _, event := range events {
if event.Type == channeltypes.EventTypeSendPacket {
packet, err := channelkeeper.ReconstructPacketFromEvent(event)
require.NoError(chain.T, err)
chain.SentPackets[packet.Sequence] = packet
}
}
}

// NextBlock sets the last header to the current header and increments the current header to be
// at the next block height. It does not update the time as that is handled by the Coordinator.
// It will call Endblock and Commit and apply the validator set changes to the next validators
Expand All @@ -285,13 +297,7 @@ func (chain *TestChain) NextBlock() (abci.ResponseEndBlock, abci.ResponseCommit,

ebRes := chain.App.EndBlock(abci.RequestEndBlock{Height: chain.CurrentHeader.Height})
// store packets sent during EndBlock
for _, event := range ebRes.Events {
if event.Type == channeltypes.EventTypeSendPacket {
packet, err := channelkeeper.ReconstructPacketFromEvent(event)
require.NoError(chain.T, err)
chain.SentPackets[packet.Sequence] = packet
}
}
chain.setSentPacketsFromEvents(ebRes.Events)

cRes := chain.App.Commit()

Expand All @@ -318,13 +324,8 @@ func (chain *TestChain) NextBlock() (abci.ResponseEndBlock, abci.ResponseCommit,

bbRes := chain.App.BeginBlock(abci.RequestBeginBlock{Header: chain.CurrentHeader})
// store packets sent during BeginBlock
for _, event := range bbRes.Events {
if event.Type == channeltypes.EventTypeSendPacket {
packet, err := channelkeeper.ReconstructPacketFromEvent(event)
require.NoError(chain.T, err)
chain.SentPackets[packet.Sequence] = packet
}
}
chain.setSentPacketsFromEvents(bbRes.Events)

return ebRes, cRes, bbRes
}

Expand Down Expand Up @@ -356,13 +357,7 @@ func (chain *TestChain) SendMsgs(msgs ...sdk.Msg) (*sdk.Result, error) {
return nil, err
}
// store packets sent during the execution of this transaction
for _, event := range r.Events {
if event.Type == channeltypes.EventTypeSendPacket {
packet, err := channelkeeper.ReconstructPacketFromEvent(event)
require.NoError(chain.T, err)
chain.SentPackets[packet.Sequence] = packet
}
}
chain.setSentPacketsFromEvents(r.Events)

// NextBlock calls app.Commit()
chain.NextBlock()
Expand Down
28 changes: 0 additions & 28 deletions testing/chain_test.go

This file was deleted.

0 comments on commit a8a6073

Please sign in to comment.