git.delta.rocks / unique-network / refs/commits / d535fbacbf44

difftreelog

refactor abi tests

Trubnikov Sergey2022-11-14parent: #00d3414.patch.diff
in: master

3 files changed

modifiedCargo.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",
modifiedcrates/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]
modifiedcrates/evm-coder/src/abi/test.rsdiffbeforeafterboth
6use 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;
109
11macro_rules! test_impl {10fn test_impl<T>(function_identifier: u32, decoded_data: T, encoded_data: &[u8])
11where
12 ($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;
19
20 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);
2418
25 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}
3324
34macro_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 deadbeef
44 00000000000000000000000000000000000000000000000000000000000000ff33 00000000000000000000000000000000000000000000000000000000000000ff
45 "34 "
46 )35 ),
47 );36 );
48 };37 };
49}38}
5039
40#[test]
41fn encode_decode_uint8() {
51test_impl_uint!(uint8);42 test_impl_uint!(uint8);
43}
44
45#[test]
46fn encode_decode_uint32() {
52test_impl_uint!(uint32);47 test_impl_uint!(uint32);
48}
49
50#[test]
51fn encode_decode_uint128() {
53test_impl_uint!(uint128);52 test_impl_uint!(uint128);
5453}
54
55#[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 deadbeef
63 00000000000000000000000000000000000000000000000000000000000000ff63 00000000000000000000000000000000000000000000000000000000000000ff
64 "64 "
65 )65 ),
66);66 );
6767}
68
69#[test]
70fn encode_decode_string() {
71 test_impl::<String>(
72 0xdeadbeef,
73 "some string".to_string(),
74 &hex!(
75 "
76 deadbeef
77 0000000000000000000000000000000000000000000000000000000000000020
78 000000000000000000000000000000000000000000000000000000000000000b
79 736f6d6520737472696e67000000000000000000000000000000000000000000
80 "
81 ),
82 );
83}
84
85#[test]
86fn encode_decode_tuple_string() {
87 test_impl::<(String,)>(
88 0xdeadbeef,
89 ("some string".to_string(),),
90 &hex!(
91 "
92 deadbeef
93 0000000000000000000000000000000000000000000000000000000000000020
94 0000000000000000000000000000000000000000000000000000000000000020
95 000000000000000000000000000000000000000000000000000000000000000b
96 736f6d6520737472696e67000000000000000000000000000000000000000000
97 "
98 ),
99 );
100}
101
102#[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 1ACF2D55
89 0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]123 0000000000000000000000000000000000000000000000000000000000000020 // offset of (address, uint256)[]
90 0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]124 0000000000000000000000000000000000000000000000000000000000000003 // length of (address, uint256)[]
91125
92 0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address126 0000000000000000000000002D2FF76104B7BACB2E8F6731D5BFC184EBECDDBC // address
93 000000000000000000000000000000000000000000000000000000000000000A // uint256127 000000000000000000000000000000000000000000000000000000000000000A // uint256
94128
95 000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address129 000000000000000000000000AB8E3D9134955566483B11E6825C9223B6737B10 // address
96 0000000000000000000000000000000000000000000000000000000000000014 // uint256130 0000000000000000000000000000000000000000000000000000000000000014 // uint256
97131
98 0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address132 0000000000000000000000008C582BDF2953046705FC56F189385255EFC1BE18 // address
99 000000000000000000000000000000000000000000000000000000000000001E // uint256133 000000000000000000000000000000000000000000000000000000000000001E // uint256
100 "134 "
101 )135 )
102);136 );
103137}
138
139#[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 deadbeef
116 0000000000000000000000000000000000000000000000000000000000000020 // offset of (uint256, string)[]151 0000000000000000000000000000000000000000000000000000000000000020 // offset of (uint256, string)[]
117 0000000000000000000000000000000000000000000000000000000000000003 // length of (uint256, string)[]152 0000000000000000000000000000000000000000000000000000000000000003 // length of (uint256, string)[]
118153
119 0000000000000000000000000000000000000000000000000000000000000060 // offset of first elem154 0000000000000000000000000000000000000000000000000000000000000060 // offset of first elem
120 00000000000000000000000000000000000000000000000000000000000000e0 // offset of second elem155 00000000000000000000000000000000000000000000000000000000000000e0 // offset of second elem
121 0000000000000000000000000000000000000000000000000000000000000160 // offset of third elem156 0000000000000000000000000000000000000000000000000000000000000160 // offset of third elem
122157
123 0000000000000000000000000000000000000000000000000000000000000001 // first token id? #60158 0000000000000000000000000000000000000000000000000000000000000001 // first token id? #60
124 0000000000000000000000000000000000000000000000000000000000000040 // offset of string159 0000000000000000000000000000000000000000000000000000000000000040 // offset of string
125 000000000000000000000000000000000000000000000000000000000000000a // size of string160 000000000000000000000000000000000000000000000000000000000000000a // size of string
126 5465737420555249203000000000000000000000000000000000000000000000 // string161 5465737420555249203000000000000000000000000000000000000000000000 // string
127162
128 000000000000000000000000000000000000000000000000000000000000000b // second token id? Why ==11? #e0163 000000000000000000000000000000000000000000000000000000000000000b // second token id? Why ==11? #e0
129 0000000000000000000000000000000000000000000000000000000000000040 // offset of string164 0000000000000000000000000000000000000000000000000000000000000040 // offset of string
130 000000000000000000000000000000000000000000000000000000000000000a // size of string165 000000000000000000000000000000000000000000000000000000000000000a // size of string
131 5465737420555249203100000000000000000000000000000000000000000000 // string166 5465737420555249203100000000000000000000000000000000000000000000 // string
132167
133 000000000000000000000000000000000000000000000000000000000000000c // third token id? Why ==12? #160168 000000000000000000000000000000000000000000000000000000000000000c // third token id? Why ==12? #160
134 0000000000000000000000000000000000000000000000000000000000000040 // offset of string169 0000000000000000000000000000000000000000000000000000000000000040 // offset of string
135 000000000000000000000000000000000000000000000000000000000000000a // size of string170 000000000000000000000000000000000000000000000000000000000000000a // size of string
136 5465737420555249203200000000000000000000000000000000000000000000 // string171 5465737420555249203200000000000000000000000000000000000000000000 // string
137 "172 "
138 )173 )
139);174 );
175}
140176
141#[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}
237273
274#[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 deadbeef
266 0000000000000000000000000000000000000000000000000000000000000020302 0000000000000000000000000000000000000000000000000000000000000020
267 0000000000000000000000000000000000000000000000000000000000000003303 0000000000000000000000000000000000000000000000000000000000000003
304
268 305 0000000000000000000000000000000000000000000000000000000000000060
269 0000000000000000000000000000000000000000000000000000000000000060306 0000000000000000000000000000000000000000000000000000000000000140
270 0000000000000000000000000000000000000000000000000000000000000140307 0000000000000000000000000000000000000000000000000000000000000220
271 0000000000000000000000000000000000000000000000000000000000000220308
272309 0000000000000000000000000000000000000000000000000000000000000040
273 0000000000000000000000000000000000000000000000000000000000000040310 0000000000000000000000000000000000000000000000000000000000000080
274 0000000000000000000000000000000000000000000000000000000000000080311 000000000000000000000000000000000000000000000000000000000000000a
275 000000000000000000000000000000000000000000000000000000000000000a312 5465737420555249203000000000000000000000000000000000000000000000
276 5465737420555249203000000000000000000000000000000000000000000000313 0000000000000000000000000000000000000000000000000000000000000030
277 0000000000000000000000000000000000000000000000000000000000000030314 1111111111111111111111111111111111111111111111111111111111111111
278 1111111111111111111111111111111111111111111111111111111111111111315 1111111111111111111111111111111100000000000000000000000000000000
279 1111111111111111111111111111111100000000000000000000000000000000316
280317 0000000000000000000000000000000000000000000000000000000000000040
281 0000000000000000000000000000000000000000000000000000000000000040318 0000000000000000000000000000000000000000000000000000000000000080
282 0000000000000000000000000000000000000000000000000000000000000080319 000000000000000000000000000000000000000000000000000000000000000a
283 000000000000000000000000000000000000000000000000000000000000000a320 5465737420555249203100000000000000000000000000000000000000000000
284 5465737420555249203100000000000000000000000000000000000000000000321 000000000000000000000000000000000000000000000000000000000000002f
285 000000000000000000000000000000000000000000000000000000000000002f322 2222222222222222222222222222222222222222222222222222222222222222
286 2222222222222222222222222222222222222222222222222222222222222222323 2222222222222222222222222222220000000000000000000000000000000000
287 2222222222222222222222222222220000000000000000000000000000000000324
288325 0000000000000000000000000000000000000000000000000000000000000040
289 0000000000000000000000000000000000000000000000000000000000000040326 0000000000000000000000000000000000000000000000000000000000000080
290 0000000000000000000000000000000000000000000000000000000000000080327 000000000000000000000000000000000000000000000000000000000000000a
291 000000000000000000000000000000000000000000000000000000000000000a328 5465737420555249203200000000000000000000000000000000000000000000
292 5465737420555249203200000000000000000000000000000000000000000000329 0000000000000000000000000000000000000000000000000000000000000002
293 0000000000000000000000000000000000000000000000000000000000000002330 3333000000000000000000000000000000000000000000000000000000000000
294 3333000000000000000000000000000000000000000000000000000000000000331 "
295 "
296 )332 ),
297);333 );
334}
298335