forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#6818: x/upgrade: Fix ReadUpgradeInfoFromDisk
- Loading branch information
1 parent
ab664e9
commit 2224be5
Showing
3 changed files
with
83 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
||
"github.com/cosmos/cosmos-sdk/simapp" | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
"github.com/cosmos/cosmos-sdk/x/upgrade/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
) | ||
|
||
type KeeperTestSuite struct { | ||
suite.Suite | ||
|
||
homeDir string | ||
app *simapp.SimApp | ||
} | ||
|
||
func (s *KeeperTestSuite) SetupTest() { | ||
app := simapp.Setup(false) | ||
|
||
homeDir, err := ioutil.TempDir(os.TempDir(), "x_upgrade_keeper_test") | ||
s.Require().NoError(err) | ||
|
||
// recreate keeper in order to use a custom home path | ||
app.UpgradeKeeper = keeper.NewKeeper( | ||
make(map[int64]bool), app.GetKey(types.StoreKey), app.AppCodec(), homeDir, | ||
) | ||
|
||
s.homeDir = homeDir | ||
s.app = app | ||
} | ||
|
||
func (s *KeeperTestSuite) TestReadUpgradeInfoFromDisk() { | ||
// require no error when the upgrade info file does not exist | ||
_, err := s.app.UpgradeKeeper.ReadUpgradeInfoFromDisk() | ||
s.Require().NoError(err) | ||
|
||
expected := store.UpgradeInfo{ | ||
Name: "test_upgrade", | ||
Height: 100, | ||
} | ||
|
||
// create an upgrade info file | ||
s.Require().NoError(s.app.UpgradeKeeper.DumpUpgradeInfoToDisk(expected.Height, expected.Name)) | ||
|
||
ui, err := s.app.UpgradeKeeper.ReadUpgradeInfoFromDisk() | ||
s.Require().NoError(err) | ||
s.Require().Equal(expected, ui) | ||
} | ||
|
||
func TestKeeperTestSuite(t *testing.T) { | ||
suite.Run(t, new(KeeperTestSuite)) | ||
} |