Packing.t.sol 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. // SPDX-License-Identifier: MIT
  2. // This file was procedurally generated from scripts/generate/templates/Packing.t.js.
  3. pragma solidity ^0.8.20;
  4. import {Test} from "forge-std/Test.sol";
  5. import {Packing} from "@openzeppelin/contracts/utils/Packing.sol";
  6. contract PackingTest is Test {
  7. using Packing for *;
  8. function testPack(bytes1 left, bytes1 right) external {
  9. assertEq(left, Packing.pack_1_1(left, right).extract_2_1(0));
  10. assertEq(right, Packing.pack_1_1(left, right).extract_2_1(1));
  11. }
  12. function testPack(bytes2 left, bytes2 right) external {
  13. assertEq(left, Packing.pack_2_2(left, right).extract_4_2(0));
  14. assertEq(right, Packing.pack_2_2(left, right).extract_4_2(2));
  15. }
  16. function testPack(bytes4 left, bytes4 right) external {
  17. assertEq(left, Packing.pack_4_4(left, right).extract_8_4(0));
  18. assertEq(right, Packing.pack_4_4(left, right).extract_8_4(4));
  19. }
  20. function testPack(bytes4 left, bytes8 right) external {
  21. assertEq(left, Packing.pack_4_8(left, right).extract_12_4(0));
  22. assertEq(right, Packing.pack_4_8(left, right).extract_12_8(4));
  23. }
  24. function testPack(bytes4 left, bytes12 right) external {
  25. assertEq(left, Packing.pack_4_12(left, right).extract_16_4(0));
  26. assertEq(right, Packing.pack_4_12(left, right).extract_16_12(4));
  27. }
  28. function testPack(bytes4 left, bytes16 right) external {
  29. assertEq(left, Packing.pack_4_16(left, right).extract_20_4(0));
  30. assertEq(right, Packing.pack_4_16(left, right).extract_20_16(4));
  31. }
  32. function testPack(bytes4 left, bytes20 right) external {
  33. assertEq(left, Packing.pack_4_20(left, right).extract_24_4(0));
  34. assertEq(right, Packing.pack_4_20(left, right).extract_24_20(4));
  35. }
  36. function testPack(bytes4 left, bytes24 right) external {
  37. assertEq(left, Packing.pack_4_24(left, right).extract_28_4(0));
  38. assertEq(right, Packing.pack_4_24(left, right).extract_28_24(4));
  39. }
  40. function testPack(bytes4 left, bytes28 right) external {
  41. assertEq(left, Packing.pack_4_28(left, right).extract_32_4(0));
  42. assertEq(right, Packing.pack_4_28(left, right).extract_32_28(4));
  43. }
  44. function testPack(bytes8 left, bytes4 right) external {
  45. assertEq(left, Packing.pack_8_4(left, right).extract_12_8(0));
  46. assertEq(right, Packing.pack_8_4(left, right).extract_12_4(8));
  47. }
  48. function testPack(bytes8 left, bytes8 right) external {
  49. assertEq(left, Packing.pack_8_8(left, right).extract_16_8(0));
  50. assertEq(right, Packing.pack_8_8(left, right).extract_16_8(8));
  51. }
  52. function testPack(bytes8 left, bytes12 right) external {
  53. assertEq(left, Packing.pack_8_12(left, right).extract_20_8(0));
  54. assertEq(right, Packing.pack_8_12(left, right).extract_20_12(8));
  55. }
  56. function testPack(bytes8 left, bytes16 right) external {
  57. assertEq(left, Packing.pack_8_16(left, right).extract_24_8(0));
  58. assertEq(right, Packing.pack_8_16(left, right).extract_24_16(8));
  59. }
  60. function testPack(bytes8 left, bytes20 right) external {
  61. assertEq(left, Packing.pack_8_20(left, right).extract_28_8(0));
  62. assertEq(right, Packing.pack_8_20(left, right).extract_28_20(8));
  63. }
  64. function testPack(bytes8 left, bytes24 right) external {
  65. assertEq(left, Packing.pack_8_24(left, right).extract_32_8(0));
  66. assertEq(right, Packing.pack_8_24(left, right).extract_32_24(8));
  67. }
  68. function testPack(bytes12 left, bytes4 right) external {
  69. assertEq(left, Packing.pack_12_4(left, right).extract_16_12(0));
  70. assertEq(right, Packing.pack_12_4(left, right).extract_16_4(12));
  71. }
  72. function testPack(bytes12 left, bytes8 right) external {
  73. assertEq(left, Packing.pack_12_8(left, right).extract_20_12(0));
  74. assertEq(right, Packing.pack_12_8(left, right).extract_20_8(12));
  75. }
  76. function testPack(bytes12 left, bytes12 right) external {
  77. assertEq(left, Packing.pack_12_12(left, right).extract_24_12(0));
  78. assertEq(right, Packing.pack_12_12(left, right).extract_24_12(12));
  79. }
  80. function testPack(bytes12 left, bytes16 right) external {
  81. assertEq(left, Packing.pack_12_16(left, right).extract_28_12(0));
  82. assertEq(right, Packing.pack_12_16(left, right).extract_28_16(12));
  83. }
  84. function testPack(bytes12 left, bytes20 right) external {
  85. assertEq(left, Packing.pack_12_20(left, right).extract_32_12(0));
  86. assertEq(right, Packing.pack_12_20(left, right).extract_32_20(12));
  87. }
  88. function testPack(bytes16 left, bytes4 right) external {
  89. assertEq(left, Packing.pack_16_4(left, right).extract_20_16(0));
  90. assertEq(right, Packing.pack_16_4(left, right).extract_20_4(16));
  91. }
  92. function testPack(bytes16 left, bytes8 right) external {
  93. assertEq(left, Packing.pack_16_8(left, right).extract_24_16(0));
  94. assertEq(right, Packing.pack_16_8(left, right).extract_24_8(16));
  95. }
  96. function testPack(bytes16 left, bytes12 right) external {
  97. assertEq(left, Packing.pack_16_12(left, right).extract_28_16(0));
  98. assertEq(right, Packing.pack_16_12(left, right).extract_28_12(16));
  99. }
  100. function testPack(bytes16 left, bytes16 right) external {
  101. assertEq(left, Packing.pack_16_16(left, right).extract_32_16(0));
  102. assertEq(right, Packing.pack_16_16(left, right).extract_32_16(16));
  103. }
  104. function testPack(bytes20 left, bytes4 right) external {
  105. assertEq(left, Packing.pack_20_4(left, right).extract_24_20(0));
  106. assertEq(right, Packing.pack_20_4(left, right).extract_24_4(20));
  107. }
  108. function testPack(bytes20 left, bytes8 right) external {
  109. assertEq(left, Packing.pack_20_8(left, right).extract_28_20(0));
  110. assertEq(right, Packing.pack_20_8(left, right).extract_28_8(20));
  111. }
  112. function testPack(bytes20 left, bytes12 right) external {
  113. assertEq(left, Packing.pack_20_12(left, right).extract_32_20(0));
  114. assertEq(right, Packing.pack_20_12(left, right).extract_32_12(20));
  115. }
  116. function testPack(bytes24 left, bytes4 right) external {
  117. assertEq(left, Packing.pack_24_4(left, right).extract_28_24(0));
  118. assertEq(right, Packing.pack_24_4(left, right).extract_28_4(24));
  119. }
  120. function testPack(bytes24 left, bytes8 right) external {
  121. assertEq(left, Packing.pack_24_8(left, right).extract_32_24(0));
  122. assertEq(right, Packing.pack_24_8(left, right).extract_32_8(24));
  123. }
  124. function testPack(bytes28 left, bytes4 right) external {
  125. assertEq(left, Packing.pack_28_4(left, right).extract_32_28(0));
  126. assertEq(right, Packing.pack_28_4(left, right).extract_32_4(28));
  127. }
  128. function testReplace(bytes2 container, bytes1 newValue, uint8 offset) external {
  129. offset = uint8(bound(offset, 0, 1));
  130. bytes1 oldValue = container.extract_2_1(offset);
  131. assertEq(newValue, container.replace_2_1(newValue, offset).extract_2_1(offset));
  132. assertEq(container, container.replace_2_1(newValue, offset).replace_2_1(oldValue, offset));
  133. }
  134. function testReplace(bytes4 container, bytes1 newValue, uint8 offset) external {
  135. offset = uint8(bound(offset, 0, 3));
  136. bytes1 oldValue = container.extract_4_1(offset);
  137. assertEq(newValue, container.replace_4_1(newValue, offset).extract_4_1(offset));
  138. assertEq(container, container.replace_4_1(newValue, offset).replace_4_1(oldValue, offset));
  139. }
  140. function testReplace(bytes4 container, bytes2 newValue, uint8 offset) external {
  141. offset = uint8(bound(offset, 0, 2));
  142. bytes2 oldValue = container.extract_4_2(offset);
  143. assertEq(newValue, container.replace_4_2(newValue, offset).extract_4_2(offset));
  144. assertEq(container, container.replace_4_2(newValue, offset).replace_4_2(oldValue, offset));
  145. }
  146. function testReplace(bytes8 container, bytes1 newValue, uint8 offset) external {
  147. offset = uint8(bound(offset, 0, 7));
  148. bytes1 oldValue = container.extract_8_1(offset);
  149. assertEq(newValue, container.replace_8_1(newValue, offset).extract_8_1(offset));
  150. assertEq(container, container.replace_8_1(newValue, offset).replace_8_1(oldValue, offset));
  151. }
  152. function testReplace(bytes8 container, bytes2 newValue, uint8 offset) external {
  153. offset = uint8(bound(offset, 0, 6));
  154. bytes2 oldValue = container.extract_8_2(offset);
  155. assertEq(newValue, container.replace_8_2(newValue, offset).extract_8_2(offset));
  156. assertEq(container, container.replace_8_2(newValue, offset).replace_8_2(oldValue, offset));
  157. }
  158. function testReplace(bytes8 container, bytes4 newValue, uint8 offset) external {
  159. offset = uint8(bound(offset, 0, 4));
  160. bytes4 oldValue = container.extract_8_4(offset);
  161. assertEq(newValue, container.replace_8_4(newValue, offset).extract_8_4(offset));
  162. assertEq(container, container.replace_8_4(newValue, offset).replace_8_4(oldValue, offset));
  163. }
  164. function testReplace(bytes12 container, bytes1 newValue, uint8 offset) external {
  165. offset = uint8(bound(offset, 0, 11));
  166. bytes1 oldValue = container.extract_12_1(offset);
  167. assertEq(newValue, container.replace_12_1(newValue, offset).extract_12_1(offset));
  168. assertEq(container, container.replace_12_1(newValue, offset).replace_12_1(oldValue, offset));
  169. }
  170. function testReplace(bytes12 container, bytes2 newValue, uint8 offset) external {
  171. offset = uint8(bound(offset, 0, 10));
  172. bytes2 oldValue = container.extract_12_2(offset);
  173. assertEq(newValue, container.replace_12_2(newValue, offset).extract_12_2(offset));
  174. assertEq(container, container.replace_12_2(newValue, offset).replace_12_2(oldValue, offset));
  175. }
  176. function testReplace(bytes12 container, bytes4 newValue, uint8 offset) external {
  177. offset = uint8(bound(offset, 0, 8));
  178. bytes4 oldValue = container.extract_12_4(offset);
  179. assertEq(newValue, container.replace_12_4(newValue, offset).extract_12_4(offset));
  180. assertEq(container, container.replace_12_4(newValue, offset).replace_12_4(oldValue, offset));
  181. }
  182. function testReplace(bytes12 container, bytes8 newValue, uint8 offset) external {
  183. offset = uint8(bound(offset, 0, 4));
  184. bytes8 oldValue = container.extract_12_8(offset);
  185. assertEq(newValue, container.replace_12_8(newValue, offset).extract_12_8(offset));
  186. assertEq(container, container.replace_12_8(newValue, offset).replace_12_8(oldValue, offset));
  187. }
  188. function testReplace(bytes16 container, bytes1 newValue, uint8 offset) external {
  189. offset = uint8(bound(offset, 0, 15));
  190. bytes1 oldValue = container.extract_16_1(offset);
  191. assertEq(newValue, container.replace_16_1(newValue, offset).extract_16_1(offset));
  192. assertEq(container, container.replace_16_1(newValue, offset).replace_16_1(oldValue, offset));
  193. }
  194. function testReplace(bytes16 container, bytes2 newValue, uint8 offset) external {
  195. offset = uint8(bound(offset, 0, 14));
  196. bytes2 oldValue = container.extract_16_2(offset);
  197. assertEq(newValue, container.replace_16_2(newValue, offset).extract_16_2(offset));
  198. assertEq(container, container.replace_16_2(newValue, offset).replace_16_2(oldValue, offset));
  199. }
  200. function testReplace(bytes16 container, bytes4 newValue, uint8 offset) external {
  201. offset = uint8(bound(offset, 0, 12));
  202. bytes4 oldValue = container.extract_16_4(offset);
  203. assertEq(newValue, container.replace_16_4(newValue, offset).extract_16_4(offset));
  204. assertEq(container, container.replace_16_4(newValue, offset).replace_16_4(oldValue, offset));
  205. }
  206. function testReplace(bytes16 container, bytes8 newValue, uint8 offset) external {
  207. offset = uint8(bound(offset, 0, 8));
  208. bytes8 oldValue = container.extract_16_8(offset);
  209. assertEq(newValue, container.replace_16_8(newValue, offset).extract_16_8(offset));
  210. assertEq(container, container.replace_16_8(newValue, offset).replace_16_8(oldValue, offset));
  211. }
  212. function testReplace(bytes16 container, bytes12 newValue, uint8 offset) external {
  213. offset = uint8(bound(offset, 0, 4));
  214. bytes12 oldValue = container.extract_16_12(offset);
  215. assertEq(newValue, container.replace_16_12(newValue, offset).extract_16_12(offset));
  216. assertEq(container, container.replace_16_12(newValue, offset).replace_16_12(oldValue, offset));
  217. }
  218. function testReplace(bytes20 container, bytes1 newValue, uint8 offset) external {
  219. offset = uint8(bound(offset, 0, 19));
  220. bytes1 oldValue = container.extract_20_1(offset);
  221. assertEq(newValue, container.replace_20_1(newValue, offset).extract_20_1(offset));
  222. assertEq(container, container.replace_20_1(newValue, offset).replace_20_1(oldValue, offset));
  223. }
  224. function testReplace(bytes20 container, bytes2 newValue, uint8 offset) external {
  225. offset = uint8(bound(offset, 0, 18));
  226. bytes2 oldValue = container.extract_20_2(offset);
  227. assertEq(newValue, container.replace_20_2(newValue, offset).extract_20_2(offset));
  228. assertEq(container, container.replace_20_2(newValue, offset).replace_20_2(oldValue, offset));
  229. }
  230. function testReplace(bytes20 container, bytes4 newValue, uint8 offset) external {
  231. offset = uint8(bound(offset, 0, 16));
  232. bytes4 oldValue = container.extract_20_4(offset);
  233. assertEq(newValue, container.replace_20_4(newValue, offset).extract_20_4(offset));
  234. assertEq(container, container.replace_20_4(newValue, offset).replace_20_4(oldValue, offset));
  235. }
  236. function testReplace(bytes20 container, bytes8 newValue, uint8 offset) external {
  237. offset = uint8(bound(offset, 0, 12));
  238. bytes8 oldValue = container.extract_20_8(offset);
  239. assertEq(newValue, container.replace_20_8(newValue, offset).extract_20_8(offset));
  240. assertEq(container, container.replace_20_8(newValue, offset).replace_20_8(oldValue, offset));
  241. }
  242. function testReplace(bytes20 container, bytes12 newValue, uint8 offset) external {
  243. offset = uint8(bound(offset, 0, 8));
  244. bytes12 oldValue = container.extract_20_12(offset);
  245. assertEq(newValue, container.replace_20_12(newValue, offset).extract_20_12(offset));
  246. assertEq(container, container.replace_20_12(newValue, offset).replace_20_12(oldValue, offset));
  247. }
  248. function testReplace(bytes20 container, bytes16 newValue, uint8 offset) external {
  249. offset = uint8(bound(offset, 0, 4));
  250. bytes16 oldValue = container.extract_20_16(offset);
  251. assertEq(newValue, container.replace_20_16(newValue, offset).extract_20_16(offset));
  252. assertEq(container, container.replace_20_16(newValue, offset).replace_20_16(oldValue, offset));
  253. }
  254. function testReplace(bytes24 container, bytes1 newValue, uint8 offset) external {
  255. offset = uint8(bound(offset, 0, 23));
  256. bytes1 oldValue = container.extract_24_1(offset);
  257. assertEq(newValue, container.replace_24_1(newValue, offset).extract_24_1(offset));
  258. assertEq(container, container.replace_24_1(newValue, offset).replace_24_1(oldValue, offset));
  259. }
  260. function testReplace(bytes24 container, bytes2 newValue, uint8 offset) external {
  261. offset = uint8(bound(offset, 0, 22));
  262. bytes2 oldValue = container.extract_24_2(offset);
  263. assertEq(newValue, container.replace_24_2(newValue, offset).extract_24_2(offset));
  264. assertEq(container, container.replace_24_2(newValue, offset).replace_24_2(oldValue, offset));
  265. }
  266. function testReplace(bytes24 container, bytes4 newValue, uint8 offset) external {
  267. offset = uint8(bound(offset, 0, 20));
  268. bytes4 oldValue = container.extract_24_4(offset);
  269. assertEq(newValue, container.replace_24_4(newValue, offset).extract_24_4(offset));
  270. assertEq(container, container.replace_24_4(newValue, offset).replace_24_4(oldValue, offset));
  271. }
  272. function testReplace(bytes24 container, bytes8 newValue, uint8 offset) external {
  273. offset = uint8(bound(offset, 0, 16));
  274. bytes8 oldValue = container.extract_24_8(offset);
  275. assertEq(newValue, container.replace_24_8(newValue, offset).extract_24_8(offset));
  276. assertEq(container, container.replace_24_8(newValue, offset).replace_24_8(oldValue, offset));
  277. }
  278. function testReplace(bytes24 container, bytes12 newValue, uint8 offset) external {
  279. offset = uint8(bound(offset, 0, 12));
  280. bytes12 oldValue = container.extract_24_12(offset);
  281. assertEq(newValue, container.replace_24_12(newValue, offset).extract_24_12(offset));
  282. assertEq(container, container.replace_24_12(newValue, offset).replace_24_12(oldValue, offset));
  283. }
  284. function testReplace(bytes24 container, bytes16 newValue, uint8 offset) external {
  285. offset = uint8(bound(offset, 0, 8));
  286. bytes16 oldValue = container.extract_24_16(offset);
  287. assertEq(newValue, container.replace_24_16(newValue, offset).extract_24_16(offset));
  288. assertEq(container, container.replace_24_16(newValue, offset).replace_24_16(oldValue, offset));
  289. }
  290. function testReplace(bytes24 container, bytes20 newValue, uint8 offset) external {
  291. offset = uint8(bound(offset, 0, 4));
  292. bytes20 oldValue = container.extract_24_20(offset);
  293. assertEq(newValue, container.replace_24_20(newValue, offset).extract_24_20(offset));
  294. assertEq(container, container.replace_24_20(newValue, offset).replace_24_20(oldValue, offset));
  295. }
  296. function testReplace(bytes28 container, bytes1 newValue, uint8 offset) external {
  297. offset = uint8(bound(offset, 0, 27));
  298. bytes1 oldValue = container.extract_28_1(offset);
  299. assertEq(newValue, container.replace_28_1(newValue, offset).extract_28_1(offset));
  300. assertEq(container, container.replace_28_1(newValue, offset).replace_28_1(oldValue, offset));
  301. }
  302. function testReplace(bytes28 container, bytes2 newValue, uint8 offset) external {
  303. offset = uint8(bound(offset, 0, 26));
  304. bytes2 oldValue = container.extract_28_2(offset);
  305. assertEq(newValue, container.replace_28_2(newValue, offset).extract_28_2(offset));
  306. assertEq(container, container.replace_28_2(newValue, offset).replace_28_2(oldValue, offset));
  307. }
  308. function testReplace(bytes28 container, bytes4 newValue, uint8 offset) external {
  309. offset = uint8(bound(offset, 0, 24));
  310. bytes4 oldValue = container.extract_28_4(offset);
  311. assertEq(newValue, container.replace_28_4(newValue, offset).extract_28_4(offset));
  312. assertEq(container, container.replace_28_4(newValue, offset).replace_28_4(oldValue, offset));
  313. }
  314. function testReplace(bytes28 container, bytes8 newValue, uint8 offset) external {
  315. offset = uint8(bound(offset, 0, 20));
  316. bytes8 oldValue = container.extract_28_8(offset);
  317. assertEq(newValue, container.replace_28_8(newValue, offset).extract_28_8(offset));
  318. assertEq(container, container.replace_28_8(newValue, offset).replace_28_8(oldValue, offset));
  319. }
  320. function testReplace(bytes28 container, bytes12 newValue, uint8 offset) external {
  321. offset = uint8(bound(offset, 0, 16));
  322. bytes12 oldValue = container.extract_28_12(offset);
  323. assertEq(newValue, container.replace_28_12(newValue, offset).extract_28_12(offset));
  324. assertEq(container, container.replace_28_12(newValue, offset).replace_28_12(oldValue, offset));
  325. }
  326. function testReplace(bytes28 container, bytes16 newValue, uint8 offset) external {
  327. offset = uint8(bound(offset, 0, 12));
  328. bytes16 oldValue = container.extract_28_16(offset);
  329. assertEq(newValue, container.replace_28_16(newValue, offset).extract_28_16(offset));
  330. assertEq(container, container.replace_28_16(newValue, offset).replace_28_16(oldValue, offset));
  331. }
  332. function testReplace(bytes28 container, bytes20 newValue, uint8 offset) external {
  333. offset = uint8(bound(offset, 0, 8));
  334. bytes20 oldValue = container.extract_28_20(offset);
  335. assertEq(newValue, container.replace_28_20(newValue, offset).extract_28_20(offset));
  336. assertEq(container, container.replace_28_20(newValue, offset).replace_28_20(oldValue, offset));
  337. }
  338. function testReplace(bytes28 container, bytes24 newValue, uint8 offset) external {
  339. offset = uint8(bound(offset, 0, 4));
  340. bytes24 oldValue = container.extract_28_24(offset);
  341. assertEq(newValue, container.replace_28_24(newValue, offset).extract_28_24(offset));
  342. assertEq(container, container.replace_28_24(newValue, offset).replace_28_24(oldValue, offset));
  343. }
  344. function testReplace(bytes32 container, bytes1 newValue, uint8 offset) external {
  345. offset = uint8(bound(offset, 0, 31));
  346. bytes1 oldValue = container.extract_32_1(offset);
  347. assertEq(newValue, container.replace_32_1(newValue, offset).extract_32_1(offset));
  348. assertEq(container, container.replace_32_1(newValue, offset).replace_32_1(oldValue, offset));
  349. }
  350. function testReplace(bytes32 container, bytes2 newValue, uint8 offset) external {
  351. offset = uint8(bound(offset, 0, 30));
  352. bytes2 oldValue = container.extract_32_2(offset);
  353. assertEq(newValue, container.replace_32_2(newValue, offset).extract_32_2(offset));
  354. assertEq(container, container.replace_32_2(newValue, offset).replace_32_2(oldValue, offset));
  355. }
  356. function testReplace(bytes32 container, bytes4 newValue, uint8 offset) external {
  357. offset = uint8(bound(offset, 0, 28));
  358. bytes4 oldValue = container.extract_32_4(offset);
  359. assertEq(newValue, container.replace_32_4(newValue, offset).extract_32_4(offset));
  360. assertEq(container, container.replace_32_4(newValue, offset).replace_32_4(oldValue, offset));
  361. }
  362. function testReplace(bytes32 container, bytes8 newValue, uint8 offset) external {
  363. offset = uint8(bound(offset, 0, 24));
  364. bytes8 oldValue = container.extract_32_8(offset);
  365. assertEq(newValue, container.replace_32_8(newValue, offset).extract_32_8(offset));
  366. assertEq(container, container.replace_32_8(newValue, offset).replace_32_8(oldValue, offset));
  367. }
  368. function testReplace(bytes32 container, bytes12 newValue, uint8 offset) external {
  369. offset = uint8(bound(offset, 0, 20));
  370. bytes12 oldValue = container.extract_32_12(offset);
  371. assertEq(newValue, container.replace_32_12(newValue, offset).extract_32_12(offset));
  372. assertEq(container, container.replace_32_12(newValue, offset).replace_32_12(oldValue, offset));
  373. }
  374. function testReplace(bytes32 container, bytes16 newValue, uint8 offset) external {
  375. offset = uint8(bound(offset, 0, 16));
  376. bytes16 oldValue = container.extract_32_16(offset);
  377. assertEq(newValue, container.replace_32_16(newValue, offset).extract_32_16(offset));
  378. assertEq(container, container.replace_32_16(newValue, offset).replace_32_16(oldValue, offset));
  379. }
  380. function testReplace(bytes32 container, bytes20 newValue, uint8 offset) external {
  381. offset = uint8(bound(offset, 0, 12));
  382. bytes20 oldValue = container.extract_32_20(offset);
  383. assertEq(newValue, container.replace_32_20(newValue, offset).extract_32_20(offset));
  384. assertEq(container, container.replace_32_20(newValue, offset).replace_32_20(oldValue, offset));
  385. }
  386. function testReplace(bytes32 container, bytes24 newValue, uint8 offset) external {
  387. offset = uint8(bound(offset, 0, 8));
  388. bytes24 oldValue = container.extract_32_24(offset);
  389. assertEq(newValue, container.replace_32_24(newValue, offset).extract_32_24(offset));
  390. assertEq(container, container.replace_32_24(newValue, offset).replace_32_24(oldValue, offset));
  391. }
  392. function testReplace(bytes32 container, bytes28 newValue, uint8 offset) external {
  393. offset = uint8(bound(offset, 0, 4));
  394. bytes28 oldValue = container.extract_32_28(offset);
  395. assertEq(newValue, container.replace_32_28(newValue, offset).extract_32_28(offset));
  396. assertEq(container, container.replace_32_28(newValue, offset).replace_32_28(oldValue, offset));
  397. }
  398. }