Esempio n. 1
0
def test_getVerkey_success(node):
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    ver_key = token_authnr.getVerkey(VALID_IDENTIFIER, Request())
    assert len(ver_key) == 23
    assert ver_key[0] == '~'
Esempio n. 2
0
def test_getVerkey_invalid_identifier(node):
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    identifier_invalid = 'INVALID_IDENTIFIER'
    with pytest.raises(UnknownIdentifier):
        token_authnr.getVerkey(identifier_invalid, Request())
Esempio n. 3
0
def test_getVerkey_pay_address_success(node):
    token_authnr = TokenAuthNr(ACCEPTABLE_WRITE_TYPES, ACCEPTABLE_QUERY_TYPES,
                               ACCEPTABLE_ACTION_TYPES,
                               node[0].db_manager.idr_cache)
    # TODO change these to indicate they are addresses
    identifier_43 = 'sjw1ceG7wtym3VcnyaYtf1xo37gCUQHDR5VWcKWNPLRZ1X8eC'
    ver_key = token_authnr.getVerkey(identifier_43, Request())
    assert ver_key == '8kjqqnF3m6agp9auU7k4TWAhuGygFAgPzbNH3shp4HFL'
Esempio n. 4
0
def test_serializeForSig_MINT_PUBLIC_path(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    outputs = [[SF_address, 30], [user1_address, 30]]
    request = helpers.request.mint(outputs)
    msg = request.as_dict
    serialize_for_sig_called = token_authnr.serializeForSig(
        msg, VALID_IDENTIFIER, None)
    token_authnr.serializeForSig.assert_called()
Esempio n. 5
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. 6
0
def test_serializeForSig_MINT_PUBLIC_path(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)
    outputs = [[SF_address, 30], [user1_address, 30]]
    request = helpers.request.mint(outputs)
    msg = request.as_dict
    serialize_for_sig_called = token_authnr.serializeForSig(
        msg, VALID_IDENTIFIER, None)
    token_authnr.serializeForSig.assert_called()
Esempio n. 7
0
def test_serializeForSig_XFER_PUBLIC_path(node, user2_token_wallet,
                                          user2_address, SF_token_wallet,
                                          SF_address, user1_address):
    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], [user1_address, 10]]
    request = xfer_request(inputs, outputs)
    msg = request.as_dict
    serialize_for_sig_called = token_authnr.serializeForSig(
        msg, VALID_IDENTIFIER, None)
    assert serialize_for_sig_called == True
Esempio n. 8
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. 9
0
def test_authenticate_success_3_sigs(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    outputs = [{
        "address": SF_address,
        "amount": 30
    }, {
        "address": user1_address,
        "amount": 30
    }]
    request = helpers.request.mint(outputs)
    req_data = request.as_dict
    correct_sigs = token_authnr.authenticate(req_data)
    assert len(correct_sigs) == 3
Esempio n. 10
0
def test_serializeForSig_XFER_PUBLIC_path(node, user2_token_wallet,
                                          user2_address, SF_token_wallet,
                                          SF_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],
              [SF_token_wallet, SF_address, 2]]
    outputs = [[user1_address, 10], [user1_address, 10]]
    request = xfer_request(inputs, outputs)
    msg = request.as_dict
    serialize_for_sig_called = token_authnr.serializeForSig(
        msg, VALID_IDENTIFIER, None)
    assert serialize_for_sig_called == True
Esempio n. 11
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. 12
0
def test_get_xfer_ser_data_success(node, user2_token_wallet, user2_address,
                                   SF_token_wallet, SF_address, user1_address):
    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], [user1_address, 10]]
    request = xfer_request(inputs, outputs)
    msg = request.as_dict
    # This test is marked as skip because the next line does not compile.  _get_xfer_ser_data was removed from
    # TokenAuthNr or its base class without explanation or update to this test.  See TOK-317
    ser_data = token_authnr._get_xfer_ser_data(msg, VALID_IDENTIFIER)
    assert ser_data[OPERATION][INPUTS] == []
    assert ser_data[OPERATION][OUTPUTS] == msg[OPERATION][OUTPUTS]
    assert ser_data[OPERATION][EXTRA] == msg[OPERATION][EXTRA]
    assert ser_data[f.REQ_ID.nm] == msg[f.REQ_ID.nm]
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_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. 15
0
def integrate_plugin_in_node(node):
    node.config = get_config(node.config)

    token_authnr = TokenAuthNr(node.states[DOMAIN_LEDGER_ID])
    hash_store = get_token_hash_store(node.dataLocation)
    ledger = get_token_ledger(node.dataLocation,
                              node.config.tokenTransactionsFile, hash_store,
                              node.config)
    state = get_token_state(node.dataLocation, node.config.tokenStateDbName,
                            node.config)
    utxo_cache = get_utxo_cache(node.dataLocation, node.config.utxoCacheDbName,
                                node.config)

    if TOKEN_LEDGER_ID not in node.ledger_ids:
        node.ledger_ids.append(TOKEN_LEDGER_ID)

    node.ledgerManager.addLedger(
        TOKEN_LEDGER_ID,
        ledger,
        postTxnAddedToLedgerClbk=node.postTxnFromCatchupAddedToLedger)
    node.on_new_ledger_added(TOKEN_LEDGER_ID)
    node.register_state(TOKEN_LEDGER_ID, state)
    node.clientAuthNr.register_authenticator(token_authnr)

    token_req_handler = TokenReqHandler(ledger, state, utxo_cache,
                                        node.states[DOMAIN_LEDGER_ID],
                                        node.bls_bft.bls_store)
    node.register_req_handler(token_req_handler, TOKEN_LEDGER_ID)

    return node
Esempio n. 16
0
def test_authenticate_success_3_sigs(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)
    outputs = [{
        "address": SF_address,
        "amount": 30
    }, {
        "address": user1_address,
        "amount": 30
    }]
    request = helpers.request.mint(outputs)
    req_data = request.as_dict
    correct_sigs = token_authnr.authenticate(req_data)
    assert len(correct_sigs) == 3
Esempio n. 17
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. 18
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. 19
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. 20
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. 21
0
def test_authenticate_insufficient_valid_signatures_data(
        helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    outputs = [{
        "address": SF_address,
        "amount": 30
    }, {
        "address": user1_address,
        "amount": 30
    }]
    request = helpers.request.mint(outputs)
    req_data = request.as_dict
    req_data[f.SIGS.nm]['E7QRhdcnhAwA6E46k9EtZo'] = \
        '2EBZxZ3E2r2ZjCCBwgD6ipnHbskZb4Y4Yqm6haYEsr7hdM1m36yqLFrmNSB7JPqjAsMx6qjw6dWV5sRou1DgiKrM'
    with pytest.raises(InsufficientCorrectSignatures):
        token_authnr.authenticate(req_data)
Esempio n. 22
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. 23
0
    def verify_signature(self, msg):
        try:
            fees = getattr(msg, f.FEES.nm)
        except (AttributeError, KeyError):
            return

        digest = msg.digest
        return TokenAuthNr.verify_signtures_on_payments(
            fees[0], fees[1], fees[2], AddressSigVerifier, digest)
Esempio n. 24
0
def test_authenticate_insufficient_valid_signatures_data(
        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)
    outputs = [{
        "address": SF_address,
        "amount": 30
    }, {
        "address": user1_address,
        "amount": 30
    }]
    request = helpers.request.mint(outputs)
    req_data = request.as_dict
    req_data[f.SIGS.nm]['E7QRhdcnhAwA6E46k9EtZo'] = \
        '2EBZxZ3E2r2ZjCCBwgD6ipnHbskZb4Y4Yqm6haYEsr7hdM1m36yqLFrmNSB7JPqjAsMx6qjw6dWV5sRou1DgiKrM'
    with pytest.raises(InsufficientCorrectSignatures):
        token_authnr.authenticate(req_data)
Esempio n. 25
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. 26
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()
Esempio n. 27
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. 28
0
def test_authenticate_invalid_signatures_format(helpers, node, addresses):
    [SF_address, user1_address] = addresses
    token_authnr = TokenAuthNr(node[0].states[DOMAIN_LEDGER_ID])
    outputs = [{
        "address": SF_address,
        "amount": 30
    }, {
        "address": user1_address,
        "amount": 30
    }]
    request = helpers.request.mint(outputs)
    req_data = request.as_dict
    req_data[f.SIGS.nm] = {
        'M9BJDuS24bqbJNvBRsoGg3': 'INVALID_SIG1',
        'B8fV7naUqLATYocqu7yZ8W': 'INVALID_SIG2',
        'E7QRhdcnhAwA6E46k9EtZo': 'INVALID_SIG3',
        'CA4bVFDU4GLbX8xZju811o': 'INVALID_SIG3'
    }
    with pytest.raises(InvalidSignatureFormat):
        token_authnr.authenticate(req_data)
Esempio n. 29
0
def test_authenticate_invalid_signatures_format(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)
    outputs = [{
        "address": SF_address,
        "amount": 30
    }, {
        "address": user1_address,
        "amount": 30
    }]
    request = helpers.request.mint(outputs)
    req_data = request.as_dict
    req_data[f.SIGS.nm] = {
        'M9BJDuS24bqbJNvBRsoGg3': 'INVALID_SIG1',
        'B8fV7naUqLATYocqu7yZ8W': 'INVALID_SIG2',
        'E7QRhdcnhAwA6E46k9EtZo': 'INVALID_SIG3',
        'CA4bVFDU4GLbX8xZju811o': 'INVALID_SIG3'
    }
    with pytest.raises(InvalidSignatureFormat):
        token_authnr.authenticate(req_data)
Esempio n. 30
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)