Skip to content

Commit

Permalink
feat: add fee grant query (#200)
Browse files Browse the repository at this point in the history
* feat: add fee grant query
* feat: add unit test
  • Loading branch information
ALPAC-4 authored Jan 6, 2022
1 parent 3fe9412 commit 57a3bd1
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/client/lcd/LCDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AuthAPI,
BankAPI,
DistributionAPI,
FeeGrantAPI,
GovAPI,
MarketAPI,
MintAPI,
Expand Down Expand Up @@ -86,6 +87,7 @@ export class LCDClient {
public auth: AuthAPI;
public bank: BankAPI;
public distribution: DistributionAPI;
public feeGrant: FeeGrantAPI;
public gov: GovAPI;
public market: MarketAPI;
public mint: MintAPI;
Expand Down Expand Up @@ -120,6 +122,7 @@ export class LCDClient {
this.auth = new AuthAPI(this.apiRequester);
this.bank = new BankAPI(this.apiRequester);
this.distribution = new DistributionAPI(this.apiRequester);
this.feeGrant = new FeeGrantAPI(this.apiRequester);
this.gov = new GovAPI(this.apiRequester);
this.market = new MarketAPI(this.apiRequester);
this.mint = new MintAPI(this.apiRequester);
Expand Down
44 changes: 44 additions & 0 deletions src/client/lcd/api/FeeGrantAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { APIRequester } from '../APIRequester';
import { FeeGrantAPI } from './FeeGrantAPI';

const c = new APIRequester('https://bombay-lcd.terra.dev/');
const feeGrant = new FeeGrantAPI(c);

describe('FeeGrantAPI', () => {
it('allowances', async () => {
const res = await feeGrant.allowances(
'terra1p204wtykwke52hcyt6vdh630725rdayczyzcvz'
);

expect(res.allowances[0]).toMatchObject({
granter: expect.any(String),
grantee: expect.any(String),
});

const allowanceData = res.allowances[0].allowance.toData();
expect(allowanceData['@type']).toMatch(/cosmos.feegrant.v1beta1/g);

expect(res.pagination).not.toBeUndefined();
});

describe('allowance', () => {
it('allowance exist', async () => {
const res = await feeGrant.allowance(
'terra13ggppncs97f4cl90fvxqelflg0upedd0n7rnd3',
'terra1p204wtykwke52hcyt6vdh630725rdayczyzcvz'
);

const allowanceData = res.toData();
expect(allowanceData['@type']).toMatch(/cosmos.feegrant.v1beta1/g);
});

it('allowance not exist', async () => {
expect(
feeGrant.allowance(
'terra1p204wtykwke52hcyt6vdh630725rdayczyzcvz',
'terra13ggppncs97f4cl90fvxqelflg0upedd0n7rnd3'
)
).rejects.toThrow();
});
});
});
51 changes: 51 additions & 0 deletions src/client/lcd/api/FeeGrantAPI.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { AccAddress } from '../../../core';
import { BaseAPI } from './BaseAPI';
import { Allowance } from '../../../core/feegrant/allowances';
import { Pagination, PaginationOptions } from '../APIRequester';

export class FeeGrantAPI extends BaseAPI {
public async allowances(
grantee: AccAddress,
params: Partial<PaginationOptions> = {}
): Promise<{
allowances: {
granter: AccAddress;
grantee: AccAddress;
allowance: Allowance;
}[];
pagination: Pagination;
}> {
return this.c
.get<{
allowances: {
granter: AccAddress;
grantee: AccAddress;
allowance: Allowance.Data;
}[];
pagination: Pagination;
}>(`/cosmos/feegrant/v1beta1/allowances/${grantee}`, params)
.then(d => ({
allowances: d.allowances.map(allowance => ({
granter: allowance.granter,
grantee: allowance.grantee,
allowance: Allowance.fromData(allowance.allowance),
})),
pagination: d.pagination,
}));
}

public async allowance(
granter: AccAddress,
grantee: AccAddress
): Promise<Allowance> {
return this.c
.get<{
allowance: {
granter: AccAddress;
grantee: AccAddress;
allowance: Allowance.Data;
};
}>(`/cosmos/feegrant/v1beta1/allowance/${granter}/${grantee}`)
.then(d => Allowance.fromData(d.allowance.allowance));
}
}
1 change: 1 addition & 0 deletions src/client/lcd/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './AuthAPI';
export * from './BankAPI';
export * from './DistributionAPI';
export * from './FeeGrantAPI';
export * from './GovAPI';
export * from './MarketAPI';
export * from './AuthzAPI';
Expand Down

0 comments on commit 57a3bd1

Please sign in to comment.