github.com/ethereum-optimism/optimism@v1.7.2/packages/sdk/test/utils/message-utils.spec.ts (about) 1 import { BigNumber } from 'ethers' 2 3 import { expect } from '../setup' 4 import { 5 migratedWithdrawalGasLimit, 6 hashLowLevelMessage, 7 hashMessageHash, 8 } from '../../src/utils/message-utils' 9 10 const goerliChainID = 420 11 12 describe('Message Utils', () => { 13 describe('migratedWithdrawalGasLimit', () => { 14 it('should have a max of 25 million', () => { 15 const data = '0x' + 'ff'.repeat(15_000_000) 16 const result = migratedWithdrawalGasLimit(data, goerliChainID) 17 expect(result).to.eq(BigNumber.from(25_000_000)) 18 }) 19 20 it('should work for mixes of zeros and ones', () => { 21 const tests = [ 22 { input: '0x', result: BigNumber.from(200_000) }, 23 { input: '0xff', result: BigNumber.from(200_000 + 16) }, 24 { input: '0xff00', result: BigNumber.from(200_000 + 16 + 16) }, 25 { input: '0x00', result: BigNumber.from(200_000 + 16) }, 26 { input: '0x000000', result: BigNumber.from(200_000 + 16 + 16 + 16) }, 27 ] 28 29 for (const test of tests) { 30 const result = migratedWithdrawalGasLimit(test.input, goerliChainID) 31 expect(result).to.eq(test.result) 32 } 33 }) 34 }) 35 36 /** 37 * Test that storage slot computation is correct. The test vectors are 38 * from actual migrated withdrawals on goerli. 39 */ 40 describe('Withdrawal Hashing', () => { 41 it('should work', () => { 42 const tests = [ 43 { 44 input: { 45 messageNonce: BigNumber.from(100000), 46 sender: '0x4200000000000000000000000000000000000007', 47 target: '0x5086d1eEF304eb5284A0f6720f79403b4e9bE294', 48 value: BigNumber.from(0), 49 minGasLimit: BigNumber.from(207744), 50 message: 51 '0xd764ad0b00000000000000000000000000000000000000000000000000000000000186a00000000000000000000000004200000000000000000000000000000000000010000000000000000000000000636af16bf2f682dd3109e60102b8e1a089fedaa80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000e4a9f9e67500000000000000000000000007865c6e87b9f70255377e024ace6630c1eaa37f0000000000000000000000003b8e53b3ab8e01fb57d0c9e893bc4d655aa67d84000000000000000000000000b91882244f7f82540f2941a759724523c7b9a166000000000000000000000000b91882244f7f82540f2941a759724523c7b9a166000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 52 }, 53 result: 54 '0x7c83d39edf60c0ab61bc7cfd2e5f741efdf02fd6e2da0f12318f0d1858d3773b', 55 }, 56 { 57 input: { 58 messageNonce: BigNumber.from(100001), 59 sender: '0x4200000000000000000000000000000000000007', 60 target: '0x5086d1eEF304eb5284A0f6720f79403b4e9bE294', 61 value: BigNumber.from(0), 62 minGasLimit: BigNumber.from(207744), 63 message: 64 '0xd764ad0b00000000000000000000000000000000000000000000000000000000000186a10000000000000000000000004200000000000000000000000000000000000010000000000000000000000000636af16bf2f682dd3109e60102b8e1a089fedaa80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000e4a9f9e67500000000000000000000000007865c6e87b9f70255377e024ace6630c1eaa37f0000000000000000000000004e62882864fb8ce54affcaf8d899a286762b011b000000000000000000000000b91882244f7f82540f2941a759724523c7b9a166000000000000000000000000b91882244f7f82540f2941a759724523c7b9a166000000000000000000000000000000000000000000000000000000000000271000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', 65 }, 66 result: 67 '0x17c90d87508a23d806962f4c5f366ef505e8d80e5cc2a5c87242560c21d7c588', 68 }, 69 ] 70 71 for (const test of tests) { 72 const hash = hashLowLevelMessage(test.input) 73 const messageSlot = hashMessageHash(hash) 74 expect(messageSlot).to.eq(test.result) 75 } 76 }) 77 }) 78 })