Skip to content

Commit

Permalink
cleaning up more code and adding optional args
Browse files Browse the repository at this point in the history
  • Loading branch information
muku314115 committed Nov 6, 2023
1 parent 4f84495 commit a9cec17
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
9 changes: 7 additions & 2 deletions testutil/keeper/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import (
)

// CreateCoordinator creates a coordinator in the store and returns ID with associated address
func (tm TestMsgServers) CreateCoordinator(ctx context.Context, r *rand.Rand) (id uint64, address sdk.AccAddress) {
addr := sample.AccAddress(r)
func (tm TestMsgServers) CreateCoordinator(ctx context.Context, r *rand.Rand, optionalAddress ...string) (id uint64, address sdk.AccAddress) {
var addr sdk.AccAddress
if optionalAddress == nil {
addr = sample.AccAddress(r)
} else {
addr = sdk.MustAccAddressFromBech32(optionalAddress[0])
}
res, err := tm.ProfileSrv.CreateCoordinator(ctx, &profiletypes.MsgCreateCoordinator{
Address: addr.String(),
Description: sample.CoordinatorDescription(r),
Expand Down
16 changes: 4 additions & 12 deletions x/launch/keeper/msg_create_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,28 +58,20 @@ func TestMsgCreateChain(t *testing.T) {
)

// Create an invalid coordinator
invalidCoordAddress := sample.Address(r)
msgCreateInvalidCoordinator := sample.MsgCreateCoordinator(invalidCoordAddress)
_, err := ts.ProfileSrv.CreateCoordinator(ctx, &msgCreateInvalidCoordinator)
require.NoError(t, err)
_, invalidCoordAddr := ts.CreateCoordinator(ctx, r)
invalidCoordAddress := invalidCoordAddr.String()

// Create coordinators
for i := range coordAddrs {
addr := sample.Address(r)
coordAddrs[i] = addr
msgCreateCoordinator := sample.MsgCreateCoordinator(addr)
resCoord, err := ts.ProfileSrv.CreateCoordinator(ctx, &msgCreateCoordinator)
require.NoError(t, err)
coordMap[addr] = resCoord.CoordinatorID
coordMap[addr], _ = ts.CreateCoordinator(ctx, r, addr)
}

// Create a project for each valid coordinator
for i := range coordAddrs {
addr := coordAddrs[i]
msgCreateProject := sample.MsgCreateProject(r, addr)
resProject, err := ts.ProjectSrv.CreateProject(ctx, &msgCreateProject)
require.NoError(t, err)
prjtMap[addr] = resProject.ProjectID
prjtMap[addr] = ts.CreateProject(ctx, r, addr)
}

// assign random sdk.Coins to `chainCreationFee` param and provide balance to coordinators
Expand Down
5 changes: 1 addition & 4 deletions x/project/keeper/msg_create_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@ func TestMsgCreateProject(t *testing.T) {
for i := range coordAddrs {
addr := sample.Address(r)
coordAddrs[i] = addr
msgCreateCoordinator := sample.MsgCreateCoordinator(addr)
resCoord, err := ts.ProfileSrv.CreateCoordinator(ctx, &msgCreateCoordinator)
require.NoError(t, err)
coordMap[addr] = resCoord.CoordinatorID
coordMap[addr], _ = ts.CreateCoordinator(ctx, r, addr)
}
})

Expand Down

0 comments on commit a9cec17

Please sign in to comment.