-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add fee grant query * feat: add unit test
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters