def test_transferUSD(): w1 = AgentWallet(USD=10.0) w2 = AgentWallet(USD=1.0) w1.transferUSD(w2, 2.0) assert w1.USD() == 10.0 - 2.0 assert w2.USD() == 1.0 + 2.0
def test_transferOCEAN(): w1 = AgentWallet(OCEAN=10.0) w2 = AgentWallet(OCEAN=1.0) w1.transferOCEAN(w2, 2.0) assert w1.OCEAN() == (10.0 - 2.0) assert w2.OCEAN() == (1.0 + 2.0)
def __init__(self, name: str, USD: float, OCEAN: float): self.name = name self._wallet = AgentWallet.AgentWallet(USD, OCEAN) #postconditions assert self.USD() == USD assert self.OCEAN() == OCEAN
def test_initFromPrivateKey(): private_key = '0xbbfbee4961061d506ffbb11dfea64eba16355cbf1d9c29613126ba7fec0aed5d' address = '0x66aB6D9362d4F35596279692F0251Db635165871' w = AgentWallet(private_key=private_key) assert w._address == address assert w._web3wallet.address == address assert w._web3wallet.private_key == private_key
def _make_info(private_key_name: str): class _Info: pass info = _Info() network = web3util.get_network() info.private_key = web3util.confFileValue(network, private_key_name) info.agent_wallet = AgentWallet.AgentWallet(OCEAN=_OCEAN_INIT, private_key=info.private_key) info.web3wallet = info.agent_wallet._web3wallet info.DT = _createDT(info.web3wallet) info.pool = _createPool(DT=info.DT, web3_w=info.web3wallet) return info
def _make_wallet(private_key_name:str, cache: bool): global _CACHED_WALLET if _CACHED_WALLET is None and cache: class _Wallet: pass wallet = _Wallet() network = web3util.get_network() wallet.private_key = web3util.confFileValue(network, private_key_name) wallet.agent_wallet = AgentWallet.AgentWallet( OCEAN=_OCEAN_INIT,private_key=wallet.private_key) wallet.web3wallet = wallet.agent_wallet._web3wallet wallet.DT = _createDT(wallet.web3wallet) wallet.pool = _createPool(DT=wallet.DT, web3_w=wallet.web3wallet) _CACHED_WALLET = wallet return _CACHED_WALLET return _CACHED_WALLET
def __init__(self, name: str, USD: float, OCEAN: float, private_key: str = None): self.name = name self._wallet = AgentWallet.AgentWallet(USD, OCEAN, private_key=private_key) #postconditions if private_key == None: assert self.USD() == USD assert self.OCEAN() == OCEAN else: # TODO # This is kind of weak - we should test for sum of current and previous assert self.USD() >= USD assert self.OCEAN() >= OCEAN
def _make_info(private_key_name: str): class _Info: def __init__(self): self.private_key: Union[str, None] = None self.agent_wallet: Union[AgentWallet.AgentWallet, None] = None self.web3wallet: Union[web3wallet, None] = None self.DT: Union[datatoken, None] = None self.pool: Union[bool, None] = None info = _Info() network = web3util.get_network() info.private_key = web3util.confFileValue(network, private_key_name) info.agent_wallet = AgentWallet.AgentWallet(OCEAN=_OCEAN_INIT, private_key=info.private_key) info.web3wallet = info.agent_wallet._web3wallet info.DT = _createDT(info.web3wallet) info.pool = _createPool(DT=info.DT, web3_w=info.web3wallet) return info
def test_initRandomPrivateKey(): w1 = AgentWallet() w2 = AgentWallet() assert w1._address != w2._address assert w1._web3wallet.private_key != w2._web3wallet.private_key
def testOCEAN(): w = AgentWallet() w.depositOCEAN(13.25) assert w.OCEAN() == 13.25 w.depositOCEAN(1.00) assert w.OCEAN() == 14.25 w.withdrawOCEAN(2.10) assert w.OCEAN() == 12.15 w.depositOCEAN(0.0) w.withdrawOCEAN(0.0) assert w.OCEAN() == 12.15 assert w.totalOCEANin() == (13.25 + 1.0) with pytest.raises(AssertionError): w.depositOCEAN(-5.0) with pytest.raises(AssertionError): w.withdrawOCEAN(-5.0) with pytest.raises(ValueError): w.withdrawOCEAN(1000.0)
def testETH1(): #super-basic test for ETH w = AgentWallet() assert isinstance(w.ETH(), float)
def testUSD(): w = AgentWallet() w.depositUSD(13.25) assert w.USD() == 13.25 w.depositUSD(1.00) assert w.USD() == 14.25 w.withdrawUSD(2.10) assert w.USD() == 12.15 w.depositUSD(0.0) w.withdrawUSD(0.0) assert w.USD() == 12.15 assert w.totalUSDin() == (13.25 + 1.0) with pytest.raises(AssertionError): w.depositUSD(-5.0) with pytest.raises(AssertionError): w.withdrawUSD(-5.0) with pytest.raises(ValueError): w.withdrawUSD(1000.0)
def testFloatingPointRoundoff_USD(): w = AgentWallet(USD=2.4) w.withdrawUSD(2.4000000000000004) #should not get ValueError assert w.USD() == 0.0 assert w.OCEAN() == 0.0
def testInitiallyEmpty(): w = AgentWallet() assert w.USD() == 0.0 assert w.OCEAN() == 0.0
def testInitiallyFilled(): w = AgentWallet(USD=1.2, OCEAN=3.4) assert w.USD() == 1.2 assert w.OCEAN() == 3.4
def test_gotSomeETHforGas(): w = AgentWallet() assert w.ETH() > 0.0
def testETH2(): #TEST_PRIVATE_KEY1 should get initialized with ETH when ganache starts network = web3util.get_network() private_key = web3util.confFileValue(network, 'TEST_PRIVATE_KEY1') w = AgentWallet(private_key=private_key) assert w.ETH() > 1.0
def testStr(): w = AgentWallet() assert "AgentWallet" in str(w)
def test_BPT(alice_agent_wallet: AgentWallet, alice_pool: bpool.BPool): assert alice_agent_wallet.BPT(alice_pool) == 100.0
def test_DT(alice_agent_wallet: AgentWallet, alice_DT: datatoken.Datatoken): alice_DT_amt: float = alice_agent_wallet.DT(alice_DT) assert alice_DT_amt == (_DT_INIT - _DT_STAKE)