wasm_client_solana/methods/
get_epoch_schedule.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use serde::Deserialize;
use serde::Serialize;
use solana_sdk::epoch_schedule::EpochSchedule;

use crate::impl_http_method;

#[derive(Debug, Serialize, Deserialize)]
pub struct GetEpochScheduleRequest;

impl_http_method!(GetEpochScheduleRequest, "getEpochSchedule");

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct GetEpochScheduleResponse(EpochSchedule);

impl From<GetEpochScheduleResponse> for EpochSchedule {
	fn from(value: GetEpochScheduleResponse) -> Self {
		value.0
	}
}

#[cfg(test)]
mod tests {
	use assert2::check;

	use super::*;
	use crate::ClientRequest;
	use crate::ClientResponse;
	use crate::methods::HttpMethod;

	#[test]
	fn request() {
		let request = ClientRequest::builder()
			.method(GetEpochScheduleRequest::NAME)
			.id(1)
			.params(GetEpochScheduleRequest)
			.build();

		insta::assert_compact_json_snapshot!(request, @r###"{"jsonrpc": "2.0", "id": 1, "method": "getEpochSchedule"}"###);
	}

	#[test]
	fn response() {
		let raw_json = r#"{"jsonrpc":"2.0","result":{"firstNormalEpoch":8,"firstNormalSlot":8160,"leaderScheduleSlotOffset":8192,"slotsPerEpoch":8192,"warmup":true},"id":1}"#;

		let response: ClientResponse<GetEpochScheduleResponse> =
			serde_json::from_str(raw_json).unwrap();

		check!(response.id == 1);
		check!(response.jsonrpc == "2.0");

		let value = response.result.0;
		check!(value.first_normal_epoch == 8);
		check!(value.first_normal_slot == 8160);
		check!(value.leader_schedule_slot_offset == 8192);
		check!(value.slots_per_epoch == 8192);
		check!(value.warmup);
	}
}