feat: getEpochInfo rpc, yarn lint (#540)
This commit is contained in:
committed by
Michael Vines
parent
29aabcb195
commit
3f38e89886
@ -87,6 +87,23 @@ const GetInflationResult = struct({
|
|||||||
terminal: 'number',
|
terminal: 'number',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EpochInfo parameters
|
||||||
|
* (see https://docs.solana.com/book/v/master/terminology#epoch)
|
||||||
|
*
|
||||||
|
* @typedef {Object} EpochInfo
|
||||||
|
* @property {number} epoch
|
||||||
|
* @property {number} slotIndex
|
||||||
|
* @property {number} slotsInEpoch
|
||||||
|
* @property {number} absoluteSlot
|
||||||
|
*/
|
||||||
|
const GetEpochInfoResult = struct({
|
||||||
|
epoch: 'number',
|
||||||
|
slotIndex: 'number',
|
||||||
|
slotsInEpoch: 'number',
|
||||||
|
absoluteSlot: 'number',
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* EpochSchedule parameters
|
* EpochSchedule parameters
|
||||||
* (see https://docs.solana.com/book/v/master/terminology#epoch)
|
* (see https://docs.solana.com/book/v/master/terminology#epoch)
|
||||||
@ -148,6 +165,16 @@ const GetInflationRpcResult = struct({
|
|||||||
result: GetInflationResult,
|
result: GetInflationResult,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expected JSON RPC response for the "getEpochInfo" message
|
||||||
|
*/
|
||||||
|
const GetEpochInfoRpcResult = struct({
|
||||||
|
jsonrpc: struct.literal('2.0'),
|
||||||
|
id: 'string',
|
||||||
|
error: 'any?',
|
||||||
|
result: GetEpochInfoResult,
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expected JSON RPC response for the "getEpochSchedule" message
|
* Expected JSON RPC response for the "getEpochSchedule" message
|
||||||
*/
|
*/
|
||||||
@ -718,6 +745,19 @@ export class Connection {
|
|||||||
return GetInflationResult(res.result);
|
return GetInflationResult(res.result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch the Epoch Info parameters
|
||||||
|
*/
|
||||||
|
async getEpochInfo(): Promise<GetEpochInfoRpcResult> {
|
||||||
|
const unsafeRes = await this._rpcRequest('getEpochInfo', []);
|
||||||
|
const res = GetEpochInfoRpcResult(unsafeRes);
|
||||||
|
if (res.error) {
|
||||||
|
throw new Error(res.error.message);
|
||||||
|
}
|
||||||
|
assert(typeof res.result !== 'undefined');
|
||||||
|
return GetEpochInfoResult(res.result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the Epoch Schedule parameters
|
* Fetch the Epoch Schedule parameters
|
||||||
*/
|
*/
|
||||||
|
@ -170,6 +170,34 @@ test('get inflation', async () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('get epoch info', async () => {
|
||||||
|
const connection = new Connection(url);
|
||||||
|
|
||||||
|
mockRpc.push([
|
||||||
|
url,
|
||||||
|
{
|
||||||
|
method: 'getEpochInfo',
|
||||||
|
params: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
error: null,
|
||||||
|
result: {
|
||||||
|
epoch: 1,
|
||||||
|
slotIndex: 1,
|
||||||
|
slotsInEpoch: 8192,
|
||||||
|
absoluteSlot: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
const epochInfo = await connection.getEpochInfo();
|
||||||
|
|
||||||
|
for (const key of ['epoch', 'slotIndex', 'slotsInEpoch', 'absoluteSlot']) {
|
||||||
|
expect(epochInfo).toHaveProperty(key);
|
||||||
|
expect(epochInfo[key]).toBeGreaterThan(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('get epoch schedule', async () => {
|
test('get epoch schedule', async () => {
|
||||||
const connection = new Connection(url);
|
const connection = new Connection(url);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user