difftreelog
refactor abi tests
in: master
3 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1058,16 +1058,6 @@
]
[[package]]
-name = "concat-idents"
-version = "1.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0fe0e1d9f7de897d18e590a7496b5facbe87813f746cf4b8db596ba77e07e832"
-dependencies = [
- "quote",
- "syn",
-]
-
-[[package]]
name = "concurrent-queue"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2349,7 +2339,6 @@
name = "evm-coder"
version = "0.1.4"
dependencies = [
- "concat-idents",
"ethereum",
"evm-coder-procedural",
"evm-core",
crates/evm-coder/Cargo.tomldiffbeforeafterboth--- a/crates/evm-coder/Cargo.toml
+++ b/crates/evm-coder/Cargo.toml
@@ -26,7 +26,6 @@
hex = "0.4.3"
hex-literal = "0.3.4"
similar-asserts = "1.4.2"
-concat-idents = "1.1.3"
trybuild = "1.0"
[features]
crates/evm-coder/src/abi/test.rsdiffbeforeafterboth6use super::{AbiReader, AbiWriter};6use super::{AbiReader, AbiWriter};7use hex_literal::hex;7use hex_literal::hex;8use primitive_types::{H160, U256};8use primitive_types::{H160, U256};9use concat_idents::concat_idents;10911macro_rules! test_impl {10fn test_impl<T>(function_identifier: u32, decoded_data: T, encoded_data: &[u8])11where12 ($name:ident, $type:ty, $function_identifier:expr, $decoded_data:expr, $encoded_data:expr) => {12 T: AbiWrite + AbiRead + std::cmp::PartialEq + std::fmt::Debug,13 concat_idents!(test_name = encode_decode_, $name {13{14 #[test]15 fn test_name() {16 let function_identifier: u32 = $function_identifier;17 let decoded_data = $decoded_data;18 let encoded_data = $encoded_data;1920 let (call, mut decoder) = AbiReader::new_call(encoded_data).unwrap();14 let (call, mut decoder) = AbiReader::new_call(encoded_data).unwrap();21 assert_eq!(call, u32::to_be_bytes(function_identifier));15 assert_eq!(call, u32::to_be_bytes(function_identifier));22 let data = <$type>::abi_read(&mut decoder).unwrap();16 let data = <T>::abi_read(&mut decoder).unwrap();23 assert_eq!(data, decoded_data);17 assert_eq!(data, decoded_data);241825 let mut writer = AbiWriter::new_call(function_identifier);19 let mut writer = AbiWriter::new_call(function_identifier);26 decoded_data.abi_write(&mut writer);20 decoded_data.abi_write(&mut writer);27 let ed = writer.finish();21 let ed = writer.finish();28 similar_asserts::assert_eq!(encoded_data, ed.as_slice());22 similar_asserts::assert_eq!(encoded_data, ed.as_slice());29 }30 });31 };23}32}332434macro_rules! test_impl_uint {25macro_rules! test_impl_uint {35 ($type:ident) => {26 ($type:ident) => {36 test_impl!(27 test_impl::<$type>(37 $type,38 $type,39 0xdeadbeef,28 0xdeadbeef,40 255 as $type,29 255 as $type,41 &hex!(30 &hex!(42 "31 "43 deadbeef32 deadbeef44 00000000000000000000000000000000000000000000000000000000000000ff33 00000000000000000000000000000000000000000000000000000000000000ff45 "34 "46 )35 ),47 );36 );48 };37 };49}38}503940#[test]41fn encode_decode_uint8() {51test_impl_uint!(uint8);42 test_impl_uint!(uint8);43}4445#[test]46fn encode_decode_uint32() {52test_impl_uint!(uint32);47 test_impl_uint!(uint32);48}4950#[test]51fn encode_decode_uint128() {53test_impl_uint!(uint128);52 test_impl_uint!(uint128);5453}5455#[test]56fn encode_decode_uint256() {55test_impl!(57 test_impl::<uint256>(56 uint256,57 uint256,58 0xdeadbeef,58 0xdeadbeef,59 U256([255, 0, 0, 0]),59 U256([255, 0, 0, 0]),60 &hex!(60 &hex!(61 "61 "62 deadbeef62 deadbeef63 00000000000000000000000000000000000000000000000000000000000000ff63 00000000000000000000000000000000000000000000000000000000000000ff64 "64 "65 )65 ),66);66 );6767}6869#[test]70fn encode_decode_string() {71 test_impl::<String>(72 0xdeadbeef,73 "some string".to_string(),74 &hex!(75 "76 deadbeef77 000000000000000000000000000000000000000000000000000000000000002078 000000000000000000000000000000000000000000000000000000000000000b79 736f6d6520737472696e6700000000000000000000000000000000000000000080 "81 ),82 );83}8485#[test]86fn encode_decode_tuple_string() {87 test_impl::<(String,)>(88 0xdeadbeef,89 ("some string".to_string(),),90 &hex!(91 "92 deadbeef93 000000000000000000000000000000000000000000000000000000000000002094 000000000000000000000000000000000000000000000000000000000000002095 000000000000000000000000000000000000000000000000000000000000000b96 736f6d6520737472696e6700000000000000000000000000000000000000000097 "98 ),99 );100}101102#[test]103fn encode_decode_vec_tuple_address_uint256() {68test_impl!(104 test_impl::<Vec<(address, uint256)>>(69 vec_tuple_address_uint256,70 Vec<(address, uint256)>,71 0x1ACF2D55,105 0x1ACF2D55,72 vec![106 vec![73 (107 (84 ),118 ),85 ],119 ],86 &hex!(120 &hex!(87 "121 "88 1ACF2D55122 1ACF2D5589 0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]123 0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]90 0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]124 0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]9112592 0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address126 0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address93 000000000000000000000000000000000000000000000000000000000000000A // uint256127 000000000000000000000000000000000000000000000000000000000000000A // uint2569412895 000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address129 000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address96 0000000000000000000000000000000000000000000000000000000000000014 // uint256130 0000000000000000000000000000000000000000000000000000000000000014 // uint2569713198 0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address132 0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address99 000000000000000000000000000000000000000000000000000000000000001E // uint256133 000000000000000000000000000000000000000000000000000000000000001E // uint256100 "134 "101 )135 )102);136 );103137}138139#[test]140fn encode_decode_vec_tuple_uint256_string() {104test_impl!(141 test_impl::<Vec<(uint256, string)>>(105 vec_tuple_uint256_string,106 Vec<(uint256, string)>,107 0xdeadbeef,142 0xdeadbeef,108 vec![143 vec![109 (1.into(), "Test URI 0".to_string()),144 (1.into(), "Test URI 0".to_string()),110 (11.into(), "Test URI 1".to_string()),145 (11.into(), "Test URI 1".to_string()),111 (12.into(), "Test URI 2".to_string()),146 (12.into(), "Test URI 2".to_string()),112 ],147 ],113 &hex!(148 &hex!(114 "149 "115 deadbeef150 deadbeef116 0000000000000000000000000000000000000000000000000000000000000020 // offset of (uint256, string)[]151 0000000000000000000000000000000000000000000000000000000000000020 // offset of (uint256, string)[]117 0000000000000000000000000000000000000000000000000000000000000003 // length of (uint256, string)[]152 0000000000000000000000000000000000000000000000000000000000000003 // length of (uint256, string)[]118153119 0000000000000000000000000000000000000000000000000000000000000060 // offset of first elem154 0000000000000000000000000000000000000000000000000000000000000060 // offset of first elem120 00000000000000000000000000000000000000000000000000000000000000e0 // offset of second elem155 00000000000000000000000000000000000000000000000000000000000000e0 // offset of second elem121 0000000000000000000000000000000000000000000000000000000000000160 // offset of third elem156 0000000000000000000000000000000000000000000000000000000000000160 // offset of third elem122157123 0000000000000000000000000000000000000000000000000000000000000001 // first token id? #60158 0000000000000000000000000000000000000000000000000000000000000001 // first token id? #60124 0000000000000000000000000000000000000000000000000000000000000040 // offset of string159 0000000000000000000000000000000000000000000000000000000000000040 // offset of string125 000000000000000000000000000000000000000000000000000000000000000a // size of string160 000000000000000000000000000000000000000000000000000000000000000a // size of string126 5465737420555249203000000000000000000000000000000000000000000000 // string161 5465737420555249203000000000000000000000000000000000000000000000 // string127162128 000000000000000000000000000000000000000000000000000000000000000b // second token id? Why ==11? #e0163 000000000000000000000000000000000000000000000000000000000000000b // second token id? Why ==11? #e0129 0000000000000000000000000000000000000000000000000000000000000040 // offset of string164 0000000000000000000000000000000000000000000000000000000000000040 // offset of string130 000000000000000000000000000000000000000000000000000000000000000a // size of string165 000000000000000000000000000000000000000000000000000000000000000a // size of string131 5465737420555249203100000000000000000000000000000000000000000000 // string166 5465737420555249203100000000000000000000000000000000000000000000 // string132167133 000000000000000000000000000000000000000000000000000000000000000c // third token id? Why ==12? #160168 000000000000000000000000000000000000000000000000000000000000000c // third token id? Why ==12? #160134 0000000000000000000000000000000000000000000000000000000000000040 // offset of string169 0000000000000000000000000000000000000000000000000000000000000040 // offset of string135 000000000000000000000000000000000000000000000000000000000000000a // size of string170 000000000000000000000000000000000000000000000000000000000000000a // size of string136 5465737420555249203200000000000000000000000000000000000000000000 // string171 5465737420555249203200000000000000000000000000000000000000000000 // string137 "172 "138 )173 )139);174 );175}140176141#[test]177#[test]142fn dynamic_after_static() {178fn dynamic_after_static() {235 similar_asserts::assert_eq!(encoded_data, ed.as_slice());271 similar_asserts::assert_eq!(encoded_data, ed.as_slice());236}272}237273274#[test]275fn encode_decode_vec_tuple_string_bytes() {238test_impl!(276 test_impl::<Vec<(string, bytes)>>(239 vec_tuple_string_bytes,240 Vec<(string, bytes)>,241 0xdeadbeef,277 0xdeadbeef,242 vec![278 vec![243 (279 (261 ("Test URI 2".to_string(), bytes(vec![0x33, 0x33])),297 ("Test URI 2".to_string(), bytes(vec![0x33, 0x33])),262 ],298 ],263 &hex!(299 &hex!(264 "300 "265 deadbeef301 deadbeef266 0000000000000000000000000000000000000000000000000000000000000020302 0000000000000000000000000000000000000000000000000000000000000020267 0000000000000000000000000000000000000000000000000000000000000003303 0000000000000000000000000000000000000000000000000000000000000003304268 305 0000000000000000000000000000000000000000000000000000000000000060269 0000000000000000000000000000000000000000000000000000000000000060306 0000000000000000000000000000000000000000000000000000000000000140270 0000000000000000000000000000000000000000000000000000000000000140307 0000000000000000000000000000000000000000000000000000000000000220271 0000000000000000000000000000000000000000000000000000000000000220308272309 0000000000000000000000000000000000000000000000000000000000000040273 0000000000000000000000000000000000000000000000000000000000000040310 0000000000000000000000000000000000000000000000000000000000000080274 0000000000000000000000000000000000000000000000000000000000000080311 000000000000000000000000000000000000000000000000000000000000000a275 000000000000000000000000000000000000000000000000000000000000000a312 5465737420555249203000000000000000000000000000000000000000000000276 5465737420555249203000000000000000000000000000000000000000000000313 0000000000000000000000000000000000000000000000000000000000000030277 0000000000000000000000000000000000000000000000000000000000000030314 1111111111111111111111111111111111111111111111111111111111111111278 1111111111111111111111111111111111111111111111111111111111111111315 1111111111111111111111111111111100000000000000000000000000000000279 1111111111111111111111111111111100000000000000000000000000000000316280317 0000000000000000000000000000000000000000000000000000000000000040281 0000000000000000000000000000000000000000000000000000000000000040318 0000000000000000000000000000000000000000000000000000000000000080282 0000000000000000000000000000000000000000000000000000000000000080319 000000000000000000000000000000000000000000000000000000000000000a283 000000000000000000000000000000000000000000000000000000000000000a320 5465737420555249203100000000000000000000000000000000000000000000284 5465737420555249203100000000000000000000000000000000000000000000321 000000000000000000000000000000000000000000000000000000000000002f285 000000000000000000000000000000000000000000000000000000000000002f322 2222222222222222222222222222222222222222222222222222222222222222286 2222222222222222222222222222222222222222222222222222222222222222323 2222222222222222222222222222220000000000000000000000000000000000287 2222222222222222222222222222220000000000000000000000000000000000324288325 0000000000000000000000000000000000000000000000000000000000000040289 0000000000000000000000000000000000000000000000000000000000000040326 0000000000000000000000000000000000000000000000000000000000000080290 0000000000000000000000000000000000000000000000000000000000000080327 000000000000000000000000000000000000000000000000000000000000000a291 000000000000000000000000000000000000000000000000000000000000000a328 5465737420555249203200000000000000000000000000000000000000000000292 5465737420555249203200000000000000000000000000000000000000000000329 0000000000000000000000000000000000000000000000000000000000000002293 0000000000000000000000000000000000000000000000000000000000000002330 3333000000000000000000000000000000000000000000000000000000000000294 3333000000000000000000000000000000000000000000000000000000000000331 "295 "296 )332 ),297);333 );334}298335