def test_discover(prepareLogger): cryptoKey = rando.newKey() db = database.KeyValueDatabase(":memory:").child("tmp") acctMgr = accounts.createNewAccountManager(tRoot, cryptoKey, "dcr", nets.mainnet, db) txs = {} class Blockchain: params = nets.mainnet addrsHaveTxs = lambda addrs: any(a in txs for a in addrs) ogChain = chains.chain("dcr") chains.registerChain("dcr", Blockchain) ogLimit = accounts.ACCOUNT_GAP_LIMIT accounts.ACCOUNT_GAP_LIMIT = 2 acctMgr.discover(cryptoKey) assert len(acctMgr.accounts) == 1 coinExtKey = acctMgr.coinKey(cryptoKey) acct2ExtKey = coinExtKey.deriveAccountKey(2).neuter().child(0) acct2Addr5 = addrlib.deriveChildAddress(acct2ExtKey, 5, nets.mainnet) txs[acct2Addr5] = ["tx"] acctMgr.discover(cryptoKey) assert len(acctMgr.accounts) == 3 chains.registerChain("dcr", ogChain) accounts.ACCOUNT_GAP_LIMIT = ogLimit
def test_discover(monkeypatch, prepareLogger): cryptoKey = rando.newKey() db = database.KeyValueDatabase(":memory:").child("tmp") acctMgr = accounts.createNewAccountManager(tRoot, cryptoKey, "dcr", nets.mainnet, db) txs = {} class Blockchain: params = nets.mainnet addrsHaveTxs = lambda addrs: any(a in txs for a in addrs) # Set up globals for test. origChain = chains.chain("dcr") chains.registerChain("dcr", Blockchain) # Set up globals for test. monkeypatch.setattr(accounts, "ACCOUNT_GAP_LIMIT", 2) monkeypatch.setattr(account, "DefaultGapLimit", 4) acctMgr.discover(cryptoKey) assert len(acctMgr.accounts) == 1 coinExtKey = acctMgr.coinKey(cryptoKey) acct2ExtKey = coinExtKey.deriveAccountKey(2).neuter().child(0) acct2Addr3 = addrlib.deriveChildAddress(acct2ExtKey, 3, nets.mainnet) txs[acct2Addr3] = ["tx"] acctMgr.discover(cryptoKey) assert len(acctMgr.accounts) == 3 # Restore globals. chains.registerChain("dcr", origChain)
def test_change_addresses(prepareLogger): """ Test internal branch address derivation. """ cryptoKey = rando.newKey() db = database.KeyValueDatabase(":memory:").child("tmp") # ticker for coin type is ok. Case insensitive. acctMgr = accounts.createNewAccountManager(tRoot, cryptoKey, "DcR", nets.mainnet, db) acct = acctMgr.openAccount(0, cryptoKey) for i in range(10): acct.nextInternalAddress()
def test_account_manager(monkeypatch, prepareLogger): # Set up globals for test. monkeypatch.setattr(account, "DefaultGapLimit", 2) cryptoKey = rando.newKey() db = database.KeyValueDatabase(":memory:").child("tmp") # 42 = Decred acctMgr = accounts.createNewAccountManager(tRoot, cryptoKey, 42, nets.mainnet, db) acct = acctMgr.openAccount(0, cryptoKey) tempAcct = acctMgr.addAccount(cryptoKey, "temp") assert acctMgr.account(1) == tempAcct assert acctMgr.listAccounts() == [acct, tempAcct] acctMgr.setNode("node") assert acctMgr.node == "node" assert tempAcct.node == "node" acctMgr.accounts[3] = tempAcct del acctMgr.accounts[1] with pytest.raises(DecredError): acctMgr.listAccounts() del acctMgr.accounts[3] with pytest.raises(DecredError): accounts.AccountManager.unblob(encode.BuildyBytes(0)) zeroth = acct.currentAddress() b = acctMgr.serialize() reAM = accounts.AccountManager.unblob(b.b) assert acctMgr.coinType == reAM.coinType assert acctMgr.netName == reAM.netName assert acctMgr.netName == reAM.netName reAM.load(db, None) reAcct = reAM.openAccount(0, cryptoKey) reZeroth = reAcct.currentAddress() assert zeroth == reZeroth acctMgr.saveAccount(0) db = acctMgr.dbForAcctIdx(0) assert db.name == "tmp$accts$0"