packing_test.go 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. // Copyright 2020 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package abi
  17. import (
  18. "math/big"
  19. "github.com/ethereum/go-ethereum/common"
  20. )
  21. type packUnpackTest struct {
  22. def string
  23. unpacked interface{}
  24. packed string
  25. }
  26. var packUnpackTests = []packUnpackTest{
  27. // Booleans
  28. {
  29. def: `[{ "type": "bool" }]`,
  30. packed: "0000000000000000000000000000000000000000000000000000000000000001",
  31. unpacked: true,
  32. },
  33. {
  34. def: `[{ "type": "bool" }]`,
  35. packed: "0000000000000000000000000000000000000000000000000000000000000000",
  36. unpacked: false,
  37. },
  38. // Integers
  39. {
  40. def: `[{ "type": "uint8" }]`,
  41. unpacked: uint8(2),
  42. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  43. },
  44. {
  45. def: `[{ "type": "uint8[]" }]`,
  46. unpacked: []uint8{1, 2},
  47. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  48. "0000000000000000000000000000000000000000000000000000000000000002" +
  49. "0000000000000000000000000000000000000000000000000000000000000001" +
  50. "0000000000000000000000000000000000000000000000000000000000000002",
  51. },
  52. {
  53. def: `[{ "type": "uint16" }]`,
  54. unpacked: uint16(2),
  55. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  56. },
  57. {
  58. def: `[{ "type": "uint16[]" }]`,
  59. unpacked: []uint16{1, 2},
  60. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  61. "0000000000000000000000000000000000000000000000000000000000000002" +
  62. "0000000000000000000000000000000000000000000000000000000000000001" +
  63. "0000000000000000000000000000000000000000000000000000000000000002",
  64. },
  65. {
  66. def: `[{"type": "uint17"}]`,
  67. packed: "0000000000000000000000000000000000000000000000000000000000000001",
  68. unpacked: big.NewInt(1),
  69. },
  70. {
  71. def: `[{"type": "uint32"}]`,
  72. packed: "0000000000000000000000000000000000000000000000000000000000000001",
  73. unpacked: uint32(1),
  74. },
  75. {
  76. def: `[{"type": "uint32[]"}]`,
  77. unpacked: []uint32{1, 2},
  78. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  79. "0000000000000000000000000000000000000000000000000000000000000002" +
  80. "0000000000000000000000000000000000000000000000000000000000000001" +
  81. "0000000000000000000000000000000000000000000000000000000000000002",
  82. },
  83. {
  84. def: `[{"type": "uint64"}]`,
  85. unpacked: uint64(2),
  86. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  87. },
  88. {
  89. def: `[{"type": "uint64[]"}]`,
  90. unpacked: []uint64{1, 2},
  91. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  92. "0000000000000000000000000000000000000000000000000000000000000002" +
  93. "0000000000000000000000000000000000000000000000000000000000000001" +
  94. "0000000000000000000000000000000000000000000000000000000000000002",
  95. },
  96. {
  97. def: `[{"type": "uint256"}]`,
  98. unpacked: big.NewInt(2),
  99. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  100. },
  101. {
  102. def: `[{"type": "uint256[]"}]`,
  103. unpacked: []*big.Int{big.NewInt(1), big.NewInt(2)},
  104. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  105. "0000000000000000000000000000000000000000000000000000000000000002" +
  106. "0000000000000000000000000000000000000000000000000000000000000001" +
  107. "0000000000000000000000000000000000000000000000000000000000000002",
  108. },
  109. {
  110. def: `[{"type": "int8"}]`,
  111. unpacked: int8(2),
  112. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  113. },
  114. {
  115. def: `[{"type": "int8[]"}]`,
  116. unpacked: []int8{1, 2},
  117. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  118. "0000000000000000000000000000000000000000000000000000000000000002" +
  119. "0000000000000000000000000000000000000000000000000000000000000001" +
  120. "0000000000000000000000000000000000000000000000000000000000000002",
  121. },
  122. {
  123. def: `[{"type": "int16"}]`,
  124. unpacked: int16(2),
  125. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  126. },
  127. {
  128. def: `[{"type": "int16[]"}]`,
  129. unpacked: []int16{1, 2},
  130. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  131. "0000000000000000000000000000000000000000000000000000000000000002" +
  132. "0000000000000000000000000000000000000000000000000000000000000001" +
  133. "0000000000000000000000000000000000000000000000000000000000000002",
  134. },
  135. {
  136. def: `[{"type": "int17"}]`,
  137. packed: "0000000000000000000000000000000000000000000000000000000000000001",
  138. unpacked: big.NewInt(1),
  139. },
  140. {
  141. def: `[{"type": "int32"}]`,
  142. unpacked: int32(2),
  143. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  144. },
  145. {
  146. def: `[{"type": "int32"}]`,
  147. packed: "0000000000000000000000000000000000000000000000000000000000000001",
  148. unpacked: int32(1),
  149. },
  150. {
  151. def: `[{"type": "int32[]"}]`,
  152. unpacked: []int32{1, 2},
  153. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  154. "0000000000000000000000000000000000000000000000000000000000000002" +
  155. "0000000000000000000000000000000000000000000000000000000000000001" +
  156. "0000000000000000000000000000000000000000000000000000000000000002",
  157. },
  158. {
  159. def: `[{"type": "int64"}]`,
  160. unpacked: int64(2),
  161. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  162. },
  163. {
  164. def: `[{"type": "int64[]"}]`,
  165. unpacked: []int64{1, 2},
  166. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  167. "0000000000000000000000000000000000000000000000000000000000000002" +
  168. "0000000000000000000000000000000000000000000000000000000000000001" +
  169. "0000000000000000000000000000000000000000000000000000000000000002",
  170. },
  171. {
  172. def: `[{"type": "int256"}]`,
  173. unpacked: big.NewInt(2),
  174. packed: "0000000000000000000000000000000000000000000000000000000000000002",
  175. },
  176. {
  177. def: `[{"type": "int256"}]`,
  178. packed: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
  179. unpacked: big.NewInt(-1),
  180. },
  181. {
  182. def: `[{"type": "int256[]"}]`,
  183. unpacked: []*big.Int{big.NewInt(1), big.NewInt(2)},
  184. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  185. "0000000000000000000000000000000000000000000000000000000000000002" +
  186. "0000000000000000000000000000000000000000000000000000000000000001" +
  187. "0000000000000000000000000000000000000000000000000000000000000002",
  188. },
  189. // Address
  190. {
  191. def: `[{"type": "address"}]`,
  192. packed: "0000000000000000000000000100000000000000000000000000000000000000",
  193. unpacked: common.Address{1},
  194. },
  195. {
  196. def: `[{"type": "address[]"}]`,
  197. unpacked: []common.Address{{1}, {2}},
  198. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  199. "0000000000000000000000000000000000000000000000000000000000000002" +
  200. "0000000000000000000000000100000000000000000000000000000000000000" +
  201. "0000000000000000000000000200000000000000000000000000000000000000",
  202. },
  203. // Bytes
  204. {
  205. def: `[{"type": "bytes1"}]`,
  206. unpacked: [1]byte{1},
  207. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  208. },
  209. {
  210. def: `[{"type": "bytes2"}]`,
  211. unpacked: [2]byte{1},
  212. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  213. },
  214. {
  215. def: `[{"type": "bytes3"}]`,
  216. unpacked: [3]byte{1},
  217. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  218. },
  219. {
  220. def: `[{"type": "bytes4"}]`,
  221. unpacked: [4]byte{1},
  222. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  223. },
  224. {
  225. def: `[{"type": "bytes5"}]`,
  226. unpacked: [5]byte{1},
  227. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  228. },
  229. {
  230. def: `[{"type": "bytes6"}]`,
  231. unpacked: [6]byte{1},
  232. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  233. },
  234. {
  235. def: `[{"type": "bytes7"}]`,
  236. unpacked: [7]byte{1},
  237. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  238. },
  239. {
  240. def: `[{"type": "bytes8"}]`,
  241. unpacked: [8]byte{1},
  242. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  243. },
  244. {
  245. def: `[{"type": "bytes9"}]`,
  246. unpacked: [9]byte{1},
  247. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  248. },
  249. {
  250. def: `[{"type": "bytes10"}]`,
  251. unpacked: [10]byte{1},
  252. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  253. },
  254. {
  255. def: `[{"type": "bytes11"}]`,
  256. unpacked: [11]byte{1},
  257. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  258. },
  259. {
  260. def: `[{"type": "bytes12"}]`,
  261. unpacked: [12]byte{1},
  262. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  263. },
  264. {
  265. def: `[{"type": "bytes13"}]`,
  266. unpacked: [13]byte{1},
  267. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  268. },
  269. {
  270. def: `[{"type": "bytes14"}]`,
  271. unpacked: [14]byte{1},
  272. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  273. },
  274. {
  275. def: `[{"type": "bytes15"}]`,
  276. unpacked: [15]byte{1},
  277. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  278. },
  279. {
  280. def: `[{"type": "bytes16"}]`,
  281. unpacked: [16]byte{1},
  282. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  283. },
  284. {
  285. def: `[{"type": "bytes17"}]`,
  286. unpacked: [17]byte{1},
  287. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  288. },
  289. {
  290. def: `[{"type": "bytes18"}]`,
  291. unpacked: [18]byte{1},
  292. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  293. },
  294. {
  295. def: `[{"type": "bytes19"}]`,
  296. unpacked: [19]byte{1},
  297. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  298. },
  299. {
  300. def: `[{"type": "bytes20"}]`,
  301. unpacked: [20]byte{1},
  302. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  303. },
  304. {
  305. def: `[{"type": "bytes21"}]`,
  306. unpacked: [21]byte{1},
  307. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  308. },
  309. {
  310. def: `[{"type": "bytes22"}]`,
  311. unpacked: [22]byte{1},
  312. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  313. },
  314. {
  315. def: `[{"type": "bytes23"}]`,
  316. unpacked: [23]byte{1},
  317. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  318. },
  319. {
  320. def: `[{"type": "bytes24"}]`,
  321. unpacked: [24]byte{1},
  322. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  323. },
  324. {
  325. def: `[{"type": "bytes25"}]`,
  326. unpacked: [25]byte{1},
  327. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  328. },
  329. {
  330. def: `[{"type": "bytes26"}]`,
  331. unpacked: [26]byte{1},
  332. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  333. },
  334. {
  335. def: `[{"type": "bytes27"}]`,
  336. unpacked: [27]byte{1},
  337. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  338. },
  339. {
  340. def: `[{"type": "bytes28"}]`,
  341. unpacked: [28]byte{1},
  342. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  343. },
  344. {
  345. def: `[{"type": "bytes29"}]`,
  346. unpacked: [29]byte{1},
  347. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  348. },
  349. {
  350. def: `[{"type": "bytes30"}]`,
  351. unpacked: [30]byte{1},
  352. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  353. },
  354. {
  355. def: `[{"type": "bytes31"}]`,
  356. unpacked: [31]byte{1},
  357. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  358. },
  359. {
  360. def: `[{"type": "bytes32"}]`,
  361. unpacked: [32]byte{1},
  362. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  363. },
  364. {
  365. def: `[{"type": "bytes32"}]`,
  366. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  367. unpacked: [32]byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  368. },
  369. {
  370. def: `[{"type": "bytes"}]`,
  371. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  372. "0000000000000000000000000000000000000000000000000000000000000020" +
  373. "0100000000000000000000000000000000000000000000000000000000000000",
  374. unpacked: common.Hex2Bytes("0100000000000000000000000000000000000000000000000000000000000000"),
  375. },
  376. {
  377. def: `[{"type": "bytes32"}]`,
  378. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  379. unpacked: [32]byte{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  380. },
  381. // Functions
  382. {
  383. def: `[{"type": "function"}]`,
  384. packed: "0100000000000000000000000000000000000000000000000000000000000000",
  385. unpacked: [24]byte{1},
  386. },
  387. // Slice and Array
  388. {
  389. def: `[{"type": "uint8[]"}]`,
  390. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  391. "0000000000000000000000000000000000000000000000000000000000000002" +
  392. "0000000000000000000000000000000000000000000000000000000000000001" +
  393. "0000000000000000000000000000000000000000000000000000000000000002",
  394. unpacked: []uint8{1, 2},
  395. },
  396. {
  397. def: `[{"type": "uint8[]"}]`,
  398. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  399. "0000000000000000000000000000000000000000000000000000000000000000",
  400. unpacked: []uint8{},
  401. },
  402. {
  403. def: `[{"type": "uint256[]"}]`,
  404. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  405. "0000000000000000000000000000000000000000000000000000000000000000",
  406. unpacked: []*big.Int{},
  407. },
  408. {
  409. def: `[{"type": "uint8[2]"}]`,
  410. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  411. "0000000000000000000000000000000000000000000000000000000000000002",
  412. unpacked: [2]uint8{1, 2},
  413. },
  414. {
  415. def: `[{"type": "int8[2]"}]`,
  416. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  417. "0000000000000000000000000000000000000000000000000000000000000002",
  418. unpacked: [2]int8{1, 2},
  419. },
  420. {
  421. def: `[{"type": "int16[]"}]`,
  422. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  423. "0000000000000000000000000000000000000000000000000000000000000002" +
  424. "0000000000000000000000000000000000000000000000000000000000000001" +
  425. "0000000000000000000000000000000000000000000000000000000000000002",
  426. unpacked: []int16{1, 2},
  427. },
  428. {
  429. def: `[{"type": "int16[2]"}]`,
  430. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  431. "0000000000000000000000000000000000000000000000000000000000000002",
  432. unpacked: [2]int16{1, 2},
  433. },
  434. {
  435. def: `[{"type": "int32[]"}]`,
  436. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  437. "0000000000000000000000000000000000000000000000000000000000000002" +
  438. "0000000000000000000000000000000000000000000000000000000000000001" +
  439. "0000000000000000000000000000000000000000000000000000000000000002",
  440. unpacked: []int32{1, 2},
  441. },
  442. {
  443. def: `[{"type": "int32[2]"}]`,
  444. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  445. "0000000000000000000000000000000000000000000000000000000000000002",
  446. unpacked: [2]int32{1, 2},
  447. },
  448. {
  449. def: `[{"type": "int64[]"}]`,
  450. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  451. "0000000000000000000000000000000000000000000000000000000000000002" +
  452. "0000000000000000000000000000000000000000000000000000000000000001" +
  453. "0000000000000000000000000000000000000000000000000000000000000002",
  454. unpacked: []int64{1, 2},
  455. },
  456. {
  457. def: `[{"type": "int64[2]"}]`,
  458. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  459. "0000000000000000000000000000000000000000000000000000000000000002",
  460. unpacked: [2]int64{1, 2},
  461. },
  462. {
  463. def: `[{"type": "int256[]"}]`,
  464. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  465. "0000000000000000000000000000000000000000000000000000000000000002" +
  466. "0000000000000000000000000000000000000000000000000000000000000001" +
  467. "0000000000000000000000000000000000000000000000000000000000000002",
  468. unpacked: []*big.Int{big.NewInt(1), big.NewInt(2)},
  469. },
  470. {
  471. def: `[{"type": "int256[3]"}]`,
  472. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  473. "0000000000000000000000000000000000000000000000000000000000000002" +
  474. "0000000000000000000000000000000000000000000000000000000000000003",
  475. unpacked: [3]*big.Int{big.NewInt(1), big.NewInt(2), big.NewInt(3)},
  476. },
  477. // multi dimensional, if these pass, all types that don't require length prefix should pass
  478. {
  479. def: `[{"type": "uint8[][]"}]`,
  480. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  481. "0000000000000000000000000000000000000000000000000000000000000000",
  482. unpacked: [][]uint8{},
  483. },
  484. {
  485. def: `[{"type": "uint8[][]"}]`,
  486. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  487. "0000000000000000000000000000000000000000000000000000000000000002" +
  488. "0000000000000000000000000000000000000000000000000000000000000040" +
  489. "00000000000000000000000000000000000000000000000000000000000000a0" +
  490. "0000000000000000000000000000000000000000000000000000000000000002" +
  491. "0000000000000000000000000000000000000000000000000000000000000001" +
  492. "0000000000000000000000000000000000000000000000000000000000000002" +
  493. "0000000000000000000000000000000000000000000000000000000000000002" +
  494. "0000000000000000000000000000000000000000000000000000000000000001" +
  495. "0000000000000000000000000000000000000000000000000000000000000002",
  496. unpacked: [][]uint8{{1, 2}, {1, 2}},
  497. },
  498. {
  499. def: `[{"type": "uint8[][]"}]`,
  500. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  501. "0000000000000000000000000000000000000000000000000000000000000002" +
  502. "0000000000000000000000000000000000000000000000000000000000000040" +
  503. "00000000000000000000000000000000000000000000000000000000000000a0" +
  504. "0000000000000000000000000000000000000000000000000000000000000002" +
  505. "0000000000000000000000000000000000000000000000000000000000000001" +
  506. "0000000000000000000000000000000000000000000000000000000000000002" +
  507. "0000000000000000000000000000000000000000000000000000000000000003" +
  508. "0000000000000000000000000000000000000000000000000000000000000001" +
  509. "0000000000000000000000000000000000000000000000000000000000000002" +
  510. "0000000000000000000000000000000000000000000000000000000000000003",
  511. unpacked: [][]uint8{{1, 2}, {1, 2, 3}},
  512. },
  513. {
  514. def: `[{"type": "uint8[2][2]"}]`,
  515. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  516. "0000000000000000000000000000000000000000000000000000000000000002" +
  517. "0000000000000000000000000000000000000000000000000000000000000001" +
  518. "0000000000000000000000000000000000000000000000000000000000000002",
  519. unpacked: [2][2]uint8{{1, 2}, {1, 2}},
  520. },
  521. {
  522. def: `[{"type": "uint8[][2]"}]`,
  523. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  524. "0000000000000000000000000000000000000000000000000000000000000040" +
  525. "0000000000000000000000000000000000000000000000000000000000000060" +
  526. "0000000000000000000000000000000000000000000000000000000000000000" +
  527. "0000000000000000000000000000000000000000000000000000000000000000",
  528. unpacked: [2][]uint8{{}, {}},
  529. },
  530. {
  531. def: `[{"type": "uint8[][2]"}]`,
  532. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  533. "0000000000000000000000000000000000000000000000000000000000000040" +
  534. "0000000000000000000000000000000000000000000000000000000000000080" +
  535. "0000000000000000000000000000000000000000000000000000000000000001" +
  536. "0000000000000000000000000000000000000000000000000000000000000001" +
  537. "0000000000000000000000000000000000000000000000000000000000000001" +
  538. "0000000000000000000000000000000000000000000000000000000000000001",
  539. unpacked: [2][]uint8{{1}, {1}},
  540. },
  541. {
  542. def: `[{"type": "uint8[2][]"}]`,
  543. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  544. "0000000000000000000000000000000000000000000000000000000000000000",
  545. unpacked: [][2]uint8{},
  546. },
  547. {
  548. def: `[{"type": "uint8[2][]"}]`,
  549. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  550. "0000000000000000000000000000000000000000000000000000000000000001" +
  551. "0000000000000000000000000000000000000000000000000000000000000001" +
  552. "0000000000000000000000000000000000000000000000000000000000000002",
  553. unpacked: [][2]uint8{{1, 2}},
  554. },
  555. {
  556. def: `[{"type": "uint8[2][]"}]`,
  557. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  558. "0000000000000000000000000000000000000000000000000000000000000002" +
  559. "0000000000000000000000000000000000000000000000000000000000000001" +
  560. "0000000000000000000000000000000000000000000000000000000000000002" +
  561. "0000000000000000000000000000000000000000000000000000000000000001" +
  562. "0000000000000000000000000000000000000000000000000000000000000002",
  563. unpacked: [][2]uint8{{1, 2}, {1, 2}},
  564. },
  565. {
  566. def: `[{"type": "uint16[]"}]`,
  567. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  568. "0000000000000000000000000000000000000000000000000000000000000002" +
  569. "0000000000000000000000000000000000000000000000000000000000000001" +
  570. "0000000000000000000000000000000000000000000000000000000000000002",
  571. unpacked: []uint16{1, 2},
  572. },
  573. {
  574. def: `[{"type": "uint16[2]"}]`,
  575. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  576. "0000000000000000000000000000000000000000000000000000000000000002",
  577. unpacked: [2]uint16{1, 2},
  578. },
  579. {
  580. def: `[{"type": "uint32[]"}]`,
  581. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  582. "0000000000000000000000000000000000000000000000000000000000000002" +
  583. "0000000000000000000000000000000000000000000000000000000000000001" +
  584. "0000000000000000000000000000000000000000000000000000000000000002",
  585. unpacked: []uint32{1, 2},
  586. },
  587. {
  588. def: `[{"type": "uint32[2][3][4]"}]`,
  589. unpacked: [4][3][2]uint32{{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}, {11, 12}}, {{13, 14}, {15, 16}, {17, 18}}, {{19, 20}, {21, 22}, {23, 24}}},
  590. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  591. "0000000000000000000000000000000000000000000000000000000000000002" +
  592. "0000000000000000000000000000000000000000000000000000000000000003" +
  593. "0000000000000000000000000000000000000000000000000000000000000004" +
  594. "0000000000000000000000000000000000000000000000000000000000000005" +
  595. "0000000000000000000000000000000000000000000000000000000000000006" +
  596. "0000000000000000000000000000000000000000000000000000000000000007" +
  597. "0000000000000000000000000000000000000000000000000000000000000008" +
  598. "0000000000000000000000000000000000000000000000000000000000000009" +
  599. "000000000000000000000000000000000000000000000000000000000000000a" +
  600. "000000000000000000000000000000000000000000000000000000000000000b" +
  601. "000000000000000000000000000000000000000000000000000000000000000c" +
  602. "000000000000000000000000000000000000000000000000000000000000000d" +
  603. "000000000000000000000000000000000000000000000000000000000000000e" +
  604. "000000000000000000000000000000000000000000000000000000000000000f" +
  605. "0000000000000000000000000000000000000000000000000000000000000010" +
  606. "0000000000000000000000000000000000000000000000000000000000000011" +
  607. "0000000000000000000000000000000000000000000000000000000000000012" +
  608. "0000000000000000000000000000000000000000000000000000000000000013" +
  609. "0000000000000000000000000000000000000000000000000000000000000014" +
  610. "0000000000000000000000000000000000000000000000000000000000000015" +
  611. "0000000000000000000000000000000000000000000000000000000000000016" +
  612. "0000000000000000000000000000000000000000000000000000000000000017" +
  613. "0000000000000000000000000000000000000000000000000000000000000018",
  614. },
  615. {
  616. def: `[{"type": "bytes32[]"}]`,
  617. unpacked: [][32]byte{{1}, {2}},
  618. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  619. "0000000000000000000000000000000000000000000000000000000000000002" +
  620. "0100000000000000000000000000000000000000000000000000000000000000" +
  621. "0200000000000000000000000000000000000000000000000000000000000000",
  622. },
  623. {
  624. def: `[{"type": "uint32[2]"}]`,
  625. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  626. "0000000000000000000000000000000000000000000000000000000000000002",
  627. unpacked: [2]uint32{1, 2},
  628. },
  629. {
  630. def: `[{"type": "uint64[]"}]`,
  631. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  632. "0000000000000000000000000000000000000000000000000000000000000002" +
  633. "0000000000000000000000000000000000000000000000000000000000000001" +
  634. "0000000000000000000000000000000000000000000000000000000000000002",
  635. unpacked: []uint64{1, 2},
  636. },
  637. {
  638. def: `[{"type": "uint64[2]"}]`,
  639. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  640. "0000000000000000000000000000000000000000000000000000000000000002",
  641. unpacked: [2]uint64{1, 2},
  642. },
  643. {
  644. def: `[{"type": "uint256[]"}]`,
  645. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  646. "0000000000000000000000000000000000000000000000000000000000000002" +
  647. "0000000000000000000000000000000000000000000000000000000000000001" +
  648. "0000000000000000000000000000000000000000000000000000000000000002",
  649. unpacked: []*big.Int{big.NewInt(1), big.NewInt(2)},
  650. },
  651. {
  652. def: `[{"type": "uint256[3]"}]`,
  653. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  654. "0000000000000000000000000000000000000000000000000000000000000002" +
  655. "0000000000000000000000000000000000000000000000000000000000000003",
  656. unpacked: [3]*big.Int{big.NewInt(1), big.NewInt(2), big.NewInt(3)},
  657. },
  658. {
  659. def: `[{"type": "string[4]"}]`,
  660. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  661. "0000000000000000000000000000000000000000000000000000000000000080" +
  662. "00000000000000000000000000000000000000000000000000000000000000c0" +
  663. "0000000000000000000000000000000000000000000000000000000000000100" +
  664. "0000000000000000000000000000000000000000000000000000000000000140" +
  665. "0000000000000000000000000000000000000000000000000000000000000005" +
  666. "48656c6c6f000000000000000000000000000000000000000000000000000000" +
  667. "0000000000000000000000000000000000000000000000000000000000000005" +
  668. "576f726c64000000000000000000000000000000000000000000000000000000" +
  669. "000000000000000000000000000000000000000000000000000000000000000b" +
  670. "476f2d657468657265756d000000000000000000000000000000000000000000" +
  671. "0000000000000000000000000000000000000000000000000000000000000008" +
  672. "457468657265756d000000000000000000000000000000000000000000000000",
  673. unpacked: [4]string{"Hello", "World", "Go-ethereum", "Ethereum"},
  674. },
  675. {
  676. def: `[{"type": "string[]"}]`,
  677. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  678. "0000000000000000000000000000000000000000000000000000000000000002" +
  679. "0000000000000000000000000000000000000000000000000000000000000040" +
  680. "0000000000000000000000000000000000000000000000000000000000000080" +
  681. "0000000000000000000000000000000000000000000000000000000000000008" +
  682. "457468657265756d000000000000000000000000000000000000000000000000" +
  683. "000000000000000000000000000000000000000000000000000000000000000b" +
  684. "676f2d657468657265756d000000000000000000000000000000000000000000",
  685. unpacked: []string{"Ethereum", "go-ethereum"},
  686. },
  687. {
  688. def: `[{"type": "bytes[]"}]`,
  689. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  690. "0000000000000000000000000000000000000000000000000000000000000002" +
  691. "0000000000000000000000000000000000000000000000000000000000000040" +
  692. "0000000000000000000000000000000000000000000000000000000000000080" +
  693. "0000000000000000000000000000000000000000000000000000000000000003" +
  694. "f0f0f00000000000000000000000000000000000000000000000000000000000" +
  695. "0000000000000000000000000000000000000000000000000000000000000003" +
  696. "f0f0f00000000000000000000000000000000000000000000000000000000000",
  697. unpacked: [][]byte{{0xf0, 0xf0, 0xf0}, {0xf0, 0xf0, 0xf0}},
  698. },
  699. {
  700. def: `[{"type": "uint256[2][][]"}]`,
  701. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  702. "0000000000000000000000000000000000000000000000000000000000000002" +
  703. "0000000000000000000000000000000000000000000000000000000000000040" +
  704. "00000000000000000000000000000000000000000000000000000000000000e0" +
  705. "0000000000000000000000000000000000000000000000000000000000000002" +
  706. "0000000000000000000000000000000000000000000000000000000000000001" +
  707. "00000000000000000000000000000000000000000000000000000000000000c8" +
  708. "0000000000000000000000000000000000000000000000000000000000000001" +
  709. "00000000000000000000000000000000000000000000000000000000000003e8" +
  710. "0000000000000000000000000000000000000000000000000000000000000002" +
  711. "0000000000000000000000000000000000000000000000000000000000000001" +
  712. "00000000000000000000000000000000000000000000000000000000000000c8" +
  713. "0000000000000000000000000000000000000000000000000000000000000001" +
  714. "00000000000000000000000000000000000000000000000000000000000003e8",
  715. unpacked: [][][2]*big.Int{{{big.NewInt(1), big.NewInt(200)}, {big.NewInt(1), big.NewInt(1000)}}, {{big.NewInt(1), big.NewInt(200)}, {big.NewInt(1), big.NewInt(1000)}}},
  716. },
  717. // struct outputs
  718. {
  719. def: `[{"components": [{"name":"int1","type":"int256"},{"name":"int2","type":"int256"}], "type":"tuple"}]`,
  720. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  721. "0000000000000000000000000000000000000000000000000000000000000002",
  722. unpacked: struct {
  723. Int1 *big.Int
  724. Int2 *big.Int
  725. }{big.NewInt(1), big.NewInt(2)},
  726. },
  727. {
  728. def: `[{"components": [{"name":"int_one","type":"int256"}], "type":"tuple"}]`,
  729. packed: "0000000000000000000000000000000000000000000000000000000000000001",
  730. unpacked: struct {
  731. IntOne *big.Int
  732. }{big.NewInt(1)},
  733. },
  734. {
  735. def: `[{"components": [{"name":"int__one","type":"int256"}], "type":"tuple"}]`,
  736. packed: "0000000000000000000000000000000000000000000000000000000000000001",
  737. unpacked: struct {
  738. IntOne *big.Int
  739. }{big.NewInt(1)},
  740. },
  741. {
  742. def: `[{"components": [{"name":"int_one_","type":"int256"}], "type":"tuple"}]`,
  743. packed: "0000000000000000000000000000000000000000000000000000000000000001",
  744. unpacked: struct {
  745. IntOne *big.Int
  746. }{big.NewInt(1)},
  747. },
  748. {
  749. def: `[{"components": [{"name":"int_one","type":"int256"}, {"name":"intone","type":"int256"}], "type":"tuple"}]`,
  750. packed: "0000000000000000000000000000000000000000000000000000000000000001" +
  751. "0000000000000000000000000000000000000000000000000000000000000002",
  752. unpacked: struct {
  753. IntOne *big.Int
  754. Intone *big.Int
  755. }{big.NewInt(1), big.NewInt(2)},
  756. },
  757. {
  758. def: `[{"type": "string"}]`,
  759. unpacked: "foobar",
  760. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  761. "0000000000000000000000000000000000000000000000000000000000000006" +
  762. "666f6f6261720000000000000000000000000000000000000000000000000000",
  763. },
  764. {
  765. def: `[{"type": "string[]"}]`,
  766. unpacked: []string{"hello", "foobar"},
  767. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  768. "0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2
  769. "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
  770. "0000000000000000000000000000000000000000000000000000000000000080" + // offset 128 to i = 1
  771. "0000000000000000000000000000000000000000000000000000000000000005" + // len(str[0]) = 5
  772. "68656c6c6f000000000000000000000000000000000000000000000000000000" + // str[0]
  773. "0000000000000000000000000000000000000000000000000000000000000006" + // len(str[1]) = 6
  774. "666f6f6261720000000000000000000000000000000000000000000000000000", // str[1]
  775. },
  776. {
  777. def: `[{"type": "string[2]"}]`,
  778. unpacked: [2]string{"hello", "foobar"},
  779. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  780. "0000000000000000000000000000000000000000000000000000000000000040" + // offset to i = 0
  781. "0000000000000000000000000000000000000000000000000000000000000080" + // offset to i = 1
  782. "0000000000000000000000000000000000000000000000000000000000000005" + // len(str[0]) = 5
  783. "68656c6c6f000000000000000000000000000000000000000000000000000000" + // str[0]
  784. "0000000000000000000000000000000000000000000000000000000000000006" + // len(str[1]) = 6
  785. "666f6f6261720000000000000000000000000000000000000000000000000000", // str[1]
  786. },
  787. {
  788. def: `[{"type": "bytes32[][]"}]`,
  789. unpacked: [][][32]byte{{{1}, {2}}, {{3}, {4}, {5}}},
  790. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  791. "0000000000000000000000000000000000000000000000000000000000000002" + // len(array) = 2
  792. "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
  793. "00000000000000000000000000000000000000000000000000000000000000a0" + // offset 160 to i = 1
  794. "0000000000000000000000000000000000000000000000000000000000000002" + // len(array[0]) = 2
  795. "0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
  796. "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
  797. "0000000000000000000000000000000000000000000000000000000000000003" + // len(array[1]) = 3
  798. "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
  799. "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
  800. "0500000000000000000000000000000000000000000000000000000000000000", // array[1][2]
  801. },
  802. {
  803. def: `[{"type": "bytes32[][2]"}]`,
  804. unpacked: [2][][32]byte{{{1}, {2}}, {{3}, {4}, {5}}},
  805. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  806. "0000000000000000000000000000000000000000000000000000000000000040" + // offset 64 to i = 0
  807. "00000000000000000000000000000000000000000000000000000000000000a0" + // offset 160 to i = 1
  808. "0000000000000000000000000000000000000000000000000000000000000002" + // len(array[0]) = 2
  809. "0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
  810. "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
  811. "0000000000000000000000000000000000000000000000000000000000000003" + // len(array[1]) = 3
  812. "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
  813. "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
  814. "0500000000000000000000000000000000000000000000000000000000000000", // array[1][2]
  815. },
  816. {
  817. def: `[{"type": "bytes32[3][2]"}]`,
  818. unpacked: [2][3][32]byte{{{1}, {2}, {3}}, {{3}, {4}, {5}}},
  819. packed: "0100000000000000000000000000000000000000000000000000000000000000" + // array[0][0]
  820. "0200000000000000000000000000000000000000000000000000000000000000" + // array[0][1]
  821. "0300000000000000000000000000000000000000000000000000000000000000" + // array[0][2]
  822. "0300000000000000000000000000000000000000000000000000000000000000" + // array[1][0]
  823. "0400000000000000000000000000000000000000000000000000000000000000" + // array[1][1]
  824. "0500000000000000000000000000000000000000000000000000000000000000", // array[1][2]
  825. },
  826. {
  827. // static tuple
  828. def: `[{"components": [{"name":"a","type":"int64"},
  829. {"name":"b","type":"int256"},
  830. {"name":"c","type":"int256"},
  831. {"name":"d","type":"bool"},
  832. {"name":"e","type":"bytes32[3][2]"}], "type":"tuple"}]`,
  833. unpacked: struct {
  834. A int64
  835. B *big.Int
  836. C *big.Int
  837. D bool
  838. E [2][3][32]byte
  839. }{1, big.NewInt(1), big.NewInt(-1), true, [2][3][32]byte{{{1}, {2}, {3}}, {{3}, {4}, {5}}}},
  840. packed: "0000000000000000000000000000000000000000000000000000000000000001" + // struct[a]
  841. "0000000000000000000000000000000000000000000000000000000000000001" + // struct[b]
  842. "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + // struct[c]
  843. "0000000000000000000000000000000000000000000000000000000000000001" + // struct[d]
  844. "0100000000000000000000000000000000000000000000000000000000000000" + // struct[e] array[0][0]
  845. "0200000000000000000000000000000000000000000000000000000000000000" + // struct[e] array[0][1]
  846. "0300000000000000000000000000000000000000000000000000000000000000" + // struct[e] array[0][2]
  847. "0300000000000000000000000000000000000000000000000000000000000000" + // struct[e] array[1][0]
  848. "0400000000000000000000000000000000000000000000000000000000000000" + // struct[e] array[1][1]
  849. "0500000000000000000000000000000000000000000000000000000000000000", // struct[e] array[1][2]
  850. },
  851. {
  852. def: `[{"components": [{"name":"a","type":"string"},
  853. {"name":"b","type":"int64"},
  854. {"name":"c","type":"bytes"},
  855. {"name":"d","type":"string[]"},
  856. {"name":"e","type":"int256[]"},
  857. {"name":"f","type":"address[]"}], "type":"tuple"}]`,
  858. unpacked: struct {
  859. A string
  860. B int64
  861. C []byte
  862. D []string
  863. E []*big.Int
  864. F []common.Address
  865. }{"foobar", 1, []byte{1}, []string{"foo", "bar"}, []*big.Int{big.NewInt(1), big.NewInt(-1)}, []common.Address{{1}, {2}}},
  866. packed: "0000000000000000000000000000000000000000000000000000000000000020" + // struct a
  867. "00000000000000000000000000000000000000000000000000000000000000c0" + // struct[a] offset
  868. "0000000000000000000000000000000000000000000000000000000000000001" + // struct[b]
  869. "0000000000000000000000000000000000000000000000000000000000000100" + // struct[c] offset
  870. "0000000000000000000000000000000000000000000000000000000000000140" + // struct[d] offset
  871. "0000000000000000000000000000000000000000000000000000000000000220" + // struct[e] offset
  872. "0000000000000000000000000000000000000000000000000000000000000280" + // struct[f] offset
  873. "0000000000000000000000000000000000000000000000000000000000000006" + // struct[a] length
  874. "666f6f6261720000000000000000000000000000000000000000000000000000" + // struct[a] "foobar"
  875. "0000000000000000000000000000000000000000000000000000000000000001" + // struct[c] length
  876. "0100000000000000000000000000000000000000000000000000000000000000" + // []byte{1}
  877. "0000000000000000000000000000000000000000000000000000000000000002" + // struct[d] length
  878. "0000000000000000000000000000000000000000000000000000000000000040" + // foo offset
  879. "0000000000000000000000000000000000000000000000000000000000000080" + // bar offset
  880. "0000000000000000000000000000000000000000000000000000000000000003" + // foo length
  881. "666f6f0000000000000000000000000000000000000000000000000000000000" + // foo
  882. "0000000000000000000000000000000000000000000000000000000000000003" + // bar offset
  883. "6261720000000000000000000000000000000000000000000000000000000000" + // bar
  884. "0000000000000000000000000000000000000000000000000000000000000002" + // struct[e] length
  885. "0000000000000000000000000000000000000000000000000000000000000001" + // 1
  886. "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + // -1
  887. "0000000000000000000000000000000000000000000000000000000000000002" + // struct[f] length
  888. "0000000000000000000000000100000000000000000000000000000000000000" + // common.Address{1}
  889. "0000000000000000000000000200000000000000000000000000000000000000", // common.Address{2}
  890. },
  891. {
  892. def: `[{"components": [{ "type": "tuple","components": [{"name": "a","type": "uint256"},
  893. {"name": "b","type": "uint256[]"}],
  894. "name": "a","type": "tuple"},
  895. {"name": "b","type": "uint256[]"}], "type": "tuple"}]`,
  896. unpacked: struct {
  897. A struct {
  898. A *big.Int
  899. B []*big.Int
  900. }
  901. B []*big.Int
  902. }{
  903. A: struct {
  904. A *big.Int
  905. B []*big.Int
  906. }{big.NewInt(1), []*big.Int{big.NewInt(1), big.NewInt(2)}},
  907. B: []*big.Int{big.NewInt(1), big.NewInt(2)}},
  908. packed: "0000000000000000000000000000000000000000000000000000000000000020" + // struct a
  909. "0000000000000000000000000000000000000000000000000000000000000040" + // a offset
  910. "00000000000000000000000000000000000000000000000000000000000000e0" + // b offset
  911. "0000000000000000000000000000000000000000000000000000000000000001" + // a.a value
  912. "0000000000000000000000000000000000000000000000000000000000000040" + // a.b offset
  913. "0000000000000000000000000000000000000000000000000000000000000002" + // a.b length
  914. "0000000000000000000000000000000000000000000000000000000000000001" + // a.b[0] value
  915. "0000000000000000000000000000000000000000000000000000000000000002" + // a.b[1] value
  916. "0000000000000000000000000000000000000000000000000000000000000002" + // b length
  917. "0000000000000000000000000000000000000000000000000000000000000001" + // b[0] value
  918. "0000000000000000000000000000000000000000000000000000000000000002", // b[1] value
  919. },
  920. {
  921. def: `[{"components": [{"name": "a","type": "int256"},
  922. {"name": "b","type": "int256[]"}],
  923. "name": "a","type": "tuple[]"}]`,
  924. unpacked: []struct {
  925. A *big.Int
  926. B []*big.Int
  927. }{
  928. {big.NewInt(-1), []*big.Int{big.NewInt(1), big.NewInt(3)}},
  929. {big.NewInt(1), []*big.Int{big.NewInt(2), big.NewInt(-1)}},
  930. },
  931. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  932. "0000000000000000000000000000000000000000000000000000000000000002" + // tuple length
  933. "0000000000000000000000000000000000000000000000000000000000000040" + // tuple[0] offset
  934. "00000000000000000000000000000000000000000000000000000000000000e0" + // tuple[1] offset
  935. "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + // tuple[0].A
  936. "0000000000000000000000000000000000000000000000000000000000000040" + // tuple[0].B offset
  937. "0000000000000000000000000000000000000000000000000000000000000002" + // tuple[0].B length
  938. "0000000000000000000000000000000000000000000000000000000000000001" + // tuple[0].B[0] value
  939. "0000000000000000000000000000000000000000000000000000000000000003" + // tuple[0].B[1] value
  940. "0000000000000000000000000000000000000000000000000000000000000001" + // tuple[1].A
  941. "0000000000000000000000000000000000000000000000000000000000000040" + // tuple[1].B offset
  942. "0000000000000000000000000000000000000000000000000000000000000002" + // tuple[1].B length
  943. "0000000000000000000000000000000000000000000000000000000000000002" + // tuple[1].B[0] value
  944. "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // tuple[1].B[1] value
  945. },
  946. {
  947. def: `[{"components": [{"name": "a","type": "int256"},
  948. {"name": "b","type": "int256"}],
  949. "name": "a","type": "tuple[2]"}]`,
  950. unpacked: [2]struct {
  951. A *big.Int
  952. B *big.Int
  953. }{
  954. {big.NewInt(-1), big.NewInt(1)},
  955. {big.NewInt(1), big.NewInt(-1)},
  956. },
  957. packed: "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + // tuple[0].a
  958. "0000000000000000000000000000000000000000000000000000000000000001" + // tuple[0].b
  959. "0000000000000000000000000000000000000000000000000000000000000001" + // tuple[1].a
  960. "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // tuple[1].b
  961. },
  962. {
  963. def: `[{"components": [{"name": "a","type": "int256[]"}],
  964. "name": "a","type": "tuple[2]"}]`,
  965. unpacked: [2]struct {
  966. A []*big.Int
  967. }{
  968. {[]*big.Int{big.NewInt(-1), big.NewInt(1)}},
  969. {[]*big.Int{big.NewInt(1), big.NewInt(-1)}},
  970. },
  971. packed: "0000000000000000000000000000000000000000000000000000000000000020" +
  972. "0000000000000000000000000000000000000000000000000000000000000040" + // tuple[0] offset
  973. "00000000000000000000000000000000000000000000000000000000000000c0" + // tuple[1] offset
  974. "0000000000000000000000000000000000000000000000000000000000000020" + // tuple[0].A offset
  975. "0000000000000000000000000000000000000000000000000000000000000002" + // tuple[0].A length
  976. "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + // tuple[0].A[0]
  977. "0000000000000000000000000000000000000000000000000000000000000001" + // tuple[0].A[1]
  978. "0000000000000000000000000000000000000000000000000000000000000020" + // tuple[1].A offset
  979. "0000000000000000000000000000000000000000000000000000000000000002" + // tuple[1].A length
  980. "0000000000000000000000000000000000000000000000000000000000000001" + // tuple[1].A[0]
  981. "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", // tuple[1].A[1]
  982. },
  983. }