Skip to content

Commit

Permalink
Merge pull request #561 from KiraCore/release/v0.3.30
Browse files Browse the repository at this point in the history
  • Loading branch information
asmodat authored Sep 18, 2023
2 parents 8f88e37 + 875f6a2 commit e98c099
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Features:

- Add a gov gRPC endpoint & CLI for querying custom prefixes
- Remove abandoned record ids from request records.
2 changes: 1 addition & 1 deletion types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package types
const (
// we set page iteration limit for safety
PageIterationLimit = 512
SekaiVersion = "v0.3.29"
SekaiVersion = "v0.3.30"
CosmosVersion = "v0.45.10"
)
37 changes: 37 additions & 0 deletions x/gov/keeper/identity_registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,37 @@ func (k Keeper) DeleteIdentityRecords(ctx sdk.Context, address sdk.AccAddress, k
}
}

recordIdMap := make(map[uint64]bool)
for _, recordId := range recordIds {
prevRecord := k.GetIdentityRecordById(ctx, recordId)
if prevRecord == nil {
return sdkerrors.Wrap(types.ErrInvalidIdentityRecordId, fmt.Sprintf("identity record with specified id does NOT exist: id=%d", recordId))
}

recordIdMap[recordId] = true
k.DeleteIdentityRecordById(ctx, recordId)
}

// remove record ids from verification request list
requests := k.GetIdRecordsVerifyRequestsByRequester(ctx, address)
for _, request := range requests {
recordIds := []uint64{}
for _, recordid := range request.RecordIds {
if !recordIdMap[recordid] {
recordIds = append(recordIds, recordid)
}
}

if len(recordIds) == 0 {
err := k.CancelIdentityRecordsVerifyRequest(ctx, sdk.MustAccAddressFromBech32(request.Address), request.Id)
if err != nil {
return err
}
} else {
request.RecordIds = recordIds
k.SetIdentityRecordsVerifyRequest(ctx, request)
}
}
return nil
}

Expand Down Expand Up @@ -351,6 +373,21 @@ func (k Keeper) SetIdentityRecordsVerifyRequest(ctx sdk.Context, request types.I
// RequestIdentityRecordsVerify defines a method to request verify request from specific verifier
func (k Keeper) RequestIdentityRecordsVerify(ctx sdk.Context, address, verifier sdk.AccAddress, recordIds []uint64, tip sdk.Coin) (uint64, error) {
requestId := k.GetLastIdRecordVerifyRequestId(ctx) + 1
store := ctx.KVStore(k.storeKey)
prefix := types.IdentityRecordByAddressPrefix(address.String())
iterator := sdk.KVStorePrefixIterator(store, prefix)
defer iterator.Close()

idsMap := make(map[uint64]bool)
for ; iterator.Valid(); iterator.Next() {
idsMap[sdk.BigEndianToUint64(iterator.Value())] = true
}

for _, recordId := range recordIds {
if !idsMap[recordId] {
return requestId, sdkerrors.Wrap(types.ErrInvalidIdentityRecordId, fmt.Sprintf("executor is not owner of the identity record: id=%d", recordId))
}
}

lastRecordEditDate := time.Time{}
for _, recordId := range recordIds {
Expand Down
16 changes: 8 additions & 8 deletions x/gov/keeper/identity_registrar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,12 @@ func TestKeeper_IdentityRecordApproveFlow(t *testing.T) {
Verifiers: []string{addr3.String()},
})

// request id record 1 and 2 to addr3 by addr1 again
reqId, err = app.CustomGovKeeper.RequestIdentityRecordsVerify(ctx, addr1, addr3, []uint64{1, 2}, sdk.NewInt64Coin(sdk.DefaultBondDenom, 200))
// request id record 2 to addr3 by addr1 again
reqId, err = app.CustomGovKeeper.RequestIdentityRecordsVerify(ctx, addr2, addr3, []uint64{2}, sdk.NewInt64Coin(sdk.DefaultBondDenom, 200))
require.Equal(t, reqId, uint64(3))
require.NoError(t, err)
coins = app.BankKeeper.GetAllBalances(ctx, addr1)
require.Equal(t, coins, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 9400)})
coins = app.BankKeeper.GetAllBalances(ctx, addr2)
require.Equal(t, coins, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 9800)})
err = app.CustomGovKeeper.HandleIdentityRecordsVerifyRequest(ctx, addr3, 3, true)
require.NoError(t, err)
coins = app.BankKeeper.GetAllBalances(ctx, addr3)
Expand Down Expand Up @@ -534,11 +534,11 @@ func TestKeeper_IdentityRecordApproveFlow(t *testing.T) {

// check get queries
requests := app.CustomGovKeeper.GetIdRecordsVerifyRequestsByRequester(ctx, addr1)
require.Len(t, requests, 1)
require.Len(t, requests, 0)
requests = app.CustomGovKeeper.GetIdRecordsVerifyRequestsByApprover(ctx, addr1)
require.Len(t, requests, 0)
requests = app.CustomGovKeeper.GetAllIdRecordsVerifyRequests(ctx)
require.Len(t, requests, 1)
require.Len(t, requests, 0)

// remove all and query again
app.CustomGovKeeper.DeleteIdRecordsVerifyRequest(ctx, 5)
Expand All @@ -550,7 +550,7 @@ func TestKeeper_IdentityRecordApproveFlow(t *testing.T) {
require.Equal(t, reqId, uint64(6))
require.NoError(t, err)
coins = app.BankKeeper.GetAllBalances(ctx, addr2)
require.Equal(t, coins, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 9600)})
require.Equal(t, coins, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 9400)})
cacheCtx, _ := ctx.CacheContext()
err = app.CustomGovKeeper.CancelIdentityRecordsVerifyRequest(cacheCtx, addr3, 6)
require.Error(t, err)
Expand All @@ -559,7 +559,7 @@ func TestKeeper_IdentityRecordApproveFlow(t *testing.T) {
request = app.CustomGovKeeper.GetIdRecordsVerifyRequest(ctx, 6)
require.Nil(t, request)
coins = app.BankKeeper.GetAllBalances(ctx, addr2)
require.Equal(t, coins, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 9800)})
require.Equal(t, coins, sdk.Coins{sdk.NewInt64Coin(sdk.DefaultBondDenom, 9600)})

// try deleting request after request creation
reqId, err = app.CustomGovKeeper.RequestIdentityRecordsVerify(ctx, addr2, addr3, []uint64{2}, sdk.NewInt64Coin(sdk.DefaultBondDenom, 200))
Expand Down

0 comments on commit e98c099

Please sign in to comment.