示例#1
0
    def test_equality(self):
        # given
        transfer1a = Transfer(
            token_address=Address(
                '0x0000011111222223333344444555556666677777'),
            from_address=Address('0x0000000000111111111100000000001111111111'),
            to_address=Address('0x1111111111000000000011111111110000000000'),
            value=Wad.from_number(20))
        transfer1b = Transfer(
            token_address=Address(
                '0x0000011111222223333344444555556666677777'),
            from_address=Address('0x0000000000111111111100000000001111111111'),
            to_address=Address('0x1111111111000000000011111111110000000000'),
            value=Wad.from_number(20))
        transfer2 = Transfer(
            token_address=Address(
                '0x0000011111222223333344444555556666677777'),
            from_address=Address('0x0000000000111111111100000000001111111111'),
            to_address=Address('0x1111111111000000000011111111112222222222'),
            value=Wad.from_number(20))

        # expect
        assert transfer1a == transfer1b
        assert transfer1b == transfer1a
        assert transfer1a != transfer2
        assert transfer1b != transfer2
        assert transfer2 != transfer1a
        assert transfer2 != transfer1b
def test_should_format_two_different_tokens(token1, token2, some_address):
    # given
    transfer1 = Transfer(token1, some_address, some_address,
                         Wad.from_number(105))
    transfer2 = Transfer(token2, some_address, some_address,
                         Wad.from_number(17))

    # expect
    assert TransferFormatter().format([transfer1, transfer2], lambda a: str(a)) \
        == "105.000000000000000000 0x0101010101010101010101010101010101010101 and 17.000000000000000000 0x0202020202020202020202020202020202020202"
def test_should_format_net_balances(token1, our_address, some_address):
    # given
    transfer1 = Transfer(token1, our_address, some_address,
                         Wad.from_number(15))
    transfer2 = Transfer(token1, some_address, our_address,
                         Wad.from_number(17))

    # expect
    assert TransferFormatter().format_net([transfer1, transfer2], our_address, lambda a: str(a)) \
        == "2.000000000000000000 0x0101010101010101010101010101010101010101"
def test_should_format_net_balances_excluding_transfers_between_us(
        token1, our_address, some_address):
    # given
    transfer1 = Transfer(token1, some_address, our_address, Wad.from_number(4))
    transfer2 = Transfer(token1, our_address, some_address,
                         Wad.from_number(1.5))
    transfer3 = Transfer(token1, our_address, our_address, Wad.from_number(50))

    # expect
    assert TransferFormatter().format_net([transfer1, transfer2, transfer3], our_address, lambda a: str(a)) \
        == "2.500000000000000000 0x0101010101010101010101010101010101010101"
def test_should_format_net_balances_if_multiple_transfers(
        token1, our_address, some_address):
    # given
    transfer1 = Transfer(token1, our_address, some_address,
                         Wad.from_number(15))
    transfer2 = Transfer(token1, some_address, our_address,
                         Wad.from_number(17))
    transfer3 = Transfer(token1, some_address, our_address,
                         Wad.from_number(3.5))

    # expect
    assert TransferFormatter().format_net([transfer1, transfer2, transfer3], our_address) \
        == "5.500000000000000000 0x0101010101010101010101010101010101010101"
def test_should_not_include_zeros_in_net_balances(token1, token2, our_address,
                                                  some_address):
    # given
    transfer1 = Transfer(token1, our_address, some_address,
                         Wad.from_number(15))
    transfer2 = Transfer(token1, some_address, our_address,
                         Wad.from_number(17))
    transfer3 = Transfer(token2, our_address, some_address,
                         Wad.from_number(22.5))
    transfer4 = Transfer(token2, some_address, our_address,
                         Wad.from_number(22.5))

    # expect
    assert TransferFormatter().format_net([transfer1, transfer2, transfer3, transfer4], our_address, lambda a: str(a)) \
        == "2.000000000000000000 0x0101010101010101010101010101010101010101"
def test_should_format_net_balances_for_more_than_one_token(
        token1, token2, our_address, some_address):
    # given
    transfer1 = Transfer(token1, our_address, some_address,
                         Wad.from_number(15))
    transfer2 = Transfer(token1, some_address, our_address,
                         Wad.from_number(17))
    transfer3 = Transfer(token2, our_address, some_address,
                         Wad.from_number(2.5))
    transfer4 = Transfer(token2, some_address, our_address,
                         Wad.from_number(100))

    # expect
    assert TransferFormatter().format_net([transfer1, transfer2, transfer3, transfer4], our_address, lambda a: str(a)) \
        == "2.000000000000000000 0x0101010101010101010101010101010101010101 and 97.500000000000000000 0x0202020202020202020202020202020202020202"
def test_should_format_single_transfer(token1, some_address):
    # given
    transfer = Transfer(token1, some_address, some_address,
                        Wad.from_number(105))

    # expect
    assert TransferFormatter().format(
        [transfer], lambda a: str(a)
    ) == "105.000000000000000000 0x0101010101010101010101010101010101010101"
def test_support_iterators(token1, some_address):
    # given
    transfer = Transfer(token1, some_address, some_address,
                        Wad.from_number(11.5))

    # expect
    assert TransferFormatter().format(
        iter([transfer]), lambda a: str(a)
    ) == "11.500000000000000000 0x0101010101010101010101010101010101010101"
示例#10
0
    def test_parsing_receipt(self, receipt_success):
        # given
        receipt = Receipt(receipt_success)

        # expect
        assert receipt.transaction_hash == '0x8b6851e40d017b2004a54eae3e9e47614398b54bbbaae150eaa889ec36470ec8'
        assert receipt.gas_used == 57192
        assert len(receipt.transfers) == 1
        assert receipt.transfers[0] == Transfer(token_address=Address('0x53eccc9246c1e537d79199d0c7231e425a40f896'),
                                                from_address=Address('0x375d52588c3f39ee7710290237a95c691d8432e7'),
                                                to_address=Address('0x0046f01ad360270605e0e5d693484ec3bfe43ba8'),
                                                value=Wad.from_number(1))