示例#1
0
    def test_store_success(self):
        context = self.get_context()

        cert, key, _ = PubKeyClient.create_certificate(
            context.pub_key_payload, signer=context.client.get_signer())

        transaction_signature, cert_address, transaction_payload = self._pre_parse_payload_and_exec(
            context, cert, key)
        crt_export, crt_bin, crt_sig, rem_sig, pub_key, \
            valid_from, valid_to = PubKeyClient.get_crt_export_bin_sig_rem_sig(cert, key, context.client)

        account = AccountClient.get_account_model(PUB_KEY_STORE_PRICE)

        storage_account = AccountClient.get_account_model(0)
        storage_signer = self.get_new_signer()
        storage_pub_key = storage_signer.get_public_key().as_hex()
        storage_address = AccountHandler().make_address_from_data(
            storage_pub_key)

        data = PubKeyStorage()
        data.owner = self.account_signer1.get_public_key().as_hex()
        data.payload.CopyFrom(transaction_payload)
        data.revoked = False

        self.expect_get({cert_address: None, self.account_address1: account})
        self.expect_get({_make_settings_key('remme.economy_enabled'): None})
        self.expect_get({
            _make_settings_key(SETTINGS_STORAGE_PUB_KEY):
            get_setting_from_key_value(SETTINGS_STORAGE_PUB_KEY,
                                       storage_pub_key)
        })
        self.expect_get({
            self.account_address1: account,
            storage_address: storage_account
        })

        context.client.store_pub_key(pub_key, rem_sig, crt_sig, valid_from,
                                     valid_to)

        account.balance -= PUB_KEY_STORE_PRICE
        account.pub_keys.append(cert_address)
        storage_account.balance += PUB_KEY_STORE_PRICE

        self.expect_set(
            transaction_signature, PubKeyMethod.STORE, {
                self.account_address1: account,
                cert_address: data,
                storage_address: storage_account
            })

        self.expect_ok()
示例#2
0
    def _pre_parse_payload_and_exec(self, context, cert, key, type='store'):
        crt_export, crt_bin, crt_sig, rem_sig, pub_key, \
            valid_from, valid_to = PubKeyClient.get_crt_export_bin_sig_rem_sig(cert, key, context.client)

        transaction_payload = context.client.get_new_pub_key_payload(
            pub_key, rem_sig, crt_sig, valid_from, valid_to)
        cert_address = PubKeyHandler().make_address_from_data(pub_key)

        transaction_signature = None
        if type == 'store':
            transaction_signature = context.client.store_pub_key(
                pub_key, rem_sig, crt_sig, valid_from, valid_to)
        elif type == 'revoke':
            transaction_signature = context.client.revoke_pub_key(cert_address)
        else:
            raise AssertionError('Type for pre parse not found')

        return transaction_signature, cert_address, transaction_payload
示例#3
0
    def test_store_fail_invalid_validity_date(self):
        context = self.get_context()

        cert, key, _ = PubKeyClient.create_certificate(
            context.pub_key_payload, signer=context.client.get_signer())
        crt_export, crt_bin, crt_sig, rem_sig, pub_key, \
            valid_from, valid_to = PubKeyClient.get_crt_export_bin_sig_rem_sig(cert, key, context.client)

        cert_address = PubKeyHandler().make_address_from_data(pub_key)

        valid_from = int(valid_from - PUB_KEY_MAX_VALIDITY.total_seconds())
        valid_to = int(valid_to + PUB_KEY_MAX_VALIDITY.total_seconds())

        context.client.store_pub_key(pub_key, rem_sig, crt_sig, valid_from,
                                     valid_to)

        self.expect_get({cert_address: None, self.account_address1: None})

        self.expect_invalid_transaction()