git.delta.rocks / unique-network / refs/commits / 2cb27561505b

difftreelog

path: Add test for simple data

Trubnikov Sergey2022-08-17parent: #420882b.patch.diff
in: master

1 file changed

modifiedcrates/evm-coder/src/abi.rsdiffbeforeafterboth
78 return Err(Error::Error(ExitError::OutOfOffset));78 return Err(Error::Error(ExitError::OutOfOffset));
79 }79 }
80 let mut block = [0; S];80 let mut block = [0; S];
81 let is_pad_zeroed = !buf[pad_start..pad_size].iter().all(|&v| v == 0);81 let is_pad_zeroed = buf[pad_start..pad_size].iter().all(|&v| v == 0);
82 if is_pad_zeroed {82 if !is_pad_zeroed {
83 return Err(Error::Error(ExitError::InvalidRange));83 return Err(Error::Error(ExitError::InvalidRange));
84 }84 }
85 block.copy_from_slice(&buf[block_start..block_size]);85 block.copy_from_slice(&buf[block_start..block_size]);
635 );635 );
636 }636 }
637
638 #[test]
639 fn parse_vec_with_simple_type() {
640 use crate::types::address;
641 use primitive_types::{H160, U256};
642
643 let (call, mut decoder) = AbiReader::new_call(&hex!(
644 "
645 1ACF2D55
646 0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]
647 0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]
648
649 0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address
650 000000000000000000000000000000000000000000000000000000000000000A // uint256
651
652 000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address
653 0000000000000000000000000000000000000000000000000000000000000014 // uint256
654
655 0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address
656 000000000000000000000000000000000000000000000000000000000000001E // uint256
657 "
658 ))
659 .unwrap();
660 assert_eq!(call, u32::to_be_bytes(0x1ACF2D55));
661 let data =
662 <AbiReader<'_> as AbiRead<Vec<(address, uint256)>>>::abi_read(&mut decoder).unwrap();
663 assert_eq!(data.len(), 3);
664 assert_eq!(
665 data,
666 vec![
667 (H160(hex!("2D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC")), U256([10, 0, 0, 0])),
668 (H160(hex!("AB8E3D9134955566483B11E6825C9223B6737B10")), U256([20, 0, 0, 0])),
669 (H160(hex!("8C582BDF2953046705FC56F189385255EFC1BE18")), U256([30, 0, 0, 0])),
670 ]
671 );
672 }
637}673}
638674