-
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.
- Loading branch information
Showing
18 changed files
with
1,916 additions
and
78 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/olimdzhon/checkers/x/checkers/types" | ||
) | ||
|
||
func (k msgServer) CreateGame(goCtx context.Context, msg *types.MsgCreateGame) (*types.MsgCreateGameResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// TODO: Handling the message | ||
_ = ctx | ||
|
||
return &types.MsgCreateGameResponse{}, nil | ||
} |
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,29 @@ | ||
package simulation | ||
|
||
import ( | ||
"math/rand" | ||
|
||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
simtypes "github.com/cosmos/cosmos-sdk/types/simulation" | ||
"github.com/olimdzhon/checkers/x/checkers/keeper" | ||
"github.com/olimdzhon/checkers/x/checkers/types" | ||
) | ||
|
||
func SimulateMsgCreateGame( | ||
ak types.AccountKeeper, | ||
bk types.BankKeeper, | ||
k keeper.Keeper, | ||
) simtypes.Operation { | ||
return func(r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, | ||
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { | ||
simAccount, _ := simtypes.RandomAcc(r, accs) | ||
msg := &types.MsgCreateGame{ | ||
Creator: simAccount.Address.String(), | ||
} | ||
|
||
// TODO: Handling the CreateGame simulation | ||
|
||
return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "CreateGame simulation not implemented"), nil, nil | ||
} | ||
} |
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,7 @@ | ||
package testutil | ||
|
||
const ( | ||
Alice = "cosmos1jmjfq0tplp9tmx4v9uemw72y4d2wa5nr3xn9d3" | ||
Bob = "cosmos1xyxs3skf3f4jfqeuv89yyaqvjc6lffavxqhc8g" | ||
Carol = "cosmos1e0w5t53nrq7p66fye6c8p0ynyhf6y24l4yuxd7" | ||
) |
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
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,53 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/olimdzhon/checkers/x/checkers/rules" | ||
"github.com/olimdzhon/checkers/x/checkers/testutil" | ||
"github.com/olimdzhon/checkers/x/checkers/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
alice = testutil.Alice | ||
bob = testutil.Bob | ||
) | ||
|
||
func GetStoredGame1() types.StoredGame { | ||
return types.StoredGame{ | ||
Black: alice, | ||
Red: bob, | ||
Index: "1", | ||
Board: rules.New().String(), | ||
Turn: "b", | ||
} | ||
} | ||
|
||
func TestCanGetAddressBlack(t *testing.T) { | ||
aliceAddress, err1 := sdk.AccAddressFromBech32(alice) | ||
black, err2 := GetStoredGame1().GetBlackAddress() | ||
require.Equal(t, aliceAddress, black) | ||
require.Nil(t, err2) | ||
require.Nil(t, err1) | ||
} | ||
|
||
func TestGetAddressWrongBlack(t *testing.T) { | ||
storedGame := GetStoredGame1() | ||
storedGame.Black = "cosmos1jmjfq0tplp9tmx4v9uemw72y4d2wa5nr3xn9d4" // Bad last digit | ||
black, err := storedGame.GetBlackAddress() | ||
require.Nil(t, black) | ||
require.EqualError(t, | ||
err, | ||
"black address is invalid: cosmos1jmjfq0tplp9tmx4v9uemw72y4d2wa5nr3xn9d4: decoding bech32 failed: invalid checksum (expected 3xn9d3 got 3xn9d4)") | ||
require.EqualError(t, storedGame.Validate(), err.Error()) | ||
} | ||
|
||
func TestCanGetAddressRed(t *testing.T) { | ||
bobAddress, err1 := sdk.AccAddressFromBech32(alice) | ||
red, err2 := GetStoredGame1().GetBlackAddress() | ||
require.Equal(t, bobAddress, red) | ||
require.Nil(t, err2) | ||
require.Nil(t, err1) | ||
} |
Oops, something went wrong.