From d05c2d4110d24d02c3be35632b0ab1505da36d33 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 2 Sep 2019 13:21:53 +1000 Subject: [PATCH] Start working on u64 json issue --- eth2/types/Cargo.toml | 1 + eth2/types/src/beacon_state/committee_cache/tests.rs | 2 +- eth2/types/src/slot_epoch.rs | 12 ++++++++++++ .../builders/testing_proposer_slashing_builder.rs | 4 ++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/eth2/types/Cargo.toml b/eth2/types/Cargo.toml index 36cfc39ec..95d7a0317 100644 --- a/eth2/types/Cargo.toml +++ b/eth2/types/Cargo.toml @@ -31,3 +31,4 @@ tree_hash_derive = "0.2" [dev-dependencies] env_logger = "0.6.0" +serde_json = "^1.0" diff --git a/eth2/types/src/beacon_state/committee_cache/tests.rs b/eth2/types/src/beacon_state/committee_cache/tests.rs index 28e9d92f8..4c17d3f96 100644 --- a/eth2/types/src/beacon_state/committee_cache/tests.rs +++ b/eth2/types/src/beacon_state/committee_cache/tests.rs @@ -9,7 +9,7 @@ fn default_values() { let cache = CommitteeCache::default(); assert_eq!(cache.is_initialized_at(Epoch::new(0)), false); - assert_eq!(cache.active_validator_indices(), &[]); + assert!(&cache.active_validator_indices().is_empty()); assert_eq!(cache.get_crosslink_committee_for_shard(0), None); assert_eq!(cache.get_attestation_duties(0), None); assert_eq!(cache.active_validator_count(), 0); diff --git a/eth2/types/src/slot_epoch.rs b/eth2/types/src/slot_epoch.rs index bd611aa0c..748d6445f 100644 --- a/eth2/types/src/slot_epoch.rs +++ b/eth2/types/src/slot_epoch.rs @@ -191,4 +191,16 @@ mod epoch_tests { Epoch::from_ssz_bytes(&max_epoch.as_ssz_bytes()).unwrap() ); } + + #[test] + fn epoch_max_value_json() { + let x: Epoch = Epoch::from(u64::max_value()); + let json = serde_json::to_string(&x).expect("should json encode"); + + assert_eq!(&json, "18446744073709552000"); + assert_eq!( + serde_json::from_str::(&json).expect("should json decode"), + x + ); + } } diff --git a/eth2/types/src/test_utils/builders/testing_proposer_slashing_builder.rs b/eth2/types/src/test_utils/builders/testing_proposer_slashing_builder.rs index 6c72b520f..b97293427 100644 --- a/eth2/types/src/test_utils/builders/testing_proposer_slashing_builder.rs +++ b/eth2/types/src/test_utils/builders/testing_proposer_slashing_builder.rs @@ -39,15 +39,15 @@ impl TestingProposerSlashingBuilder { ..header_1.clone() }; + let epoch = slot.epoch(T::slots_per_epoch()); + header_1.signature = { let message = header_1.signed_root(); - let epoch = slot.epoch(T::slots_per_epoch()); signer(proposer_index, &message[..], epoch, Domain::BeaconProposer) }; header_2.signature = { let message = header_2.signed_root(); - let epoch = slot.epoch(T::slots_per_epoch()); signer(proposer_index, &message[..], epoch, Domain::BeaconProposer) };