Exemplo n.º 1
0
    def test_confirmation_timeout(self):
        contract = Escrow()

        tx = Tx(sender=CUSTOMER, value=PRICE_ETHER)
        block = Block(timestamp=TS)
        self.run(tx, contract, block)

        tx = Tx(sender=CUSTOMER, value=MIN_FEE)
        block = Block(timestamp=TS + CONFIRMATION_TIMEOUT + 1)
        self.run(tx, contract, block)

        assert contract.storage[I_STATUS] == S_REFUNDED
        assert len(contract.txs) == 1
        assert contract.txs == [(CUSTOMER, PRICE_ETHER, 0, 0)]
Exemplo n.º 2
0
    def test_shipped(self):
        contract = Escrow()

        tx = Tx(sender=CUSTOMER, value=PRICE_ETHER)
        block = Block(timestamp=TS)
        self.run(tx, contract, block)

        tx = Tx(sender=SHIPPER, value=MIN_FEE)
        block = Block(timestamp=TS + 1)
        self.run(tx, contract, block)

        assert contract.storage[I_STATUS] == S_SHIPPED
        assert len(contract.txs) == 1
        assert contract.txs == [(MERCHANT, PRICE_ETHER, 0, 0)]
Exemplo n.º 3
0
 def test_ether_drops(self):
     block = Block(timestamp=self.ts_zero + 30 * 86400 + 1)
     block.contract_storage(self.contract.D)[self.contract.I] = 400
     tx = Tx(sender='bob', value=200)
     self.run(tx, self.contract, block)
     assert len(self.contract.txs) == 1
     assert self.contract.txs == [('bob', 5000 * 10 ** 18, 0, 0)]
Exemplo n.º 4
0
    def test_withdraw_approval(self):
        tx = Tx(sender=PARTNER_2, value=100, data=[TX_WITHDRAW, MERCHANT_ADDRESS, MERCHANT_AMOUNT])
        self.run(tx, self.contract)

        assert len(self.contract.txs) == 1
        assert self.contract.txs == [(MERCHANT_ADDRESS, MERCHANT_AMOUNT, 0, 0)]
        assert self.stopped == "Withdrawed"
Exemplo n.º 5
0
 def test_cancel_proposal(self, early=0):
     tx = Tx(sender=PARTNER_1, value=100, data=[PARTNER_1])
     self.run(tx, self.contract, Block(timestamp=(0 if early else 2000)))
     if early:
         assert self.stopped == "Cant cancel early"
     else:
         assert self.stopped == "Cancelled"
Exemplo n.º 6
0
 def test_ether_rises(self):
     block = Block(timestamp=self.ts_zero + 30 * 86400 + 1)
     block.contract_storage(self.contract.D)[self.contract.I] = 4000
     tx = Tx(sender='bob', value=200)
     self.run(tx, self.contract, block)
     assert len(self.contract.txs) == 2
     assert self.contract.txs == [('bob', 623 * 10 ** 18, 0, 0), ('alice', 4377 * 10 ** 18, 0, 0)]
Exemplo n.º 7
0
    def test_insufficient_fee(self):
        contract = Escrow()

        tx = Tx(sender=CUSTOMER, value=10)
        self.run(tx, contract)

        assert self.stopped == 'Insufficient fee'
Exemplo n.º 8
0
    def test_withdraw_request(self):
        tx = Tx(sender=PARTNER_1, value=100, data=[TX_WITHDRAW, MERCHANT_ADDRESS, MERCHANT_AMOUNT])
        self.run(tx, self.contract)

        assert self.contract.storage[I_WITHDRAW_TO] == MERCHANT_ADDRESS
        assert self.contract.storage[I_WITHDRAW_AMOUNT] == MERCHANT_AMOUNT
        assert self.contract.storage[I_WITHDRAW_CREATOR] == PARTNER_1
        assert self.stopped == "Withdraw requested"
Exemplo n.º 9
0
    def test_accept(self):
        tx = Tx(sender=PARTNER_2, value=100, data=[PARTNER_1])
        self.run(tx, self.contract)

        assert self.contract.storage[I_PARTNER_1] == PARTNER_1
        assert self.contract.storage[I_PARTNER_2] == PARTNER_2
        assert self.contract.storage[I_STATE] == S_MARRIED
        assert self.stopped == "Married"
Exemplo n.º 10
0
    def test_withdraw_not_married_fails(self):
        tx = Tx(sender=PARTNER_1, value=100, data=[TX_WITHDRAW, MERCHANT_ADDRESS, MERCHANT_AMOUNT])
        self.run(tx, self.contract)

        assert self.contract.storage[I_WITHDRAW_TO] == 0
        assert self.contract.storage[I_WITHDRAW_AMOUNT] == 0
        assert self.contract.storage[I_WITHDRAW_CREATOR] == 0
        assert self.stopped == "Invalid during proposal"
Exemplo n.º 11
0
    def test_proposal(self):
        tx = Tx(sender=PARTNER_1, value=100, data=[PARTNER_2])
        self.run(tx, self.contract)

        assert self.contract.storage[I_PARTNER_1] == PARTNER_1
        assert self.contract.storage[I_PARTNER_2] == PARTNER_2
        assert self.contract.storage[I_STATE] == S_PROPOSED
        assert self.stopped == "Proposed"
Exemplo n.º 12
0
    def test_withdraw_after_divorce_fails(self):
        tx = Tx(sender=PARTNER_1, value=100, data=[TX_WITHDRAW, MERCHANT_ADDRESS, MERCHANT_AMOUNT])
        self.run(tx, self.contract)

        assert self.contract.storage[I_WITHDRAW_TO] == 0
        assert self.contract.storage[I_WITHDRAW_AMOUNT] == 0
        assert self.contract.storage[I_WITHDRAW_CREATOR] == 0
        assert self.stopped == "Should be divorced"
Exemplo n.º 13
0
 def test_creation(self):
     block = Block(timestamp=self.ts_zero)
     block.contract_storage(self.contract.D)[self.contract.I] = 2500
     tx = Tx(sender='bob', value=1000 * 10 ** 18)
     self.run(tx, self.contract, block)
     assert self.contract.storage[1000] == 1
     assert self.contract.storage[1001] == 2495000
     assert self.contract.storage[1002] == self.ts_zero + 30 * 86400
     assert self.contract.storage[1003] == tx.sender
     assert len(self.contract.txs) == 0
Exemplo n.º 14
0
    def test_customer_paid(self):
        contract = Escrow()

        tx = Tx(sender=CUSTOMER, value=PRICE_ETHER)
        block = Block(timestamp=TS)
        self.run(tx, contract, block)

        assert contract.storage[I_STATUS] == S_CUSTOMER_PAID
        assert contract.storage[I_CUSTOMER_ADDRESS] == CUSTOMER
        assert contract.storage[I_CUSTOMER_PAID_AMOUNT] == PRICE_ETHER
        assert contract.storage[I_CUSTOMER_PAID_TS] == TS
Exemplo n.º 15
0
    def test_divorce_approval(self):
        tx = Tx(sender=PARTNER_2, value=100, data=[TX_DIVORCE])

        block = Block()
        block.set_account_balance('myaddress', 1000)
        self.run(tx, self.contract, block)

        assert self.contract.storage[I_STATE] == S_DIVORCED
        assert len(self.contract.txs) == 2
        assert self.contract.txs == [(PARTNER_1, 500, 0, 0), (PARTNER_2, 500, 0, 0)]
        assert self.stopped == "Divorced"
Exemplo n.º 16
0
 def test_bob_to_charlie_valid(self):
     tx = Tx(sender='bob', value=100, data=['charlie', 1000])
     self.run(tx, self.contract)
     assert self.contract.storage['bob'] == 0
     assert self.contract.storage['charlie'] == 1000
Exemplo n.º 17
0
 def test_alice_to_invalid(self):
     tx = Tx(sender='alice', value=100, data=[123, 1000])
     self.run(tx, self.contract)
     assert self.stopped == 'tx.data[0] out of bounds: 123'
     assert self.contract.storage['bob'] == 1000
     assert self.contract.storage['charlie'] == 0
Exemplo n.º 18
0
 def test_bob_to_charlie_invalid(self):
     tx = Tx(sender='bob', value=100, data=['charlie', 1001])
     self.run(tx, self.contract)
     assert self.stopped == 'Insufficient funds, bob has 1000 needs 1001'
     assert self.contract.storage['bob'] == 1000
     assert self.contract.storage['charlie'] == 0
Exemplo n.º 19
0
 def test_creation(self):
     tx = Tx(sender='alice', value=100)
     self.run(tx, self.contract)
     assert self.contract.storage['alice'] == 10**18
Exemplo n.º 20
0
 def test_alice_to_bob(self):
     tx = Tx(sender='alice', value=100, data=['bob', 1000])
     self.run(tx, self.contract)
     assert self.contract.storage['alice'] == 10**18 - 1000
     assert self.contract.storage['bob'] == 1000
Exemplo n.º 21
0
    def test_insufficient_fee(self):

        tx = Tx(sender=PARTNER_1, value=10)
        self.run(tx, self.contract)

        assert self.stopped == "Insufficient fee"
Exemplo n.º 22
0
 def test_insufficient_fee(self):
     tx = Tx(sender='alice', value=10)
     self.run(tx, self.contract)
     assert self.stopped == 'Insufficient fee'
Exemplo n.º 23
0
    def test_divorce_request(self):
        tx = Tx(sender=PARTNER_1, value=100, data=[TX_DIVORCE])
        self.run(tx, self.contract)

        assert self.contract.storage[I_DIVORCE_CREATOR] == PARTNER_1
        assert self.stopped == "Divorce requested"
Exemplo n.º 24
0
 def test_invalid_sender(self):
     tx = Tx(sender='bob')
     self.run(tx, self.contract)
     assert self.stopped == 'Sender is not feed owner'
Exemplo n.º 25
0
 def test_insufficient_value(self):
     tx = Tx(sender='alice', value=1000)
     self.run(tx, self.contract)
     assert self.stopped == 'Insufficient value'
     assert self.contract.storage[1000] == 0
Exemplo n.º 26
0
 def test_double_reservation(self):
     tx = Tx(sender='alice', value=200, data=['ethereum.bit', '127.0.0.1'])
     self.run(tx, self.contract)
     assert self.stopped == 'Key already reserved'
     assert self.contract.storage['ethereum.bit'] == '54.200.236.204'
Exemplo n.º 27
0
 def test_reservation(self):
     tx = Tx(sender='alice', value=200, data=['ethereum.bit', '54.200.236.204'])
     self.run(tx, self.contract)
     assert self.contract.storage['ethereum.bit'] == '54.200.236.204'
Exemplo n.º 28
0
 def test_valid_sender(self):
     tx = Tx(sender='alice', data=['Temperature', '53.2'])
     self.run(tx, self.contract)
     assert self.contract.storage['Temperature'] == '53.2'
Exemplo n.º 29
0
 def run_tx(self, value=0, sender="", data=[]):
     self.run(Tx(value=value, sender=sender, data=data),
              self.contract,
              self.block,
              method_name=inspect.stack()[1][3])