예제 #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 test_revoke_fail_wrong_signer(self):
        context = self.get_context()

        cert, key, key_export = PubKeyClient.create_certificate(
            context.pub_key_payload,
            org_name='different',
            signer=self.account_signer2)
        signature, cert_address, transaction_payload = self._pre_parse_payload_and_exec(
            context, cert, key, 'revoke')

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

        self.expect_get({cert_address: data})

        self.expect_invalid_transaction()
예제 #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()
예제 #4
0
    def test_revoke_success(self):
        context = self.get_context()

        cert, key, key_export = PubKeyClient.create_certificate(
            context.pub_key_payload,
            org_name='different',
            signer=self.account_signer2)
        transaction_signature, cert_address, transaction_payload = self._pre_parse_payload_and_exec(
            context, cert, key, 'revoke')

        data = PubKeyStorage()
        data.owner = context.client.get_signer().get_public_key().as_hex()
        data.payload.CopyFrom(transaction_payload)
        data.revoked = False

        self.expect_get({cert_address: data})

        data.revoked = True

        self.expect_set(transaction_signature, PubKeyMethod.REVOKE,
                        {cert_address: data})

        self.expect_ok()