add more tx tests (#11038)

This commit is contained in:
Andronik Ordian 2019-09-12 16:38:25 +02:00 committed by GitHub
parent 5e2def1b23
commit ad9a53f486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,7 +54,11 @@ impl Default for Action {
impl rlp::Decodable for Action { impl rlp::Decodable for Action {
fn decode(rlp: &Rlp) -> Result<Self, DecoderError> { fn decode(rlp: &Rlp) -> Result<Self, DecoderError> {
if rlp.is_empty() { if rlp.is_empty() {
Ok(Action::Create) if rlp.is_data() {
Ok(Action::Create)
} else {
Err(DecoderError::RlpExpectedToBeData)
}
} else { } else {
Ok(Action::Call(rlp.as_val()?)) Ok(Action::Call(rlp.as_val()?))
} }
@ -571,6 +575,20 @@ mod tests {
assert_eq!(t.chain_id(), None); assert_eq!(t.chain_id(), None);
} }
#[test]
fn empty_atom_as_create_action() {
let empty_atom = [0x80];
let action: Action = rlp::decode(&empty_atom).unwrap();
assert_eq!(action, Action::Create);
}
#[test]
fn empty_list_as_create_action_rejected() {
let empty_list = [0xc0];
let action: Result<Action, DecoderError> = rlp::decode(&empty_list);
assert_eq!(action, Err(DecoderError::RlpExpectedToBeData));
}
#[test] #[test]
fn signing_eip155_zero_chainid() { fn signing_eip155_zero_chainid() {
use ethkey::{Random, Generator}; use ethkey::{Random, Generator};