Skip to content

Commit

Permalink
CNS-352: fix calls to ProjectDelete() in testing
Browse files Browse the repository at this point in the history
Signed-off-by: Oren Laadan <orenl@lavanet.xyz>
  • Loading branch information
orenl-lava committed Apr 10, 2023
1 parent 9d27944 commit bc092a9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
37 changes: 30 additions & 7 deletions x/pairing/keeper/pairing_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,55 @@ import (
func TestGetPairingForSubscription(t *testing.T) {
ts := setupForPaymentTest(t)
var balance int64 = 10000
consumer := common.CreateNewAccount(ts.ctx, *ts.keepers, balance)

consumer := common.CreateNewAccount(ts.ctx, *ts.keepers, balance).Addr.String()
vrfpk_stub := "testvrfpk"
_, err := ts.servers.SubscriptionServer.Buy(ts.ctx, &subtypes.MsgBuy{Creator: consumer.Addr.String(), Consumer: consumer.Addr.String(), Index: ts.plan.Index, Duration: 1, Vrfpk: vrfpk_stub})
msgBuy := &subtypes.MsgBuy{
Creator: consumer,
Consumer: consumer,
Index: ts.plan.Index,
Duration: 1,
Vrfpk: vrfpk_stub,
}
_, err := ts.servers.SubscriptionServer.Buy(ts.ctx, msgBuy)
require.Nil(t, err)

ts.ctx = testkeeper.AdvanceEpoch(ts.ctx, ts.keepers)
ctx := sdk.UnwrapSDKContext(ts.ctx)

pairingReq := types.QueryGetPairingRequest{ChainID: ts.spec.Index, Client: consumer.Addr.String()}
pairingReq := types.QueryGetPairingRequest{
ChainID: ts.spec.Index,
Client: consumer,
}
pairing, err := ts.keepers.Pairing.GetPairing(ts.ctx, &pairingReq)
require.Nil(t, err)

verifyPairingQuery := &types.QueryVerifyPairingRequest{ChainID: ts.spec.Index, Client: consumer.Addr.String(), Provider: pairing.Providers[0].Address, Block: uint64(sdk.UnwrapSDKContext(ts.ctx).BlockHeight())}
verifyPairingQuery := &types.QueryVerifyPairingRequest{
ChainID: ts.spec.Index,
Client: consumer,
Provider: pairing.Providers[0].Address,
Block: uint64(ctx.BlockHeight()),
}
vefiry, err := ts.keepers.Pairing.VerifyPairing(ts.ctx, verifyPairingQuery)
require.Nil(t, err)
require.True(t, vefiry.Valid)

project, vrfpk, err := ts.keepers.Projects.GetProjectForDeveloper(sdk.UnwrapSDKContext(ts.ctx), consumer.Addr.String(), uint64(sdk.UnwrapSDKContext(ts.ctx).BlockHeight()))
project, vrfpk, err := ts.keepers.Projects.GetProjectForDeveloper(ctx, consumer, uint64(ctx.BlockHeight()))
require.Nil(t, err)
require.Equal(t, vrfpk, vrfpk_stub)
err = ts.keepers.Projects.DeleteProject(sdk.UnwrapSDKContext(ts.ctx), project.Index)

err = ts.keepers.Projects.DeleteProject(ctx, project.Index)
require.Nil(t, err)

_, err = ts.keepers.Pairing.GetPairing(ts.ctx, &pairingReq)
require.NotNil(t, err)

verifyPairingQuery = &types.QueryVerifyPairingRequest{ChainID: ts.spec.Index, Client: consumer.Addr.String(), Provider: pairing.Providers[0].Address, Block: uint64(sdk.UnwrapSDKContext(ts.ctx).BlockHeight())}
verifyPairingQuery = &types.QueryVerifyPairingRequest{
ChainID: ts.spec.Index,
Client: consumer,
Provider: pairing.Providers[0].Address,
Block: uint64(ctx.BlockHeight()),
}
vefiry, err = ts.keepers.Pairing.VerifyPairing(ts.ctx, verifyPairingQuery)
require.NotNil(t, err)
require.False(t, vefiry.Valid)
Expand Down
8 changes: 6 additions & 2 deletions x/subscription/keeper/subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,10 @@ func TestExpiryTime(t *testing.T) {
require.Equal(t, tt.months, sub.DurationTotal)

keeper.RemoveSubscription(ts.ctx, creator)

// TODO: remove when RemoveSubscriptions properly removes projects
ts.keepers.Projects.DeleteProject(ts.ctx, projectstypes.ProjectIndex(creator, "default"))
projectID := projectstypes.ProjectIndex(creator, projectstypes.ADMIN_PROJECT_NAME)
ts.keepers.Projects.DeleteProject(ts.ctx, projectID)
})
}
}
Expand Down Expand Up @@ -467,8 +469,10 @@ func TestPrice(t *testing.T) {
require.Equal(t, balance.Amount.Int64(), int64(10000-tt.cost))

keeper.RemoveSubscription(ts.ctx, creator)

// TODO: remove when RemoveSubscriptions properly removes projects
ts.keepers.Projects.DeleteProject(ts.ctx, projectstypes.ProjectIndex(creator, "default"))
projectID := projectstypes.ProjectIndex(creator, projectstypes.ADMIN_PROJECT_NAME)
ts.keepers.Projects.DeleteProject(ts.ctx, projectID)
})
}
}

0 comments on commit bc092a9

Please sign in to comment.