Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'constantinople',
'petersburg',
'istanbul',
'muirGlacier',
]
this._common = new Common(chain, hardfork, supportedHardforks)
}
// Set list of opcodes based on HF
this._opcodes = getOpcodesForHF(this._common.hardfork()!)
if (opts.stateManager) {
this.stateManager = opts.stateManager
} else {
const trie = opts.state || new Trie()
if (opts.activatePrecompiles) {
for (let i = 1; i <= 8; i++) {
trie.put(new BN(i).toArrayLike(Buffer, 'be', 20), new Account().serialize())
}
}
this.stateManager = new StateManager({ trie, common: this._common })
}
this.pStateManager = new PStateManager(this.stateManager)
this.blockchain = opts.blockchain || new Blockchain({ common: this._common })
this.allowUnlimitedContractSize =
opts.allowUnlimitedContractSize === undefined ? false : opts.allowUnlimitedContractSize
// We cache this promisified function as it's called from the main execution loop, and
constructor(opts: StateManagerOpts = {}) {
let common = opts.common
if (!common) {
common = new Common('mainnet', 'petersburg')
}
this._common = common
this._trie = opts.trie || new Trie()
this._storageTries = {} // the storage trie cache
this._cache = new Cache(this._trie)
this._touched = new Set()
this._touchedStack = []
this._checkpointCount = 0
this._originalStorageCache = new Map()
}
tape('cache put and get account', (t) => {
const trie = new Trie()
const c = new Cache(trie)
const flushP = promisify(c.flush.bind(c))
const trieGetP = promisify(trie.get.bind(trie))
const addr = Buffer.from('cd2a3d9f938e13cd947ec05abc7fe734df8dd826', 'hex')
const acc = utils.createAccount('0x00', '0xff11')
t.test('should fail to get non-existent account', async (st) => {
const res = c.get(addr)
st.notOk(res.balance.equals(acc.balance))
st.end()
})
t.test('should put account', async (st) => {
c.put(addr, acc)
const res = c.get(addr)
tape('cache checkpointing', (t) => {
const trie = new Trie()
const c = new Cache(trie)
const addr = Buffer.from('cd2a3d9f938e13cd947ec05abc7fe734df8dd826', 'hex')
const acc = utils.createAccount('0x00', '0xff11')
const updatedAcc = utils.createAccount('0x00', '0xff00')
t.test('should revert to correct state', async (st) => {
c.put(addr, acc)
c.checkpoint()
c.put(addr, updatedAcc)
let res = c.get(addr)
st.ok(res.balance.equals(updatedAcc.balance))
c.revert()
t.test('should initialize', async (st) => {
const trie = new Trie()
const c = new Cache(trie)
st.ok(trie.root.equals(c._trie.root), 'initializes given trie')
st.end()
})
})