def test_xdai_root_gauge_transfer_crv(alice, chain, gauge_controller, xdai_root_gauge, token): gauge_controller.add_type("Test", 10 ** 18, {"from": alice}) gauge_controller.add_gauge(xdai_root_gauge, 0, 1, {"from": alice}) chain.mine(timedelta=2 * WEEK) amount = token.rate() * WEEK tx = xdai_root_gauge.checkpoint() # since we use a raw call won't show up in subcalls but we can check the trace # and values in memory at the time of the call relay_tokens_call_memory = list(filter(lambda t: t["op"] == "CALL", tx.trace))[-1]["memory"] memory = HexBytes("".join(relay_tokens_call_memory)) # our expectation of what should be at the end of memory # mirror of what is in the source code # pad the end with 28 empty bytes, because we have the fn selector at the beginning expected_data = ( web3.keccak(text="relayTokens(address,address,uint256)")[:4] + to_bytes(HexBytes(token.address)) + to_bytes(HexBytes(xdai_root_gauge.address)) + to_bytes(amount) + (0).to_bytes(28, "big") ) data_length = len(expected_data) # check that we are calling the bridge addr with the appropriate data assert memory[-data_length:] == expected_data
def _add_member(kyc, i, country, rating): id_ = to_bytes(f"member{i}".encode()).hex() kyc.addMember( id_, country, "0x000001", rating, 9999999999, (accounts[i],), {"from": accounts[0]}, ) return id_
def test_invalid_type(): with pytest.raises(TypeError): to_bytes(None) with pytest.raises(TypeError): to_bytes(3.1337) with pytest.raises(TypeError): to_bytes(True)
def _mint_for_testing(self, target, amount, kwargs=None): if hasattr(self, "getRoleMember"): role = "0x8f4f2da22e8ac8f11e15f9fc141cddbb5deea8800186560abb6e68c5496619a9" minter = self.getRoleMember(role, 0) amount = to_bytes(amount, "bytes32") self.deposit(target, amount, {"from": minter}) elif hasattr(self, "POOL"): token = _MintableTestToken(self.UNDERLYING_ASSET_ADDRESS(), "BridgeToken") lending_pool = interface.AaveLendingPool(self.POOL()) token._mint_for_testing(target, amount) token.approve(lending_pool, amount, {"from": target}) lending_pool.deposit(token, amount, target, 0, {"from": target}) else: raise ValueError("Unsupported Token")
def crypto_pool( alice, crypto_project, crypto_math, crypto_lp_token, crypto_views, crypto_coins, crypto_initial_prices, ): # taken from curvefi/curve-crypto-contract keys = [0, 1, 2, 16, 17, 18, "1,#0", "1,#1", "1,#2"] values = ( [crypto_math.address, crypto_lp_token.address, crypto_views.address] + [coin.address for coin in crypto_coins] + [f"{10 ** (18 - coin.decimals())}," for coin in crypto_coins] ) source = crypto_project.CurveCryptoSwap._build["source"] for k, v in zip(keys, values): if isinstance(k, int): k = convert.to_address(convert.to_bytes(k, "bytes20")) source.replace(k, v) CryptoPool = compile_source(source, vyper_version="0.2.12").Vyper swap = CryptoPool.deploy( alice, 135 * 3 ** 3, # A int(7e-5 * 1e18), # gamma int(4e-4 * 1e10), # mid_fee int(4e-3 * 1e10), # out_fee int(0.0028 * 1e18), # price_threshold int(0.01 * 1e18), # fee_gamma int(0.0015 * 1e18), # adjustment_step 0, # admin_fee 600, # ma_half_time crypto_initial_prices, {"from": alice}, ) crypto_lp_token.set_minter(swap, {"from": alice}) return swap
def test_type_bounds(): with pytest.raises(ValueError): to_bytes("0x00", "bytes0") with pytest.raises(ValueError): to_bytes("0x00", "bytes33")
def test_zero_value(): assert to_bytes("", "bytes1").hex() == "00" assert to_bytes("0x", "bytes1").hex() == "00" assert to_bytes(0, "bytes1").hex() == "00"
def test_byte_is_bytes1(): assert to_bytes(42, "byte") == to_bytes(42, "bytes1")
def test_int_bounds(): for i in range(1, 33): type_ = "bytes" + str(i) assert to_bytes(2**(i * 8) - 1, type_).hex() == "ff" * i with pytest.raises(OverflowError): to_bytes(2**(i * 8), type_)
def test_left_pad(): for i in range(1, 33): type_ = "bytes" + str(i) assert to_bytes("0xff", type_).hex() == (i - 1) * "00" + "ff"
def test_hexstring(): assert to_bytes("0xffff", "bytes") == b"\xff\xff" assert to_bytes("0xffff", "bytes2") == b"\xff\xff" assert to_bytes("0xffff", "bytes4") == b"\x00\x00\xff\xff" assert to_bytes("abcdef")
def test_string_raises(): with pytest.raises(ValueError): to_bytes("abcdefg")
def test_length_bounds(): for i in range(1, 33): type_ = "bytes" + str(i) to_bytes("0x" + "ff" * i, type_) with pytest.raises(OverflowError): to_bytes("0x" + "ff" * (i + 1), type_)
def _add_investor(kyc, i, country, rating): id_ = to_bytes(f"investor{i}".encode()).hex() kyc.addInvestor(id_, country, '0x000001', rating, 9999999999, (accounts[i], ), {'from': accounts[0]}) return id_