def setUp(self): self.fatd = FATd() config = configparser.ConfigParser() config.read("../test_data/pegnet_config.ini") self.private_key = FactoidPrivateKey(key_string=config['data']['fct_private_key_1']) self.address = self.private_key.get_factoid_address() self.output_addresses = [ FactoidAddress(address_string=config['data']['output_address1']), FactoidAddress(address_string=config['data']['output_address2']), ]
def setup(cls): # These are throwaway private keys. cls.chain_id = "1e5037be95e108c34220d724763444098528e88d08ec30bc15204c98525c3f7d" cls.coinbase_address = "FA1zT4aFpEvcnPqPCigB3fvGu4Q4mTXY22iiuV69DqE1pNhdF2MC" cls.address1 = FactoidAddress(address_string="FA2gCmih3PaSYRVMt1jLkdG4Xpo2koebUpQ6FpRRnqw5FfTSN2vW") cls._private_fct_key1 = FactoidPrivateKey(key_string="Fs1fR4dMNdyp1a6qYfkLFPJZUyRg1uFW3b6NEK9VaRELD4qALstq") cls.address2 = FactoidAddress(address_string="FA3j68XNwKwvHXV2TKndxPpyCK3KrWTDyyfxzi8LwuM5XRuEmhy6") cls._private_fct_key2 = FactoidPrivateKey(key_string="Fs2jSmXgaysrqiADPmAvvb71NfAa9MqvXvRemozTE8LRc64hLqtf") cls.address3 = FactoidAddress(address_string="FA3rsxWx4WSN5Egj2ZxPoju1mzwfjBivTDMcEvoC1JSsqkddZPCB") cls._private_fct_key3 = FactoidPrivateKey(key_string="Fs2EDKpBA4QQgarTUhJnZeZ4HeymT5U6RSWGsoTtkt1ezGCmNdSo") cls._issuer_signer = ServerIDPrivateKey(key_string="sk12hDMpMzcm9XEdvcy77XwxYU57hpLoCMY1kHtKnyjdGWUpsAvXD")
def setup(cls): # These are throwaway private keys. cls.chain_id = "145d5207a1ca2978e2a1cb43c97d538cd516d65cd5d14579549664bfecd80296" cls.address1 = FactoidAddress( address_string= "FA2gCmih3PaSYRVMt1jLkdG4Xpo2koebUpQ6FpRRnqw5FfTSN2vW") cls._private_fct_key1 = FactoidPrivateKey( key_string="Fs1fR4dMNdyp1a6qYfkLFPJZUyRg1uFW3b6NEK9VaRELD4qALstq") cls.address2 = FactoidAddress( address_string= "FA3j68XNwKwvHXV2TKndxPpyCK3KrWTDyyfxzi8LwuM5XRuEmhy6") cls._private_fct_key2 = FactoidPrivateKey( key_string="Fs2jSmXgaysrqiADPmAvvb71NfAa9MqvXvRemozTE8LRc64hLqtf") cls.address3 = FactoidAddress( address_string= "FA3rsxWx4WSN5Egj2ZxPoju1mzwfjBivTDMcEvoC1JSsqkddZPCB") cls._private_fct_key3 = FactoidPrivateKey( key_string="Fs2EDKpBA4QQgarTUhJnZeZ4HeymT5U6RSWGsoTtkt1ezGCmNdSo") cls._issue_signer = ServerIDPrivateKey( key_string="sk12hDMpMzcm9XEdvcy77XwxYU57hpLoCMY1kHtKnyjdGWUpsAvXD")
class PegnetTransactionTests(unittest.TestCase): def setUp(self): self.fatd = FATd() config = configparser.ConfigParser() config.read("../test_data/pegnet_config.ini") self.private_key = FactoidPrivateKey(key_string=config['data']['fct_private_key_1']) self.address = self.private_key.get_factoid_address() self.output_addresses = [ FactoidAddress(address_string=config['data']['output_address1']), FactoidAddress(address_string=config['data']['output_address2']), ] def test_pegnet_default_balance(self): balances = self.fatd.get_pegnet_balances(self.address) print(balances) def test_send_transaction(self): tx = fat2.Transaction() tx.set_input(self.address, "PEG", 1000) tx.add_transfer(self.output_addresses[0], 500) tx.add_transfer(self.output_addresses[1], 500) tx_batch = fat2.TransactionBatch() tx_batch.add_transaction(tx) tx_batch.add_signer(self.private_key) ext_ids, content = tx_batch.sign() print(content.decode()) print(self.fatd.send_transaction(consts.TRANSACTIONS_CHAIN_ID, ext_ids, content)) def test_get_sync_status(self): sync_status = self.fatd.get_sync_status() print(sync_status) while(sync_status['syncheight'] != sync_status['factomheight']): print("pegnet not yet synched") time.sleep(5) def test_pegnet_issuance(self): print(self.fatd.get_pegnet_issuance()) def test_currency_is_not_zero(self): sync_status = self.fatd.get_sync_status() print(sync_status['syncheight']) for i in range(sync_status['syncheight'],0,-1): rates = self.fatd.get_pegnet_rates(i) if rates != None: for key in rates.keys(): if rates[key] == 0: print(f"rate should not be 0 but it is for {key} at the height : {i}")
def test_key_string_validity_checkers(self): # Valid pair. All zeros private key private = 'Fs1KWJrpLdfucvmYwN2nWrwepLn8ercpMbzXshd1g8zyhKXLVLWj' public = 'FA1zT4aFpEvcnPqPCigB3fvGu4Q4mTXY22iiuV69DqE1pNhdF2MC' assert FactoidPrivateKey.is_valid(private) assert FactoidAddress.is_valid(public) # Bad prefix private = 'Xs1KWJrpLdfucvmYwN2nWrwepLn8ercpMbzXshd1g8zyhKXLVLWj' public = 'XA1zT4aFpEvcnPqPCigB3fvGu4Q4mTXY22iiuV69DqE1pNhdF2MC' assert not FactoidAddress.is_valid(private) assert not FactoidAddress.is_valid(public) # Bad body private = 'Fs1KWJrpLdfucvmYwN2nWXXXpLn8ercpMbzXshd1g8zyhKXLVLWj' public = 'FA1zT4aFpEvcnPqPCigB3fXXX4Q4mTXY22iiuV69DqE1pNhdF2MC' assert not FactoidPrivateKey.is_valid(private) assert not FactoidAddress.is_valid(public) # Bad checksums private = 'Fs1KWJrpLdfucvmYwN2nWrwepLn8ercpMbzXshd1g8zyhKXLVLWX' public = 'FA1zT4aFpEvcnPqPCigB3fvGu4Q4mTXY22iiuV69DqE1pNhdF2MX' assert not FactoidPrivateKey.is_valid(private) assert not FactoidAddress.is_valid(public)
def test_key_imports_and_exports(self): private_bytes = b'\0' * 32 private_string = 'Fs1KWJrpLdfucvmYwN2nWrwepLn8ercpMbzXshd1g8zyhKXLVLWj' public_string = 'FA1zT4aFpEvcnPqPCigB3fvGu4Q4mTXY22iiuV69DqE1pNhdF2MC' private_from_bytes = FactoidPrivateKey(seed_bytes=private_bytes) private_from_string = FactoidPrivateKey(key_string=private_string) assert private_from_bytes.key_bytes == private_bytes assert private_from_string.key_bytes == private_bytes assert private_from_bytes.to_string() == private_string assert private_from_string.to_string() == private_string public_from_private = private_from_string.get_factoid_address() public_from_string = FactoidAddress(address_string=public_string) assert public_from_private.key_bytes is not None assert public_from_string.key_bytes is None assert public_from_private.rcd_hash == public_from_string.rcd_hash assert public_from_private.to_string() == public_string assert public_from_string.to_string() == public_string
def validate_signer( self, signer: Union[FactoidPrivateKey, ServerIDPrivateKey, str] ) -> Union[FactoidPrivateKey, ServerIDPrivateKey]: """ Validate a privatekey and convert it to a str. :param signer: a signing key as a FactoidPrivateKey, ServerIDPrivateKey or a str """ if self.is_mint(): if isinstance(signer, str): signer = ServerIDPrivateKey(signer) elif isinstance(signer, ServerIDPrivateKey): pass else: raise InvalidParam("Invalid signer key for transaction type!") else: if isinstance(signer, str): signer = FactoidPrivateKey(signer) elif isinstance(signer, FactoidPrivateKey): pass else: raise InvalidParam("Invalid signer key for transaction type!") return signer
import fat_py.fat2 as fat2 import fat_py.fat2.consts as consts from factom_keys.fct import FactoidPrivateKey, FactoidAddress from fat_py import FATd fatd = FATd() private_key = FactoidPrivateKey(key_string="Fs3E9gV6DXsYzf7Fqx1fVBQPQXV695eP3k5XbmHEZVRLkMdD9qCK") address = private_key.get_factoid_address() output_addresses = [ FactoidAddress(address_string="FA2ybgFNYQiZFgTjkwQwp74uGsEUHJc6hGEh4YA3ai7FcssemapP"), FactoidAddress(address_string="FA34L6m7rQypr5PVmKGJ1Y4FQ6gDWbVaA49kFTGn1sSVZj6D8pFJ"), ] print(fatd.get_pegnet_balances(address)) tx = fat2.Transaction() tx.set_input(address, "PEG", 1000) tx.add_transfer(output_addresses[0], 500) tx.add_transfer(output_addresses[1], 500) tx_batch = fat2.TransactionBatch() tx_batch.add_transaction(tx) tx_batch.add_signer(private_key) ext_ids, content = tx_batch.sign() print(content.decode()) print(fatd.send_transaction(consts.TRANSACTIONS_CHAIN_ID, ext_ids, content))