|
| 1 | +import { assert } from "chai"; |
| 2 | + |
| 3 | +import { |
| 4 | + numberToRpcQuantity, |
| 5 | + rpcDataToBigInt, |
| 6 | +} from "../../../../src/internal/core/jsonrpc/types/base-types"; |
| 7 | +import { workaroundWindowsCiFailures } from "../../../utils/workaround-windows-ci-failures"; |
| 8 | +import { DAI_ADDRESS } from "../helpers/constants"; |
| 9 | +import { setCWD } from "../helpers/cwd"; |
| 10 | +import { |
| 11 | + DEFAULT_ACCOUNTS_ADDRESSES, |
| 12 | + FORKED_PROVIDERS, |
| 13 | +} from "../helpers/providers"; |
| 14 | + |
| 15 | +const TOTAL_SUPPLY_SELECTOR = "0x18160ddd"; |
| 16 | + |
| 17 | +const SHANGHAI_HARDFORK_BLOCK_NUMBER = 17_034_870; |
| 18 | +const MERGE_HARDFORK_BLOCK_NUMBER = 15_537_394; |
| 19 | + |
| 20 | +describe("Forking a block with a different hardfork", function () { |
| 21 | + FORKED_PROVIDERS.forEach(({ rpcProvider, useProvider }) => { |
| 22 | + workaroundWindowsCiFailures.call(this, { isFork: true }); |
| 23 | + |
| 24 | + describe(`Using ${rpcProvider}`, function () { |
| 25 | + setCWD(); |
| 26 | + |
| 27 | + describe("shanghai hardfork", function () { |
| 28 | + const hardfork = "shanghai"; |
| 29 | + |
| 30 | + describe("forking a 'shanghai' block", function () { |
| 31 | + const forkBlockNumber = SHANGHAI_HARDFORK_BLOCK_NUMBER + 100; |
| 32 | + |
| 33 | + useProvider({ |
| 34 | + hardfork, |
| 35 | + forkBlockNumber, |
| 36 | + }); |
| 37 | + |
| 38 | + it("should mine transactions", async function () { |
| 39 | + await this.provider.send("eth_sendTransaction", [ |
| 40 | + { |
| 41 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 42 | + to: DEFAULT_ACCOUNTS_ADDRESSES[1], |
| 43 | + }, |
| 44 | + ]); |
| 45 | + }); |
| 46 | + |
| 47 | + it("should make calls in the forked block", async function () { |
| 48 | + const daiSupply = await this.provider.send("eth_call", [ |
| 49 | + { |
| 50 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 51 | + to: DAI_ADDRESS.toString(), |
| 52 | + data: TOTAL_SUPPLY_SELECTOR, |
| 53 | + }, |
| 54 | + numberToRpcQuantity(forkBlockNumber), |
| 55 | + ]); |
| 56 | + |
| 57 | + assert.equal( |
| 58 | + rpcDataToBigInt(daiSupply), |
| 59 | + 5022305384218217259061852351n |
| 60 | + ); |
| 61 | + }); |
| 62 | + |
| 63 | + it("should make calls in blocks before the forked block", async function () { |
| 64 | + const daiSupply = await this.provider.send("eth_call", [ |
| 65 | + { |
| 66 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 67 | + to: DAI_ADDRESS.toString(), |
| 68 | + data: TOTAL_SUPPLY_SELECTOR, |
| 69 | + }, |
| 70 | + numberToRpcQuantity(forkBlockNumber - 1), |
| 71 | + ]); |
| 72 | + |
| 73 | + assert.equal( |
| 74 | + rpcDataToBigInt(daiSupply), |
| 75 | + 5022305384218217259061852351n |
| 76 | + ); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + describe("forking a 'merge' block", function () { |
| 81 | + const forkBlockNumber = MERGE_HARDFORK_BLOCK_NUMBER + 100; |
| 82 | + |
| 83 | + useProvider({ |
| 84 | + forkBlockNumber, |
| 85 | + }); |
| 86 | + |
| 87 | + it("should mine transactions", async function () { |
| 88 | + await this.provider.send("eth_sendTransaction", [ |
| 89 | + { |
| 90 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 91 | + to: DEFAULT_ACCOUNTS_ADDRESSES[1], |
| 92 | + }, |
| 93 | + ]); |
| 94 | + }); |
| 95 | + |
| 96 | + it("should make calls in the forked block", async function () { |
| 97 | + const daiSupply = await this.provider.send("eth_call", [ |
| 98 | + { |
| 99 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 100 | + to: DAI_ADDRESS.toString(), |
| 101 | + data: TOTAL_SUPPLY_SELECTOR, |
| 102 | + }, |
| 103 | + numberToRpcQuantity(forkBlockNumber), |
| 104 | + ]); |
| 105 | + |
| 106 | + assert.equal( |
| 107 | + rpcDataToBigInt(daiSupply), |
| 108 | + 6378560137543824474512862351n |
| 109 | + ); |
| 110 | + }); |
| 111 | + |
| 112 | + it("should make calls in blocks before the forked block", async function () { |
| 113 | + const daiSupply = await this.provider.send("eth_call", [ |
| 114 | + { |
| 115 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 116 | + to: DAI_ADDRESS.toString(), |
| 117 | + data: TOTAL_SUPPLY_SELECTOR, |
| 118 | + }, |
| 119 | + numberToRpcQuantity(forkBlockNumber - 1), |
| 120 | + ]); |
| 121 | + |
| 122 | + assert.equal( |
| 123 | + rpcDataToBigInt(daiSupply), |
| 124 | + 6378560137543824474512862351n |
| 125 | + ); |
| 126 | + }); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + describe("merge hardfork", function () { |
| 131 | + const hardfork = "merge"; |
| 132 | + |
| 133 | + describe("forking a 'shanghai' block", function () { |
| 134 | + const forkBlockNumber = SHANGHAI_HARDFORK_BLOCK_NUMBER + 100; |
| 135 | + |
| 136 | + useProvider({ |
| 137 | + forkBlockNumber, |
| 138 | + hardfork, |
| 139 | + }); |
| 140 | + |
| 141 | + it("should mine transactions", async function () { |
| 142 | + await this.provider.send("eth_sendTransaction", [ |
| 143 | + { |
| 144 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 145 | + to: DEFAULT_ACCOUNTS_ADDRESSES[1], |
| 146 | + }, |
| 147 | + ]); |
| 148 | + }); |
| 149 | + |
| 150 | + it("should make calls in the forked block", async function () { |
| 151 | + const daiSupply = await this.provider.send("eth_call", [ |
| 152 | + { |
| 153 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 154 | + to: DAI_ADDRESS.toString(), |
| 155 | + data: TOTAL_SUPPLY_SELECTOR, |
| 156 | + }, |
| 157 | + numberToRpcQuantity(forkBlockNumber), |
| 158 | + ]); |
| 159 | + |
| 160 | + assert.equal( |
| 161 | + rpcDataToBigInt(daiSupply), |
| 162 | + 5022305384218217259061852351n |
| 163 | + ); |
| 164 | + }); |
| 165 | + |
| 166 | + it("should make calls in blocks before the forked block", async function () { |
| 167 | + const daiSupply = await this.provider.send("eth_call", [ |
| 168 | + { |
| 169 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 170 | + to: DAI_ADDRESS.toString(), |
| 171 | + data: TOTAL_SUPPLY_SELECTOR, |
| 172 | + }, |
| 173 | + numberToRpcQuantity(forkBlockNumber - 1), |
| 174 | + ]); |
| 175 | + |
| 176 | + assert.equal( |
| 177 | + rpcDataToBigInt(daiSupply), |
| 178 | + 5022305384218217259061852351n |
| 179 | + ); |
| 180 | + }); |
| 181 | + }); |
| 182 | + |
| 183 | + describe("forking a 'merge' block", function () { |
| 184 | + const forkBlockNumber = MERGE_HARDFORK_BLOCK_NUMBER + 100; |
| 185 | + |
| 186 | + useProvider({ |
| 187 | + forkBlockNumber, |
| 188 | + }); |
| 189 | + |
| 190 | + it("should mine transactions", async function () { |
| 191 | + await this.provider.send("eth_sendTransaction", [ |
| 192 | + { |
| 193 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 194 | + to: DEFAULT_ACCOUNTS_ADDRESSES[1], |
| 195 | + }, |
| 196 | + ]); |
| 197 | + }); |
| 198 | + |
| 199 | + it("should make calls in the forked block", async function () { |
| 200 | + const daiSupply = await this.provider.send("eth_call", [ |
| 201 | + { |
| 202 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 203 | + to: DAI_ADDRESS.toString(), |
| 204 | + data: TOTAL_SUPPLY_SELECTOR, |
| 205 | + }, |
| 206 | + numberToRpcQuantity(forkBlockNumber), |
| 207 | + ]); |
| 208 | + |
| 209 | + assert.equal( |
| 210 | + rpcDataToBigInt(daiSupply), |
| 211 | + 6378560137543824474512862351n |
| 212 | + ); |
| 213 | + }); |
| 214 | + |
| 215 | + it("should make calls in blocks before the forked block", async function () { |
| 216 | + const daiSupply = await this.provider.send("eth_call", [ |
| 217 | + { |
| 218 | + from: DEFAULT_ACCOUNTS_ADDRESSES[0], |
| 219 | + to: DAI_ADDRESS.toString(), |
| 220 | + data: TOTAL_SUPPLY_SELECTOR, |
| 221 | + }, |
| 222 | + numberToRpcQuantity(forkBlockNumber - 1), |
| 223 | + ]); |
| 224 | + |
| 225 | + assert.equal( |
| 226 | + rpcDataToBigInt(daiSupply), |
| 227 | + 6378560137543824474512862351n |
| 228 | + ); |
| 229 | + }); |
| 230 | + }); |
| 231 | + }); |
| 232 | + }); |
| 233 | + }); |
| 234 | +}); |
0 commit comments