import os

from tendermint.db import VanillaDB
from tendermint.utils import home_dir

def test_database():
    dbfile = home_dir('temp', 'test.db')
    db = VanillaDB(dbfile)

    db.set(b'dave',b'one')
    result = db.get(b'dave')
    assert(b'one' == result)

    db.set(b'dave',b'two')
    result = db.get(b'dave')
    assert(b'two' == result)

    assert(None == db.get(b'doesntexist'))
    assert(db.exists(b'dave'))

    db.delete(b'dave')
    assert(db.exists(b'dave') == False)

    if os.path.exists(dbfile):
        os.remove(dbfile)

[((7, 13, 7, 40), 'tendermint.utils.home_dir', 'home_dir', ({(7, 22, 7, 28): '"""temp"""', (7, 30, 7, 39): '"""test.db"""'}, {}), "('temp', 'test.db')", False, 'from tendermint.utils import home_dir\n'), ((8, 9, 8, 26), 'tendermint.db.VanillaDB', 'VanillaDB', ({(8, 19, 8, 25): 'dbfile'}, {}), '(dbfile)', False, 'from tendermint.db import VanillaDB\n'), ((24, 7, 24, 29), 'os.path.exists', 'os.path.exists', ({(24, 22, 24, 28): 'dbfile'}, {}), '(dbfile)', False, 'import os\n'), ((25, 8, 25, 25), 'os.remove', 'os.remove', ({(25, 18, 25, 24): 'dbfile'}, {}), '(dbfile)', False, 'import os\n')]