Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 10x 60x 60x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 50x 10x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 4x 4x 24x 24x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 8x 8x 8x 8x 16x 20x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 20x 20x 20x 4x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 6x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 14x 14x 14x 14x 14x 14x 9x 9x 9x 9x 9x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 6x 6x 6x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 6x 6x 6x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x | import assert from "assert"; import { concat, dataSlice, id, toBeArray, zeroPadValue, isCallException, isError, Wallet } from "../index.js"; import { getProvider, setupProviders, providerNames } from "./create-provider.js"; import { FAUCET_PRIVATEKEY, stall } from "./utils.js"; import type { TransactionResponse } from "../index.js"; type TestCustomError = { name: string; signature: string; message: string, data: string; reason: null | string, revert: null | { signature: string, name: string, args: Array<any> }, }; setupProviders(); describe("Tests Provider Call Exception", function() { const panics: Array<{ code: number, reason: string }> = [ //{ code: 0x00, reason: "GENERIC_PANIC" }, { code: 0x01, reason: "ASSERT_FALSE" }, { code: 0x11, reason: "OVERFLOW" }, { code: 0x12, reason: "DIVIDE_BY_ZERO" }, //{ code: 0x21, reason: "ENUM_RANGE_ERROR" }, //{ code: 0x22, reason: "BAD_STORAGE_DATA" }, { code: 0x31, reason: "STACK_UNDERFLOW" }, { code: 0x32, reason: "ARRAY_RANGE_ERROR" }, //{ code: 0x41, reason: "OUT_OF_MEMORY" }, //{ code: 0x51, reason: "UNINITIALIZED_FUNCTION_CALL" }, ]; const testAddr = "0x86d19fF4b2EB0D451511B5B930b01DC71fD9a2Ee"; const networkName = "sepolia"; for (const { code, reason } of panics) { for (const method of [ "call", "estimateGas" ]) { for (const providerName of providerNames) { const provider = getProvider(providerName, networkName); if (provider == null) { continue; } it(`tests panic code: ${ providerName }.${ method }.${ reason }`, async function() { this.timeout(10000); const data = concat([ dataSlice(id("testPanic(uint256)"), 0, 4), zeroPadValue(toBeArray(code), 32) ]); await stall(1000); const tx = { to: testAddr, data }; try { const result = await (method === "call" ? provider.call(tx): provider.estimateGas(tx)); console.log(result); assert.ok(false, "panic call did not throw"); } catch (error) { assert.ok(isCallException(error), "isCallException"); // Check some basics assert.equal(error.action, method, `error.action == ${ method }`); assert.equal(error.reason, `Panic due to ${ reason }(${ code })`, "error.reason"); // Check the transaciton assert.equal(error.transaction.to, tx.to, `error.transaction.to`); assert.equal(error.transaction.data, tx.data, `error.transaction.data`); // We have no invocation data assert.equal(error.invocation, null, `error.invocation != null`); // Check the revert assert.ok(error.revert != null, "error.revert == null"); assert.equal(error.revert.name, "Panic", `error.revert.name`); assert.equal(error.revert.signature, "Panic(uint256)", `error.revert.signature`); assert.equal(error.revert.args.length, 1, `error.revert.args.length`); assert.equal(error.revert.args[0], code, `error.revert.args[0]`); } }); } } } const customErrors: Array<TestCustomError> = [ { name: "CustomError1", signature: "testCustomError1(bool,uint256,string)", data: "0xdb7342480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000", //data: "0x852d0c740000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002a0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000b48656c6c6f20576f726c64000000000000000000000000000000000000000000", message: `execution reverted (unknown custom error)`, reason: null, revert: null, }, { name: "Error", signature: "testErrorString(bool,string)", data: "0xb206699b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000b68656c6c6f20776f726c64000000000000000000000000000000000000000000", //data: "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b48656c6c6f20576f726c64000000000000000000000000000000000000000000" message: `execution reverted: "hello world"`, reason: "hello world", revert: { signature: "Error(string)", name: "Error", args: [ 'hello world' ] } }, ]; for (const { data, message, name, reason, revert } of customErrors) { for (const method of [ "call", "estimateGas" ]) { const tx = { to: testAddr, data }; for (const providerName of providerNames) { const provider = getProvider(providerName, networkName); if (provider == null) { continue; } it(`tests custom errors: ${ providerName }.${ method }.${ name }`, async function() { this.timeout(10000) try { const result = await (method === "call" ? provider.call(tx): provider.estimateGas(tx)); console.log(result); assert.ok(false, "panic call did not throw"); } catch (error) { assert.ok(isCallException(error), "isCallException"); // Check some basics assert.equal(error.action, method, `error.action == ${ method }`); assert.ok(error.message.startsWith(message), "error.message == message"); if (reason) { assert.equal(error.reason, reason, "error.reason"); } else { assert.ok(error.reason == null, "error.reason != null"); } if (revert) { assert.ok(error.revert != null, "error.revert == null"); assert.equal(error.revert.name, revert.name, "error.revert.name"); assert.equal(error.revert.signature, revert.signature, "error.revert.signature"); assert.equal(error.revert.args.length, revert.args.length, "error.revert.args.length"); for (let i = 0; i < revert.args.length; i++) { assert.equal(error.revert.args[i], revert.args[i], `error.revert.args[${ i }]`); } } else { assert.ok(error.revert == null, "error.revert != null"); } } }); } } } }); describe("Test Provider Blockchain Errors", function() { if (!FAUCET_PRIVATEKEY) { console.log("Missing Faucet Private Key! Tests Skipped."); return; } const wallet = new Wallet(FAUCET_PRIVATEKEY); const networkName = "sepolia"; for (const providerName of providerNames) { const provider = getProvider(providerName, networkName); if (provider == null) { continue; } // The CI runs multiple tests at once; minimize colliding with // the initial tx by using a random value, so we can detect // replacements we didn't do. const value = Math.trunc(Math.random() * 2048) + 2; it(`tests underpriced replacement transaction: ${ providerName }`, async function() { this.timeout(60000); const w = wallet.connect(provider); let tx1: null | TransactionResponse = null; let nonce: null | number = null;; for (let i = 0; i < 10; i++) { nonce = await w.getNonce("pending"); try { tx1 = await w.sendTransaction({ nonce, to: wallet, value }); } catch (error: any) { // Another CI host beat us to this nonce if (isError(error, "REPLACEMENT_UNDERPRICED") || isError(error, "NONCE_EXPIRED")) { await stall(1000); continue; } console.log("EE-tx1", nonce, value, error); throw error; } break; } if (tx1 == null || nonce == null) { throw new Error("could not send initial tx"); } const rejection = assert.rejects(async function() { // Send another tx with the same nonce const tx2 = await w.sendTransaction({ nonce, to: wallet, value: 1 }); console.log({ tx1, tx2 }); }, (error: unknown) => { return isError(error, "REPLACEMENT_UNDERPRICED"); }); // Wait for the first tx to get mined so we start with a // clean slate on the next provider await tx1.wait(); // This should have already happened await rejection; }); } for (const providerName of providerNames) { const provider = getProvider(providerName, networkName); if (provider == null) { continue; } it(`tests insufficient funds: ${ providerName }`, async function() { this.timeout(60000); const w = Wallet.createRandom().connect(provider); await assert.rejects(async function() { const tx = await w.sendTransaction({ to: wallet, value: 1 }); console.log(tx); }, (error) => { return (isError(error, "INSUFFICIENT_FUNDS") && typeof(error.transaction.from) === "string" && error.transaction.from.toLowerCase() === w.address.toLowerCase()); }); }); } for (const providerName of providerNames) { const provider = getProvider(providerName, networkName); if (provider == null) { continue; } it(`tests nonce expired: ${ providerName }`, async function() { this.timeout(60000); const w = wallet.connect(provider); await assert.rejects(async function() { const tx = await w.sendTransaction({ to: wallet, nonce: 1, value: 1 }); console.log(tx); }, (error) => { if (!isError(error, "NONCE_EXPIRED")) { console.log(error); } return isError(error, "NONCE_EXPIRED"); }); }); } }); |