quantumcoin 7.0.12 → 7.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README-SDK.md +828 -823
  2. package/README.md +4 -0
  3. package/config.d.ts +50 -50
  4. package/examples/example-generated-sdk-js/README.md +65 -0
  5. package/examples/example-generated-sdk-js/examples/_test-wallet.js +17 -0
  6. package/examples/example-generated-sdk-js/examples/deploy.js +41 -0
  7. package/examples/example-generated-sdk-js/examples/events.js +36 -0
  8. package/examples/example-generated-sdk-js/examples/read-operations.js +46 -0
  9. package/examples/example-generated-sdk-js/examples/write-operations.js +44 -0
  10. package/examples/example-generated-sdk-js/index.d.ts +1 -0
  11. package/examples/example-generated-sdk-js/index.js +15 -0
  12. package/examples/example-generated-sdk-js/package-lock.json +59 -0
  13. package/examples/example-generated-sdk-js/package.json +22 -0
  14. package/examples/example-generated-sdk-js/src/SimpleERC20.d.ts +19 -0
  15. package/examples/example-generated-sdk-js/src/SimpleERC20.js +353 -0
  16. package/examples/example-generated-sdk-js/src/SimpleERC20__factory.d.ts +10 -0
  17. package/examples/example-generated-sdk-js/src/SimpleERC20__factory.js +29 -0
  18. package/examples/example-generated-sdk-js/src/index.d.ts +4 -0
  19. package/examples/example-generated-sdk-js/src/index.js +5 -0
  20. package/examples/example-generated-sdk-js/src/quantumcoin-shims.d.ts +23 -0
  21. package/examples/example-generated-sdk-js/src/types.d.ts +3 -0
  22. package/examples/example-generated-sdk-js/src/types.js +3 -0
  23. package/examples/example-generated-sdk-js/test/e2e/SimpleERC20.e2e.test.js +78 -0
  24. package/examples/example-generated-sdk-ts/README.md +65 -0
  25. package/examples/example-generated-sdk-ts/examples/_test-wallet.js +17 -0
  26. package/examples/example-generated-sdk-ts/examples/deploy.js +41 -0
  27. package/examples/example-generated-sdk-ts/examples/events.js +36 -0
  28. package/examples/example-generated-sdk-ts/examples/read-operations.js +46 -0
  29. package/examples/example-generated-sdk-ts/examples/write-operations.js +44 -0
  30. package/examples/example-generated-sdk-ts/index.d.ts +1 -0
  31. package/examples/example-generated-sdk-ts/index.js +15 -0
  32. package/examples/example-generated-sdk-ts/package-lock.json +59 -0
  33. package/examples/example-generated-sdk-ts/package.json +23 -0
  34. package/examples/example-generated-sdk-ts/src/SimpleERC20.ts +334 -0
  35. package/examples/example-generated-sdk-ts/src/SimpleERC20__factory.ts +28 -0
  36. package/examples/example-generated-sdk-ts/src/index.ts +4 -0
  37. package/examples/example-generated-sdk-ts/src/quantumcoin-shims.d.ts +23 -0
  38. package/examples/example-generated-sdk-ts/src/types.ts +4 -0
  39. package/examples/example-generated-sdk-ts/test/e2e/SimpleERC20.e2e.test.js +78 -0
  40. package/examples/example-generated-sdk-ts/tsconfig.json +14 -0
  41. package/examples/node_modules/.package-lock.json +5 -5
  42. package/examples/node_modules/quantum-coin-js-sdk/README.md +5 -5
  43. package/examples/node_modules/quantum-coin-js-sdk/example/package-lock.json +1 -1
  44. package/examples/node_modules/quantum-coin-js-sdk/index.d.ts +1031 -1031
  45. package/examples/node_modules/quantum-coin-js-sdk/index.js +15 -15
  46. package/examples/node_modules/quantum-coin-js-sdk/package.json +1 -1
  47. package/examples/node_modules/quantum-coin-js-sdk/wasmBase64.js +2 -2
  48. package/examples/package-lock.json +6 -6
  49. package/examples/package.json +1 -1
  50. package/examples/sdk-generator-erc20.inline.json +251 -251
  51. package/generate-sdk.js +1845 -1822
  52. package/package.json +2 -2
  53. package/src/abi/fragments.d.ts +42 -42
  54. package/src/abi/index.d.ts +13 -13
  55. package/src/abi/interface.js +11 -2
  56. package/src/abi/js-abi-coder.js +61 -2
  57. package/src/contract/contract.js +53 -5
  58. package/src/contract/index.d.ts +9 -9
  59. package/src/errors/index.d.ts +92 -92
  60. package/src/generator/index.d.ts +11 -4
  61. package/src/generator/index.js +185 -18
  62. package/src/internal/hex.d.ts +68 -61
  63. package/src/internal/hex.js +36 -0
  64. package/src/providers/json-rpc-provider.d.ts +12 -12
  65. package/src/providers/provider.js +141 -8
  66. package/src/utils/address.d.ts +58 -58
  67. package/src/utils/encoding.d.ts +120 -120
  68. package/src/utils/hashing.js +298 -298
  69. package/src/utils/index.d.ts +63 -63
  70. package/src/utils/index.js +14 -14
  71. package/src/utils/result.d.ts +57 -57
  72. package/src/utils/rlp.d.ts +12 -12
  73. package/src/utils/rlp.js +13 -1
  74. package/src/utils/units.d.ts +29 -29
  75. package/src/wallet/index.d.ts +10 -10
  76. package/src/wallet/wallet.d.ts +192 -192
  77. package/src/wallet/wallet.js +713 -630
  78. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/README.md +83 -0
  79. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/artifacts/AllSolidityTypes.abi.json +12544 -0
  80. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/artifacts/AllSolidityTypes.bin +1 -0
  81. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/_test-wallet.js +17 -0
  82. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/_test-wallet.ts +10 -0
  83. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/deploy.js +41 -0
  84. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/deploy.ts +41 -0
  85. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/events.js +36 -0
  86. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/events.ts +36 -0
  87. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/offline-signing.js +82 -0
  88. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/offline-signing.ts +80 -0
  89. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/read-operations.js +46 -0
  90. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/read-operations.ts +44 -0
  91. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/write-operations.js +44 -0
  92. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/examples/write-operations.ts +44 -0
  93. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/index.d.ts +1 -0
  94. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/index.js +21 -0
  95. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/package-lock.json +597 -0
  96. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/package.json +25 -0
  97. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes.d.ts +1280 -0
  98. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes.js +14021 -0
  99. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes__factory.d.ts +11 -0
  100. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/AllSolidityTypes__factory.js +31 -0
  101. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/index.d.ts +4 -0
  102. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/index.js +5 -0
  103. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/quantumcoin-shims.d.ts +25 -0
  104. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/types.d.ts +3 -0
  105. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/src/types.js +3 -0
  106. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/test/e2e/AllSolidityTypes.e2e.test.js +77 -0
  107. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-js/test/e2e/AllSolidityTypes.extra.test.js +195 -0
  108. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/README.md +83 -0
  109. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/artifacts/AllSolidityTypes.abi.json +12544 -0
  110. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/artifacts/AllSolidityTypes.bin +1 -0
  111. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/_test-wallet.js +17 -0
  112. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/_test-wallet.ts +10 -0
  113. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/deploy.js +41 -0
  114. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/deploy.ts +41 -0
  115. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/events.js +36 -0
  116. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/events.ts +36 -0
  117. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/offline-signing.js +82 -0
  118. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/offline-signing.ts +80 -0
  119. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/read-operations.js +46 -0
  120. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/read-operations.ts +44 -0
  121. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/write-operations.js +44 -0
  122. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/examples/write-operations.ts +44 -0
  123. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/index.d.ts +1 -0
  124. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/index.js +21 -0
  125. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/package-lock.json +597 -0
  126. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/package.json +26 -0
  127. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/AllSolidityTypes.ts +13940 -0
  128. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/AllSolidityTypes__factory.ts +31 -0
  129. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/index.ts +4 -0
  130. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/quantumcoin-shims.d.ts +25 -0
  131. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/src/types.ts +4 -0
  132. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/test/e2e/AllSolidityTypes.e2e.test.js +77 -0
  133. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/test/e2e/AllSolidityTypes.extra.test.js +195 -0
  134. package/test/e2e/generated-sdks/all-solidity-types/all-solidity-types-ts/tsconfig.json +18 -0
  135. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/README.md +74 -0
  136. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/artifacts/SimpleERC20.abi.json +245 -0
  137. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/artifacts/SimpleERC20.bin +1 -0
  138. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/_test-wallet.js +17 -0
  139. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/_test-wallet.ts +10 -0
  140. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/deploy.js +41 -0
  141. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/deploy.ts +41 -0
  142. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/events.js +36 -0
  143. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/events.ts +36 -0
  144. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/offline-signing.js +82 -0
  145. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/offline-signing.ts +80 -0
  146. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/read-operations.js +46 -0
  147. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/read-operations.ts +44 -0
  148. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/write-operations.js +44 -0
  149. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/examples/write-operations.ts +44 -0
  150. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/index.d.ts +1 -0
  151. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/index.js +16 -0
  152. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/package-lock.json +597 -0
  153. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/package.json +25 -0
  154. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20.d.ts +24 -0
  155. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20.js +378 -0
  156. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20__factory.d.ts +10 -0
  157. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/SimpleERC20__factory.js +31 -0
  158. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/index.d.ts +4 -0
  159. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/index.js +5 -0
  160. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/quantumcoin-shims.d.ts +25 -0
  161. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/types.d.ts +3 -0
  162. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/src/types.js +3 -0
  163. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-js/test/e2e/SimpleERC20.e2e.test.js +90 -0
  164. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/README.md +74 -0
  165. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/artifacts/SimpleERC20.abi.json +245 -0
  166. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/artifacts/SimpleERC20.bin +1 -0
  167. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/_test-wallet.js +17 -0
  168. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/_test-wallet.ts +10 -0
  169. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/deploy.js +41 -0
  170. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/deploy.ts +41 -0
  171. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/events.js +36 -0
  172. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/events.ts +36 -0
  173. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/offline-signing.js +82 -0
  174. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/offline-signing.ts +80 -0
  175. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/read-operations.js +46 -0
  176. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/read-operations.ts +44 -0
  177. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/write-operations.js +44 -0
  178. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/examples/write-operations.ts +44 -0
  179. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/index.d.ts +1 -0
  180. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/index.js +16 -0
  181. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/package-lock.json +597 -0
  182. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/package.json +26 -0
  183. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/SimpleERC20.ts +361 -0
  184. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/SimpleERC20__factory.ts +30 -0
  185. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/index.ts +4 -0
  186. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/quantumcoin-shims.d.ts +25 -0
  187. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/src/types.ts +4 -0
  188. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/test/e2e/SimpleERC20.e2e.test.js +90 -0
  189. package/test/e2e/generated-sdks/simple-erc20/simple-erc20-ts/tsconfig.json +18 -0
  190. package/test/e2e/generator-interface.e2e.test.js +165 -0
  191. package/test/e2e/generator-interface.e2e.test.ts +160 -0
  192. package/test/e2e/signing-context-and-fee.e2e.test.js +141 -141
  193. package/test/e2e/signing-context-and-fee.e2e.test.ts +128 -128
  194. package/test/integration/provider.test.js +88 -88
  195. package/test/security/abi-decoder-bounds.test.js +122 -0
  196. package/test/security/contract-overrides.test.js +112 -0
  197. package/test/security/generator-injection.test.js +195 -0
  198. package/test/security/malformed-input.test.js +26 -27
  199. package/test/security/rpc-numeric-bounds.test.js +81 -0
  200. package/test/security/rpc-trust.test.js +202 -0
  201. package/test/unit/abi-interface.test.js +12 -5
  202. package/test/unit/abi-interface.test.ts +8 -1
  203. package/test/unit/address-wallet.test.js +923 -892
  204. package/test/unit/address-wallet.test.ts +877 -877
  205. package/test/unit/encoding-units-rlp.test.js +35 -0
  206. package/test/unit/generator.test.js +48 -1
  207. package/test/unit/generator.test.ts +48 -1
  208. package/test/unit/hashing.test.js +64 -64
  209. package/test/unit/hashing.test.ts +63 -63
  210. package/test/unit/internal-hex.test.js +32 -1
  211. package/test/unit/internal-hex.test.ts +32 -1
  212. package/test/unit/populate-transaction.test.js +33 -0
  213. package/test/unit/providers.test.js +51 -1
  214. package/test/unit/providers.test.ts +53 -0
@@ -89,4 +89,39 @@
89
89
  assert.equal(decoded, "0x");
90
90
  });
91
91
  });
92
+
93
+ describe("Security: RLP canonical encoding & length overflow", () => {
94
+ it("rejects a single byte < 0x80 encoded as a 1-byte string (negative)", () => {
95
+ // 0x81 0x00 = "short string of length 1 containing 0x00" — must be 0x00.
96
+ assert.throws(() => qc.decodeRlp("0x8100"), /non-canonical single byte/i);
97
+ });
98
+
99
+ it("rejects a long-string form whose length fits the short form (negative)", () => {
100
+ // 0xb8 (long string, lenOfLen=1) 0x01 0xff -> declared length 1 (<= 55).
101
+ assert.throws(() => qc.decodeRlp("0xb801ff"), /non-canonical long string/i);
102
+ });
103
+
104
+ it("rejects a length field with a leading zero byte (negative)", () => {
105
+ // 0xb9 (long string, lenOfLen=2) 0x00 0x38 -> leading zero in the length.
106
+ assert.throws(() => qc.decodeRlp("0xb9003800"), /leading zero/i);
107
+ });
108
+
109
+ it("rejects a length that overflows MAX_SAFE_INTEGER (negative)", () => {
110
+ // 0xbf (long string, lenOfLen=8) followed by an 8-byte length starting at 0x20.
111
+ assert.throws(() => qc.decodeRlp("0xbf2000000000000000"), /maximum safe integer/i);
112
+ });
113
+
114
+ it("round-trips a canonical long string (> 55 bytes) (positive)", () => {
115
+ const big = "0x" + "ab".repeat(60); // 60-byte string -> long-string form
116
+ const encoded = qc.encodeRlp(big);
117
+ const decoded = qc.decodeRlp(encoded);
118
+ assert.equal(decoded, big);
119
+ });
120
+
121
+ it("round-trips a canonical nested list (positive)", () => {
122
+ const encoded = qc.encodeRlp([["0x01", "0x02"], "0x03"]);
123
+ const decoded = qc.decodeRlp(encoded);
124
+ assert.deepEqual(decoded, [["0x01", "0x02"], "0x03"]);
125
+ });
126
+ });
92
127
 
@@ -11,7 +11,7 @@ const fs = require("node:fs");
11
11
  const os = require("node:os");
12
12
  const path = require("node:path");
13
13
 
14
- const { generate, generateFromArtifacts } = require("../../src/generator");
14
+ const { generate, generateFromArtifacts, generateTransactionalTestJs } = require("../../src/generator");
15
15
  const { logSuite, logTest } = require("../verbose-logger");
16
16
 
17
17
  describe("typed contract generator", () => {
@@ -62,6 +62,53 @@ describe("typed contract generator", () => {
62
62
  assert.ok(factorySrc.includes("export class TestToken__factory"));
63
63
  });
64
64
 
65
+ it("generated test for a concrete contract (with bytecode) contains the provider.getCode bytecode assertion", () => {
66
+ logTest("generated test for a concrete contract contains the bytecode assertion", {});
67
+ const src = generateTransactionalTestJs({
68
+ contractName: "ConcreteToken",
69
+ abi: [{ type: "constructor", inputs: [], stateMutability: "nonpayable" }],
70
+ bytecode: "0x6080604052",
71
+ });
72
+ assert.ok(src.includes("provider.getCode(contract.target"));
73
+ assert.ok(src.includes('assert.ok(code && code !== "0x")'));
74
+ assert.ok(!src.includes("Skipping bytecode check"));
75
+ });
76
+
77
+ it("generated test for an interface (bytecode '0x') omits the provider.getCode bytecode assertion", () => {
78
+ logTest("generated test for an interface omits the bytecode assertion", {});
79
+ const src = generateTransactionalTestJs({
80
+ contractName: "IThing",
81
+ abi: [{
82
+ type: "function", name: "doThing",
83
+ inputs: [], outputs: [], stateMutability: "nonpayable",
84
+ }],
85
+ bytecode: "0x",
86
+ });
87
+ assert.ok(!src.includes("provider.getCode(contract.target"));
88
+ assert.ok(!src.includes('assert.ok(code && code !== "0x")'));
89
+ assert.ok(src.includes("Skipping bytecode check"));
90
+ assert.ok(src.includes("IThing is an interface"));
91
+ });
92
+
93
+ it("empty/undefined/null/'0X' bytecode variants are all treated as interface", () => {
94
+ logTest("empty bytecode variants are all treated as interface", {});
95
+ for (const bc of [undefined, null, "", "0x", "0X", " 0x "]) {
96
+ const src = generateTransactionalTestJs({
97
+ contractName: "IThing",
98
+ abi: [],
99
+ bytecode: bc,
100
+ });
101
+ assert.ok(
102
+ !src.includes("provider.getCode(contract.target"),
103
+ `bytecode=${JSON.stringify(bc)} should be treated as interface (no getCode assertion)`,
104
+ );
105
+ assert.ok(
106
+ src.includes("Skipping bytecode check"),
107
+ `bytecode=${JSON.stringify(bc)} should emit skip comment`,
108
+ );
109
+ }
110
+ });
111
+
65
112
  it("includes injected docs in generated TypeScript", () => {
66
113
  const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-docs-"));
67
114
  const outDir = path.join(tmp, "out");
@@ -11,7 +11,7 @@ import fs from "node:fs";
11
11
  import os from "node:os";
12
12
  import path from "node:path";
13
13
 
14
- import { generate, generateFromArtifacts } from "../../src/generator";
14
+ import { generate, generateFromArtifacts, generateTransactionalTestJs } from "../../src/generator";
15
15
  import { logSuite, logTest } from "../verbose-logger";
16
16
 
17
17
  describe("typed contract generator", () => {
@@ -62,6 +62,53 @@ describe("typed contract generator", () => {
62
62
  assert.ok(factorySrc.includes("export class TestToken__factory"));
63
63
  });
64
64
 
65
+ it("generated test for a concrete contract (with bytecode) contains the provider.getCode bytecode assertion", () => {
66
+ logTest("generated test for a concrete contract contains the bytecode assertion", {});
67
+ const src = generateTransactionalTestJs({
68
+ contractName: "ConcreteToken",
69
+ abi: [{ type: "constructor", inputs: [], stateMutability: "nonpayable" }],
70
+ bytecode: "0x6080604052",
71
+ });
72
+ assert.ok(src.includes("provider.getCode(contract.target"));
73
+ assert.ok(src.includes('assert.ok(code && code !== "0x")'));
74
+ assert.ok(!src.includes("Skipping bytecode check"));
75
+ });
76
+
77
+ it("generated test for an interface (bytecode '0x') omits the provider.getCode bytecode assertion", () => {
78
+ logTest("generated test for an interface omits the bytecode assertion", {});
79
+ const src = generateTransactionalTestJs({
80
+ contractName: "IThing",
81
+ abi: [{
82
+ type: "function", name: "doThing",
83
+ inputs: [], outputs: [], stateMutability: "nonpayable",
84
+ }],
85
+ bytecode: "0x",
86
+ });
87
+ assert.ok(!src.includes("provider.getCode(contract.target"));
88
+ assert.ok(!src.includes('assert.ok(code && code !== "0x")'));
89
+ assert.ok(src.includes("Skipping bytecode check"));
90
+ assert.ok(src.includes("IThing is an interface"));
91
+ });
92
+
93
+ it("empty/undefined/null/'0X' bytecode variants are all treated as interface", () => {
94
+ logTest("empty bytecode variants are all treated as interface", {});
95
+ for (const bc of [undefined, null, "", "0x", "0X", " 0x "] as Array<string | null | undefined>) {
96
+ const src = generateTransactionalTestJs({
97
+ contractName: "IThing",
98
+ abi: [],
99
+ bytecode: bc as unknown as string,
100
+ });
101
+ assert.ok(
102
+ !src.includes("provider.getCode(contract.target"),
103
+ `bytecode=${JSON.stringify(bc)} should be treated as interface (no getCode assertion)`,
104
+ );
105
+ assert.ok(
106
+ src.includes("Skipping bytecode check"),
107
+ `bytecode=${JSON.stringify(bc)} should emit skip comment`,
108
+ );
109
+ }
110
+ });
111
+
65
112
  it("includes injected docs in generated TypeScript", () => {
66
113
  const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "qcgen-docs-"));
67
114
  const outDir = path.join(tmp, "out");
@@ -1,64 +1,64 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Hashing helpers (optional params, deterministic behavior)
6
- */
7
-
8
- const { describe, it } = require("node:test");
9
- const assert = require("node:assert/strict");
10
-
11
- const qc = require("../../index");
12
- const { logSuite, logTest } = require("../verbose-logger");
13
-
14
- describe("Hashing", () => {
15
- logSuite("Hashing");
16
- it("keccak256 returns a 32-byte hex digest for empty bytes", () => {
17
- logTest("keccak256 returns a 32-byte hex digest for empty bytes", {});
18
- const out = qc.keccak256(new Uint8Array([]));
19
- assert.equal(typeof out, "string");
20
- assert.ok(out.startsWith("0x"));
21
- assert.equal(out.length, 66);
22
- });
23
-
24
- it("sha256/sha512/ripemd160 output lengths are correct", () => {
25
- const data = qc.toUtf8Bytes("hello");
26
- assert.equal(qc.sha256(data).length, 66);
27
- assert.equal(qc.sha512(data).length, 130);
28
- assert.equal(qc.ripemd160(data).length, 42);
29
- });
30
-
31
- it("randomBytes returns requested length", () => {
32
- const b = qc.randomBytes(16);
33
- assert.ok(b instanceof Uint8Array);
34
- assert.equal(b.length, 16);
35
- });
36
-
37
- it("pbkdf2 algorithm defaults when omitted vs null vs explicit", () => {
38
- const pw = qc.toUtf8Bytes("password");
39
- const salt = qc.toUtf8Bytes("salt");
40
-
41
- const a = qc.pbkdf2(pw, salt, 1, 32);
42
- const b = qc.pbkdf2(pw, salt, 1, 32, "sha256");
43
- const c = qc.pbkdf2(pw, salt, 1, 32, null);
44
-
45
- assert.equal(a, b);
46
- assert.equal(a, c);
47
- assert.ok(a.startsWith("0x") && a.length === 66);
48
- });
49
-
50
- it("computeHmac produces a hex string", () => {
51
- const key = qc.toUtf8Bytes("key");
52
- const data = qc.toUtf8Bytes("data");
53
- const out = qc.computeHmac("sha256", key, data);
54
- assert.ok(typeof out === "string" && out.startsWith("0x") && out.length === 66);
55
- });
56
-
57
- it("scryptSync with N=262144, r=8, p=1 produces expected hardcoded output", () => {
58
- const pw = qc.toUtf8Bytes("password");
59
- const salt = qc.toUtf8Bytes("salt");
60
- const out = qc.scryptSync(pw, salt, 262144, 8, 1, 32);
61
- assert.equal(out, "0xd36e883d93698af49daa529419bb1d97da262bbaa225c12fcf05651268659f42");
62
- });
63
- });
64
-
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Hashing helpers (optional params, deterministic behavior)
6
+ */
7
+
8
+ const { describe, it } = require("node:test");
9
+ const assert = require("node:assert/strict");
10
+
11
+ const qc = require("../../index");
12
+ const { logSuite, logTest } = require("../verbose-logger");
13
+
14
+ describe("Hashing", () => {
15
+ logSuite("Hashing");
16
+ it("keccak256 returns a 32-byte hex digest for empty bytes", () => {
17
+ logTest("keccak256 returns a 32-byte hex digest for empty bytes", {});
18
+ const out = qc.keccak256(new Uint8Array([]));
19
+ assert.equal(typeof out, "string");
20
+ assert.ok(out.startsWith("0x"));
21
+ assert.equal(out.length, 66);
22
+ });
23
+
24
+ it("sha256/sha512/ripemd160 output lengths are correct", () => {
25
+ const data = qc.toUtf8Bytes("hello");
26
+ assert.equal(qc.sha256(data).length, 66);
27
+ assert.equal(qc.sha512(data).length, 130);
28
+ assert.equal(qc.ripemd160(data).length, 42);
29
+ });
30
+
31
+ it("randomBytes returns requested length", () => {
32
+ const b = qc.randomBytes(16);
33
+ assert.ok(b instanceof Uint8Array);
34
+ assert.equal(b.length, 16);
35
+ });
36
+
37
+ it("pbkdf2 algorithm defaults when omitted vs null vs explicit", () => {
38
+ const pw = qc.toUtf8Bytes("password");
39
+ const salt = qc.toUtf8Bytes("salt");
40
+
41
+ const a = qc.pbkdf2(pw, salt, 1, 32);
42
+ const b = qc.pbkdf2(pw, salt, 1, 32, "sha256");
43
+ const c = qc.pbkdf2(pw, salt, 1, 32, null);
44
+
45
+ assert.equal(a, b);
46
+ assert.equal(a, c);
47
+ assert.ok(a.startsWith("0x") && a.length === 66);
48
+ });
49
+
50
+ it("computeHmac produces a hex string", () => {
51
+ const key = qc.toUtf8Bytes("key");
52
+ const data = qc.toUtf8Bytes("data");
53
+ const out = qc.computeHmac("sha256", key, data);
54
+ assert.ok(typeof out === "string" && out.startsWith("0x") && out.length === 66);
55
+ });
56
+
57
+ it("scryptSync with N=262144, r=8, p=1 produces expected hardcoded output", () => {
58
+ const pw = qc.toUtf8Bytes("password");
59
+ const salt = qc.toUtf8Bytes("salt");
60
+ const out = qc.scryptSync(pw, salt, 262144, 8, 1, 32);
61
+ assert.equal(out, "0xd36e883d93698af49daa529419bb1d97da262bbaa225c12fcf05651268659f42");
62
+ });
63
+ });
64
+
@@ -1,63 +1,63 @@
1
- /**
2
- * @testCategory unit
3
- * @blockchainRequired false
4
- * @transactional false
5
- * @description Hashing helpers (optional params, deterministic behavior)
6
- */
7
-
8
- import { describe, it } from "node:test";
9
- import assert from "node:assert/strict";
10
-
11
- import qc from "../../index";
12
- import { logSuite, logTest } from "../verbose-logger";
13
-
14
- describe("Hashing", () => {
15
- logSuite("Hashing");
16
- it("keccak256 returns a 32-byte hex digest for empty bytes", () => {
17
- logTest("keccak256 returns a 32-byte hex digest for empty bytes", {});
18
- const out = qc.keccak256(new Uint8Array([]));
19
- assert.equal(typeof out, "string");
20
- assert.ok(out.startsWith("0x"));
21
- assert.equal(out.length, 66);
22
- });
23
-
24
- it("sha256/sha512/ripemd160 output lengths are correct", () => {
25
- const data = qc.toUtf8Bytes("hello");
26
- assert.equal(qc.sha256(data).length, 66);
27
- assert.equal(qc.sha512(data).length, 130);
28
- assert.equal(qc.ripemd160(data).length, 42);
29
- });
30
-
31
- it("randomBytes returns requested length", () => {
32
- const b = qc.randomBytes(16);
33
- assert.ok(b instanceof Uint8Array);
34
- assert.equal(b.length, 16);
35
- });
36
-
37
- it("pbkdf2 algorithm defaults when omitted vs null vs explicit", () => {
38
- const pw = qc.toUtf8Bytes("password");
39
- const salt = qc.toUtf8Bytes("salt");
40
-
41
- const a = qc.pbkdf2(pw, salt, 1, 32);
42
- const b = qc.pbkdf2(pw, salt, 1, 32, "sha256");
43
- const c = qc.pbkdf2(pw, salt, 1, 32, null);
44
-
45
- assert.equal(a, b);
46
- assert.equal(a, c);
47
- assert.ok(a.startsWith("0x") && a.length === 66);
48
- });
49
-
50
- it("computeHmac produces a hex string", () => {
51
- const key = qc.toUtf8Bytes("key");
52
- const data = qc.toUtf8Bytes("data");
53
- const out = qc.computeHmac("sha256", key, data);
54
- assert.ok(typeof out === "string" && out.startsWith("0x") && out.length === 66);
55
- });
56
-
57
- it("scryptSync with N=262144, r=8, p=1 produces expected hardcoded output", () => {
58
- const pw = qc.toUtf8Bytes("password");
59
- const salt = qc.toUtf8Bytes("salt");
60
- const out = qc.scryptSync(pw, salt, 262144, 8, 1, 32);
61
- assert.equal(out, "0xd36e883d93698af49daa529419bb1d97da262bbaa225c12fcf05651268659f42");
62
- });
63
- });
1
+ /**
2
+ * @testCategory unit
3
+ * @blockchainRequired false
4
+ * @transactional false
5
+ * @description Hashing helpers (optional params, deterministic behavior)
6
+ */
7
+
8
+ import { describe, it } from "node:test";
9
+ import assert from "node:assert/strict";
10
+
11
+ import qc from "../../index";
12
+ import { logSuite, logTest } from "../verbose-logger";
13
+
14
+ describe("Hashing", () => {
15
+ logSuite("Hashing");
16
+ it("keccak256 returns a 32-byte hex digest for empty bytes", () => {
17
+ logTest("keccak256 returns a 32-byte hex digest for empty bytes", {});
18
+ const out = qc.keccak256(new Uint8Array([]));
19
+ assert.equal(typeof out, "string");
20
+ assert.ok(out.startsWith("0x"));
21
+ assert.equal(out.length, 66);
22
+ });
23
+
24
+ it("sha256/sha512/ripemd160 output lengths are correct", () => {
25
+ const data = qc.toUtf8Bytes("hello");
26
+ assert.equal(qc.sha256(data).length, 66);
27
+ assert.equal(qc.sha512(data).length, 130);
28
+ assert.equal(qc.ripemd160(data).length, 42);
29
+ });
30
+
31
+ it("randomBytes returns requested length", () => {
32
+ const b = qc.randomBytes(16);
33
+ assert.ok(b instanceof Uint8Array);
34
+ assert.equal(b.length, 16);
35
+ });
36
+
37
+ it("pbkdf2 algorithm defaults when omitted vs null vs explicit", () => {
38
+ const pw = qc.toUtf8Bytes("password");
39
+ const salt = qc.toUtf8Bytes("salt");
40
+
41
+ const a = qc.pbkdf2(pw, salt, 1, 32);
42
+ const b = qc.pbkdf2(pw, salt, 1, 32, "sha256");
43
+ const c = qc.pbkdf2(pw, salt, 1, 32, null);
44
+
45
+ assert.equal(a, b);
46
+ assert.equal(a, c);
47
+ assert.ok(a.startsWith("0x") && a.length === 66);
48
+ });
49
+
50
+ it("computeHmac produces a hex string", () => {
51
+ const key = qc.toUtf8Bytes("key");
52
+ const data = qc.toUtf8Bytes("data");
53
+ const out = qc.computeHmac("sha256", key, data);
54
+ assert.ok(typeof out === "string" && out.startsWith("0x") && out.length === 66);
55
+ });
56
+
57
+ it("scryptSync with N=262144, r=8, p=1 produces expected hardcoded output", () => {
58
+ const pw = qc.toUtf8Bytes("password");
59
+ const salt = qc.toUtf8Bytes("salt");
60
+ const out = qc.scryptSync(pw, salt, 262144, 8, 1, 32);
61
+ assert.equal(out, "0xd36e883d93698af49daa529419bb1d97da262bbaa225c12fcf05651268659f42");
62
+ });
63
+ });
@@ -8,7 +8,7 @@
8
8
  const { describe, it } = require("node:test");
9
9
  const assert = require("node:assert/strict");
10
10
 
11
- const { normalizeHex, isHexString, hexToBytes, bytesToHex, arrayify } = require("../../src/internal/hex");
11
+ const { normalizeHex, toQuantityHex, toQuantity, isHexString, hexToBytes, bytesToHex, arrayify } = require("../../src/internal/hex");
12
12
  const { logSuite, logTest } = require("../verbose-logger");
13
13
 
14
14
  describe("internal/hex", () => {
@@ -20,6 +20,37 @@
20
20
  assert.equal(normalizeHex("0xa"), "0x0a");
21
21
  assert.equal(normalizeHex("0x0A"), "0x0a");
22
22
  });
23
+
24
+ it("toQuantityHex produces spec-compliant quantities (no leading zeros, 0x0 for zero)", () => {
25
+ logTest("toQuantityHex produces spec-compliant quantities", {});
26
+ assert.equal(toQuantityHex(0), "0x0");
27
+ assert.equal(toQuantityHex(0n), "0x0");
28
+ assert.equal(toQuantityHex(1), "0x1");
29
+ assert.equal(toQuantityHex(5), "0x5");
30
+ assert.equal(toQuantityHex(15), "0xf");
31
+ assert.equal(toQuantityHex(16), "0x10");
32
+ assert.equal(toQuantityHex(255), "0xff");
33
+ assert.equal(toQuantityHex(256), "0x100");
34
+ assert.equal(toQuantityHex(4095), "0xfff");
35
+ assert.equal(toQuantityHex(4096), "0x1000");
36
+ assert.equal(toQuantityHex(65535n), "0xffff");
37
+ assert.equal(toQuantityHex(2n ** 64n), "0x10000000000000000");
38
+
39
+ assert.equal(toQuantity, toQuantityHex);
40
+ assert.equal(toQuantity(5), "0x5");
41
+ });
42
+
43
+ it("toQuantityHex rejects invalid inputs", () => {
44
+ logTest("toQuantityHex rejects invalid inputs", {});
45
+ assert.throws(() => toQuantityHex(-1), RangeError);
46
+ assert.throws(() => toQuantityHex(-1n), RangeError);
47
+ assert.throws(() => toQuantityHex(1.5), TypeError);
48
+ assert.throws(() => toQuantityHex(NaN), TypeError);
49
+ assert.throws(() => toQuantityHex(Infinity), TypeError);
50
+ assert.throws(() => toQuantityHex("5"), TypeError);
51
+ assert.throws(() => toQuantityHex(null), TypeError);
52
+ assert.throws(() => toQuantityHex(undefined), TypeError);
53
+ });
23
54
 
24
55
  it("isHexString validates and supports optional lengthBytes", () => {
25
56
  const h32 = "0x" + "11".repeat(32);
@@ -8,7 +8,7 @@
8
8
  import { describe, it } from "node:test";
9
9
  import assert from "node:assert/strict";
10
10
 
11
- import { normalizeHex, isHexString, hexToBytes, bytesToHex, arrayify } from "../../src/internal/hex";
11
+ import { normalizeHex, toQuantityHex, toQuantity, isHexString, hexToBytes, bytesToHex, arrayify } from "../../src/internal/hex";
12
12
  import { logSuite, logTest } from "../verbose-logger";
13
13
 
14
14
  describe("internal/hex", () => {
@@ -21,6 +21,37 @@ describe("internal/hex", () => {
21
21
  assert.equal(normalizeHex("0x0A"), "0x0a");
22
22
  });
23
23
 
24
+ it("toQuantityHex produces spec-compliant quantities (no leading zeros, 0x0 for zero)", () => {
25
+ logTest("toQuantityHex produces spec-compliant quantities", {});
26
+ assert.equal(toQuantityHex(0), "0x0");
27
+ assert.equal(toQuantityHex(0n), "0x0");
28
+ assert.equal(toQuantityHex(1), "0x1");
29
+ assert.equal(toQuantityHex(5), "0x5");
30
+ assert.equal(toQuantityHex(15), "0xf");
31
+ assert.equal(toQuantityHex(16), "0x10");
32
+ assert.equal(toQuantityHex(255), "0xff");
33
+ assert.equal(toQuantityHex(256), "0x100");
34
+ assert.equal(toQuantityHex(4095), "0xfff");
35
+ assert.equal(toQuantityHex(4096), "0x1000");
36
+ assert.equal(toQuantityHex(65535n), "0xffff");
37
+ assert.equal(toQuantityHex(2n ** 64n), "0x10000000000000000");
38
+
39
+ assert.equal(toQuantity, toQuantityHex);
40
+ assert.equal(toQuantity(5), "0x5");
41
+ });
42
+
43
+ it("toQuantityHex rejects invalid inputs", () => {
44
+ logTest("toQuantityHex rejects invalid inputs", {});
45
+ assert.throws(() => toQuantityHex(-1), RangeError);
46
+ assert.throws(() => toQuantityHex(-1n), RangeError);
47
+ assert.throws(() => toQuantityHex(1.5), TypeError);
48
+ assert.throws(() => toQuantityHex(NaN), TypeError);
49
+ assert.throws(() => toQuantityHex(Infinity), TypeError);
50
+ assert.throws(() => toQuantityHex("5" as unknown as number), TypeError);
51
+ assert.throws(() => toQuantityHex(null as unknown as number), TypeError);
52
+ assert.throws(() => toQuantityHex(undefined as unknown as number), TypeError);
53
+ });
54
+
24
55
  it("isHexString validates and supports optional lengthBytes", () => {
25
56
  const h32 = "0x" + "11".repeat(32);
26
57
  assert.equal(isHexString(h32), true);
@@ -63,3 +63,36 @@ describe("populateTransaction + sendRawTransaction", () => {
63
63
  });
64
64
  });
65
65
 
66
+ describe("Security: mandatory chainId for signing", () => {
67
+ logSuite("Security: mandatory chainId for signing");
68
+
69
+ it("offline signing without a chainId throws (negative)", async () => {
70
+ logTest("offline signing without a chainId throws", {});
71
+ await Initialize(null);
72
+ const w = qc.Wallet.createRandom(); // no provider connected
73
+ await assert.rejects(
74
+ () => w.signTransaction({ to: w.address, value: 0n, nonce: 0 }),
75
+ /chainId is required for signing/i,
76
+ );
77
+ });
78
+
79
+ it("offline signing with an explicit chainId succeeds (positive)", async () => {
80
+ logTest("offline signing with an explicit chainId succeeds", {});
81
+ await Initialize(null);
82
+ const w = qc.Wallet.createRandom();
83
+ const raw = await w.signTransaction({ to: w.address, value: 0n, nonce: 0, chainId: 123123 });
84
+ assert.equal(typeof raw, "string");
85
+ assert.ok(raw.startsWith("0x"));
86
+ });
87
+
88
+ it("signing resolves chainId from a connected provider (positive)", async () => {
89
+ logTest("signing resolves chainId from a connected provider", {});
90
+ await Initialize(null);
91
+ const provider = new qc.JsonRpcProvider("http://127.0.0.1:9999", 123123);
92
+ const w = qc.Wallet.createRandom().connect(provider);
93
+ const raw = await w.signTransaction({ to: w.address, value: 0n, nonce: 0 });
94
+ assert.equal(typeof raw, "string");
95
+ assert.ok(raw.startsWith("0x"));
96
+ });
97
+ });
98
+
@@ -94,7 +94,57 @@
94
94
  });
95
95
  });
96
96
 
97
- describe("TransactionResponse.wait", () => {
97
+ describe("AbstractProvider block-tag QUANTITY formatting", () => {
98
+ logSuite("AbstractProvider block-tag QUANTITY formatting");
99
+
100
+ it("getBlock encodes block numbers as spec-compliant quantities (no leading zeros)", async () => {
101
+ logTest("getBlock encodes block numbers as spec-compliant quantities", {});
102
+ class BlockStub extends qc.AbstractProvider {
103
+ constructor() { super(); this.calls = []; }
104
+ async _perform(method, params) {
105
+ this.calls.push({ method, params });
106
+ return { number: "0x5", timestamp: "0x64" };
107
+ }
108
+ }
109
+ const p = new BlockStub();
110
+ await p.getBlock(0); assert.equal(p.calls.at(-1).params[0], "0x0");
111
+ await p.getBlock(5); assert.equal(p.calls.at(-1).params[0], "0x5");
112
+ await p.getBlock(15); assert.equal(p.calls.at(-1).params[0], "0xf");
113
+ await p.getBlock(16); assert.equal(p.calls.at(-1).params[0], "0x10");
114
+ await p.getBlock(256); assert.equal(p.calls.at(-1).params[0], "0x100");
115
+ await p.getBlock(4095); assert.equal(p.calls.at(-1).params[0], "0xfff");
116
+ await p.getBlock(4096); assert.equal(p.calls.at(-1).params[0], "0x1000");
117
+ await p.getBlock("latest"); assert.equal(p.calls.at(-1).params[0], "latest");
118
+ });
119
+
120
+ it("getLogs encodes fromBlock/toBlock as spec-compliant quantities (no leading zeros)", async () => {
121
+ logTest("getLogs encodes fromBlock/toBlock as spec-compliant quantities", {});
122
+ class LogStub extends qc.AbstractProvider {
123
+ constructor() { super(); this.calls = []; }
124
+ async _perform(method, params) { this.calls.push({ method, params }); return []; }
125
+ }
126
+ const lp = new LogStub();
127
+ await lp.getLogs({ fromBlock: 5, toBlock: 256 });
128
+ assert.equal(lp.calls[0].params[0].fromBlock, "0x5");
129
+ assert.equal(lp.calls[0].params[0].toBlock, "0x100");
130
+ await lp.getLogs({ fromBlock: "latest", toBlock: "pending" });
131
+ assert.equal(lp.calls[1].params[0].fromBlock, "latest");
132
+ assert.equal(lp.calls[1].params[0].toBlock, "pending");
133
+ });
134
+
135
+ it("getBlock rejects invalid block numbers with a clear typed error", async () => {
136
+ logTest("getBlock rejects invalid block numbers", {});
137
+ class StubP extends qc.AbstractProvider {
138
+ async _perform() { return { number: "0x0" }; }
139
+ }
140
+ const p = new StubP();
141
+ await assert.rejects(() => p.getBlock(-1), (e) => e instanceof RangeError);
142
+ await assert.rejects(() => p.getBlock(1.5), (e) => e instanceof TypeError);
143
+ await assert.rejects(() => p.getBlock(NaN), (e) => e instanceof TypeError);
144
+ });
145
+ });
146
+
147
+ describe("TransactionResponse.wait", () => {
98
148
  logSuite("TransactionResponse.wait");
99
149
  it("uses default confirmations when omitted vs null", async () => {
100
150
  logTest("uses default confirmations when omitted vs null", {});