Skip to content

Commit

Permalink
Review changes taken into account
Browse files Browse the repository at this point in the history
  • Loading branch information
suhasagg committed Mar 21, 2019
1 parent 075a468 commit d3a1bb6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions builtin/plugins/karma/karma.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (k *Karma) GetUserState(ctx contract.StaticContext, req *ktypes.GetUserStat
if err != nil {
return nil, err
}
userStateResponse := ktypes.GetUserStateResponse{Karmastate: curState}
userStateResponse := ktypes.GetUserStateResponse{UserState: curState}
return &userStateResponse, nil
}

Expand Down Expand Up @@ -272,7 +272,7 @@ func (k *Karma) ResetSources(ctx contract.Context, req *ktypes.SetAllowedKarmaSo
return ErrNotAuthorized
}

kpo := req.Karmasources
kpo := req.Sources

if err := SetAllowedKarmaSources(ctx, kpo.Sources); err != nil {
return errors.Wrap(err, "failed to set allowed karma sources")
Expand Down
24 changes: 12 additions & 12 deletions builtin/plugins/karma/karma_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestKarmaInit(t *testing.T) {
require.True(t, ctx.Has(key))
userStateResp, err := contract.GetUserState(ctx, &userStateRequest)
require.NoError(t, err)
require.Equal(t, len(sourceStates), len(userStateResp.Karmastate.SourceStates))
require.Equal(t, len(sourceStates), len(userStateResp.UserState.SourceStates))
}
config, err := contract.GetConfig(ctx, &ktypes.GetConfigRequest{})
require.NoError(t, err)
Expand Down Expand Up @@ -205,9 +205,9 @@ func TestKarmaCoin(t *testing.T) {

userState, err = karmaContract.GetUserState(ctx, &userStateRequest)
require.NoError(t, err)
require.Equal(t, 1, len(userState.Karmastate.SourceStates))
require.Equal(t, CoinDeployToken, userState.Karmastate.SourceStates[0].Name)
require.Equal(t, int64(17), userState.Karmastate.SourceStates[0].Count.Value.Int64())
require.Equal(t, 1, len(userState.UserState.SourceStates))
require.Equal(t, CoinDeployToken, userState.UserState.SourceStates[0].Name)
require.Equal(t, int64(17), userState.UserState.SourceStates[0].Count.Value.Int64())

err = karmaContract.WithdrawCoin(ctx, &ktypes.KarmaUserAmount{User: user, Amount: &types.BigUInt{Value: *loom.NewBigUIntFromInt(5)}})
require.NoError(t, err)
Expand All @@ -218,9 +218,9 @@ func TestKarmaCoin(t *testing.T) {

userState, err = karmaContract.GetUserState(ctx, &userStateRequest)
require.NoError(t, err)
require.Equal(t, 1, len(userState.Karmastate.SourceStates))
require.Equal(t, CoinDeployToken, userState.Karmastate.SourceStates[0].Name)
require.Equal(t, int64(12), userState.Karmastate.SourceStates[0].Count.Value.Int64())
require.Equal(t, 1, len(userState.UserState.SourceStates))
require.Equal(t, CoinDeployToken, userState.UserState.SourceStates[0].Name)
require.Equal(t, int64(12), userState.UserState.SourceStates[0].Count.Value.Int64())

total, err := karmaContract.GetUserKarma(ctx, &ktypes.KarmaUserTarget{
User: user,
Expand Down Expand Up @@ -256,8 +256,8 @@ func TestKarmaLifeCycleTest(t *testing.T) {
state, err := contract.GetUserState(ctx, &userStateRequest)
require.NoError(t, err)
for k := range extremeSourceStates {
require.Equal(t, extremeSourceStates[k].Name, state.Karmastate.SourceStates[k].Name)
require.Equal(t, 0, extremeSourceStates[k].Count.Value.Cmp(&state.Karmastate.SourceStates[k].Count.Value))
require.Equal(t, extremeSourceStates[k].Name, state.UserState.SourceStates[k].Name)
require.Equal(t, 0, extremeSourceStates[k].Count.Value.Cmp(&state.UserState.SourceStates[k].Count.Value))
}

// GetUserState after UpdateSourcesForUser and also MaxKarma Test to test the change
Expand All @@ -278,7 +278,7 @@ func TestKarmaLifeCycleTest(t *testing.T) {
// GetUserState after DeleteSourcesForUser Test
state, err = contract.GetUserState(ctx, &userStateRequest)
require.NoError(t, err)
require.Equal(t, []*ktypes.KarmaSource{{Name: "token", Count: &types.BigUInt{Value: *loom.NewBigUIntFromInt(10)}}}, state.Karmastate.SourceStates)
require.Equal(t, []*ktypes.KarmaSource{{Name: "token", Count: &types.BigUInt{Value: *loom.NewBigUIntFromInt(10)}}}, state.UserState.SourceStates)

// GetTotal after DeleteSourcesForUser Test to test the change
karmaTotal, err = contract.GetUserKarma(ctx, &ktypes.KarmaUserTarget{
Expand All @@ -293,7 +293,7 @@ func TestKarmaLifeCycleTest(t *testing.T) {
})
require.NoError(t, err)

karmaSourcesRequest := ktypes.SetAllowedKarmaSourcesRequest{Karmasources: &ktypes.KarmaSources{
karmaSourcesRequest := ktypes.SetAllowedKarmaSourcesRequest{Sources: &ktypes.KarmaSources{
Sources: newSources,
}}

Expand All @@ -302,7 +302,7 @@ func TestKarmaLifeCycleTest(t *testing.T) {

ctx2 := contractpb.WrapPluginContext(fakeContext.WithSender(addr2))

karmaSourcesRequest1 := ktypes.SetAllowedKarmaSourcesRequest{Karmasources: &ktypes.KarmaSources{
karmaSourcesRequest1 := ktypes.SetAllowedKarmaSourcesRequest{Sources: &ktypes.KarmaSources{
Sources: newSources,
}}

Expand Down
4 changes: 2 additions & 2 deletions cmd/loom/karma.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func GetUserStateCmd() *cobra.Command {
if err != nil {
return errors.Wrap(err, "static call contract")
}
resp = response.Karmastate
resp = response.UserState
out, err := formatJSON(resp)
if err != nil {
return errors.Wrap(err, "format JSON response")
Expand Down Expand Up @@ -385,7 +385,7 @@ func ResetSourcesCmd() *cobra.Command {
})
}

karmaSourcesRequest := ktypes.SetAllowedKarmaSourcesRequest{Karmasources: &newSources}
karmaSourcesRequest := ktypes.SetAllowedKarmaSourcesRequest{Sources: &newSources}

err := cli.CallContract(KarmaContractName, "ResetSources", &karmaSourcesRequest, nil)
if err != nil {
Expand Down

0 comments on commit d3a1bb6

Please sign in to comment.