-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add player info migration and tests.
- Loading branch information
1 parent
19c3413
commit ae255f6
Showing
10 changed files
with
536 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package v1tov1_1 | ||
|
||
const ( | ||
UpgradeName = "v1tov1_1" | ||
) |
50 changes: 50 additions & 0 deletions
50
tests/integration/checkers/migrations/cv3/upgrade_integration_suite_test.go
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,50 @@ | ||
package cv3_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
checkersapp "github.com/b9lab/checkers/app" | ||
"github.com/b9lab/checkers/x/checkers/keeper" | ||
cv2types "github.com/b9lab/checkers/x/checkers/migrations/cv2/types" | ||
"github.com/b9lab/checkers/x/checkers/types" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
module "github.com/cosmos/cosmos-sdk/types/module" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/stretchr/testify/suite" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
) | ||
|
||
type IntegrationTestSuite struct { | ||
suite.Suite | ||
|
||
app *checkersapp.App | ||
msgServer types.MsgServer | ||
ctx sdk.Context | ||
queryClient types.QueryClient | ||
} | ||
|
||
func TestUpgradeTestSuite(t *testing.T) { | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) SetupTest() { | ||
app := checkersapp.Setup(false) | ||
ctx := app.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()}) | ||
|
||
app.AccountKeeper.SetParams(ctx, authtypes.DefaultParams()) | ||
app.BankKeeper.SetParams(ctx, banktypes.DefaultParams()) | ||
initialVM := module.VersionMap{types.ModuleName: cv2types.ConsensusVersion} | ||
app.UpgradeKeeper.SetModuleVersionMap(ctx, initialVM) | ||
|
||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) | ||
types.RegisterQueryServer(queryHelper, app.CheckersKeeper) | ||
queryClient := types.NewQueryClient(queryHelper) | ||
|
||
suite.app = app | ||
suite.msgServer = keeper.NewMsgServerImpl(app.CheckersKeeper) | ||
suite.ctx = ctx | ||
suite.queryClient = queryClient | ||
} |
110 changes: 110 additions & 0 deletions
110
tests/integration/checkers/migrations/cv3/upgrade_test.go
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,110 @@ | ||
package cv3_test | ||
|
||
import ( | ||
"github.com/b9lab/checkers/app/upgrades/v1tov1_1" | ||
cv2types "github.com/b9lab/checkers/x/checkers/migrations/cv2/types" | ||
cv3types "github.com/b9lab/checkers/x/checkers/migrations/cv3/types" | ||
"github.com/b9lab/checkers/x/checkers/rules" | ||
"github.com/b9lab/checkers/x/checkers/testutil" | ||
"github.com/b9lab/checkers/x/checkers/types" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
) | ||
|
||
const ( | ||
alice = testutil.Alice | ||
bob = testutil.Bob | ||
carol = testutil.Carol | ||
) | ||
|
||
func (suite *IntegrationTestSuite) TestUpgradeConsensusVersion() { | ||
vmBefore := suite.app.UpgradeKeeper.GetModuleVersionMap(suite.ctx) | ||
suite.Require().Equal(cv2types.ConsensusVersion, vmBefore[types.ModuleName]) | ||
|
||
v1Tov1_1Plan := upgradetypes.Plan{ | ||
Name: v1tov1_1.UpgradeName, | ||
Info: "some text here", | ||
Height: 123450000, | ||
} | ||
suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, v1Tov1_1Plan) | ||
|
||
vmAfter := suite.app.UpgradeKeeper.GetModuleVersionMap(suite.ctx) | ||
suite.Require().Equal(cv3types.ConsensusVersion, vmAfter[types.ModuleName]) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) TestNotUpgradeConsensusVersion() { | ||
vmBefore := suite.app.UpgradeKeeper.GetModuleVersionMap(suite.ctx) | ||
suite.Require().Equal(cv2types.ConsensusVersion, vmBefore[types.ModuleName]) | ||
|
||
dummyPlan := upgradetypes.Plan{ | ||
Name: v1tov1_1.UpgradeName + "no", | ||
Info: "some text here", | ||
Height: 123450000, | ||
} | ||
defer func() { | ||
r := recover() | ||
suite.Require().NotNil(r, "The code did not panic") | ||
suite.Require().Equal(r, "ApplyUpgrade should never be called without first checking HasHandler") | ||
|
||
vmAfter := suite.app.UpgradeKeeper.GetModuleVersionMap(suite.ctx) | ||
suite.Require().Equal(cv2types.ConsensusVersion, vmAfter[types.ModuleName]) | ||
}() | ||
suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, dummyPlan) | ||
} | ||
|
||
func (suite *IntegrationTestSuite) TestUpgradeTallyPlayerInfo() { | ||
suite.app.CheckersKeeper.SetStoredGame(suite.ctx, types.StoredGame{ | ||
Index: "1", | ||
Black: alice, | ||
Red: bob, | ||
Winner: rules.PieceStrings[rules.BLACK_PLAYER], | ||
}) | ||
suite.app.CheckersKeeper.SetStoredGame(suite.ctx, types.StoredGame{ | ||
Index: "2", | ||
Black: alice, | ||
Red: carol, | ||
Winner: rules.PieceStrings[rules.RED_PLAYER], | ||
}) | ||
suite.app.CheckersKeeper.SetStoredGame(suite.ctx, types.StoredGame{ | ||
Index: "3", | ||
Black: alice, | ||
Red: carol, | ||
Winner: rules.PieceStrings[rules.BLACK_PLAYER], | ||
}) | ||
suite.app.CheckersKeeper.SetStoredGame(suite.ctx, types.StoredGame{ | ||
Index: "4", | ||
Black: alice, | ||
Red: bob, | ||
Winner: rules.PieceStrings[rules.NO_PLAYER], | ||
}) | ||
suite.Require().EqualValues([]types.PlayerInfo(nil), suite.app.CheckersKeeper.GetAllPlayerInfo(suite.ctx)) | ||
|
||
v1Tov1_1Plan := upgradetypes.Plan{ | ||
Name: v1tov1_1.UpgradeName, | ||
Info: "some text here", | ||
Height: 123450000, | ||
} | ||
suite.app.UpgradeKeeper.ApplyUpgrade(suite.ctx, v1Tov1_1Plan) | ||
|
||
expectedInfos := map[string]types.PlayerInfo{ | ||
alice: { | ||
Index: alice, | ||
LostCount: 1, | ||
WonCount: 2, | ||
}, | ||
bob: { | ||
Index: bob, | ||
LostCount: 1, | ||
}, | ||
carol: { | ||
Index: carol, | ||
LostCount: 1, | ||
WonCount: 1, | ||
}, | ||
} | ||
|
||
for who, expectedInfo := range expectedInfos { | ||
storedInfo, found := suite.app.CheckersKeeper.GetPlayerInfo(suite.ctx, who) | ||
suite.Require().True(found) | ||
suite.Require().Equal(expectedInfo, storedInfo) | ||
} | ||
} |
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,5 @@ | ||
package types | ||
|
||
const ( | ||
ConsensusVersion = uint64(2) | ||
) |
Oops, something went wrong.