Skip to content

Commit

Permalink
implement request-response pattern for ListAdmins and update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
damiramirez committed Jan 24, 2025
1 parent b0818df commit b01efd5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
18 changes: 13 additions & 5 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,22 @@ func (r *ChainReader) ListPendingAdmins(

func (r *ChainReader) ListAdmins(
ctx context.Context,
accountAddress gethcommon.Address,
) ([]gethcommon.Address, error) {
pendingAdmins, err := r.permissionController.GetAdmins(&bind.CallOpts{Context: ctx}, accountAddress)
blockNumber *big.Int,
request ListAdminsRequest,
) (ListAdminsResponse, error) {
if r.permissionController == nil {
return ListAdminsResponse{}, errors.New("PermissionController contract not provided")
}

admins, err := r.permissionController.GetAdmins(
&bind.CallOpts{Context: ctx, BlockNumber: blockNumber},
request.AccountAddress,
)
// This call should not fail since it's a getter
if err != nil {
return nil, utils.WrapError("call to permission controller failed", err)
return ListAdminsResponse{}, utils.WrapError("call to permission controller failed", err)
}
return pendingAdmins, nil
return ListAdminsResponse{Admins: admins}, nil
}

func (r *ChainReader) IsPendingAdmin(
Expand Down
9 changes: 6 additions & 3 deletions chainio/clients/elcontracts/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,14 @@ func TestAdminFunctions(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, receipt.Status, gethtypes.ReceiptStatusSuccessful)

listAdmins, err := chainReader.ListAdmins(context.Background(), operatorAddr)
requestAdmin := elcontracts.ListAdminsRequest{
AccountAddress: operatorAddr,
}
response, err := chainReader.ListAdmins(context.Background(), nil, requestAdmin)
assert.NoError(t, err)
assert.Len(t, listAdmins, 1)
assert.Len(t, response.Admins, 1)

admin := listAdmins[0]
admin := response.Admins[0]
isAdmin, err := chainReader.IsAdmin(context.Background(), operatorAddr, admin)
assert.NoError(t, err)
assert.True(t, isAdmin)
Expand Down
8 changes: 8 additions & 0 deletions chainio/clients/elcontracts/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,11 @@ type ListPendingAdminsRequest struct {
type ListPendingAdminsResponse struct {
PendingAdmins []common.Address
}

type ListAdminsRequest struct {
AccountAddress common.Address
}

type ListAdminsResponse struct {
Admins []common.Address
}

0 comments on commit b01efd5

Please sign in to comment.