extern crate elrond_codec_derive;
use elrond_codec_derive::*;
use elrond_codec::test_util::{check_top_decode, check_top_encode, check_top_encode_decode};
#[derive(TopEncodeOrDefault, TopDecodeOrDefault, PartialEq, Eq, Clone, Debug)]
enum TrickyEnumWithDefault {
FirstVariant,
SecondVariant,
VariantWithFields {
int: u16,
seq: Vec<u8>,
another_byte: u8,
uint_32: u32,
uint_64: u64,
},
}
impl elrond_codec::EncodeDefault for TrickyEnumWithDefault {
fn is_default(&self) -> bool {
matches!(self, TrickyEnumWithDefault::SecondVariant)
}
}
impl elrond_codec::DecodeDefault for TrickyEnumWithDefault {
fn default() -> Self {
TrickyEnumWithDefault::SecondVariant
}
}
#[test]
fn tricky_enum_defaults() {
check_top_encode_decode(TrickyEnumWithDefault::SecondVariant, &[]);
assert_eq!(check_top_encode(&TrickyEnumWithDefault::FirstVariant), &[]);
assert_eq!(TrickyEnumWithDefault::FirstVariant, check_top_decode(&[0]));
}