Skip to content

Commit

Permalink
Merge branch 'master' into snap-tests-and-highest-hash-optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech authored Aug 15, 2023
2 parents 64d9c9a + 6d283b1 commit 31690c7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ function parseGethParams(json: any, mergeForkIdPostMerge: boolean = true) {
}))
.filter((fork) => fork.block !== null || fork.timestamp !== undefined) as ConfigHardfork[]

for (const hf of params.hardforks) {
if (hf.timestamp === genesisTimestamp) {
hf.timestamp = 0
}
}

params.hardforks.sort(function (a: ConfigHardfork, b: ConfigHardfork) {
return (a.block ?? Infinity) - (b.block ?? Infinity)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/devp2p/src/ext/kbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class KBucket {
}

// the bucket is full
if (node.dontSplit !== undefined) {
if (node.dontSplit) {
// we are not allowed to split the bucket
// we need to ping the first this._numberOfNodesToPing
// in order to determine if they are alive
Expand Down
16 changes: 11 additions & 5 deletions packages/statemanager/test/ethersStateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@ethereumjs/util'
import { VM } from '@ethereumjs/vm'
import { ethers } from 'ethers'
import { assert, describe, it } from 'vitest'
import { assert, describe, expect, it } from 'vitest'

import { EthersStateManager } from '../src/ethersStateManager.js'

Expand Down Expand Up @@ -84,10 +84,9 @@ describe('Ethers State Manager API tests', () => {
)

assert.ok(retrievedVitalikAccount.nonce > 0n, 'Vitalik.eth is stored in cache')
const doesThisAccountExist =
(await state.getAccount(
Address.fromString('0xccAfdD642118E5536024675e776d32413728DD07')
)) === undefined
const doesThisAccountExist = await state.accountExists(
Address.fromString('0xccAfdD642118E5536024675e776d32413728DD07')
)
assert.ok(!doesThisAccountExist, 'getAccount returns undefined for non-existent account')

assert.ok(state.getAccount(vitalikDotEth) !== undefined, 'vitalik.eth does exist')
Expand All @@ -111,6 +110,13 @@ describe('Ethers State Manager API tests', () => {
)
assert.ok(storageSlot.length > 0, 'was able to retrieve storage slot 1 for the UNI contract')

await expect(async () => {
await state.getContractStorage(
UNIerc20ContractAddress,
setLengthLeft(bigIntToBytes(1n), 31)
)
}).rejects.toThrowError('Storage key must be 32 bytes long')

await state.putContractStorage(
UNIerc20ContractAddress,
setLengthLeft(bigIntToBytes(2n), 32),
Expand Down
25 changes: 24 additions & 1 deletion packages/statemanager/test/statemanager.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KECCAK256_RLP } from '@ethereumjs/util'
import { Address, KECCAK256_RLP, bigIntToBytes, setLengthLeft, utf8ToBytes } from '@ethereumjs/util'
import { assert, describe, it } from 'vitest'

import { CacheType, DefaultStateManager } from '../src/index.js'
Expand All @@ -12,6 +12,29 @@ describe('StateManager -> General', () => {
assert.deepEqual(res, KECCAK256_RLP, 'it has default root')
})

it(`should clear contract storage`, async () => {
const sm = new DefaultStateManager()

const contractAddress = Address.fromString('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984')
const contractCode = Uint8Array.from([0, 1, 2, 3])
const storageKey = setLengthLeft(bigIntToBytes(2n), 32)
const storedData = utf8ToBytes('abcd')

await sm.putContractCode(contractAddress, contractCode)
await sm.putContractStorage(contractAddress, storageKey, storedData)

let storage = await sm.getContractStorage(contractAddress, storageKey)
assert.equal(JSON.stringify(storage), JSON.stringify(storedData), 'contract storage updated')

await sm.clearContractStorage(contractAddress)
storage = await sm.getContractStorage(contractAddress, storageKey)
assert.equal(
JSON.stringify(storage),
JSON.stringify(new Uint8Array()),
'clears contract storage'
)
})

it(`copy()`, async () => {
let sm = new DefaultStateManager({
prefixCodeHashes: false,
Expand Down

0 comments on commit 31690c7

Please sign in to comment.