コード例 #1
0
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
コード例 #2
0
 def get_proof(self, el):
     el = web3.keccak(hexstr=el)
     idx = self.elements.index(el)
     proof = []
     for layer in self.layers:
         pair_idx = idx + 1 if idx % 2 == 0 else idx - 1
         if pair_idx < len(layer):
             proof.append(encode_hex(layer[pair_idx]))
         idx //= 2
     return proof
コード例 #3
0
 def __init__(self, elements):
     self.elements = sorted(set(web3.keccak(hexstr=el) for el in elements))
     self.layers = MerkleTree.get_layers(self.elements)
コード例 #4
0
 def combined_hash(a, b):
     if a is None:
         return b
     if b is None:
         return a
     return web3.keccak(b''.join(sorted([a, b])))
コード例 #5
0
def strToFunctionSignature(definition):
    '''
        takes function definition and computes the hex signature
    '''
    return web3.keccak(text=definition)[:4].hex()
コード例 #6
0
def position_key(address, tickLower, tickUpper):
    return web3.keccak(
        int(address, 16).to_bytes(20, 'big') + tickLower.to_bytes(3, 'big') +
        tickUpper.to_bytes(3, 'big'))
コード例 #7
0
try:
    interact = Contract.from_abi(name = name_SC, address = address_SC, abi = abi_SC, owner = account)
except:
    print("Something went wrong while loading the contract")

# Change price
newPrice = int(random.normalvariate(1e18, 2e17))
newPriceETH = web3.fromWei(newPrice, "ether")
try:
    #interact.setPrice(newPrice)

    print(f"Price has correctly been set to {newPriceETH} ether/token\n\n")
except:
    print("Something went wrong while changing the price")

# See last 10 transactions
buyTkn_event = web3.keccak(text="buyTknEvent(address,uint256)").hex()
LOGS = get_logs(address=address_SC, from_block=7956358, to_block="latest", signature=buyTkn_event, topic1=None, topic2=None, topic3=None)

i=0
data = [['#', 'From', 'Timestamp', 'Token Amount', 'Cost ETH']]
for event in LOGS:
    block = web3.eth.getBlock(event['blockNumber'])
    transaction = web3.eth.getTransaction(event['transactionHash'].hex())
    i+=1
    dt_object = datetime.fromtimestamp(block['timestamp'])
    data.append([i, transaction['from'], dt_object, web3.fromWei(int(event['data'], 0), "ether"), web3.fromWei(transaction['value'], "ether")])
    
data_table = AsciiTable(data)
print(data_table.table)