2019-02-01 09:25:10 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2019-02-06 10:43:44 +00:00
|
|
|
import unittest, strutils, eth/trie/[hexary, db],
|
2019-07-07 10:12:01 +00:00
|
|
|
../nimbus/db/state_db, stew/byteutils, eth/common,
|
|
|
|
stew/ranges
|
2019-02-01 09:25:10 +00:00
|
|
|
|
|
|
|
suite "Account State DB":
|
|
|
|
var
|
|
|
|
memDB = newMemoryDB()
|
|
|
|
trie = initHexaryTrie(memDB)
|
|
|
|
stateDB = newAccountStateDB(memDB, trie.rootHash, true)
|
|
|
|
address: EthAddress
|
2019-02-02 09:17:57 +00:00
|
|
|
|
2019-02-01 09:25:10 +00:00
|
|
|
hexToByteArray("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", address)
|
2019-02-02 09:17:57 +00:00
|
|
|
|
|
|
|
test "accountExists and isDeadAccount":
|
|
|
|
check stateDB.accountExists(address) == false
|
2019-02-01 09:25:10 +00:00
|
|
|
check stateDB.isDeadAccount(address) == true
|
2019-02-02 09:17:57 +00:00
|
|
|
|
2019-02-01 09:25:10 +00:00
|
|
|
var acc = stateDB.getAccount(address)
|
|
|
|
acc.balance = 1000.u256
|
|
|
|
stateDB.setAccount(address, acc)
|
2019-02-02 09:17:57 +00:00
|
|
|
|
|
|
|
check stateDB.accountExists(address) == true
|
2019-02-01 09:25:10 +00:00
|
|
|
check stateDB.isDeadAccount(address) == false
|
|
|
|
|
|
|
|
acc.balance = 0.u256
|
|
|
|
acc.nonce = 1
|
|
|
|
stateDB.setAccount(address, acc)
|
|
|
|
check stateDB.isDeadAccount(address) == false
|
2019-02-02 09:17:57 +00:00
|
|
|
|
2019-02-01 09:25:10 +00:00
|
|
|
var code = hexToSeqByte("0x0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6")
|
|
|
|
stateDB.setCode(address, code.toRange)
|
|
|
|
stateDB.setNonce(address, 0)
|
|
|
|
check stateDB.isDeadAccount(address) == false
|
2019-02-02 09:17:57 +00:00
|
|
|
|
2019-02-01 09:25:10 +00:00
|
|
|
code = @[]
|
|
|
|
stateDB.setCode(address, code.toRange)
|
|
|
|
check stateDB.isDeadAccount(address) == true
|
2019-02-02 09:17:57 +00:00
|
|
|
check stateDB.accountExists(address) == true
|