Esempio n. 1
0
def test_authenticate_xfer_invalid_signature_format(node, user2_token_wallet,
                                                    user2_address,
                                                    user1_address):
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    inputs = [[user2_token_wallet, user2_address, 1]]
    outputs = [[user1_address, 10], [user2_address, 10]]
    request = xfer_request(inputs, outputs)
    req_data = request.as_dict
    req_data[OPERATION]["signatures"][0] = 'INVALID_SIGNATURE'
    with pytest.raises(InvalidSignatureFormat):
        token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 2
0
def test_authenticate_xfer_invalid_signature_format(node, user2_token_wallet,
                                                    user2_address,
                                                    user1_address):
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    inputs = [[user2_token_wallet, user2_address, 1]]
    outputs = [[user1_address, 10], [user2_address, 10]]
    request = xfer_request(inputs, outputs)
    req_data = request.as_dict
    req_data[OPERATION]["signatures"][0] = 'INVALID_SIGNATURE'
    with pytest.raises(InvalidSignatureFormat):
        token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 3
0
def test_authenticate_xfer_insufficient_correct_signatures(
        node, user2_token_wallet, user2_address, user1_address, SF_address,
        SF_token_wallet):
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    inputs = [[user2_token_wallet, user2_address, 1],
              [SF_token_wallet, SF_address, 2]]
    outputs = [[user1_address, 10], [user2_address, 10]]
    request = xfer_request(inputs, outputs)
    req_data = request.as_dict

    # creating invalid signature in index 0
    req_data[OPERATION]["signatures"][0] = req_data[OPERATION]["signatures"][1]
    with pytest.raises(InsufficientCorrectSignatures):
        token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 4
0
def test_authenticate_xfer_insufficient_correct_signatures(
        node, user2_token_wallet, user2_address, user1_address, SF_address,
        SF_token_wallet):
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    inputs = [[user2_token_wallet, user2_address, 1],
              [SF_token_wallet, SF_address, 2]]
    outputs = [[user1_address, 10], [user2_address, 10]]
    request = xfer_request(inputs, outputs)
    req_data = request.as_dict

    # creating invalid signature in index 0
    req_data[OPERATION]["signatures"][0] = req_data[OPERATION]["signatures"][1]
    with pytest.raises(InsufficientCorrectSignatures):
        token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 5
0
def test_authenticate_xfer_with_taa(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    extra = helpers.request.add_transaction_author_agreement_to_extra(
        None, "text", "mechanism", "version")
    request = helpers.request.transfer(inputs, outputs, extra)
    req_data = request.as_dict
    token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 6
0
def test_authenticate_xfer_with_extra_not_signed(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    request = helpers.request.transfer(inputs, outputs)
    req_data = request.as_dict
    token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
    req_data[OPERATION][EXTRA] = {"aaa": "bbb"}
    with pytest.raises(InsufficientCorrectSignatures):
        token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 7
0
def test_authenticate_xfer_with_extra(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    request = helpers.request.transfer(inputs,
                                       outputs,
                                       extra=json.dumps({"aaa": "bbb"}))
    req_data = request.as_dict

    token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 8
0
def test_authenticate_xfer_with_taa(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    extra = helpers.request.add_transaction_author_agreement_to_extra(
        None, "text", "mechanism", "version")
    request = helpers.request.transfer(inputs, outputs, extra)
    req_data = request.as_dict
    token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 9
0
def test_authenticate_xfer_with_extra_not_signed(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    request = helpers.request.transfer(inputs, outputs)
    req_data = request.as_dict
    token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
    req_data[OPERATION][EXTRA] = {"aaa": "bbb"}
    with pytest.raises(InsufficientCorrectSignatures):
        token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 10
0
def test_authenticate_xfer_with_extra(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    request = helpers.request.transfer(inputs,
                                       outputs,
                                       extra=json.dumps({"aaa": "bbb"}))
    req_data = request.as_dict

    token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 11
0
def test_authenticate_xfer_with_taa_not_signed(helpers, node, addresses,
                                               looper):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    request = helpers.request.transfer(inputs, outputs)
    request_future = append_txn_author_agreement_acceptance_to_request(
        json.dumps(request.as_dict), "text", "version", None, "mechanism",
        round(time.time()))
    request = looper.loop.run_until_complete(request_future)
    req_data = json.loads(request)
    with pytest.raises(InsufficientCorrectSignatures):
        token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 12
0
def test_authenticate_xfer_with_taa_not_signed(helpers, node, addresses,
                                               looper):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    request = helpers.request.transfer(inputs, outputs)
    request_future = append_txn_author_agreement_acceptance_to_request(
        json.dumps(request.as_dict), "text", "version", None, "mechanism",
        int(time.time()) // SEC_PER_DAY * SEC_PER_DAY)
    request = looper.loop.run_until_complete(request_future)
    req_data = json.loads(request)
    with pytest.raises(InsufficientCorrectSignatures):
        token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
Esempio n. 13
0
def test_authenticate_xfer_success(node, user2_token_wallet, user2_address,
                                   user1_address):
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    inputs = [[user2_token_wallet, user2_address, 1]]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": user2_address,
        "amount": 10
    }]
    request = xfer_request(inputs, outputs)
    req_data = request.as_dict
    correct_sigs = token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
    assert len(correct_sigs) == 1
Esempio n. 14
0
def test_authenticate_xfer_success(node, user2_token_wallet, user2_address,
                                   user1_address):
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    inputs = [[user2_token_wallet, user2_address, 1]]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": user2_address,
        "amount": 10
    }]
    request = xfer_request(inputs, outputs)
    req_data = request.as_dict
    correct_sigs = token_authnr.authenticate_xfer(req_data, AddressSigVerifier)
    assert len(correct_sigs) == 1
Esempio n. 15
0
def test_authenticate_calls_authenticate_xfer(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    request = helpers.request.transfer(inputs, outputs)
    req_data = request.as_dict

    token_authnr.authenticate_xfer = mock.Mock()
    token_authnr.authenticate(req_data)
    token_authnr.authenticate_xfer.assert_called()
Esempio n. 16
0
def test_authenticate_calls_authenticate_xfer(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    inputs = [{"source": utxo_from_addr_and_seq_no(SF_address, 1)}]
    outputs = [{
        "address": user1_address,
        "amount": 10
    }, {
        "address": SF_address,
        "amount": 10
    }]
    request = helpers.request.transfer(inputs, outputs)
    req_data = request.as_dict

    token_authnr.authenticate_xfer = mock.Mock()
    token_authnr.authenticate(req_data)
    token_authnr.authenticate_xfer.assert_called()