Example #1
0
def close(**data):
    data = data['payload']
    swap_info = client.swap_get(data['swap_id'])
    LOGGER.info('swap_info: {}'.format(swap_info))
    payload = get_swap_close_payload(**data)
    return client.swap_close(payload,
                             receiver_address=swap_info.receiver_address)
Example #2
0
    def test_swap_close_success(self):
        context = self.get_context()
        close_data = {
            "swap_id": context.swap_id,
            "secret_key": context.secret_key
        }

        signature = context.client.swap_close(
            get_swap_close_payload(**close_data),
            context.swap_info.receiver_address)

        self.expect_get({context.swap_address: context.swap_info})
        updated_state = self.transfer(ZERO_ADDRESS, context.AMOUNT,
                                      self.account_address2, 0, context.AMOUNT)

        swap_info = context.swap_info

        swap_info.secret_key = context.secret_key
        context.swap_info.state = AtomicSwapInfo.CLOSED

        self.expect_set(signature, AtomicSwapMethod.CLOSE, {
            **{
                context.swap_address: swap_info
            },
            **updated_state
        })

        self.expect_ok()
Example #3
0
    def test_swap_close_fail_wrong_secret_key(self):
        context = self.get_context()
        close_data = {
            "swap_id": context.swap_id,
            "secret_key": context.secret_key[:-1] + '1'
        }

        context.client.swap_close(get_swap_close_payload(**close_data), context.swap_info.receiver_address)

        self.expect_get({context.swap_address: context.swap_info})

        self.expect_invalid_transaction()
Example #4
0
    def test_swap_close_fail_not_approved(self):
        context = self.get_context()
        close_data = {
            "swap_id": context.swap_id,
            "secret_key": context.secret_key,
        }
        context.swap_info.is_initiator = True

        context.client.swap_close(get_swap_close_payload(**close_data), context.swap_info.receiver_address)

        self.expect_get({context.swap_address: context.swap_info})

        self.expect_invalid_transaction()
Example #5
0
    def test_swap_close_success(self):
        context = self.get_context()
        close_data = {
            "swap_id": context.swap_id,
            "secret_key": context.secret_key
        }

        context.client.swap_close(get_swap_close_payload(**close_data),
                                  context.swap_info.receiver_address)

        self.expect_get({context.swap_address: context.swap_info})
        updated_state = self.transfer(ZERO_ADDRESS, context.AMOUNT,
                                      self.account_address2, 0, context.AMOUNT)

        swap_info = context.swap_info
        swap_info.is_closed = True

        self.expect_set({**{context.swap_address: swap_info}, **updated_state})

        self.expect_ok()