-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d93984
commit 576bf2a
Showing
5 changed files
with
123 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
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,58 @@ | ||
import { Tendermint34Client } from "@cosmjs/tendermint-rpc"; | ||
|
||
import { QueryClient } from "../"; | ||
import { pendingWithoutSimapp, simapp } from "../testutils.spec"; | ||
import { MintExtension, setupMintExtension } from "./mint"; | ||
|
||
async function makeClientWithMint( | ||
rpcUrl: string, | ||
): Promise<[QueryClient & MintExtension, Tendermint34Client]> { | ||
const tmClient = await Tendermint34Client.connect(rpcUrl); | ||
return [QueryClient.withExtensions(tmClient, setupMintExtension), tmClient]; | ||
} | ||
|
||
describe("MintExtension", () => { | ||
describe("params", () => { | ||
it("works", async () => { | ||
pendingWithoutSimapp(); | ||
const [client, tmClient] = await makeClientWithMint(simapp.tendermintUrl); | ||
|
||
const params = await client.mint.params(); | ||
expect(params.blocksPerYear.toNumber()).toBeGreaterThan(100_000); | ||
expect(params.blocksPerYear.toNumber()).toBeLessThan(100_000_000); | ||
expect(params.goalBonded.toString()).toEqual("0.67"); | ||
expect(params.inflationMin.toString()).toEqual("0.07"); | ||
expect(params.inflationMax.toString()).toEqual("0.2"); | ||
expect(params.inflationRateChange.toString()).toEqual("0.13"); | ||
expect(params.mintDenom).toEqual(simapp.denomStaking); | ||
|
||
tmClient.disconnect(); | ||
}); | ||
}); | ||
|
||
describe("inflation", () => { | ||
it("works", async () => { | ||
pendingWithoutSimapp(); | ||
const [client, tmClient] = await makeClientWithMint(simapp.tendermintUrl); | ||
|
||
const inflation = await client.mint.inflation(); | ||
expect(inflation.toFloatApproximation()).toBeGreaterThan(0.13); | ||
expect(inflation.toFloatApproximation()).toBeLessThan(0.1301); | ||
|
||
tmClient.disconnect(); | ||
}); | ||
}); | ||
|
||
describe("annualProvisions", () => { | ||
it("works", async () => { | ||
pendingWithoutSimapp(); | ||
const [client, tmClient] = await makeClientWithMint(simapp.tendermintUrl); | ||
|
||
const annualProvisions = await client.mint.annualProvisions(); | ||
expect(annualProvisions.toFloatApproximation()).toBeGreaterThan(5_400_000_000); | ||
expect(annualProvisions.toFloatApproximation()).toBeLessThan(5_500_000_000); | ||
|
||
tmClient.disconnect(); | ||
}); | ||
}); | ||
}); |
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,60 @@ | ||
import { Decimal } from "@cosmjs/math"; | ||
import { assert } from "@cosmjs/utils"; | ||
import { Params } from "cosmjs-types/cosmos/mint/v1beta1/mint"; | ||
import { QueryClientImpl } from "cosmjs-types/cosmos/mint/v1beta1/query"; | ||
|
||
import { createProtobufRpcClient } from "../"; | ||
import { QueryClient } from "./queryclient"; | ||
import { decodeCosmosSdkDecFromProto } from "./utils"; | ||
|
||
/** | ||
* Like Params from "cosmjs-types/cosmos/mint/v1beta1/mint" | ||
* but using decimal types. | ||
*/ | ||
export interface MintParams extends Pick<Params, "blocksPerYear" | "mintDenom"> { | ||
readonly goalBonded: Decimal; | ||
readonly inflationMin: Decimal; | ||
readonly inflationMax: Decimal; | ||
readonly inflationRateChange: Decimal; | ||
} | ||
|
||
export interface MintExtension { | ||
readonly mint: { | ||
readonly params: () => Promise<MintParams>; | ||
readonly inflation: () => Promise<Decimal>; | ||
readonly annualProvisions: () => Promise<Decimal>; | ||
}; | ||
} | ||
|
||
export function setupMintExtension(base: QueryClient): MintExtension { | ||
const rpc = createProtobufRpcClient(base); | ||
// Use this service to get easy typed access to query methods | ||
// This cannot be used for proof verification | ||
const queryService = new QueryClientImpl(rpc); | ||
|
||
return { | ||
mint: { | ||
params: async (): Promise<MintParams> => { | ||
const { params } = await queryService.Params({}); | ||
assert(params); | ||
|
||
return { | ||
blocksPerYear: params.blocksPerYear, | ||
goalBonded: decodeCosmosSdkDecFromProto(params.goalBonded), | ||
inflationMin: decodeCosmosSdkDecFromProto(params.inflationMin), | ||
inflationMax: decodeCosmosSdkDecFromProto(params.inflationMax), | ||
inflationRateChange: decodeCosmosSdkDecFromProto(params.inflationRateChange), | ||
mintDenom: params.mintDenom, | ||
}; | ||
}, | ||
inflation: async () => { | ||
const { inflation } = await queryService.Inflation({}); | ||
return decodeCosmosSdkDecFromProto(inflation); | ||
}, | ||
annualProvisions: async () => { | ||
const { annualProvisions } = await queryService.AnnualProvisions({}); | ||
return decodeCosmosSdkDecFromProto(annualProvisions); | ||
}, | ||
}, | ||
}; | ||
} |