fix accounts cache init API

This commit is contained in:
andri lim 2020-04-29 12:00:44 +07:00
parent ff028982d6
commit c9e49bf68a
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
2 changed files with 13 additions and 1 deletions

View File

@ -45,12 +45,15 @@ proc beginSavepoint*(ac: var AccountsCache): SavePoint {.gcsafe.}
# The AccountsCache is modeled after TrieDatabase for it's transaction style
proc init*(x: typedesc[AccountsCache], db: TrieDatabaseRef,
root: KeccakHash, pruneTrie: bool): AccountsCache =
root: KeccakHash, pruneTrie: bool = true): AccountsCache =
result.db = db
result.trie = initSecureHexaryTrie(db, root, pruneTrie)
result.unrevertablyTouched = initHashSet[EthAddress]()
discard result.beginSavepoint
proc init*(x: typedesc[AccountsCache], db: TrieDatabaseRef, pruneTrie: bool = true): AccountsCache =
init(x, db, emptyRlpHash, pruneTrie)
proc rootHash*(ac: AccountsCache): KeccakHash =
# make sure all savepoint already committed
doAssert(ac.savePoint.parentSavePoint.isNil)

View File

@ -141,5 +141,14 @@ proc stateDBMain*() =
# state trie at all
check ac.rootHash == rootHash
test "accounts cache code retrieval after persist called":
var ac = init(AccountsCache, acDB)
var addr2 = initAddr(2)
ac.setCode(addr2, code)
ac.persist()
check ac.getCode(addr2) == code
let key = contractHashKey(hexary.keccak(code))
check acDB.get(key.toOpenArray) == code
when isMainModule:
stateDBMain()