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

Store historic header information for IBC #93

Merged
merged 5 commits into from
Aug 17, 2021
Merged
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
40 changes: 39 additions & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
ibcclienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types"
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"os"
"testing"
"time"
Expand All @@ -22,7 +25,6 @@ import (
var emptyWasmOpts []wasm.Option = nil

func TestTgradeExport(t *testing.T) {
t.Skip("Alex, this is not implemented")
db := db.NewMemDB()
gapp := NewTgradeApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, EmptyBaseAppOptions{}, emptyWasmOpts)
genesisState := NewDefaultGenesisState()
Expand All @@ -44,6 +46,8 @@ func TestTgradeExport(t *testing.T) {

// Making a new app object with the db, so that initchain hasn't been called
newGapp := NewTgradeApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, EmptyBaseAppOptions{}, emptyWasmOpts)

t.Skip("Alex, export is not implemented")
_, err = newGapp.ExportAppStateAndValidators(false, []string{})
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
}
Expand Down Expand Up @@ -119,3 +123,37 @@ func setGenesis(gapp *TgradeApp) error {
gapp.Commit()
return nil
}

func TestIBCKeeperLazyInitialization(t *testing.T) {
db := db.NewMemDB()
gapp := NewTgradeApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, EmptyBaseAppOptions{}, emptyWasmOpts)
genesisState := NewDefaultGenesisState()

setupWithSingleValidatorGenTX(t, genesisState)

stateBytes, err := json.MarshalIndent(genesisState, "", " ")
require.NoError(t, err)

// Initialize the chain
gapp.InitChain(
abci.RequestInitChain{
Time: time.Now().UTC(),
Validators: []abci.ValidatorUpdate{},
AppStateBytes: stateBytes,
},
)
gapp.Commit()
// store some historic information
header := tmproto.Header{ChainID: "testing-1", Height: 2}
gapp.BaseApp.BeginBlock(abci.RequestBeginBlock{Header: header})
gapp.Commit()

ctx := gapp.BaseApp.NewContext(true, header)
height := ibcclienttypes.Height{RevisionNumber: 1, RevisionHeight: 2}

// when
state, found := gapp.ibcKeeper.ClientKeeper.GetSelfConsensusState(ctx, height)
Copy link
Contributor

Choose a reason for hiding this comment

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

This uses the staking adaptor? Can you link to where that call happens?

Can we assert that data that we expect to be returned from such an adaptor (unbonding period?) is actually set properly? Not just that it returns "some data"

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 have extended the test to verify that the data returned is what was persisted before on begin block

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you. Looks convincing.

// then
require.True(t, found)
assert.NotNil(t, state)
}