Exemple #1
0
def test_find_program_address():
    """Test create associated_token_address."""
    program_id = PublicKey("BPFLoader1111111111111111111111111111111111")
    program_address, nonce = PublicKey.find_program_address([bytes()],
                                                            program_id)
    assert program_address == PublicKey.create_program_address(
        [bytes(), helpers.to_uint8_bytes(nonce)], program_id)
Exemple #2
0
 def settle_funds(  # pylint: disable=too-many-arguments
     self,
     owner: Account,
     open_orders: OpenOrdersAccount,
     base_wallet: PublicKey,
     quote_wallet: PublicKey,  # TODO: add referrer_quote_wallet.
     opts: TxOpts = TxOpts(),
 ) -> RPCResponse:
     # TODO: Handle wrapped sol accounts
     if open_orders.owner != owner.public_key():
         raise Exception("Invalid open orders account")
     vault_signer = PublicKey.create_program_address(
         [
             bytes(self.state.public_key()),
             self.state.vault_signer_nonce().to_bytes(8, byteorder="little")
         ],
         self.state.program_id(),
     )
     transaction = Transaction()
     transaction.add(
         self.make_settle_funds_instruction(open_orders, base_wallet,
                                            quote_wallet, vault_signer))
     return self._conn.send_transaction(transaction, owner, opts=opts)
Exemple #3
0
def test_create_program_address():
    """Test create program address."""
    program_id = PublicKey("BPFLoader1111111111111111111111111111111111")
    program_address = PublicKey.create_program_address(
        [bytes(), bytes([1])], program_id)
    assert program_address == PublicKey(
        "3gF2KMe9KiC6FNVBmfg9i267aMPvK37FewCip4eGBFcT")

    program_address = PublicKey.create_program_address([bytes("☉", "utf-8")],
                                                       program_id)
    assert program_address == PublicKey(
        "7ytmC1nT1xY4RfxCV2ZgyA7UakC93do5ZdyhdF3EtPj7")

    seeds = [bytes("Talking", "utf8"), bytes("Squirrels", "utf8")]
    program_address = PublicKey.create_program_address(seeds, program_id)
    assert program_address == PublicKey(
        "HwRVBufQ4haG5XSgpspwKtNd3PC9GM9m1196uJW36vds")

    program_address = PublicKey.create_program_address(
        [bytes(PublicKey("SeedPubey1111111111111111111111111111111111"))],
        program_id)
    assert program_address == PublicKey(
        "GUs5qLUfsEHkcMB9T38vjr18ypEhRuNWiePW2LoK4E3K")

    program_address_2 = PublicKey.create_program_address(
        [bytes("Talking", "utf8")], program_id)
    assert program_address_2 != program_address

    # https://github.com/solana-labs/solana/issues/11950
    seeds = [
        bytes(PublicKey("H4snTKK9adiU15gP22ErfZYtro3aqR9BTMXiH3AwiUTQ")),
        bytes.fromhex("0200000000000000")
    ]
    program_address = PublicKey.create_program_address(
        seeds, PublicKey("4ckmDgGdxQoPDLUkDT3vHgSAkzA3QRdNq5ywwY4sUSJn"))
    assert program_address == PublicKey(
        "12rqwuEgBYiGhBrDJStCiqEtzQpTTiZbh7teNVLuYcFA")