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

Set ChainID on InitChain #1367

Merged
merged 16 commits into from
Jun 27, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix bug
  • Loading branch information
AdityaSripal committed Jun 25, 2018
commit e4f319452724276560f03b6a606a8ba695048f7e
10 changes: 6 additions & 4 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ func (app *BaseApp) SetOption(req abci.RequestSetOption) (res abci.ResponseSetOp
// Implements ABCI
// InitChain runs the initialization logic directly on the CommitMultiStore and commits it.
func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitChain) {
if app.initChainer == nil {
return
}

// Initialize the deliver state and check state with ChainID and run initChain
app.setDeliverState(abci.Header{ChainID: req.ChainId})
app.setCheckState(abci.Header{ChainID: req.ChainId})

if app.initChainer == nil {
return
}
app.initChainer(app.deliverState.ctx, req) // no error

// NOTE: we don't commit, but BeginBlock for block 1
Expand Down Expand Up @@ -381,6 +381,8 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
// if this is a test and InitChain was never called.
if app.deliverState == nil {
app.setDeliverState(req.Header)
} else {
app.deliverState.ctx = app.deliverState.ctx.WithBlockHeader(req.Header)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this now necessary? app.DeliverState is set to nil when Commit() is called. Also, I think the comment on line 381 is wrong for this reason.

}
if app.beginBlocker != nil {
res = app.beginBlocker(app.deliverState.ctx, req)
Expand Down
8 changes: 5 additions & 3 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,15 @@ func TestSimulateTx(t *testing.T) {
return ttx, nil
})

app.InitChain(abci.RequestInitChain{})

nBlocks := 3
for blockN := 0; blockN < nBlocks; blockN++ {
// block1
header.Height = int64(blockN + 1)
app.BeginBlock(abci.RequestBeginBlock{Header: header})
result := app.Simulate(tx)
require.Equal(t, result.Code, sdk.ABCICodeOK)
require.Equal(t, result.Code, sdk.ABCICodeOK, result.Log)
require.Equal(t, int64(80), result.GasUsed)
counter--
encoded, err := json.Marshal(tx)
Expand All @@ -405,8 +407,8 @@ func TestSimulateTx(t *testing.T) {
require.Equal(t, queryResult.Code, uint32(sdk.ABCICodeOK))
var res sdk.Result
app.cdc.MustUnmarshalBinary(queryResult.Value, &res)
require.Equal(t, sdk.ABCICodeOK, res.Code)
require.Equal(t, int64(160), res.GasUsed)
require.Equal(t, sdk.ABCICodeOK, res.Code, res.Log)
require.Equal(t, int64(160), res.GasUsed, res.Log)
app.EndBlock(abci.RequestEndBlock{})
app.Commit()
}
Expand Down